chiark / gitweb /
Produce error if you say "register spong". Change mustpingbefore to muststartby...
[ircbot] / bot.tcl
CommitLineData
281f2c0e
IJ
1# Actual IRC bot code
2
3set helpfile helpinfos
9bc33297 4
574abac6 5source irccore.tcl
281f2c0e
IJ
6source parsecmd.tcl
7source stdhelp.tcl
7818b6af 8
281f2c0e
IJ
9proc privmsg_unlogged {prefix ischan params} {
10 if {!$ischan ||
574abac6 11 [regexp {^![a-z][-a-z]*[a-z]( .*)?$} [lindex $params 1]]} {
281f2c0e 12 return 0
7818b6af 13 }
574abac6
IJ
14 # on-channel message, ignore
15 set chan [lindex $params 0]
16 upvar #0 chan_lastactivity([irctolower $chan]) la
17 set la [clock seconds]
18 catch { recordlastseen_p $prefix "talking on $chan" 1 }
281f2c0e 19 return 1
422f52e4
IJ
20}
21
ef177383
IJ
22proc showintervalsecs {howlong abbrev} {
23 return [showintervalsecs/[opt timeformat] $howlong $abbrev]
d83fb8db
IJ
24}
25
ef177383 26proc showintervalsecs/ks {howlong abbrev} {
7ce72032
IJ
27 if {$howlong < 1000} {
28 return "${howlong}s"
83dd1224
IJ
29 } else {
30 if {$howlong < 1000000} {
31 set pfx k
32 set scale 1000
33 } else {
34 set pfx M
35 set scale 1000000
36 }
37 set value [expr "$howlong.0 / $scale"]
38 foreach {min format} {100 %.0f 10 %.1f 1 %.2f} {
39 if {$value < $min} continue
7ce72032 40 return [format "$format${pfx}s" $value]
83dd1224
IJ
41 }
42 }
43}
44
ef177383 45proc format_qty {qty unit abbrev} {
d83fb8db 46 set o $qty
ef177383
IJ
47 if {$abbrev} {
48 append o [string range $unit 0 0]
49 } else {
50 append o " "
51 append o $unit
52 if {$qty != 1} { append o s }
53 }
d83fb8db
IJ
54 return $o
55}
56
ef177383 57proc showintervalsecs/hms {qty abbrev} {
d83fb8db
IJ
58 set ul {second 60 minute 60 hour 24 day 7 week}
59 set remainv 0
60 while {[llength $ul] > 1 && $qty >= [set uv [lindex $ul 1]]} {
61 set remainu [lindex $ul 0]
62 set remainv [expr {$qty % $uv}]
63 set qty [expr {($qty-$remainv)/$uv}]
64 set ul [lreplace $ul 0 1]
65 }
ef177383 66 set o [format_qty $qty [lindex $ul 0] $abbrev]
d83fb8db 67 if {$remainv} {
ef177383
IJ
68 if {!$abbrev} { append o " " }
69 append o [format_qty $remainv $remainu $abbrev]
d83fb8db
IJ
70 }
71 return $o
72}
73
7ce72032
IJ
74proc showinterval {howlong} {
75 if {$howlong <= 0} {
76 return {just now}
77 } else {
ef177383 78 return "[showintervalsecs $howlong 0] ago"
7ce72032
IJ
79 }
80}
81
83dd1224
IJ
82proc showtime {when} {
83 return [showinterval [expr {[clock seconds] - $when}]]
84}
85
86proc def_msgproc {name argl body} {
87 proc msg_$name "varbase $argl" "\
88 upvar #0 msg/\$varbase/dest d\n\
89 upvar #0 msg/\$varbase/str s\n\
90 upvar #0 msg/\$varbase/accum a\n\
91$body"
92}
93
94def_msgproc begin {dest str} {
95 set d $dest
96 set s $str
97 set a {}
98}
99
100def_msgproc append {str} {
101 set ns "$s$str"
102 if {[string length $s] && [string length $ns] > 65} {
103 msg__sendout $varbase
104 set s " [string trimleft $str]"
105 } else {
106 set s $ns
107 }
108}
109
110def_msgproc finish {} {
111 msg__sendout $varbase
112 unset s
113 unset d
114 return $a
115}
116
117def_msgproc _sendout {} {
118 lappend a [string trimright $s]
119 set s {}
120}
121
122proc looking_whenwhere {when where} {
123 set str [showtime [expr {$when-1}]]
124 if {[string length $where]} { append str " on $where" }
125 return $str
126}
127
128proc recordlastseen_n {n how here} {
129 global lastseen lookedfor
422f52e4 130 set lastseen([irctolower $n]) [list $n [clock seconds] $how]
83dd1224
IJ
131 if {!$here} return
132 upvar #0 lookedfor([irctolower $n]) lf
133 if {[info exists lf]} {
134 switch -exact [llength $lf] {
135 0 {
136 set ml {}
137 }
138 1 {
139 manyset [lindex $lf 0] when who where
140 set ml [list \
141 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
142 }
143 default {
144 msg_begin tosend $n "FYI, people have been looking for you:"
145 set i 0
146 set fin ""
147 foreach e $lf {
148 incr i
149 if {$i == 1} {
150 msg_append tosend " "
151 } elseif {$i == [llength $lf]} {
152 msg_append tosend " and "
153 set fin .
154 } else {
155 msg_append tosend ", "
156 }
157 manyset $e when who where
158 msg_append tosend \
159 "$who ([looking_whenwhere $when $where])$fin"
160 }
161 set ml [msg_finish tosend]
162 }
163 }
164 unset lf
165 msendprivmsg_delayed 1000 $n $ml
166 }
422f52e4 167}
281b5f05
IJ
168
169proc note_topic {showoff whoby topic} {
35e19219 170 set msg "FYI, $whoby has changed the topic on $showoff"
281b5f05
IJ
171 if {[string length $topic] < 160} {
172 append msg " to $topic"
173 } else {
174 append msg " but it is too long to reproduce here !"
175 }
176 set showoff [irctolower $showoff]
177 set tell [chandb_get $showoff topictell]
178 if {[lsearch -exact $tell *] >= 0} {
179 set tryspies [chandb_list]
180 } else {
181 set tryspies $tell
182 }
281b5f05
IJ
183 foreach spy $tryspies {
184 set see [chandb_get $spy topicsee]
281b5f05
IJ
185 if {[lsearch -exact $see $showoff] >= 0 || \
186 ([lsearch -exact $see *] >= 0 && \
187 [lsearch -exact $tell $spy] >= 0)} {
188 sendprivmsg $spy $msg
189 }
190 }
191}
192
83dd1224 193proc recordlastseen_p {p how here} {
422f52e4 194 prefix_nick
83dd1224 195 recordlastseen_n $n $how $here
422f52e4
IJ
196}
197
198proc chanmode_arg {} {
199 upvar 2 args cm_args
200 set rv [lindex $cm_args 0]
201 set cm_args [lreplace cm_args 0 0]
202 return $rv
203}
204
83dd1224 205proc chanmode_o1 {m g p chan} {
20087363 206 global nick chan_initialop
83dd1224
IJ
207 prefix_nick
208 set who [chanmode_arg]
209 recordlastseen_n $n "being nice to $who" 1
210 if {"[irctolower $who]" == "[irctolower $nick]"} {
534e26a9
IJ
211 set nlower [irctolower $n]
212 upvar #0 nick_unique($nlower) u
20087363
IJ
213 if {[chandb_exists $chan]} {
214 sendprivmsg $n Thanks.
215 } elseif {![info exists u]} {
216 sendprivmsg $n {Op me while not on the channel, why don't you ?}
217 } else {
218 set chan_initialop([irctolower $chan]) $u
219 sendprivmsg $n \
220 "Thanks. You can use `channel manager ...' to register this channel."
221 if {![nickdb_exists $n] || ![string length [nickdb_get $n username]]} {
222 sendprivmsg $n \
223 "(But to do that you must register your nick securely first.)"
224 }
225 }
83dd1224
IJ
226 }
227}
228
422f52e4
IJ
229proc chanmode_o0 {m g p chan} {
230 global nick chandeop
231 prefix_nick
232 set who [chanmode_arg]
83dd1224 233 recordlastseen_p $p "being mean to $who" 1
422f52e4
IJ
234 if {"[irctolower $who]" == "[irctolower $nick]"} {
235 set chandeop($chan) [list [clock seconds] $p]
236 }
cc2d31de 237}
9bc33297 238
422f52e4
IJ
239proc msg_MODE {p c dest modelist args} {
240 if {![ischan $dest]} return
241 if {[regexp {^\-(.+)$} $modelist dummy modelist]} {
242 set give 0
243 } elseif {[regexp {^\+(.+)$} $modelist dummy modelist]} {
244 set give 1
245 } else {
246 error "invalid modelist"
247 }
248 foreach m [split $modelist] {
249 set procname chanmode_$m$give
250 if {[catch { info body $procname }]} {
83dd1224 251 recordlastseen_p $p "fiddling with $dest" 1
422f52e4
IJ
252 } else {
253 $procname $m $give $p $dest
254 }
255 }
256}
257
534e26a9
IJ
258proc leaving {lchan} {
259 foreach luser [array names nick_onchans] {
260 upvar #0 nick_onchans($luser) oc
261 set oc [grep tc {"$tc" != "$lchan"} $oc]
262 }
263 upvar #0 chan_nicks($lchan) nlist
264 unset nlist
ebbae0a9
IJ
265 upvar #0 chan_lastactivity($lchan) la
266 catch { unset la }
534e26a9
IJ
267}
268
cf6ea4de
IJ
269proc doleave {lchan} {
270 sendout PART $lchan
271 leaving $lchan
272}
273
534e26a9
IJ
274proc dojoin {lchan} {
275 global chan_nicks
276 sendout JOIN $lchan
277 set chan_nicks($lchan) {}
278}
279
280proc check_justme {lchan} {
281 global nick
282 upvar #0 chan_nicks($lchan) nlist
283 if {[llength $nlist] != 1} return
e2af9bcb 284 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
534e26a9
IJ
285 if {[chandb_exists $lchan]} {
286 set mode [chandb_get $lchan mode]
287 if {"$mode" != "*"} {
288 sendout MODE $lchan $mode
289 }
281b5f05
IJ
290 set topic [chandb_get $lchan topicset]
291 if {[string length $topic]} {
292 sendout TOPIC $lchan $topic
281b5f05 293 }
534e26a9 294 } else {
cf6ea4de 295 doleave $lchan
a4a1f396
IJ
296 }
297}
298
a056c4bd 299proc process_kickpart {chan user} {
a4a1f396 300 global nick
a056c4bd 301 check_nick $user
534e26a9
IJ
302 set luser [irctolower $user]
303 set lchan [irctolower $chan]
a056c4bd 304 if {![ischan $chan]} { error "not a channel" }
534e26a9
IJ
305 if {"$luser" == "[irctolower $nick]"} {
306 leaving $lchan
307 } else {
308 upvar #0 nick_onchans($luser) oc
309 upvar #0 chan_nicks($lchan) nlist
310 set oc [grep tc {"$tc" != "$lchan"} $oc]
311 set nlist [grep tn {"$tn" != "$luser"} $nlist]
312 nick_case $user
313 if {![llength $oc]} {
314 nick_forget $luser
315 } else {
316 check_justme $lchan
317 }
a4a1f396 318 }
534e26a9 319}
a056c4bd 320
281b5f05
IJ
321proc msg_TOPIC {p c dest topic} {
322 prefix_nick
323 if {![ischan $dest]} return
324 recordlastseen_n $n "changing the topic on $dest" 1
325 note_topic [irctolower $dest] $n $topic
326}
327
a056c4bd
IJ
328proc msg_KICK {p c chans users comment} {
329 set chans [split $chans ,]
330 set users [split $users ,]
331 if {[llength $chans] > 1} {
332 foreach chan $chans user $users { process_kickpart $chan $user }
333 } else {
334 foreach user $users { process_kickpart [lindex $chans 0] $user }
335 }
336}
337
338proc msg_KILL {p c user why} {
339 nick_forget $user
340}
341
20087363
IJ
342set nick_counter 0
343set nick_arys {onchans username unique}
534e26a9
IJ
344# nick_onchans($luser) -> [list ... $lchan ...]
345# nick_username($luser) -> <securely known local username>
346# nick_unique($luser) -> <counter>
347# nick_case($luser) -> $user (valid even if no longer visible)
ebbae0a9 348# nick_markid($luser) -> <after id for marktime>
534e26a9
IJ
349
350# chan_nicks($lchan) -> [list ... $luser ...]
ebbae0a9 351# chan_lastactivity($lchan) -> [clock seconds]
a056c4bd 352
534e26a9
IJ
353proc lnick_forget {luser} {
354 global nick_arys chan_nicks
ebbae0a9 355 lnick_marktime_cancel $luser
a056c4bd 356 foreach ary $nick_arys {
534e26a9 357 upvar #0 nick_${ary}($luser) av
a056c4bd
IJ
358 catch { unset av }
359 }
534e26a9
IJ
360 foreach lch [array names chan_nicks] {
361 upvar #0 chan_nicks($lch) nlist
362 set nlist [grep tn {"$tn" != "$luser"} $nlist]
363 check_justme $lch
364 }
365}
366
367proc nick_forget {user} {
368 global nick_arys chan_nicks
369 lnick_forget [irctolower $user]
370 nick_case $user
a4a1f396
IJ
371}
372
534e26a9 373proc nick_case {user} {
a4a1f396 374 global nick_case
534e26a9 375 set nick_case([irctolower $user]) $user
a056c4bd
IJ
376}
377
83dd1224 378proc msg_NICK {p c newnick} {
a4a1f396 379 global nick_arys nick_case
83dd1224
IJ
380 prefix_nick
381 recordlastseen_n $n "changing nicks to $newnick" 0
382 recordlastseen_n $newnick "changing nicks from $n" 1
6425c2d6 383 set luser [irctolower $n]
ebbae0a9 384 lnick_marktime_cancel $luser
6425c2d6 385 set lusernew [irctolower $newnick]
a056c4bd 386 foreach ary $nick_arys {
6425c2d6
IJ
387 upvar #0 nick_${ary}($luser) old
388 upvar #0 nick_${ary}($lusernew) new
a056c4bd
IJ
389 if {[info exists new]} { error "nick collision ?! $ary $n $newnick" }
390 if {[info exists old]} { set new $old; unset old }
391 }
6425c2d6 392 upvar #0 nick_onchans($lusernew) oc
534e26a9
IJ
393 foreach ch $oc {
394 upvar #0 chan_nicks($ch) nlist
395 set nlist [grep tn {"$tn" != "$luser"} $nlist]
396 lappend nlist $lusernew
397 }
ebbae0a9 398 lnick_marktime_start $lusernew "Hi." 500
a4a1f396 399 nick_case $newnick
83dd1224
IJ
400}
401
20087363
IJ
402proc nick_ishere {n} {
403 global nick_counter
534e26a9 404 upvar #0 nick_unique([irctolower $n]) u
20087363
IJ
405 if {![info exists u]} { set u [incr nick_counter].$n.[clock seconds] }
406 nick_case $n
407}
408
a056c4bd
IJ
409proc msg_JOIN {p c chan} {
410 prefix_nick
411 recordlastseen_n $n "joining $chan" 1
cf6ea4de
IJ
412 set nl [irctolower $n]
413 set lchan [irctolower $chan]
414 upvar #0 nick_onchans($nl) oc
415 upvar #0 chan_nicks($lchan) nlist
ebbae0a9
IJ
416 if {![info exists oc]} {
417 global marktime_join_startdelay
418 lnick_marktime_start $nl "Welcome." $marktime_join_startdelay
419 }
cf6ea4de
IJ
420 lappend oc $lchan
421 lappend nlist $nl
20087363 422 nick_ishere $n
a056c4bd
IJ
423}
424proc msg_PART {p c chan} {
425 prefix_nick
426 recordlastseen_n $n "leaving $chan" 1
427 process_kickpart $chan $n
428}
429proc msg_QUIT {p c why} {
430 prefix_nick
431 recordlastseen_n $n "leaving ($why)" 0
432 nick_forget $n
433}
422f52e4 434
cc2d31de 435proc msg_PRIVMSG {p c dest text} {
a01859b6
IJ
436 global errorCode
437
cc2d31de 438 prefix_nick
422f52e4 439 if {[ischan $dest]} {
83dd1224 440 recordlastseen_n $n "invoking me in $dest" 1
422f52e4 441 set output $dest
cc2d31de 442 } else {
83dd1224 443 recordlastseen_n $n "talking to me" 1
422f52e4
IJ
444 set output $n
445 }
a4a1f396 446 nick_case $n
422f52e4 447
281f2c0e 448 execute_usercommand $p $c $n $output $dest $text
422f52e4
IJ
449}
450
a056c4bd 451proc msg_INVITE {p c n chan} {
534e26a9 452 after 1000 [list dojoin [irctolower $chan]]
a056c4bd
IJ
453}
454
455proc grep {var predicate list} {
456 set o {}
457 upvar 1 $var v
458 foreach v $list {
459 if {[uplevel 1 [list expr $predicate]]} { lappend o $v }
460 }
461 return $o
462}
463
464proc msg_353 {p c dest type chan nicklist} {
465 global names_chans nick_onchans
534e26a9
IJ
466 set lchan [irctolower $chan]
467 upvar #0 chan_nicks($lchan) nlist
468 lappend names_chans $lchan
469 if {![info exists nlist]} {
470 # We don't think we're on this channel, so ignore it !
471 # Unfortunately, because we don't get a reply to PART,
472 # we have to remember ourselves whether we're on a channel,
473 # and ignore stuff if we're not, to avoid races. Feh.
474 return
475 }
476 set nlist_new {}
477 foreach user [split $nicklist { }] {
478 regsub {^[@+]} $user {} user
479 if {![string length $user]} continue
480 check_nick $user
481 set luser [irctolower $user]
482 upvar #0 nick_onchans($luser) oc
483 lappend oc $lchan
484 lappend nlist_new $luser
485 nick_ishere $user
a056c4bd 486 }
534e26a9 487 set nlist $nlist_new
a056c4bd
IJ
488}
489
490proc msg_366 {p c args} {
491 global names_chans nick_onchans
534e26a9
IJ
492 set lchan [irctolower $c]
493 foreach luser [array names nick_onchans] {
494 upvar #0 nick_onchans($luser) oc
495 if {[llength names_chans] > 1} {
a056c4bd 496 set oc [grep tc {[lsearch -exact $tc $names_chans] >= 0} $oc]
a056c4bd 497 }
534e26a9 498 if {![llength $oc]} { lnick_forget $n }
a056c4bd
IJ
499 }
500 unset names_chans
501}
502
4fd2739c 503proc check_username {target} {
7ce72032
IJ
504 if {
505 [string length $target] > 8 ||
506 [regexp {[^-0-9a-z]} $target] ||
507 ![regexp {^[a-z]} $target]
508 } { error "invalid username" }
4fd2739c
IJ
509}
510
20087363 511proc somedb__head {} {
7a70431a 512 uplevel 1 {
20087363
IJ
513 set idl [irctolower $id]
514 upvar #0 ${nickchan}db($idl) ndbe
515 binary scan $idl H* idh
516 set idfn $fprefix$idh
517 if {![info exists iddbe] && [file exists $idfn]} {
518 set f [open $idfn r]
7a70431a
IJ
519 try_except_finally { set newval [read $f] } {} { close $f }
520 if {[llength $newval] % 2} { error "invalid length" }
20087363 521 set iddbe $newval
7a70431a
IJ
522 }
523 }
524}
525
20087363
IJ
526proc def_somedb {name arglist body} {
527 foreach {nickchan fprefix} {nick users/n chan chans/c} {
528 proc ${nickchan}db_$name $arglist \
534e26a9
IJ
529 "set nickchan $nickchan; set fprefix $fprefix; $body"
530 }
531}
532
533def_somedb list {} {
534 set list {}
535 foreach path [glob -nocomplain -path $fprefix *] {
536 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
537 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
538 lappend list [binary format H* $thinghex]
20087363 539 }
534e26a9
IJ
540 return $list
541}
542
543proc def_somedb_id {name arglist body} {
544 def_somedb $name [concat id $arglist] "somedb__head; $body"
7a70431a
IJ
545}
546
534e26a9 547def_somedb_id exists {} {
20087363 548 return [info exists iddbe]
7a70431a
IJ
549}
550
534e26a9 551def_somedb_id delete {} {
20087363
IJ
552 catch { unset iddbe }
553 file delete $idfn
7a70431a
IJ
554}
555
ebbae0a9 556set default_settings_nick {timeformat ks marktime off}
281b5f05
IJ
557set default_settings_chan {
558 autojoin 1
559 mode *
560 userinvite pub
561 topicset {}
562 topicsee {}
563 topictell {}
564}
7a70431a 565
534e26a9 566def_somedb_id set {args} {
20087363
IJ
567 upvar #0 default_settings_$nickchan def
568 if {![info exists iddbe]} { set iddbe $def }
569 foreach {key value} [concat $iddbe $args] { set a($key) $value }
7a70431a
IJ
570 set newval {}
571 foreach {key value} [array get a] { lappend newval $key $value }
20087363 572 set f [open $idfn.new w]
7a70431a
IJ
573 try_except_finally {
574 puts $f $newval
575 close $f
20087363 576 file rename -force $idfn.new $idfn
7a70431a 577 } {
7a70431a 578 } {
d83fb8db 579 catch { close $f }
7a70431a 580 }
20087363 581 set iddbe $newval
7a70431a
IJ
582}
583
534e26a9 584def_somedb_id get {key} {
20087363
IJ
585 upvar #0 default_settings_$nickchan def
586 if {[info exists iddbe]} {
534e26a9 587 set l [concat $iddbe $def]
7a70431a 588 } else {
20087363 589 set l $def
7a70431a
IJ
590 }
591 foreach {tkey value} $l {
592 if {"$tkey" == "$key"} { return $value }
593 }
594 error "unset setting $key"
595}
596
20087363
IJ
597proc opt {key} {
598 global calling_nick
599 if {[info exists calling_nick]} { set n $calling_nick } { set n {} }
600 return [nickdb_get $n $key]
601}
602
7a70431a
IJ
603proc check_notonchan {} {
604 upvar 1 dest dest
a01859b6 605 if {[ischan $dest]} { usererror "That command must be sent privately." }
7a70431a
IJ
606}
607
608proc nick_securitycheck {strict} {
609 upvar 1 n n
a01859b6
IJ
610 if {![nickdb_exists $n]} {
611 usererror "You are unknown to me, use `register'."
612 }
20087363 613 set wantu [nickdb_get $n username]
7a70431a
IJ
614 if {![string length $wantu]} {
615 if {$strict} {
a01859b6 616 usererror "That feature is only available to secure users, sorry."
7a70431a
IJ
617 } else {
618 return
619 }
620 }
534e26a9
IJ
621 set luser [irctolower $n]
622 upvar #0 nick_username($luser) nu
7a70431a 623 if {![info exists nu]} {
a01859b6 624 usererror "Nick $n is secure, you must identify yourself first."
7a70431a
IJ
625 }
626 if {"$wantu" != "$nu"} {
a01859b6
IJ
627 usererror "You are the wrong user -\
628 the nick $n belongs to $wantu, not $nu."
7a70431a
IJ
629 }
630}
631
a01859b6 632proc channel_ismanager {channel n} {
c362e172 633 set mgrs [chandb_get $channel managers]
a01859b6
IJ
634 return [expr {[lsearch -exact [irctolower $mgrs] [irctolower $n]] >= 0}]
635}
636
637proc channel_securitycheck {channel} {
638 upvar n n
639 if {![channel_ismanager $channel $n]} {
640 usererror "You are not a manager of $channel."
20087363 641 }
a01859b6 642 nick_securitycheck 1
20087363
IJ
643}
644
645proc def_chancmd {name body} {
646 proc channel/$name {} \
647 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
648}
649
281b5f05
IJ
650proc ta_listop {findnow procvalue} {
651 # findnow and procvalue are code fragments which will be executed
652 # in the caller's level. findnow should set ta_listop_ev to
653 # the current list, and procvalue should treat ta_listop_ev as
654 # a proposed value in the list and check and possibly modify
655 # (canonicalise?) it. After ta_listop, ta_listop_ev will
656 # be the new value of the list.
657 upvar 1 ta_listop_ev exchg
658 upvar 1 text text
20087363
IJ
659 set opcode [ta_word]
660 switch -exact _$opcode {
281b5f05 661 _= { }
20087363 662 _+ - _- {
281b5f05
IJ
663 uplevel 1 $findnow
664 foreach item $exchg { set array($item) 1 }
20087363
IJ
665 }
666 default {
281b5f05 667 error "list change opcode must be one of + - ="
20087363
IJ
668 }
669 }
281b5f05
IJ
670 foreach exchg [split $text " "] {
671 if {![string length $exchg]} continue
672 uplevel 1 $procvalue
20087363 673 if {"$opcode" != "-"} {
281b5f05 674 set array($exchg) 1
20087363 675 } else {
281b5f05 676 catch { unset array($exchg) }
20087363
IJ
677 }
678 }
281b5f05
IJ
679 set exchg [lsort [array names array]]
680}
681
682def_chancmd manager {
683 ta_listop {
684 if {[chandb_exists $chan]} {
685 set ta_listop_ev [chandb_get $chan managers]
686 } else {
687 set ta_listop_ev [list [irctolower $n]]
688 }
689 } {
690 check_nick $ta_listop_ev
691 set ta_listop_ev [irctolower $ta_listop_ev]
692 }
693 if {[llength $ta_listop_ev]} {
694 chandb_set $chan managers $ta_listop_ev
695 ucmdr "Managers of $chan: $ta_listop_ev" {}
20087363
IJ
696 } else {
697 chandb_delete $chan
698 ucmdr {} {} "forgets about managing $chan." {}
699 }
700}
701
702def_chancmd autojoin {
703 set yesno [ta_word]
704 switch -exact [string tolower $yesno] {
705 no { set nv 0 }
706 yes { set nv 1 }
707 default { error "channel autojoin must be `yes' or `no' }
708 }
709 chandb_set $chan autojoin $nv
a49f2997
IJ
710 ucmdr [expr {$nv ? "I will join $chan when I'm restarted " : \
711 "I won't join $chan when I'm restarted "}] {}
534e26a9
IJ
712}
713
5e5be903
IJ
714def_chancmd userinvite {
715 set nv [string tolower [ta_word]]
716 switch -exact $nv {
717 pub { set txt "!invite will work for $chan, but it won't work by /msg" }
718 here { set txt "!invite and /msg invite will work, but only for users who are already on $chan." }
719 all { set txt "Any user will be able to invite themselves or anyone else to $chan." }
720 none { set txt "I will not invite anyone to $chan." }
721 default {
722 error "channel userinvite must be `pub', `here', `all' or `none'
723 }
724 }
725 chandb_set $chan userinvite $nv
726 ucmdr $txt {}
727}
728
281b5f05
IJ
729def_chancmd topic {
730 set what [ta_word]
731 switch -exact $what {
732 leave {
733 ta_nomore
734 chandb_set $chan topicset {}
735 ucmdr "I won't ever change the topic of $chan." {}
736 }
737 set {
738 set t [string trim $text]
739 if {![string length $t]} {
740 error "you must specific the topic to set"
741 }
742 chandb_set $chan topicset $t
a49f2997 743 ucmdr "Whenever I'm alone on $chan, I'll set the topic to $t." {}
281b5f05
IJ
744 }
745 see - tell {
746 ta_listop {
747 set ta_listop_ev [chandb_get $chan topic$what]
748 } {
749 if {"$ta_listop_ev" != "*"} {
750 if {![ischan $ta_listop_ev]} {
751 error "bad channel \`$ta_listop_ev' in topic $what"
752 }
753 set ta_listop_ev [irctolower $ta_listop_ev]
754 }
755 }
756 chandb_set $chan topic$what $ta_listop_ev
757 ucmdr "Topic $what list for $chan: $ta_listop_ev" {}
758 }
759 default {
a01859b6 760 usererror "Unknown channel topic subcommand - see help channel."
281b5f05
IJ
761 }
762 }
763}
764
534e26a9
IJ
765def_chancmd mode {
766 set mode [ta_word]
767 if {"$mode" != "*" && ![regexp {^(([-+][imnpst]+)+)$} $mode mode]} {
768 error {channel mode must be * or match ([-+][imnpst]+)+}
769 }
770 chandb_set $chan mode $mode
771 if {"$mode" == "*"} {
281b5f05 772 ucmdr "I won't ever change the mode of $chan." {}
534e26a9 773 } else {
281b5f05 774 ucmdr "Whenever I'm alone on $chan, I'll set the mode to $mode." {}
534e26a9 775 }
20087363
IJ
776}
777
778def_chancmd show {
779 if {[chandb_exists $chan]} {
780 set l "Settings for $chan: autojoin "
781 append l [lindex {no yes} [chandb_get $chan autojoin]]
b60b5a0f
IJ
782 append l ", mode " [chandb_get $chan mode]
783 append l ", userinvite " [chandb_get $chan userinvite] "."
20087363 784 append l "\nManagers: "
8b6ee626 785 append l [join [chandb_get $chan managers] " "]
281b5f05
IJ
786 foreach {ts sep} {see "\n" tell " "} {
787 set t [chandb_get $chan topic$ts]
788 append l $sep
789 if {[llength $t]} {
790 append l "Topic $ts list: $t."
791 } else {
792 append l "Topic $ts list is empty."
793 }
794 }
8b6ee626
IJ
795 append l "\n"
796 set t [chandb_get $chan topicset]
797 if {[string length $t]} {
798 append l "Topic to set: $t"
799 } else {
800 append l "I will not change the topic."
801 }
20087363
IJ
802 ucmdr {} $l
803 } else {
804 ucmdr {} "The channel $chan is not managed."
805 }
806}
807
cf6ea4de
IJ
808proc channelmgr_monoop {} {
809 upvar 1 dest dest
810 upvar 1 text text
811 upvar 1 n n
812 upvar 1 p p
813 upvar 1 target target
814 global chan_nicks
815
3c9af14f
IJ
816 prefix_nick
817
20087363
IJ
818 if {[ischan $dest]} { set target $dest }
819 if {[ta_anymore]} { set target [ta_word] }
820 ta_nomore
cf6ea4de 821 if {![info exists target]} {
a01859b6 822 usererror "You must specify, or invoke me on, the relevant channel."
cf6ea4de
IJ
823 }
824 if {![info exists chan_nicks([irctolower $target])]} {
a01859b6 825 usererror "I am not on $target."
cf6ea4de 826 }
20087363 827 if {![ischan $target]} { error "not a valid channel" }
3c9af14f 828
a01859b6
IJ
829 if {![chandb_exists $target]} {
830 usererror "$target is not a managed channel."
831 }
832 channel_securitycheck $target
cf6ea4de
IJ
833}
834
835def_ucmd op {
836 channelmgr_monoop
20087363
IJ
837 sendout MODE $target +o $n
838}
839
cf6ea4de
IJ
840def_ucmd leave {
841 channelmgr_monoop
842 doleave $target
843}
844
5e5be903 845def_ucmd invite {
a01859b6
IJ
846 global chan_nicks errorCode errorInfo
847 prefix_nick
5e5be903
IJ
848
849 if {[ischan $dest]} {
850 set target $dest
851 set onchan 1
852 } else {
853 set target [ta_word]
854 set onchan 0
855 }
856 set ltarget [irctolower $target]
a01859b6
IJ
857 if {![ischan $target]} { error "$target is not a channel" }
858 if {![info exists chan_nicks($ltarget)]} {
859 usererror "I am not on $target."
5e5be903 860 }
a01859b6
IJ
861 set ui [chandb_get $ltarget userinvite]
862 if {[catch {
863 if {"$ui" == "pub" && !$onchan} {
864 usererror "Invitations to $target must be made there with !invite."
865 }
866 if {"$ui" != "all"} {
867 if {[lsearch -exact $chan_nicks($ltarget) [irctolower $n]] < 0} {
868 usererror "Invitations to $target may only be made\
869 by a user on the channel."
870 }
871 }
872 if {"$ui" == "none"} {
873 usererror "Sorry, I've not been authorised\
874 to invite people to $target."
875 }
876 } emsg]} {
877 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager $target $n]} {
878 if {[catch {
879 nick_securitycheck 1
880 } emsg2]} {
881 if {"$errorCode" == "BLIGHT USER"} {
882 usererror "$emsg2 Therefore you can't use your\
883 channel manager privilege. $emsg"
884 } else {
885 error $error $errorInfo $errorCode
886 }
887 }
888 } else {
889 error $emsg $errorInfo $errorCode
5e5be903 890 }
5e5be903
IJ
891 }
892 if {![ta_anymore]} {
a01859b6 893 usererror "You have to say who to invite."
5e5be903
IJ
894 }
895 set invitees {}
896 while {[ta_anymore]} {
897 set invitee [ta_word]
898 check_nick $invitee
899 lappend invitees $invitee
900 }
901 foreach invitee $invitees {
902 sendout INVITE $invitee $ltarget
903 }
904 set who [lindex $invitees 0]
905 switch -exact llength $invitees {
906 0 { error "zero invitees" }
907 1 { }
908 2 { append who " and [lindex $invitees 1]" }
909 * {
910 set who [join [lreplace $invitees end end] ", "]
911 append who " and [lindex $invitees [llength $invitees]]"
912 }
913 }
33718ee2 914 ucmdr {} {} {} "invites $who to $target."
5e5be903
IJ
915}
916
20087363
IJ
917def_ucmd channel {
918 if {[ischan $dest]} { set target $dest }
919 if {![ta_anymore]} {
920 set subcmd show
921 } else {
922 set subcmd [ta_word]
923 }
924 if {[ischan $subcmd]} {
925 set target $subcmd
926 if {![ta_anymore]} {
927 set subcmd show
928 } else {
929 set subcmd [ta_word]
930 }
931 }
932 if {![info exists target]} { error "privately, you must specify a channel" }
933 set procname channel/$subcmd
934 if {"$subcmd" != "show"} {
a01859b6
IJ
935 if {[catch { info body $procname }]} {
936 usererror "unknown channel setting $subcmd."
937 }
20087363 938 prefix_nick
20087363 939 if {[chandb_exists $target]} {
a01859b6 940 channel_securitycheck $target
20087363 941 } else {
a01859b6 942 nick_securitycheck 1
20087363 943 upvar #0 chan_initialop([irctolower $target]) io
534e26a9 944 upvar #0 nick_unique([irctolower $n]) u
a01859b6
IJ
945 if {![info exists io]} {
946 usererror "$target is not a managed channel."
947 }
948 if {"$io" != "$u"} {
949 usererror "You are not the interim manager of $target."
950 }
951 if {"$subcmd" != "manager"} {
952 usererror "Please use `channel manager' first."
953 }
20087363
IJ
954 }
955 }
956 channel/$subcmd
957}
958
a4a1f396
IJ
959def_ucmd who {
960 if {[ta_anymore]} {
961 set target [ta_word]; ta_nomore
962 set myself 1
963 } else {
964 prefix_nick
965 set target $n
966 set myself [expr {"$target" != "$n"}]
967 }
534e26a9
IJ
968 set ltarget [irctolower $target]
969 upvar #0 nick_case($ltarget) ctarget
a4a1f396 970 set nshow $target
534e26a9
IJ
971 if {[info exists ctarget]} {
972 upvar #0 nick_onchans($ltarget) oc
973 upvar #0 nick_username($ltarget) nu
974 if {[info exists oc]} { set nshow $ctarget }
a4a1f396 975 }
534e26a9 976 if {![nickdb_exists $ltarget]} {
a4a1f396 977 set ol "$nshow is not a registered nick."
20087363 978 } elseif {[string length [set username [nickdb_get $target username]]]} {
a4a1f396
IJ
979 set ol "The nick $nshow belongs to the user $username."
980 } else {
981 set ol "The nick $nshow is registered (but not to a username)."
982 }
534e26a9 983 if {![info exists ctarget] || ![info exists oc]} {
a4a1f396
IJ
984 if {$myself} {
985 append ol "\nI can't see $nshow on anywhere."
986 } else {
987 append ol "\nYou aren't on any channels with me."
988 }
989 } elseif {![info exists nu]} {
990 append ol "\n$nshow has not identified themselves."
991 } elseif {![info exists username]} {
992 append ol "\n$nshow has identified themselves as the user $nu."
993 } elseif {"$nu" != "$username"} {
994 append ol "\nHowever, $nshow is being used by the user $nu."
995 } else {
996 append ol "\n$nshow has identified themselves to me."
997 }
998 ucmdr {} $ol
999}
1000
7a70431a
IJ
1001def_ucmd register {
1002 prefix_nick
1003 check_notonchan
1004 set old [nickdb_exists $n]
1005 if {$old} { nick_securitycheck 0 }
534e26a9 1006 set luser [irctolower $n]
7a70431a
IJ
1007 switch -exact [string tolower [string trim $text]] {
1008 {} {
534e26a9 1009 upvar #0 nick_username($luser) nu
7a70431a
IJ
1010 if {![info exists nu]} {
1011 ucmdr {} \
a4a1f396 1012 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
7a70431a
IJ
1013 }
1014 nickdb_set $n username $nu
1015 ucmdr {} {} "makes a note of your username." {}
1016 }
1017 delete {
1018 nickdb_delete $n
1019 ucmdr {} {} "forgets your nickname." {}
1020 }
1021 insecure {
1022 nickdb_set $n username {}
1023 if {$old} {
1024 ucmdr {} "Security is now disabled for your nickname !"
1025 } else {
1026 ucmdr {} "This is fine, but bear in mind that people will be able to mess with your settings. Channel management features need a secure registration." "makes an insecure registration for your nick."
1027 }
1028 }
0d3ea3aa
IJ
1029 default {
1030 error "you mean register / register delete / register insecure"
1031 }
7a70431a 1032 }
11d9bff9
IJ
1033}
1034
1035proc timeformat_desc {tf} {
1036 switch -exact $tf {
86892128 1037 ks { return "Times will be displayed in seconds or kiloseconds." }
11d9bff9
IJ
1038 hms { return "Times will be displayed in hours, minutes, etc." }
1039 default { error "invalid timeformat: $v" }
1040 }
1041}
1042
1043proc def_setting {opt show_body set_body} {
1044 proc set_show/$opt {} "
1045 upvar 1 n n
1046 set opt $opt
1047 $show_body"
1048 if {![string length $set_body]} return
1049 proc set_set/$opt {} "
1050 upvar 1 n n
1051 upvar 1 text text
1052 set opt $opt
1053 $set_body"
1054}
1055
1056def_setting timeformat {
20087363 1057 set tf [nickdb_get $n timeformat]
11d9bff9
IJ
1058 return "$tf: [timeformat_desc $tf]"
1059} {
1060 set tf [string tolower [ta_word]]
1061 ta_nomore
1062 set desc [timeformat_desc $tf]
1063 nickdb_set $n timeformat $tf
1064 ucmdr {} $desc
1065}
1066
ebbae0a9
IJ
1067proc marktime_desc {mt} {
1068 if {"$mt" == "off"} {
1069 return "I will not send you periodic messages."
1070 } elseif {"$mt" == "once"} {
1071 return "I will send you one informational message when I see you."
1072 } else {
ef177383 1073 return "I'll send you a message every [showintervalsecs $mt 0]."
ebbae0a9
IJ
1074 }
1075}
1076
1077def_setting marktime {
1078 set mt [nickdb_get $n marktime]
1079 set p $mt
a4e294d4 1080 if {[string match {[0-9]*} $mt]} { append p s }
ebbae0a9
IJ
1081 append p ": "
1082 append p [marktime_desc $mt]
1083 return $p
1084} {
1085 global marktime_min
1086 set mt [string tolower [ta_word]]
1087 ta_nomore
1088
1089 if {"$mt" == "off" || "$mt" == "once"} {
1090 } elseif {[regexp {^([0-9]+)([a-z]+)$} $mt dummy value unit]} {
1091 switch -exact $unit {
1092 s { set u 1 }
1093 ks { set u 1000 }
1094 m { set u 60 }
1095 h { set u 3600 }
1096 default { error "unknown unit of time $unit" }
1097 }
1098 if {$value > 86400*21/$u} { error "marktime interval too large" }
1099 set mt [expr {$value*$u}]
1100 if {$mt < $marktime_min} { error "marktime interval too small" }
1101 } else {
1102 error "invalid syntax for marktime"
1103 }
1104 nickdb_set $n marktime $mt
1105 lnick_marktime_start [irctolower $n] "So:" 500
1106 ucmdr {} [marktime_desc $mt]
1107}
1108
11d9bff9 1109def_setting security {
20087363 1110 set s [nickdb_get $n username]
11d9bff9
IJ
1111 if {[string length $s]} {
1112 return "Your nick, $n, is controlled by the user $s."
1113 } else {
1114 return "Your nick, $n, is not secure."
1115 }
1116} {}
1117
1118def_ucmd set {
1119 prefix_nick
1120 check_notonchan
1121 if {![nickdb_exists $n]} {
d83fb8db 1122 ucmdr {} "You are unknown to me and so have no settings. (Use `register'.)"
11d9bff9
IJ
1123 }
1124 if {![ta_anymore]} {
1125 set ol {}
1126 foreach proc [lsort [info procs]] {
1127 if {![regexp {^set_show/(.*)$} $proc dummy opt]} continue
1128 lappend ol [format "%-10s %s" $opt [set_show/$opt]]
1129 }
1130 ucmdr {} [join $ol "\n"]
1131 } else {
1132 set opt [ta_word]
1133 if {[catch { info body set_show/$opt }]} {
1134 error "no setting $opt"
1135 }
1136 if {![ta_anymore]} {
1137 ucmdr {} "$opt [set_show/$opt]"
1138 } else {
86892128 1139 nick_securitycheck 0
11d9bff9
IJ
1140 if {[catch { info body set_set/$opt }]} {
1141 error "setting $opt cannot be set with `set'"
1142 }
1143 set_set/$opt
1144 }
1145 }
1146}
7a70431a 1147
4fd2739c
IJ
1148def_ucmd identpass {
1149 set username [ta_word]
d83fb8db 1150 set passmd5 [md5sum "[ta_word]\n"]
4fd2739c
IJ
1151 ta_nomore
1152 prefix_nick
11d9bff9 1153 check_notonchan
534e26a9
IJ
1154 set luser [irctolower $n]
1155 upvar #0 nick_onchans($luser) onchans
4fd2739c 1156 if {![info exists onchans] || ![llength $onchans]} {
7a70431a 1157 ucmdr "You must be on a channel with me to identify yourself." {}
4fd2739c
IJ
1158 }
1159 check_username $username
1160 exec userv --timeout 3 $username << "$passmd5\n" > /dev/null \
1161 irc-identpass $n
534e26a9 1162 upvar #0 nick_username($luser) rec_username
4fd2739c 1163 set rec_username $username
7a70431a 1164 ucmdr "Pleased to see you, $username." {}
4fd2739c
IJ
1165}
1166
1167def_ucmd summon {
1168 set target [ta_word]
1169 ta_nomore
1170 check_username $target
7ce72032
IJ
1171 prefix_nick
1172
1173 upvar #0 lastsummon($target) ls
1174 set now [clock seconds]
1175 if {[info exists ls]} {
1176 set interval [expr {$now - $ls}]
1177 if {$interval < 30} {
1178 ucmdr {} \
1179 "Please be patient; $target was summoned only [showinterval $interval]."
1180 }
1181 }
1182 regsub {^[^!]*!} $p {} path
1183 if {[catch {
1184 exec userv --timeout 3 $target irc-summon $n $path \
1185 [expr {[ischan $dest] ? "$dest" : ""}] \
1186 < /dev/null
1187 } rv]} {
1188 regsub -all "\n" $rv { / } rv
1189 error $rv
1190 }
1191 if {[regexp {^problem (.*)} $rv dummy problem]} {
8a8d337d 1192 ucmdr {} "The user `$target' $problem."
7ce72032
IJ
1193 } elseif {[regexp {^ok ([^ ]+) ([0-9]+)$} $rv dummy tty idlesince]} {
1194 set idletime [expr {$now - $idlesince}]
1195 set ls $now
1196 ucmdr {} {} {} "invites $target ($tty[expr {
ef177383 1197 $idletime > 10 ? ", idle for [showintervalsecs $idletime 0]" : ""
7ce72032
IJ
1198 }]) to [expr {
1199 [ischan $dest] ? "join us here" : "talk to you"
1200 }]."
1201 } else {
1202 error "unexpected response from userv service: $rv"
1203 }
1204}
1205
a69f7d2c
IJ
1206proc md5sum {value} { exec md5sum << $value }
1207
83dd1224 1208def_ucmd seen {
422f52e4 1209 global lastseen nick
83dd1224
IJ
1210 prefix_nick
1211 set ncase [ta_nick]
1212 set nlower [irctolower $ncase]
422f52e4 1213 ta_nomore
83dd1224
IJ
1214 set now [clock seconds]
1215 if {"$nlower" == "[irctolower $nick]"} {
a01859b6 1216 usererror "I am not self-aware."
83dd1224
IJ
1217 } elseif {![info exists lastseen($nlower)]} {
1218 set rstr "I've never seen $ncase."
422f52e4 1219 } else {
83dd1224
IJ
1220 manyset $lastseen($nlower) realnick time what
1221 set howlong [expr {$now - $time}]
1222 set string [showinterval $howlong]
1223 set rstr "I last saw $realnick $string, $what."
1224 }
1225 if {[ischan $dest]} {
1226 set where $dest
1227 } else {
1228 set where {}
1229 }
1230 upvar #0 lookedfor($nlower) lf
1231 if {[info exists lf]} { set oldvalue $lf } else { set oldvalue {} }
1232 set lf [list [list $now $n $where]]
1233 foreach v $oldvalue {
1234 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1235 lappend lf $v
cc2d31de 1236 }
83dd1224 1237 ucmdr {} $rstr
cc2d31de
IJ
1238}
1239
ebbae0a9
IJ
1240proc lnick_marktime_cancel {luser} {
1241 upvar #0 nick_markid($luser) mi
1242 if {![info exists mi]} return
1243 catch { after cancel $mi }
1244 catch { unset mi }
1245}
1246
1247proc lnick_marktime_doafter {luser why ms} {
1248 lnick_marktime_cancel $luser
1249 upvar #0 nick_markid($luser) mi
1250 set mi [after $ms [list lnick_marktime_now $luser $why]]
1251}
1252
1253proc lnick_marktime_reset {luser} {
1254 set mt [nickdb_get $luser marktime]
1255 if {"$mt" == "off" || "$mt" == "once"} return
1256 lnick_marktime_doafter $luser "Time passes." [expr {$mt*1000}]
1257}
1258
1259proc lnick_marktime_start {luser why ms} {
1260 set mt [nickdb_get $luser marktime]
1261 if {"$mt" == "off"} {
1262 lnick_marktime_cancel $luser
1263 } else {
1264 lnick_marktime_doafter $luser $why $ms
1265 }
1266}
1267
1268proc lnick_marktime_now {luser why} {
1269 upvar #0 nick_onchans($luser) oc
93e9bcff
IJ
1270 global calling_nick
1271 set calling_nick $luser
ebbae0a9
IJ
1272 sendprivmsg $luser [lnick_pingstring $why $oc ""]
1273 lnick_marktime_reset $luser
1274}
1275
1276proc lnick_pingstring {why oc apstring} {
1277 global nick_onchans
1278 catch { exec uptime } uptime
1279 set nnicks [llength [array names nick_onchans]]
1280 if {[regexp \
1281 {^ *([0-9:apm]+) +up.*, +(\d+) users, +load average: +([0-9., ]+) *$} \
1282 $uptime dummy time users load]} {
93e9bcff 1283 regsub -all , $load {} load
ebbae0a9
IJ
1284 set uptime "$time $nnicks/$users $load"
1285 } else {
1286 append uptime ", $nnicks nicks"
1287 }
1288 if {[llength $oc]} {
1289 set best_la 0
1290 set activity quiet
1291 foreach ch $oc {
1292 upvar #0 chan_lastactivity($ch) la
1293 if {![info exists la]} continue
1294 if {$la <= $best_la} continue
ef177383
IJ
1295 set since [showintervalsecs [expr {[clock seconds]-$la}] 1]
1296 set activity "$ch $since"
ebbae0a9
IJ
1297 set best_la $la
1298 }
1299 } else {
1300 set activity unseen
1301 }
1302 set str $why
1303 append str " " $uptime " " $activity
1304 if {[string length $apstring]} { append str " " $apstring }
1305 return $str
1306}
1307
1308def_ucmd ping {
1309 if {[ischan $dest]} {
1310 set oc [irctolower $dest]
1311 } else {
1312 global nick_onchans
1313 prefix_nick
1314 set ln [irctolower $n]
1315 if {[info exists nick_onchans($ln)]} {
1316 set oc $nick_onchans($ln)
1317 } else {
1318 set oc {}
1319 }
1320 if {[llength $oc]} { lnick_marktime_reset $ln }
1321 }
1322 ucmdr {} [lnick_pingstring "Pong!" $oc $text]
1323}
1324
28c8ab78
IJ
1325proc ensure_globalsecret {} {
1326 global globalsecret
1327
1328 if {[info exists globalsecret]} return
1329 set gsfile [open /dev/urandom r]
1330 fconfigure $gsfile -translation binary
1331 set globalsecret [read $gsfile 32]
1332 binary scan $globalsecret H* globalsecret
1333 close $gsfile
1334 unset gsfile
1335}
1336
534e26a9 1337proc connected {} {
534e26a9
IJ
1338 foreach chan [chandb_list] {
1339 if {[chandb_get $chan autojoin]} { dojoin $chan }
1340 }
1341}
1342
28c8ab78 1343ensure_globalsecret
e6cc22dc 1344loadhelp
28c8ab78 1345ensure_connecting