chiark / gitweb /
new topicedit bot
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 11 Apr 2014 15:21:35 +0000 (16:21 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 11 Apr 2014 15:21:35 +0000 (16:21 +0100)
topicedit.tcl [new file with mode: 0755]

diff --git a/topicedit.tcl b/topicedit.tcl
new file mode 100755 (executable)
index 0000000..cc33c13
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/tclsh8.5
+# usage:
+#   cd ../ircbot
+#   ./topicedit.tcl SERVER PORT NICK IDENT FULLNAME CHANNEL TOPICINFO
+
+source irccore.tcl
+
+manyset $argv host port nick ident ownfullname channel topicinfo
+
+set done 0
+
+proc connected {} {
+    global channel
+    sendout JOIN $channel
+}
+proc new_event {} { }
+proc privmsg_unlogged {args} { return 1 }
+proc msg_332 {server code us channel topic args} {
+    global oldtopic nick
+    if {[string compare $nick $us]} return
+    set oldtopic $topic
+}
+proc msg_333 {server code us channel setter when} {
+    global nick done
+    # might happen as a result of us connecting, or as a result of
+    # our own TOPIC query
+    set now [clock seconds]
+    if {![string compare $nick $setter] && $when > $now - 3600} {
+       if {$done} {
+           puts "topic set."
+           exit 0
+       } else {
+           puts stderr "*** topic recently set by us, not setting again!"
+           exit 1
+       }
+    }
+}
+proc msg_366 {args} {
+    global oldtopic topicinfo channel done
+    set newtopic "$oldtopic | $topicinfo"
+    sendout TOPIC $channel $newtopic
+    sendout TOPIC $channel
+    set done 1
+}
+
+ensure_connecting
+vwait forever