Forráskód Böngészése

update topic.tcl

Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com>
hwipl 6 éve
szülő
commit
e5f4505b6b
1 módosított fájl, 72 hozzáadás és 10 törlés
  1. 72 10
      scripts/topic.tcl

+ 72 - 10
scripts/topic.tcl

@@ -1,19 +1,81 @@
 # topic.tcl
+#
+# This script sets the topic in a channel with the !topic command.
+# Additionally, it contains examples of setting a specific topic, e.g., if a
+# stream is online/offline with the !on and !off commands.
+#
+# Usage:
+#       !topic topic            set topic in channel to topic
+#       !on                     set preconfigured "on" topic in channel
+#       !off                    set preconfigured "off" topic in channel
+#
+# Enable for a channel with:    .chanset #channel +topic
+# Disable for a channel with:   .chanset #channel -topic
 
-proc set_topic_off { nick host hand chan arg } {
-	putserv "TOPIC $chan :Something is now offline"
+# tested versions, might run on earlier versions
+package require Tcl 8.6
+package require eggdrop 1.8.4
+
+namespace eval ::topic {
+	# channel flag for enabling/disabling
+	setudef flag topic
+
+	# topic for !on command
+	variable onTopic "Something is now online."
+
+	# topic for !off command
+	variable offTopic "Something is now offline."
 }
 
-proc set_topic_on { nick host hand chan arg } {
-	putserv "TOPIC $chan :Something is now online"
+proc ::topic::setOffTopic { nick host hand chan arg } {
+	variable offTopic
+
+	# check channel flag if enabled in this channel
+	if {![channel get $chan topic]} {
+		return 0
+	}
+
+	# set topic
+	putserv "TOPIC $chan :$offTopic"
+	return 1
 }
 
-proc set_topic { nick host hand chan arg } {
-	if [isop $chan $nick] {
-	putserv "TOPIC $chan :$arg"
+proc ::topic::setOnTopic { nick host hand chan arg } {
+	variable onTopic
+
+	# check channel flag if enabled in this channel
+	if {![channel get $chan topic]} {
+		return 0
+	}
+
+	# set topic
+	putserv "TOPIC $chan :$onTopic"
+	return 1
+}
+
+proc ::topic::setTopic { nick host hand chan arg } {
+	# check channel flag if enabled in this channel
+	if {![channel get $chan topic]} {
+		return 0
+	}
+
+	# only allow ops to change topic
+	if {![isop $nick $chan]} {
+		return 0
 	}
+
+	# set topic
+	if {$arg == ""} {
+		return 0
+	}
+	putserv "TOPIC $chan :$arg"
+	return 1
 }
 
-bind pub o|o !off set_topic_off
-bind pub o|o !on set_topic_on
-bind pub - !topic set_topic
+namespace eval ::topic {
+	# bind pub o|o !off ::topic::setOffTopic
+	# bind pub o|o !on ::topic::setOnTopic
+	bind pub - !off ::topic::setOffTopic
+	bind pub - !on ::topic::setOnTopic
+	bind pub - !topic ::topic::setTopic
+}