4
0

topic.tcl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # topic.tcl
  2. #
  3. # This script sets the topic in a channel with the !topic command.
  4. # Additionally, it contains examples of setting a specific topic, e.g., if a
  5. # stream is online/offline with the !on and !off commands.
  6. #
  7. # Usage:
  8. # !topic topic set topic in channel to topic
  9. # !on set preconfigured "on" topic in channel
  10. # !off set preconfigured "off" topic in channel
  11. #
  12. # Enable for a channel with: .chanset #channel +topic
  13. # Disable for a channel with: .chanset #channel -topic
  14. #
  15. # See https://github.com/hwipl/eggdrop-scripts for the latest version and
  16. # additional information including the license (MIT).
  17. # tested versions, might run on earlier versions
  18. package require Tcl 8.6
  19. package require eggdrop 1.8.4
  20. namespace eval ::topic {
  21. # channel flag for enabling/disabling
  22. setudef flag topic
  23. # topic for !on command
  24. variable onTopic "Something is now online."
  25. # topic for !off command
  26. variable offTopic "Something is now offline."
  27. }
  28. proc ::topic::setOffTopic { nick host hand chan arg } {
  29. variable offTopic
  30. # check channel flag if enabled in this channel
  31. if {![channel get $chan topic]} {
  32. return 0
  33. }
  34. # set topic
  35. putserv "TOPIC $chan :$offTopic"
  36. return 1
  37. }
  38. proc ::topic::setOnTopic { nick host hand chan arg } {
  39. variable onTopic
  40. # check channel flag if enabled in this channel
  41. if {![channel get $chan topic]} {
  42. return 0
  43. }
  44. # set topic
  45. putserv "TOPIC $chan :$onTopic"
  46. return 1
  47. }
  48. proc ::topic::setTopic { nick host hand chan arg } {
  49. # check channel flag if enabled in this channel
  50. if {![channel get $chan topic]} {
  51. return 0
  52. }
  53. # only allow ops to change topic
  54. if {![isop $nick $chan]} {
  55. return 0
  56. }
  57. # set topic
  58. if {$arg == ""} {
  59. return 0
  60. }
  61. putserv "TOPIC $chan :$arg"
  62. return 1
  63. }
  64. namespace eval ::topic {
  65. # bind pub o|o !off ::topic::setOffTopic
  66. # bind pub o|o !on ::topic::setOnTopic
  67. bind pub - !off ::topic::setOffTopic
  68. bind pub - !on ::topic::setOnTopic
  69. bind pub - !topic ::topic::setTopic
  70. putlog "Loaded topic.tcl"
  71. }