chiark / gitweb /
topicedit: add new topic info at front
[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 bgerror {msg} {
13     global errorInfo errorCode
14     puts stderr "$msg\n$errorCode\n$errorInfo\n"
15     exit 16
16 }
17
18 proc connected {} {
19     global channel
20     sendout JOIN $channel
21 }
22 proc new_event {} { }
23 proc privmsg_unlogged {args} { return 1 }
24 proc msg_332 {server code us channel topic args} {
25     global oldtopic nick
26     if {[string compare $nick $us]} return
27     set oldtopic $topic
28 }
29 proc msg_333 {server code us channel setter when} {
30     global nick done
31     # might happen as a result of us connecting, or as a result of
32     # our own TOPIC query
33     set now [clock seconds]
34     if {![string compare $nick $setter] && $when > $now - 3600} {
35         if {$done} {
36             puts "topic set."
37             exit 0
38         } else {
39             puts stderr "*** topic recently set by us, not setting again!"
40             exit 1
41         }
42     }
43 }
44 proc msg_366 {args} {
45     global oldtopic topicinfo channel done
46     if {![info exists oldtopic]} return
47     set newtopic "$topicinfo | $oldtopic"
48     sendout TOPIC $channel $newtopic
49     sendout TOPIC $channel
50     set done 1
51 }
52
53 ensure_connecting
54 vwait forever