topic.tcl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. # tested versions, might run on earlier versions
  15. package require Tcl 8.6
  16. package require eggdrop 1.8.4
  17. namespace eval ::topic {
  18. # channel flag for enabling/disabling
  19. setudef flag topic
  20. # topic for !on command
  21. variable onTopic "Something is now online."
  22. # topic for !off command
  23. variable offTopic "Something is now offline."
  24. }
  25. proc ::topic::setOffTopic { nick host hand chan arg } {
  26. variable offTopic
  27. # check channel flag if enabled in this channel
  28. if {![channel get $chan topic]} {
  29. return 0
  30. }
  31. # set topic
  32. putserv "TOPIC $chan :$offTopic"
  33. return 1
  34. }
  35. proc ::topic::setOnTopic { nick host hand chan arg } {
  36. variable onTopic
  37. # check channel flag if enabled in this channel
  38. if {![channel get $chan topic]} {
  39. return 0
  40. }
  41. # set topic
  42. putserv "TOPIC $chan :$onTopic"
  43. return 1
  44. }
  45. proc ::topic::setTopic { nick host hand chan arg } {
  46. # check channel flag if enabled in this channel
  47. if {![channel get $chan topic]} {
  48. return 0
  49. }
  50. # only allow ops to change topic
  51. if {![isop $nick $chan]} {
  52. return 0
  53. }
  54. # set topic
  55. if {$arg == ""} {
  56. return 0
  57. }
  58. putserv "TOPIC $chan :$arg"
  59. return 1
  60. }
  61. namespace eval ::topic {
  62. # bind pub o|o !off ::topic::setOffTopic
  63. # bind pub o|o !on ::topic::setOnTopic
  64. bind pub - !off ::topic::setOffTopic
  65. bind pub - !on ::topic::setOnTopic
  66. bind pub - !topic ::topic::setTopic
  67. putlog "Loaded topic.tcl"
  68. }