10 defset marktime_min 300
11 defset marktime_join_startdelay 5000
13 proc privmsg_unlogged {prefix ischan params} {
15 [regexp {^![a-z][-a-z]*[a-z]( .*)?$} [lindex $params 1]]} {
18 # on-channel message, ignore
19 set chan [lindex $params 0]
20 upvar #0 chan_lastactivity([irctolower $chan]) la
21 set la [clock seconds]
22 catch_logged { recordlastseen_p $prefix "talking on $chan" 2 }
26 proc showintervalsecs {howlong abbrev} {
27 return [showintervalsecs/[opt timeformat] $howlong $abbrev]
30 proc formatsf {pfx value} {
31 foreach {min format} { 100 %.0f 10 %.1f 0 %.2f} {
32 set fval [format $format $value]
33 if {$fval < $min} continue
34 return [format "$fval${pfx}" $value]
38 proc showintervalsecs/beat {howlong abbrev} {
39 # We split in two to avoid overflow problems.
43 return [format "%.0fmB" [expr {round($howlong * 1.157)*10} ]]
45 if {$howlong < 86400 } {
48 set value [expr {$howlong / 86.4}]
52 set value [expr {$howlong / 86400.0}]
55 return [formatsf $pfx $value]
58 proc showintervalsecs/ks {howlong abbrev} {
59 if {$howlong < 1000} {
62 if {$howlong < 1000000} {
69 set value [expr "$howlong.0 / $scale"]
70 return [formatsf $pfx $value]
74 proc format_qty {qty unit abbrev} {
77 append o [string range $unit 0 0]
81 if {$qty != 1} { append o s }
86 proc showintervalsecs/hms {qty abbrev} {
87 set ul {second 60 minute 60 hour 24 day 7 week}
89 while {[llength $ul] > 1 && $qty >= [set uv [lindex $ul 1]]} {
90 set remainu [lindex $ul 0]
91 set remainv [expr {$qty % $uv}]
92 set qty [expr {($qty-$remainv)/$uv}]
93 set ul [lreplace $ul 0 1]
95 set o [format_qty $qty [lindex $ul 0] $abbrev]
97 if {!$abbrev} { append o " " }
98 append o [format_qty $remainv $remainu $abbrev]
103 proc showinterval {howlong} {
107 return "[showintervalsecs $howlong 0] ago"
111 proc showtime {when} {
112 return [showinterval [expr {[clock seconds] - $when}]]
115 proc parse_interval {specified min} {
116 if {![regexp {^([0-9]+)([a-z]+)$} $specified dummy value unit]} {
117 error "invalid syntax for interval"
119 switch -exact $unit {
127 default { error "unknown unit of time $unit" }
129 if {$value > 86400*21/$u} { error "interval too large" }
130 set result [expr {round($value*$u)}]
131 if {$result < $min} { error "interval too small (<${min}s)" }
135 proc def_msgproc {name argl body} {
136 proc msg_$name "varbase $argl" "\
137 upvar #0 msg/\$varbase/dest d\n\
138 upvar #0 msg/\$varbase/str s\n\
139 upvar #0 msg/\$varbase/accum a\n\
143 def_msgproc begin {dest str} {
149 def_msgproc append {str} {
151 if {[string length $s] && [string length $ns] > 65} {
152 msg__sendout $varbase
153 set s " [string trimleft $str]"
159 def_msgproc finish {} {
160 msg__sendout $varbase
166 def_msgproc _sendout {} {
167 lappend a [string trimright $s]
171 proc looking_whenwhere {when where} {
172 set str [showtime [expr {$when-1}]]
173 if {[string length $where]} { append str " on $where" }
177 proc tell_getcstate {} {
178 # uses nl from caller's context
179 # imports telling (as the nick_telling) and u
180 # sets stt, telling_when
182 upvar #0 nick_telling($nl) telling
183 upvar #0 nick_unique($nl) u
185 if {[info exists telling]} {
186 manyset $telling u_last stt telling_when
187 if {![info exists u] || "$u_last" != "$u"} {
197 proc tell_event {nl event} {
198 # For `act' we *haven't* yet done the 750ms delay; we implement
199 # that here. Also, here we turn `talk' into `talk' now and `act'
200 # later. We also support the psuedo-event `none'. The del msg
201 # and new msg events are handled by the command procedures, not here.
203 if {[info exists calling_nick]} { set save $calling_nick }
205 switch -exact $event {
208 tell_event_core $nl talk
212 after 750 [list tell_event_core $nl $event]
215 tell_event_core $nl $event
218 set r [tell_event_core $nl TELLME]
221 error "tell_event $nl $event"
224 if {[info exists save]} { set calling_nick $save }
228 proc tell_event_core {nl event} {
229 global tell_event_teventi errorInfo
230 set tell_event_teventi "*$event* $nl"
232 tell_event_core1 $nl $event
234 log_intern "tell event error" "$emsg >$errorInfo<"
237 if {"$emsg" != "nomsgs"} {
238 log_intern "tell event" "done $tell_event_teventi $emsg"
244 proc tell_event_core1 {nl event} {
245 # event is `talk', `act', `ident', `msgsarrive' or `TELLME'
246 # When user talks we actually get talk now and act later
249 set iml [msgsdb_get $nl inbound]
250 if {![llength $iml]} { return nomsgs }
252 set now [clock seconds]
254 set ago [expr {$now - $telling_when}]
256 # Now we have the components of a telling state
257 # u - nick_unique (unset if not visible)
258 # stt - state: undelivered, mentioned, passede
259 # ago - how long ago since we did anything
261 # We compute an evstate to dispatch on as follows:
263 # evstate is string of letters
265 # u UNDELIVERED (MESSAGES)
273 # T tellme (user command)
274 # security level and timing
276 # ss Secure and soon (before interval)
277 # sl Secure and late (after interval)
278 # current identification
281 # reliability and timing
283 # rv Remind, very soon (before within-interval)
284 # rs Remind, soon (between)
285 # rl Remind, late (after every-interval)
286 # ps Pester, soon (before interval)
287 # pl Pester, late (after interval)
291 append evstate [string range $stt 0 0]
292 append evstate [string range $event 0 0]
294 manyset [nickdb_get_sec_effective $nl] sec secwhen
296 insecure { append evstate ii }
297 secure { append evstate [expr {$ago<$secwhen ? "ss" : "sl"}] }
298 default { append evstate "#$sec#" }
301 upvar #0 nick_username($nl) nu
302 if {[info exists nu] && ![string compare $nu [nickdb_get_username $nl]]} {
308 manyset [nickdb_get $nl tellrel] rel relint relwithin
310 unreliable { append evstate uu }
311 remind { append evstate [expr {
312 $ago<$relwithin ? "rv" : $ago<$relint ? "rs" : "rl"
314 pester { append evstate [expr {$ago<$relint ? "ps" : "pl"}] }
315 default { append evstate "#$rel#" }
318 global tell_event_teventi
319 set tell_event_teventi "$evstate $ago $nl"
320 switch -glob $evstate {
322 # consider delivered:
323 # (very recently passed, and the user talks)
324 set ndel [tell_delete_msgs {} $nl]
326 "I'm assuming you got the $ndel message(s) I just passed on."
330 # oops, messages passed are now out of date
331 catch_restoreei { unset telling }
335 # ignore new msgs if we haven't passed yet
339 pt???uu - pt???rs - pt???rl - pt???p? {
340 # ignore (any other `talk's) - act handles these
344 uaii?uu - uaii??l - uas?iuu - uas?i?l -
347 # pass and then stuff
348 if {[llength $iml] == 3} {
349 manyset $iml sender sentwhen msg
351 "$sender asked me, [showinterval [expr {$now-$sentwhen}]],\
355 "I have [expr {[llength $iml]/3}] messages for you:"
356 while {[llength $iml] >= 3} {
357 manyset [lrange $iml 0 2] sender sentwhen msg
358 set iml [lrange $iml 3 end]
360 " [showintervalsecs [expr {$now-$sentwhen}] 1] <$sender> $msg"
363 if {![string compare $rel "unreliable"]} {
364 tell_delete_msgs {} $nl
365 return toldunreliable
371 sendprivmsg $nl {You have messages (so identify yourself please).}
376 sendprivmsg $nl {You must identify yourself to see your messages.}
380 sendprivmsg $nl {Don't forget about your messages.}
386 mass??? - pa????v - pa????s -
394 error "tell_event_core nl=$nl evstate=$evstate ?"
397 if {![info exists u]} {
398 set telling [list {} undelivered $now]
400 set telling [list $u $stt $now]
405 proc recordlastseen_n {n how here} {
407 # 0 - nick was seen leaving (or changing to another nicks or some such)
408 # 1 - nick was seen doing something else
409 # 2 - nick was seen talking on channel
410 global lastseen lookedfor
411 set nl [irctolower $n]
412 set now [clock seconds]
413 set lastseen($nl) [list $n $now $how]
417 tell_event $nl [lindex {none act talk} $here]
419 upvar #0 lookedfor($nl) lf
420 if {[info exists lf]} {
421 switch -exact [llength $lf] {
426 manyset [lindex $lf 0] when who where
428 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
431 msg_begin tosend $n "FYI, people have been looking for you:"
437 msg_append tosend " "
438 } elseif {$i == [llength $lf]} {
439 msg_append tosend " and "
442 msg_append tosend ", "
444 manyset $e when who where
446 "$who ([looking_whenwhere $when $where])$fin"
448 set ml [msg_finish tosend]
452 msendprivmsg_delayed 1000 $n $ml
456 proc note_topic {showoff whoby topic} {
457 set msg "FYI, $whoby has changed the topic on $showoff"
458 if {[string length $topic] < 160} {
459 append msg " to $topic"
461 append msg " but it is too long to reproduce here !"
463 set showoff [irctolower $showoff]
464 set tell [chandb_get $showoff topictell]
465 if {[lsearch -exact $tell *] >= 0} {
466 set tryspies [chandb_list]
470 foreach spy $tryspies {
471 set see [chandb_get $spy topicsee]
472 if {[lsearch -exact $see $showoff] >= 0 || \
473 ([lsearch -exact $see *] >= 0 && \
474 [lsearch -exact $tell $spy] >= 0)} {
475 sendprivmsg $spy $msg
480 proc recordlastseen_p {p how here} {
482 recordlastseen_n $n $how $here
485 proc chanmode_arg {} {
487 set rv [lindex $cm_args 0]
488 set cm_args [lreplace cm_args 0 0]
492 proc chanmode_o1 {m g p chan} {
493 global nick chan_initialop
495 set who [chanmode_arg]
496 recordlastseen_n $n "being nice to $who" 1
497 if {![ircnick_compare $who $nick]} {
498 set nlower [irctolower $n]
499 upvar #0 nick_unique($nlower) u
500 if {[chandb_exists $chan]} {
501 sendprivmsg $n Thanks.
502 } elseif {![info exists u]} {
503 sendprivmsg $n {Op me while not on the channel, why don't you ?}
505 set chan_initialop([irctolower $chan]) $u
507 "Thanks. You can use `channel manager ...' to register this channel."
508 if {![string length [nickdb_get_username $n username]]} {
510 "(But to do that you must register your nick securely first.)"
516 proc chanmode_o0 {m g p chan} {
519 set who [chanmode_arg]
520 recordlastseen_p $p "being mean to $who" 1
521 if {![ircnick_compare $who $nick]} {
522 set chandeop($chan) [list [clock seconds] $p]
526 proc msg_MODE {p c dest modelist args} {
527 if {![ischan $dest]} return
528 if {[regexp {^\-(.+)$} $modelist dummy modelist]} {
530 } elseif {[regexp {^\+(.+)$} $modelist dummy modelist]} {
533 error "invalid modelist"
535 foreach m [split $modelist] {
536 set procname chanmode_$m$give
537 if {[catch { info body $procname }]} {
538 recordlastseen_p $p "fiddling with $dest" 1
540 $procname $m $give $p $dest
545 proc leaving {lchan} {
547 foreach luser [array names nick_onchans] {
548 upvar #0 nick_onchans($luser) oc
549 set oc [grep tc {"$tc" != "$lchan"} $oc]
551 upvar #0 chan_nicks($lchan) nlist
553 upvar #0 chan_lastactivity($lchan) la
557 proc doleave {lchan} {
562 proc dojoin {lchan} {
565 set chan_nicks($lchan) {}
568 proc check_justme {lchan} {
570 upvar #0 chan_nicks($lchan) nlist
571 if {[llength $nlist] != 1} return
572 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
573 if {[chandb_exists $lchan]} {
574 set mode [chandb_get $lchan mode]
575 if {"$mode" != "*"} {
576 sendout MODE $lchan $mode
578 set topic [chandb_get $lchan topicset]
579 if {[string length $topic]} {
580 sendout TOPIC $lchan $topic
587 proc process_kickpart {chan user} {
590 set luser [irctolower $user]
591 set lchan [irctolower $chan]
592 if {![ischan $chan]} { error "not a channel" }
593 if {![ircnick_compare $luser $nick]} {
596 upvar #0 nick_onchans($luser) oc
597 upvar #0 chan_nicks($lchan) nlist
598 set oc [grep tc {"$tc" != "$lchan"} $oc]
599 set nlist [grep tn {"$tn" != "$luser"} $nlist]
601 if {![llength $oc]} {
609 proc msg_TOPIC {p c dest topic} {
611 if {![ischan $dest]} return
612 recordlastseen_n $n "changing the topic on $dest" 1
613 note_topic [irctolower $dest] $n $topic
616 proc msg_KICK {p c chans users comment} {
617 set chans [split $chans ,]
618 set users [split $users ,]
619 if {[llength $chans] > 1} {
620 foreach chan $chans user $users { process_kickpart $chan $user }
622 foreach user $users { process_kickpart [lindex $chans 0] $user }
626 proc msg_KILL {p c user why} {
631 set nick_arys {onchans username unique}
632 # nick_onchans($luser) -> [list ... $lchan ...]
633 # nick_username($luser) -> <securely known local username>
634 # nick_unique($luser) -> <includes-counter>
635 # nick_case($luser) -> $user (valid even if no longer visible)
636 # nick_markid($luser) -> <after id for marktime>
637 # nick_telling($luser) -> <unique> mentioned|passed <when>
639 # chan_nicks($lchan) -> [list ... $luser ...]
640 # chan_lastactivity($lchan) -> [clock seconds]
642 proc lnick_forget {luser} {
643 global nick_arys chan_nicks
644 lnick_marktime_cancel $luser
645 foreach ary $nick_arys {
646 upvar #0 nick_${ary}($luser) av
649 foreach lch [array names chan_nicks] {
650 upvar #0 chan_nicks($lch) nlist
651 set nlist [grep tn {"$tn" != "$luser"} $nlist]
656 proc nick_forget {user} {
657 global nick_arys chan_nicks
658 lnick_forget [irctolower $user]
662 proc nick_case {user} {
664 set nick_case([irctolower $user]) $user
667 proc msg_NICK {p c newnick} {
668 global nick_arys nick_case calling_nick
670 recordlastseen_n $n "changing nicks to $newnick" 0
671 set calling_nick $newnick
672 recordlastseen_n $newnick "changing nicks from $n" 1
673 set luser [irctolower $n]
674 lnick_marktime_cancel $luser
675 set lusernew [irctolower $newnick]
676 foreach ary $nick_arys {
677 upvar #0 nick_${ary}($luser) old
678 upvar #0 nick_${ary}($lusernew) new
679 if {[info exists new]} { error "nick collision ?! $ary $n $newnick" }
680 if {[info exists old]} { set new $old; unset old }
682 upvar #0 nick_onchans($lusernew) oc
684 upvar #0 chan_nicks($ch) nlist
685 set nlist [grep tn {"$tn" != "$luser"} $nlist]
686 lappend nlist $lusernew
688 lnick_marktime_start $lusernew "Hi." 500 1
692 proc nick_ishere {n} {
694 upvar #0 nick_unique([irctolower $n]) u
695 if {![info exists u]} { set u [incr nick_counter].$n.[clock seconds] }
699 proc msg_JOIN {p c chan} {
702 recordlastseen_n $n "joining $chan" 1
703 set nl [irctolower $n]
704 set lchan [irctolower $chan]
705 upvar #0 nick_onchans($nl) oc
706 upvar #0 chan_nicks($lchan) nlist
707 if {![info exists oc]} {
708 global marktime_join_startdelay
709 lnick_marktime_start $nl "Welcome." $marktime_join_startdelay 1
714 proc msg_PART {p c chan args} {
716 set msg "leaving $chan"
717 if {[llength $args]} {
718 set why [lindex $args 0]
719 if {"[irctolower $why]" != "[irctolower $n]"} { append msg " ($why)" }
721 recordlastseen_n $n $msg 1
722 process_kickpart $chan $n
724 proc msg_QUIT {p c why} {
726 recordlastseen_n $n "leaving ($why)" 0
730 proc msg_PRIVMSG {p c dest text} {
734 if {[ischan $dest]} {
735 recordlastseen_n $n "invoking me in $dest" 1
738 recordlastseen_n $n "talking to me" 1
743 execute_usercommand $p $c $n $output $dest $text
746 proc msg_INVITE {p c n chan} {
747 after 1000 [list dojoin [irctolower $chan]]
750 proc grep {var predicate list} {
754 if {[uplevel 1 [list expr $predicate]]} { lappend o $v }
759 proc msg_353 {p c dest type chan nicklist} {
760 global names_chans nick_onchans
761 set lchan [irctolower $chan]
762 upvar #0 chan_nicks($lchan) nlist
763 lappend names_chans $lchan
764 if {![info exists nlist]} {
765 # We don't think we're on this channel, so ignore it !
766 # Unfortunately, because we don't get a reply to PART,
767 # we have to remember ourselves whether we're on a channel,
768 # and ignore stuff if we're not, to avoid races. Feh.
772 foreach user [split $nicklist { }] {
773 regsub {^[@+]} $user {} user
774 if {![string length $user]} continue
776 set luser [irctolower $user]
777 upvar #0 nick_onchans($luser) oc
779 lappend nlist_new $luser
785 proc msg_366 {p c args} {
786 global names_chans nick_onchans
787 set lchan [irctolower $c]
788 foreach luser [array names nick_onchans] {
789 upvar #0 nick_onchans($luser) oc
790 if {[llength names_chans] > 1} {
791 set oc [grep tc {[lsearch -exact $tc $names_chans] >= 0} $oc]
793 if {![llength $oc]} { lnick_forget $luser }
798 proc somedb__head {} {
800 set idl [irctolower $id]
801 upvar #0 ${nickchan}db($idl) ndbe
802 binary scan $idl H* idh
803 set idfn $fprefix$idh
804 if {![info exists iddbe] && [file exists $idfn]} {
806 try_except_finally { set newval [read $f] } {} { close $f }
807 if {[llength $newval] % 2} { error "invalid length" }
813 proc def_somedb {name arglist body} {
814 foreach {nickchan fprefix} {
819 proc ${nickchan}db_$name $arglist \
820 "set nickchan $nickchan; set fprefix $fprefix; $body"
826 foreach path [glob -nocomplain -path $fprefix *] {
827 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
828 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
829 lappend list [binary format H* $thinghex]
834 proc def_somedb_id {name arglist body} {
835 def_somedb $name [concat id $arglist] "somedb__head; $body"
838 def_somedb_id exists {} {
839 return [info exists iddbe]
842 def_somedb_id delete {} {
843 catch { unset iddbe }
847 set default_settings_nick {
851 tellrel {remind 3600 30}
854 set default_settings_chan {
863 set default_settings_msgs {
867 # inbound -> [<nick> <time_t> <message>] ...
868 # outbound -> [<nick> <time_t(earliest)> <count>] ...
869 # neither are sorted particularly; only one entry per recipient in
870 # output; both sender and recipient are cased
872 def_somedb_id set {args} {
873 upvar #0 default_settings_$nickchan def
874 if {![info exists iddbe]} { set iddbe $def }
875 foreach {key value} [concat $iddbe $args] { set a($key) $value }
877 foreach {key value} [array get a] { lappend newval $key $value }
878 set f [open $idfn.new w]
882 file rename -force $idfn.new $idfn
890 def_somedb_id get {key} {
891 upvar #0 default_settings_$nickchan def
892 if {[info exists iddbe]} {
893 set l [concat $iddbe $def]
897 foreach {tkey value} $l {
898 if {![string compare $tkey $key]} { return $value }
900 error "unset setting $key"
905 if {[info exists calling_nick]} { set n $calling_nick } { set n {} }
906 return [nickdb_get $n $key]
909 proc check_notonchan {} {
911 if {[ischan $dest]} { usererror "That command must be sent privately." }
914 proc nick_securitycheck {strict} {
916 if {![nickdb_exists $n]} {
917 usererror "You are unknown to me, use `register'."
919 set wantu [nickdb_get $n username]
920 if {![string length $wantu]} {
922 usererror "That feature is only available to secure users, sorry."
927 set luser [irctolower $n]
928 upvar #0 nick_username($luser) nu
929 if {![info exists nu]} {
930 usererror "Nick $n is secure, you must identify yourself first."
932 if {"$wantu" != "$nu"} {
933 usererror "You are the wrong user -\
934 the nick $n belongs to $wantu, not $nu."
938 proc channel_ismanager {channel n} {
939 set mgrs [chandb_get $channel managers]
940 return [expr {[lsearch -exact [irctolower $mgrs] [irctolower $n]] >= 0}]
943 proc channel_securitycheck {channel} {
945 if {![channel_ismanager $channel $n]} {
946 usererror "You are not a manager of $channel."
951 proc def_chancmd {name body} {
952 proc channel/$name {} \
953 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
956 proc ta_listop {findnow procvalue} {
957 # findnow and procvalue are code fragments which will be executed
958 # in the caller's level. findnow should set ta_listop_ev to
959 # the current list, and procvalue should treat ta_listop_ev as
960 # a proposed value in the list and check and possibly modify
961 # (canonicalise?) it. After ta_listop, ta_listop_ev will
962 # be the new value of the list.
963 upvar 1 ta_listop_ev exchg
966 switch -exact _$opcode {
970 foreach item $exchg { set array($item) 1 }
973 error "list change opcode must be one of + - ="
976 foreach exchg [split $text " "] {
977 if {![string length $exchg]} continue
979 if {"$opcode" != "-"} {
982 catch { unset array($exchg) }
985 set exchg [lsort [array names array]]
988 def_chancmd manager {
990 if {[chandb_exists $chan]} {
991 set ta_listop_ev [chandb_get $chan managers]
993 set ta_listop_ev [list [irctolower $n]]
996 check_nick $ta_listop_ev
997 set ta_listop_ev [irctolower $ta_listop_ev]
999 if {[llength $ta_listop_ev]} {
1000 chandb_set $chan managers $ta_listop_ev
1001 ucmdr "Managers of $chan: $ta_listop_ev" {}
1004 ucmdr {} {} "forgets about managing $chan." {}
1008 def_chancmd autojoin {
1010 switch -exact [string tolower $yesno] {
1013 default { error "channel autojoin must be `yes' or `no' }
1015 chandb_set $chan autojoin $nv
1016 ucmdr [expr {$nv ? "I will join $chan when I'm restarted " : \
1017 "I won't join $chan when I'm restarted "}] {}
1020 def_chancmd userinvite {
1021 set nv [string tolower [ta_word]]
1023 pub { set txt "!invite will work for $chan, but it won't work by /msg" }
1024 here { set txt "!invite and /msg invite will work, but only for users who are already on $chan." }
1025 all { set txt "Any user will be able to invite themselves or anyone else to $chan." }
1026 none { set txt "I will not invite anyone to $chan." }
1028 error "channel userinvite must be `pub', `here', `all' or `none'
1031 chandb_set $chan userinvite $nv
1037 switch -exact $what {
1040 chandb_set $chan topicset {}
1041 ucmdr "I won't ever change the topic of $chan." {}
1044 set t [string trim $text]
1045 if {![string length $t]} {
1046 error "you must specific the topic to set"
1048 chandb_set $chan topicset $t
1049 ucmdr "Whenever I'm alone on $chan, I'll set the topic to $t." {}
1053 set ta_listop_ev [chandb_get $chan topic$what]
1055 if {"$ta_listop_ev" != "*"} {
1056 if {![ischan $ta_listop_ev]} {
1057 error "bad channel \`$ta_listop_ev' in topic $what"
1059 set ta_listop_ev [irctolower $ta_listop_ev]
1062 chandb_set $chan topic$what $ta_listop_ev
1063 ucmdr "Topic $what list for $chan: $ta_listop_ev" {}
1066 usererror "Unknown channel topic subcommand - see help channel."
1073 if {"$mode" != "*" && ![regexp {^(([-+][imnpst]+)+)$} $mode mode]} {
1074 error {channel mode must be * or match ([-+][imnpst]+)+}
1076 chandb_set $chan mode $mode
1077 if {![string compare $mode "*"]} {
1078 ucmdr "I won't ever change the mode of $chan." {}
1080 ucmdr "Whenever I'm alone on $chan, I'll set the mode to $mode." {}
1085 if {[chandb_exists $chan]} {
1086 set l "Settings for $chan: autojoin "
1087 append l [lindex {no yes} [chandb_get $chan autojoin]]
1088 append l ", mode " [chandb_get $chan mode]
1089 append l ", userinvite " [chandb_get $chan userinvite] "."
1090 append l "\nManagers: "
1091 append l [join [chandb_get $chan managers] " "]
1092 foreach {ts sep} {see "\n" tell " "} {
1093 set t [chandb_get $chan topic$ts]
1096 append l "Topic $ts list: $t."
1098 append l "Topic $ts list is empty."
1102 set t [chandb_get $chan topicset]
1103 if {[string length $t]} {
1104 append l "Topic to set: $t"
1106 append l "I will not change the topic."
1110 ucmdr {} "The channel $chan is not managed."
1114 proc channelmgr_monoop {} {
1119 upvar 1 target target
1124 if {[ischan $dest]} { set target $dest }
1125 if {[ta_anymore]} { set target [ta_word] }
1127 if {![info exists target]} {
1128 usererror "You must specify, or invoke me on, the relevant channel."
1130 if {![info exists chan_nicks([irctolower $target])]} {
1131 usererror "I am not on $target."
1133 if {![ischan $target]} { error "not a valid channel" }
1135 if {![chandb_exists $target]} {
1136 usererror "$target is not a managed channel."
1138 channel_securitycheck $target
1143 sendout MODE $target +o $n
1154 global chan_nicks errorCode errorInfo
1157 if {[ischan $dest]} {
1161 set target [ta_word]
1164 set ltarget [irctolower $target]
1165 if {![ischan $target]} { error "$target is not a channel" }
1166 if {![info exists chan_nicks($ltarget)]} {
1167 usererror "I am not on $target."
1169 set ui [chandb_get $ltarget userinvite]
1171 if {![string compare $ui "pub"] && !$onchan} {
1172 usererror "Invitations to $target must be made there with !invite."
1174 if {"$ui" != "all"} {
1175 if {[lsearch -exact $chan_nicks($ltarget) [irctolower $n]] < 0} {
1176 usererror "Invitations to $target may only be made\
1177 by a user on the channel."
1180 if {[!string compare $ui "none"]} {
1181 usererror "Sorry, I've not been authorised\
1182 to invite people to $target."
1185 if {![string compare $errorCode "BLIGHT USER"] &&
1186 [channel_ismanager $target $n]} {
1188 nick_securitycheck 1
1190 if {![string compare $errorCode "BLIGHT USER"]} {
1191 usererror "$emsg2 Therefore you can't use your\
1192 channel manager privilege. $emsg"
1194 error $error $errorInfo $errorCode
1198 error $emsg $errorInfo $errorCode
1201 if {![ta_anymore]} {
1202 usererror "You have to say who to invite."
1205 while {[ta_anymore]} {
1206 set invitee [ta_nick]
1207 lappend invitees $invitee
1209 foreach invitee $invitees {
1210 sendout INVITE $invitee $ltarget
1212 set who [lindex $invitees 0]
1213 switch -exact llength $invitees {
1214 0 { error "zero invitees" }
1216 2 { append who " and [lindex $invitees 1]" }
1218 set who [join [lreplace $invitees end end] ", "]
1219 append who " and [lindex $invitees [llength $invitees]]"
1222 ucmdr {} {} {} "invites $who to $target."
1226 if {[ischan $dest]} { set target $dest }
1227 if {![ta_anymore]} {
1230 set subcmd [ta_word]
1232 if {[ischan $subcmd]} {
1234 if {![ta_anymore]} {
1237 set subcmd [ta_word]
1240 if {![info exists target]} { error "privately, you must specify a channel" }
1241 set procname channel/$subcmd
1242 if {"$subcmd" != "show"} {
1243 if {[catch { info body $procname }]} {
1244 usererror "unknown channel setting $subcmd."
1247 if {[chandb_exists $target]} {
1248 channel_securitycheck $target
1250 nick_securitycheck 1
1251 upvar #0 chan_initialop([irctolower $target]) io
1252 upvar #0 nick_unique([irctolower $n]) u
1253 if {![info exists io]} {
1254 usererror "$target is not a managed channel."
1256 if {"$io" != "$u"} {
1257 usererror "You are not the interim manager of $target."
1259 if {"$subcmd" != "manager"} {
1260 usererror "Please use `channel manager' first."
1267 proc nickdb_get_username {n} {
1268 if {![nickdb_exists $n]} { return "" }
1269 return [nickdb_get $n username]
1272 proc nickdb_get_sec_effective {n} {
1273 set l [nickdb_get $n tellsec]
1274 set u [nickdb_get_username $n]
1275 if {![string compare [lindex $l 0] "secure"] &&
1276 ![string length $u]} { set l insecure }
1280 proc tell_peernicks {text} {
1281 global errorInfo errorCode
1282 set text [irctolower [string trim $text]]
1283 set senders [split $text " "]
1284 foreach sender $senders {
1285 if {[catch { check_nick $sender } emsg]} {
1286 error "invalid nick `$sender': $emsg" $errorInfo $errorCode
1292 proc msgsdb_set_maydelete {n key l otherkey} {
1293 msgsdb_set $n $key $l
1294 if {[llength $l]} return
1295 if {[llength [msgsdb_get $n $otherkey]]} return
1299 proc tell_delete_msgs {lsenders lrecip} {
1302 foreach {s t m} [msgsdb_get $lrecip inbound] {
1303 if {[llength $lsenders]} {
1304 if {[lsearch -exact $lsenders [irctolower $s]] == -1} {
1305 lappend new_inbound $s $t $m
1312 msgsdb_set_maydelete $lrecip inbound $new_inbound outbound
1313 if {![llength $new_inbound]} {
1314 upvar #0 nick_telling($lrecip) telling
1315 catch { unset telling }
1317 foreach s [array names rsenders] {
1319 foreach {r t c} [msgsdb_get $s outbound] {
1320 if {![ircnick_compare $r $lrecip]} continue
1321 lappend new_outbound $r $t $c
1323 msgsdb_set_maydelete $s outbound $new_outbound inbound
1331 if {[nickdb_exists $n]} { nick_securitycheck 0 }
1332 set recipients [tell_peernicks $text]
1333 if {![llength $recipients]} {
1334 usererror "You must say which recipients' messages from you to forget."
1337 foreach recip $recipients {
1338 incr ndel [tell_delete_msgs [irctolower $n] $recip]
1340 ucmdr "Removed $ndel as yet undelivered message(s)." {}
1343 def_ucmd_alias delmsgs delmsg
1345 global errorInfo errorCode
1347 set nl [irctolower $n]
1349 manyset [nickdb_get_sec_effective $n] sec secwhen
1350 switch -exact $sec {
1354 "There are no messages to delete\
1355 because your message disposition prevents them from being left."
1358 nick_securitycheck 1
1361 error "delmsg sec $sec"
1364 if {![llength [msgsdb_get $n inbound]]} {
1365 ucmdr "No incoming messages to delete." {}
1368 if {![info exists u]} {
1370 "I can't delete your messages unless I can see you on a channel with me.\
1371 Otherwise I might delete a message I hadn't told you about yet."
1373 if {"$stt" != "passed"} {
1374 set telling [list $u undelivered 0]
1376 "There are message(s) you may not yet have seen;\
1377 I'll deliver them to you now.\
1378 If you actually want to delete them, just tell me `delmsg' again."
1380 set senders [tell_peernicks $text]
1381 set ndel [tell_delete_msgs [irctolower $senders] [irctolower $n]]
1383 if {[llength $senders]} {
1384 ucmdr "No relevant incoming messages to delete." {}
1387 switch -exact [llength $senders] {
1388 0 { ucmdr {} {} "deletes your $ndel message(s)." }
1389 1 { ucmdr {} {} "deletes your $ndel message(s) from $senders." }
1391 ucmdr {} {} "deletes your $ndel message(s) from\
1392 [lreplace $senders end end] and/or [lindex $senders end]."
1401 manyset [nickdb_get $n tellsec] sec
1402 switch -exact $sec {
1403 reject { ucmdr "But, you asked me to reject messages for you !" {} }
1404 mailto { ucmdr "But, you asked me to mail your messages to you !" {} }
1406 switch -exact [tell_event [irctolower $n] tellme] {
1407 ERROR - INVALID { ucmdr {} {is ill. Help!} }
1408 nomsgs { ucmdr {You have no messages.} {} }
1414 global nick_case ownmailaddr ownfullname
1417 set target [ta_nick]
1418 if {![string length $text]} { error "tell them what?" }
1419 if {[string length $text] > 400} { error "message too long" }
1421 set ltarget [irctolower $target]
1423 if {[info exists nick_case($ltarget)]} { set ctarget $nick_case($ltarget) }
1425 manyset [nickdb_get_sec_effective $target] sec mailtoint mailwhy
1426 manyset [nickdb_get $target tellrel] rel relint relwithin
1427 switch -exact $sec {
1429 set now [clock seconds]
1430 set inbound [msgsdb_get $ltarget inbound]
1431 lappend inbound $n $now $text
1432 msgsdb_set $ltarget inbound $inbound
1434 set outbound [msgsdb_get $n outbound]
1437 foreach {recip time count} $outbound {
1438 if {![ircnick_compare $recip $ltarget]} {
1443 lappend noutbound $recip $time $count
1446 lappend noutbound $ctarget $now 1
1448 msgsdb_set $n outbound $noutbound
1449 set msg "OK, I'll tell $ctarget"
1450 if {$found} { append msg " that too" }
1452 if {"$sec" != "secure"} {
1453 switch -exact $rel {
1454 unreliable { append msg "neither reliably nor securely" }
1455 remind { append msg "pretty reliably, but not securely" }
1456 pester { append msg "reliably but not securely" }
1459 switch -exact $rel {
1460 unreliable { append msg "securely but not reliably" }
1461 remind { append msg "securely and pretty reliably" }
1462 pester { append msg "reliably and securely" }
1466 tell_event $ltarget msgsarrive
1470 set fmtmsg [exec fmt << " $text"]
1471 exec /usr/sbin/sendmail -odb -oi -t -oee -f $mailwhy \
1473 "From: $ownmailaddr ($ownfullname)
1475 Subject: IRC tell from $n
1477 $n asked me[expr {[ischan $dest] ? " on $dest" : ""}] to tell you:
1478 [exec fmt << " $text"]
1480 (This message was for your nick $ctarget; your account $mailwhy
1481 arranged for it to be forwarded to $mailtoint.)
1484 "I've mailed $ctarget, which is what they prefer." \
1488 usererror "Sorry, $ctarget does not want me to take messages."
1491 error "bad tellsec $sec"
1498 set target [ta_nick]; ta_nomore
1503 set myself [expr {"$target" != "$n"}]
1505 set ltarget [irctolower $target]
1506 upvar #0 nick_case($ltarget) ctarget
1508 if {[info exists ctarget]} {
1509 upvar #0 nick_onchans($ltarget) oc
1510 upvar #0 nick_username($ltarget) nu
1511 if {[info exists oc]} { set nshow $ctarget }
1513 if {![nickdb_exists $ltarget]} {
1514 set ol "$nshow is not a registered nick."
1515 } elseif {[string length [set username [nickdb_get $target username]]]} {
1516 set ol "The nick $nshow belongs to the user $username."
1518 set ol "The nick $nshow is registered (but not to a username)."
1520 if {![info exists ctarget] || ![info exists oc]} {
1522 append ol "\nI can't see $nshow on anywhere."
1524 append ol "\nYou aren't on any channels with me."
1526 } elseif {![info exists nu]} {
1527 append ol "\n$nshow has not identified themselves."
1528 } elseif {![info exists username]} {
1529 append ol "\n$nshow has identified themselves as the user $nu."
1530 } elseif {"$nu" != "$username"} {
1531 append ol "\nHowever, $nshow is being used by the user $nu."
1533 append ol "\n$nshow has identified themselves to me."
1541 set old [nickdb_exists $n]
1542 if {$old} { nick_securitycheck 0 }
1543 set luser [irctolower $n]
1544 switch -exact [string tolower [string trim $text]] {
1546 upvar #0 nick_username($luser) nu
1547 if {![info exists nu]} {
1549 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1551 nickdb_set $n username $nu
1552 ucmdr {} {} "makes a note of your username." {}
1556 ucmdr {} {} "forgets your nickname." {}
1559 nickdb_set $n username {}
1561 ucmdr {} "Security is now disabled for your nickname !"
1563 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."
1567 error "you mean register / register delete / register insecure"
1572 proc timeformat_desc {tf} {
1574 ks { return "Times will be displayed in seconds or kiloseconds." }
1575 hms { return "Times will be displayed in hours, minutes, etc." }
1576 beat { return "Times will be displayed in beats (1000B = 1d)." }
1577 default { error "invalid timeformat: $v" }
1582 proc def_setting {opt show_body set_body} {
1584 lappend settings $opt
1585 proc set_show/$opt {} "
1589 if {![string length $set_body]} return
1590 proc set_set/$opt {} "
1597 proc tellme_sec_desc {v n} {
1598 manyset $v sec mailtoint
1599 switch -exact $sec {
1601 return "I'll tell you your messages whenever I see you."
1604 if {[string length [nickdb_get_username $n]]} {
1606 "I'll keep the bodies of your messages private until you identify yourself, reminding you every [showintervalsecs $mailtoint 1]."
1609 "I'll tell you your messages whenever I see you.\
1610 (Secure message delivery is enabled, but your nick is not registered\
1611 securely. See `help register'.)"
1615 return "I shan't accept messages for you."
1618 return "I'll forward your messages by email to $mailtoint."
1621 error "bad tellsec $sec"
1626 proc tellme_rel_desc {v n} {
1627 manyset $v rel every within
1628 switch -exact $rel {
1630 return "As soon as I've told you message(s), I'll forget them\
1631 - note that this means messages can get lost !"
1637 set u ", or talk on channel within [showintervalsecs $within 1] of me having told you"
1640 error "bad tellrel $rel"
1643 return "After delivering messages, I'll remind you every\
1644 [showintervalsecs $every 1] until you say delmsg$u."
1647 def_setting timeformat {
1648 set tf [nickdb_get $n timeformat]
1649 return "$tf: [timeformat_desc $tf]"
1651 set tf [string tolower [ta_word]]
1653 set desc [timeformat_desc $tf]
1654 nickdb_set $n timeformat $tf
1658 proc marktime_desc {mt} {
1661 return "I will not send you periodic messages."
1664 return "I will send you one informational message when I see you."
1667 return "I'll send you a message every [showintervalsecs $mt 0]."
1672 def_setting marktime {
1673 set mt [nickdb_get $n marktime]
1675 if {[string match {[0-9]*} $mt]} { append p s }
1677 append p [marktime_desc $mt]
1681 set mt [string tolower [ta_word]]
1688 set mt [parse_interval $mt $marktime_min]
1691 nickdb_set $n marktime $mt
1692 lnick_marktime_start [irctolower $n] "So:" 500 0
1693 ucmdr {} [marktime_desc $mt]
1696 def_setting security {
1697 set s [nickdb_get $n username]
1698 if {[string length $s]} {
1699 return "Your nick, $n, is controlled by the user $s."
1701 return "Your nick, $n, is not secure."
1705 proc tellme_setting_sec_simple {} {
1713 proc tellme_setting_neednomsgs {} {
1715 if {[llength [msgsdb_get $n inbound]]} {
1716 usererror "You must delete the incoming messages you have, first."
1721 def_setting tellme {
1722 set secv [nickdb_get $n tellsec]
1723 set ms [tellme_sec_desc $secv $n]
1725 switch -exact $sec {
1727 set mr [tellme_rel_desc [nickdb_get $n tellrel] $n]
1735 set setting [string tolower [ta_word]]
1736 set nl [irctolower $n]
1737 switch -exact $setting {
1739 tellme_setting_sec_simple
1742 set every [ta_interval_optional 60 600]
1745 set v [list secure $every]
1748 tellme_setting_neednomsgs
1749 tellme_setting_sec_simple
1752 tellme_setting_neednomsgs
1754 upvar #0 nick_username($nl) nu
1755 if {!([info exists nu] && [string length $nu])} {
1757 "Sorry, you must register securely to have your messages mailed\
1758 (to prevent the use of this feature for spamming). See `help register'."
1761 set v [list mailto [ta_word] $nu]
1763 unreliable - pester - remind {
1764 manyset [nickdb_get $n tellsec] sec
1765 switch -exact $sec {
1768 "Sorry, I shan't change when I'll consider a message delivered, because\
1769 you've asked me not to keep messages, or to mail them to you.\
1770 You should say `set tellme secure' or some such, first."
1775 if {"$setting" != "unreliable"} {
1776 set every [ta_interval_optional 300 3600]
1779 if {![string compare $setting remind]} {
1780 set within [ta_interval_optional 5 30]
1781 if {$within > $every} {
1782 error "remind interval must be at least time to respond"
1789 error "invalid tellme setting $setting"
1792 nickdb_set $n tell$sr $v
1793 upvar #0 nick_telling($nl) telling
1794 catch { unset telling }
1795 ucmdr [tellme_${sr}_desc $v $n] {}
1798 proc lnick_checktold {luser} {
1799 set ml [msgsdb_get $luser outbound]
1800 if {![llength $ml]} return
1801 set is1 [expr {[llength $ml]==3}]
1802 set m1 "FYI, I haven't yet delivered your"
1804 set now [clock seconds]
1805 while {[llength $ml]} {
1807 set ml [lreplace $ml 0 2]
1808 set td [expr {$now-$t}]
1810 set iv [showinterval $td]
1812 set if1 "message to $r, $iv."
1814 set iv [showintervalsecs $td 0]
1815 set ifo "$r, $n messages, oldest $iv"
1816 set if1 "$n messages to $r, oldest $iv."
1819 sendprivmsg $luser "$m1 $if1"
1822 lappend ol " to $ifo[expr {[llength $ml] ? ";" : "."}]"
1825 sendprivmsg $luser "$m1 messages:"
1826 msendprivmsg $luser $ol
1833 if {![nickdb_exists $n]} {
1834 ucmdr {} "You are unknown to me and so have no settings. (Use `register'.)"
1836 if {![ta_anymore]} {
1838 foreach opt $settings {
1839 lappend ol [format "%-10s %s" $opt [set_show/$opt]]
1841 ucmdr {} [join $ol "\n"]
1844 if {[catch { info body set_show/$opt }]} {
1845 error "no setting $opt"
1847 if {![ta_anymore]} {
1848 ucmdr {} "$opt: [set_show/$opt]"
1850 nick_securitycheck 0
1851 if {[catch { info body set_set/$opt }]} {
1852 error "setting $opt cannot be set with `set'"
1859 def_ucmd identpass {
1862 set luser [irctolower $n]
1863 set username [ta_word]
1864 set passmd5 [md5sum "[ta_word]\n"]
1866 upvar #0 nick_onchans($luser) onchans
1867 if {![info exists onchans] || ![llength $onchans]} {
1868 ucmdr "You must be on a channel with me to identify yourself." {}
1870 check_username $username
1871 exec userv --timeout 3 $username << "$passmd5\n" > /dev/null \
1873 upvar #0 nick_username($luser) rec_username
1874 set rec_username $username
1875 after 50 [list tell_event $luser ident]
1876 ucmdr "Pleased to see you, $username." {}
1882 set target [ta_nick]
1883 if {![nickdb_exists $target]} { error "$target is not a registered nick." }
1884 set wantu [nickdb_get $target username]
1885 if {![string length $wantu]} { error "$target is insecurely registred." }
1886 upvar #0 nick_username([irctolower $n]) nu
1887 if {![info exists nu]} { error "You must identify yourself first." }
1888 if {"$wantu" != "$nu"} {
1889 error "You are the wrong user, $nu - $target belongs to $wantu."
1891 set reason "at request of user $nu"
1892 if {[ta_anymore]} { append reason "; $text" }
1893 sendout KILL $target $reason
1898 set target [ta_word]
1900 # fixme would be nice if the rest of the text was passed on instead
1901 check_username $target
1904 upvar #0 lastsummon($target) ls
1905 set now [clock seconds]
1906 if {[info exists ls]} {
1907 set interval [expr {$now - $ls}]
1908 if {$interval < 30} {
1910 "Please be patient; $target was summoned only [showinterval $interval]."
1913 regsub {^[^!]*!} $p {} path
1915 exec userv --timeout 3 $target irc-summon $n $path \
1916 [expr {[ischan $dest] ? "$dest" : ""}] \
1919 regsub -all "\n" $rv { / } rv
1922 if {[regexp {^problem (.*)} $rv dummy problem]} {
1923 ucmdr {} "The user `$target' $problem."
1924 } elseif {[regexp {^ok ([^ ]+) ([0-9]+)$} $rv dummy tty idlesince]} {
1925 set idletime [expr {$now - $idlesince}]
1927 ucmdr {} {} {} "invites $target ($tty[expr {
1928 $idletime > 10 ? ", idle for [showintervalsecs $idletime 0]" : ""
1930 [ischan $dest] ? "join us here" : "talk to you"
1933 error "unexpected response from userv service: $rv"
1937 proc md5sum {value} { lindex [exec md5sum << $value] 0 }
1940 global lastseen nick
1943 set nlower [irctolower $ncase]
1945 set now [clock seconds]
1946 if {![ircnick_compare $nlower $nick]} {
1947 usererror "I am not self-aware."
1948 } elseif {![info exists lastseen($nlower)]} {
1949 set rstr "I've never seen $ncase."
1951 manyset $lastseen($nlower) realnick time what
1952 set howlong [expr {$now - $time}]
1953 set string [showinterval $howlong]
1954 set rstr "I last saw $realnick $string, $what."
1956 if {[ischan $dest]} {
1961 upvar #0 lookedfor($nlower) lf
1962 if {[info exists lf]} { set oldvalue $lf } else { set oldvalue {} }
1963 set lf [list [list $now $n $where]]
1964 foreach v $oldvalue {
1965 if {![ircnick_compare [lindex $v 1] $n]} continue
1971 proc lnick_marktime_cancel {luser} {
1972 upvar #0 nick_markid($luser) mi
1973 if {![info exists mi]} return
1974 catch { after cancel $mi }
1978 proc lnick_marktime_doafter {luser why ms mentiontold} {
1979 lnick_marktime_cancel $luser
1980 upvar #0 nick_markid($luser) mi
1981 set mi [after $ms [list lnick_marktime_now $luser $why 0]]
1984 proc lnick_marktime_reset {luser} {
1985 set mt [nickdb_get $luser marktime]
1989 lnick_marktime_doafter $luser "Time passes." [expr {$mt*1000}] 0
1994 proc lnick_marktime_start {luser why ms mentiontold} {
1995 set mt [nickdb_get $luser marktime]
1998 lnick_marktime_cancel $luser
1999 if {$mentiontold} { after $ms [list lnick_checktold $luser] }
2002 lnick_marktime_doafter $luser $why $ms $mentiontold
2007 proc lnick_marktime_now {luser why mentiontold} {
2008 upvar #0 nick_onchans($luser) oc
2010 set calling_nick $luser
2011 sendprivmsg $luser [lnick_pingstring $why $oc ""]
2012 if {$mentiontold} { after 150 [list lnick_checktold $luser] }
2013 lnick_marktime_reset $luser
2016 proc lnick_pingstring {why oc apstring} {
2018 catch { exec uptime } uptime
2019 set nnicks [llength [array names nick_onchans]]
2021 {^ *([0-9:apm]+) +up.*, +(\d+) users?, +load average: +([0-9., ]+) *$} \
2022 $uptime dummy time users load]} {
2023 regsub -all , $load {} load
2024 set uptime "$time $nnicks/$users $load"
2026 append uptime ", $nnicks nicks"
2028 if {[llength $oc]} {
2032 upvar #0 chan_lastactivity($ch) la
2033 if {![info exists la]} continue
2034 if {$la <= $best_la} continue
2035 set since [showintervalsecs [expr {[clock seconds]-$la}] 1]
2036 set activity "$ch $since"
2043 append str " " $uptime " " $activity
2044 if {[string length $apstring]} { append str " " $apstring }
2050 set ln [irctolower $n]
2051 if {[ischan $dest]} {
2052 set oc [irctolower $dest]
2055 if {[info exists nick_onchans($ln)]} {
2056 set oc $nick_onchans($ln)
2060 if {[llength $oc]} { lnick_marktime_reset $ln }
2062 after 150 [list lnick_checktold $ln]
2063 ucmdr {} [lnick_pingstring "Pong!" $oc $text]
2066 proc ensure_globalsecret {} {
2069 if {[info exists globalsecret]} return
2070 set gsfile [open /dev/urandom r]
2071 fconfigure $gsfile -translation binary
2072 set globalsecret [read $gsfile 32]
2073 binary scan $globalsecret H* globalsecret
2080 if {[info exists operuserpass]} {
2081 eval sendout OPER $operuserpass
2083 foreach chan [chandb_list] {
2084 if {[chandb_get $chan autojoin]} { dojoin $chan }