chiark / gitweb /
new topicedit bot
[ircbot.git] / topicedit.tcl
1 #!/usr/bin/tclsh8.5
2 # usage:
3 #   cd ../ircbot
4 #   ./topicedit.tcl SERVER PORT NICK IDENT FULLNAME CHANNEL TOPICINFO
5
6 source irccore.tcl
7
8 manyset $argv host port nick ident ownfullname channel topicinfo
9
10 set done 0
11
12 proc connected {} {
13     global channel
14     sendout JOIN $channel
15 }
16 proc new_event {} { }
17 proc privmsg_unlogged {args} { return 1 }
18 proc msg_332 {server code us channel topic args} {
19     global oldtopic nick
20     if {[string compare $nick $us]} return
21     set oldtopic $topic
22 }
23 proc msg_333 {server code us channel setter when} {
24     global nick done
25     # might happen as a result of us connecting, or as a result of
26     # our own TOPIC query
27     set now [clock seconds]
28     if {![string compare $nick $setter] && $when > $now - 3600} {
29         if {$done} {
30             puts "topic set."
31             exit 0
32         } else {
33             puts stderr "*** topic recently set by us, not setting again!"
34             exit 1
35         }
36     }
37 }
38 proc msg_366 {args} {
39     global oldtopic topicinfo channel done
40     set newtopic "$oldtopic | $topicinfo"
41     sendout TOPIC $channel $newtopic
42     sendout TOPIC $channel
43     set done 1
44 }
45
46 ensure_connecting
47 vwait forever