9 defset marktime_min
300
10 defset marktime_join_startdelay
5000
12 proc privmsg_unlogged
{prefix ischan params
} {
14 [regexp {^
![a-z
][-a-z
]*[a-z
]( .
*)?
$} [lindex $params 1]]} {
17 # on-channel message, ignore
18 set chan
[lindex $params 0]
19 upvar #0 chan_lastactivity([irctolower $chan]) la
20 set la
[clock seconds
]
21 catch_logged
{ recordlastseen_p
$prefix "talking on $chan" 2 }
25 proc showintervalsecs
{howlong abbrev
} {
26 return [showintervalsecs
/[opt timeformat
] $howlong $abbrev]
29 proc formatsf
{pfx value
} {
30 foreach {min
format} { 100 %.0f
10 %.1f
0 %.2f
} {
31 set fval
[format $format $value]
32 if {$fval < $min} continue
33 return [format "$fval${pfx}" $value]
37 proc showintervalsecs
/beat
{howlong abbrev
} {
38 # We split in two to avoid overflow problems.
42 return [format "%.0fmB" [expr {round
($howlong * 1.157)*10} ]]
44 if {$howlong < 86400 } {
47 set value
[expr {$howlong / 86.4}]
51 set value
[expr {$howlong / 86400.0}]
54 return [formatsf
$pfx $value]
57 proc showintervalsecs
/ks
{howlong abbrev
} {
58 if {$howlong < 1000} {
61 if {$howlong < 1000000} {
68 set value
[expr "$howlong.0 / $scale"]
69 return [formatsf
$pfx $value]
73 proc format_qty
{qty unit abbrev
} {
76 append o
[string range
$unit 0 0]
80 if {$qty != 1} { append o s
}
85 proc showintervalsecs
/hms
{qty abbrev
} {
86 set ul
{second
60 minute
60 hour
24 day
7 week
}
88 while {[llength $ul] > 1 && $qty >= [set uv
[lindex $ul 1]]} {
89 set remainu
[lindex $ul 0]
90 set remainv
[expr {$qty % $uv}]
91 set qty
[expr {($qty-$remainv)/$uv}]
92 set ul
[lreplace $ul 0 1]
94 set o
[format_qty
$qty [lindex $ul 0] $abbrev]
96 if {!$abbrev} { append o
" " }
97 append o
[format_qty
$remainv $remainu $abbrev]
102 proc showinterval
{howlong
} {
106 return "[showintervalsecs $howlong 0] ago"
110 proc showtime
{when
} {
111 return [showinterval
[expr {[clock seconds
] - $when}]]
114 proc parse_interval
{specified min
} {
115 if {![regexp {^
([0-9]+)([a-z
]+)$} $specified dummy value unit
]} {
116 error "invalid syntax for interval"
118 switch -exact $unit {
126 default { error "unknown unit of time $unit" }
128 if {$value > 86400*21/$u} { error "interval too large" }
129 set result
[expr {round
($value*$u)}]
130 if {$result < $min} { error "interval too small (<${min}s)" }
134 proc def_msgproc
{name argl body
} {
135 proc msg_
$name "varbase $argl" "\
136 upvar #0 msg/\$varbase/dest d\n\
137 upvar #0 msg/\$varbase/str s\n\
138 upvar #0 msg/\$varbase/accum a\n\
142 def_msgproc begin
{dest str
} {
148 def_msgproc
append {str
} {
150 if {[string length
$s] && [string length
$ns] > 65} {
151 msg__sendout
$varbase
152 set s
" [string trimleft $str]"
158 def_msgproc finish
{} {
159 msg__sendout
$varbase
165 def_msgproc _sendout
{} {
166 lappend a
[string trimright
$s]
170 proc looking_whenwhere
{when where
} {
171 set str
[showtime
[expr {$when-1}]]
172 if {[string length
$where]} { append str
" on $where" }
176 proc tell_getcstate
{} {
177 # uses nl from caller's context
178 # imports telling (as the nick_telling) and u
179 # sets stt, telling_when
181 upvar #0 nick_telling($nl) telling
182 upvar #0 nick_unique($nl) u
184 if {[info exists telling
]} {
185 manyset
$telling u_last stt telling_when
186 if {![info exists u
] ||
"$u_last" != "$u"} {
196 proc tell_event
{nl
event} {
197 # For `act' we *haven't* yet done the 750ms delay; we implement
198 # that here. Also, here we turn `talk' into `talk' now and `act'
199 # later. We also support the psuedo-event `none'. The del msg
200 # and new msg events are handled by the command procedures, not here.
202 if {[info exists calling_nick
]} { set save
$calling_nick }
204 switch -exact $event {
207 tell_event_core
$nl talk
211 after 750 [list tell_event_core
$nl $event]
214 tell_event_core
$nl $event
217 set r
[tell_event_core
$nl TELLME
]
220 error "tell_event $nl $event"
223 if {[info exists save
]} { set calling_nick
$save }
227 proc tell_event_core
{nl
event} {
228 global tell_event_teventi errorInfo
229 set tell_event_teventi
"*$event* $nl"
231 tell_event_core1
$nl $event
233 log_intern
"tell event error" "$emsg >$errorInfo<"
236 log_intern
"tell event" "done $tell_event_teventi $emsg"
241 proc tell_event_core1
{nl
event} {
242 # event is `talk', `act', `ident', `msgsarrive' or `TELLME'
243 # When user talks we actually get talk now and act later
246 set iml
[msgsdb_get
$nl inbound
]
247 if {![llength $iml]} { return nomsgs
}
249 set now
[clock seconds
]
251 set ago
[expr {$now - $telling_when}]
253 # Now we have the components of a telling state
254 # u - nick_unique (unset if not visible)
255 # stt - state: undelivered, mentioned, passede
256 # ago - how long ago since we did anything
258 # We compute an evstate to dispatch on as follows:
260 # evstate is string of letters
262 # u UNDELIVERED (MESSAGES)
270 # T tellme (user command)
271 # security level and timing
273 # ss Secure and soon (before interval)
274 # sl Secure and late (after interval)
275 # current identification
278 # reliability and timing
280 # rv Remind, very soon (before within-interval)
281 # rs Remind, soon (between)
282 # rl Remind, late (after every-interval)
283 # ps Pester, soon (before interval)
284 # pl Pester, late (after interval)
288 append evstate
[string range
$stt 0 0]
289 append evstate
[string range
$event 0 0]
291 manyset
[nickdb_get_sec_effective
$nl] sec secwhen
293 insecure
{ append evstate ii
}
294 secure
{ append evstate
[expr {$ago<$secwhen ?
"ss" : "sl"}] }
295 default { append evstate
"#$sec#" }
298 upvar #0 nick_username($nl) nu
299 if {[info exists nu
] && "$nu" == "[nickdb_get_username $nl]"} {
305 manyset
[nickdb_get
$nl tellrel
] rel relint relwithin
307 unreliable
{ append evstate uu
}
308 remind
{ append evstate
[expr {
309 $ago<$relwithin ?
"rv" : $ago<$relint ?
"rs" : "rl"
311 pester
{ append evstate
[expr {$ago<$relint ?
"ps" : "pl"}] }
312 default { append evstate
"#$rel#" }
315 global tell_event_teventi
316 set tell_event_teventi
"$evstate $ago $nl"
317 switch -glob $evstate {
319 # consider delivered:
320 # (very recently passed, and the user talks)
321 set ndel
[tell_delete_msgs
{} $nl]
323 "I'm assuming you got the $ndel message(s) I just passed on."
327 # oops, messages passed are now out of date
328 catch_restoreei
{ unset telling
}
332 # ignore new msgs if we haven't passed yet
336 pt???uu
- pt???rs
- pt???rl
- pt???p?
{
337 # ignore (any other `talk's) - act handles these
341 uaii?uu
- uaii??l
- uas?iuu
- uas?i?l
-
344 # pass and then stuff
345 if {[llength $iml] == 3} {
346 manyset
$iml sender sentwhen msg
348 "$sender asked me, [showinterval [expr {$now-$sentwhen}]],\
352 "I have [expr {[llength $iml]/3}] messages for you:"
353 while {[llength $iml] >= 3} {
354 manyset
[lrange $iml 0 2] sender sentwhen msg
355 set iml
[lrange $iml 3 end
]
357 " [showintervalsecs [expr {$now-$sentwhen}] 1] <$sender> $msg"
360 if {"$rel" == "unreliable"} {
361 tell_delete_msgs
{} $nl
362 return toldunreliable
368 sendprivmsg
$nl {You have messages
(so identify yourself please
).
}
373 sendprivmsg
$nl {You must identify yourself to see your messages.
}
377 sendprivmsg
$nl {Don't forget about your messages.
}
383 mass???
- pa????v
- pa????s
-
391 error "tell_event_core nl=$nl evstate=$evstate ?"
394 if {![info exists u
]} {
395 set telling
[list {} undelivered
$now]
397 set telling
[list $u $stt $now]
402 proc recordlastseen_n
{n how here
} {
404 # 0 - nick was seen leaving (or changing to another nicks or some such)
405 # 1 - nick was seen doing something else
406 # 2 - nick was seen talking on channel
407 global lastseen lookedfor
408 set nl
[irctolower
$n]
409 set now
[clock seconds
]
410 set lastseen
($nl) [list $n $now $how]
414 tell_event
$nl [lindex {none act talk
} $here]
416 upvar #0 lookedfor($nl) lf
417 if {[info exists lf
]} {
418 switch -exact [llength $lf] {
423 manyset
[lindex $lf 0] when who where
425 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
428 msg_begin tosend
$n "FYI, people have been looking for you:"
434 msg_append tosend
" "
435 } elseif
{$i == [llength $lf]} {
436 msg_append tosend
" and "
439 msg_append tosend
", "
441 manyset
$e when who where
443 "$who ([looking_whenwhere $when $where])$fin"
445 set ml
[msg_finish tosend
]
449 msendprivmsg_delayed
1000 $n $ml
453 proc note_topic
{showoff whoby topic
} {
454 set msg
"FYI, $whoby has changed the topic on $showoff"
455 if {[string length
$topic] < 160} {
456 append msg
" to $topic"
458 append msg
" but it is too long to reproduce here !"
460 set showoff
[irctolower
$showoff]
461 set tell [chandb_get
$showoff topictell
]
462 if {[lsearch -exact $tell *] >= 0} {
463 set tryspies
[chandb_list
]
467 foreach spy
$tryspies {
468 set see
[chandb_get
$spy topicsee
]
469 if {[lsearch -exact $see $showoff] >= 0 ||
\
470 ([lsearch -exact $see *] >= 0 && \
471 [lsearch -exact $tell $spy] >= 0)} {
472 sendprivmsg
$spy $msg
477 proc recordlastseen_p
{p how here
} {
479 recordlastseen_n
$n $how $here
482 proc chanmode_arg
{} {
484 set rv
[lindex $cm_args 0]
485 set cm_args
[lreplace cm_args
0 0]
489 proc chanmode_o1
{m g p chan
} {
490 global nick chan_initialop
492 set who
[chanmode_arg
]
493 recordlastseen_n
$n "being nice to $who" 1
494 if {"[irctolower $who]" == "[irctolower $nick]"} {
495 set nlower
[irctolower
$n]
496 upvar #0 nick_unique($nlower) u
497 if {[chandb_exists
$chan]} {
498 sendprivmsg
$n Thanks.
499 } elseif
{![info exists u
]} {
500 sendprivmsg
$n {Op me
while not on the channel
, why don't you ?
}
502 set chan_initialop
([irctolower
$chan]) $u
504 "Thanks. You can use `channel manager ...' to register this channel."
505 if {![string length
[nickdb_get_username
$n username
]]} {
507 "(But to do that you must register your nick securely first.)"
513 proc chanmode_o0
{m g p chan
} {
516 set who
[chanmode_arg
]
517 recordlastseen_p
$p "being mean to $who" 1
518 if {"[irctolower $who]" == "[irctolower $nick]"} {
519 set chandeop
($chan) [list [clock seconds
] $p]
523 proc msg_MODE
{p c dest modelist args
} {
524 if {![ischan
$dest]} return
525 if {[regexp {^
\-(.
+)$} $modelist dummy modelist
]} {
527 } elseif
{[regexp {^
\+(.
+)$} $modelist dummy modelist
]} {
530 error "invalid modelist"
532 foreach m
[split $modelist] {
533 set procname chanmode_
$m$give
534 if {[catch { info body
$procname }]} {
535 recordlastseen_p
$p "fiddling with $dest" 1
537 $procname $m $give $p $dest
542 proc leaving
{lchan
} {
543 foreach luser
[array names nick_onchans
] {
544 upvar #0 nick_onchans($luser) oc
545 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
547 upvar #0 chan_nicks($lchan) nlist
549 upvar #0 chan_lastactivity($lchan) la
553 proc doleave
{lchan
} {
558 proc dojoin
{lchan
} {
561 set chan_nicks
($lchan) {}
564 proc check_justme
{lchan
} {
566 upvar #0 chan_nicks($lchan) nlist
567 if {[llength $nlist] != 1} return
568 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
569 if {[chandb_exists
$lchan]} {
570 set mode
[chandb_get
$lchan mode
]
571 if {"$mode" != "*"} {
572 sendout MODE
$lchan $mode
574 set topic
[chandb_get
$lchan topicset
]
575 if {[string length
$topic]} {
576 sendout TOPIC
$lchan $topic
583 proc process_kickpart
{chan user
} {
586 set luser
[irctolower
$user]
587 set lchan
[irctolower
$chan]
588 if {![ischan
$chan]} { error "not a channel" }
589 if {"$luser" == "[irctolower $nick]"} {
592 upvar #0 nick_onchans($luser) oc
593 upvar #0 chan_nicks($lchan) nlist
594 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
595 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
597 if {![llength $oc]} {
605 proc msg_TOPIC
{p c dest topic
} {
607 if {![ischan
$dest]} return
608 recordlastseen_n
$n "changing the topic on $dest" 1
609 note_topic
[irctolower
$dest] $n $topic
612 proc msg_KICK
{p c chans users comment
} {
613 set chans
[split $chans ,]
614 set users
[split $users ,]
615 if {[llength $chans] > 1} {
616 foreach chan
$chans user
$users { process_kickpart
$chan $user }
618 foreach user
$users { process_kickpart
[lindex $chans 0] $user }
622 proc msg_KILL
{p c user why
} {
627 set nick_arys
{onchans username unique
}
628 # nick_onchans($luser) -> [list ... $lchan ...]
629 # nick_username($luser) -> <securely known local username>
630 # nick_unique($luser) -> <includes-counter>
631 # nick_case($luser) -> $user (valid even if no longer visible)
632 # nick_markid($luser) -> <after id for marktime>
633 # nick_telling($luser) -> <unique> mentioned|passed <when>
635 # chan_nicks($lchan) -> [list ... $luser ...]
636 # chan_lastactivity($lchan) -> [clock seconds]
638 proc lnick_forget
{luser
} {
639 global nick_arys chan_nicks
640 lnick_marktime_cancel
$luser
641 foreach ary
$nick_arys {
642 upvar #0 nick_${ary}($luser) av
645 foreach lch
[array names chan_nicks
] {
646 upvar #0 chan_nicks($lch) nlist
647 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
652 proc nick_forget
{user
} {
653 global nick_arys chan_nicks
654 lnick_forget
[irctolower
$user]
658 proc nick_case
{user
} {
660 set nick_case
([irctolower
$user]) $user
663 proc msg_NICK
{p c newnick
} {
664 global nick_arys nick_case calling_nick
666 recordlastseen_n
$n "changing nicks to $newnick" 0
667 set calling_nick
$newnick
668 recordlastseen_n
$newnick "changing nicks from $n" 1
669 set luser
[irctolower
$n]
670 lnick_marktime_cancel
$luser
671 set lusernew
[irctolower
$newnick]
672 foreach ary
$nick_arys {
673 upvar #0 nick_${ary}($luser) old
674 upvar #0 nick_${ary}($lusernew) new
675 if {[info exists new
]} { error "nick collision ?! $ary $n $newnick" }
676 if {[info exists old
]} { set new
$old; unset old
}
678 upvar #0 nick_onchans($lusernew) oc
680 upvar #0 chan_nicks($ch) nlist
681 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
682 lappend nlist
$lusernew
684 lnick_marktime_start
$lusernew "Hi." 500 1
688 proc nick_ishere
{n
} {
690 upvar #0 nick_unique([irctolower $n]) u
691 if {![info exists u
]} { set u
[incr nick_counter
].
$n.
[clock seconds
] }
695 proc msg_JOIN
{p c chan
} {
698 recordlastseen_n
$n "joining $chan" 1
699 set nl
[irctolower
$n]
700 set lchan
[irctolower
$chan]
701 upvar #0 nick_onchans($nl) oc
702 upvar #0 chan_nicks($lchan) nlist
703 if {![info exists oc
]} {
704 global marktime_join_startdelay
705 lnick_marktime_start
$nl "Welcome." $marktime_join_startdelay 1
710 proc msg_PART
{p c chan args
} {
712 set msg
"leaving $chan"
713 if {[llength $args]} {
714 set why
[lindex $args 0]
715 if {"[irctolower $why]" != "[irctolower $n]"} { append msg
" ($why)" }
717 recordlastseen_n
$n $msg 1
718 process_kickpart
$chan $n
720 proc msg_QUIT
{p c why
} {
722 recordlastseen_n
$n "leaving ($why)" 0
726 proc msg_PRIVMSG
{p c dest
text} {
730 if {[ischan
$dest]} {
731 recordlastseen_n
$n "invoking me in $dest" 1
734 recordlastseen_n
$n "talking to me" 1
739 execute_usercommand
$p $c $n $output $dest $text
742 proc msg_INVITE
{p c n chan
} {
743 after 1000 [list dojoin
[irctolower
$chan]]
746 proc grep
{var predicate
list} {
750 if {[uplevel 1 [list expr $predicate]]} { lappend o
$v }
755 proc msg_353
{p c dest type chan nicklist
} {
756 global names_chans nick_onchans
757 set lchan
[irctolower
$chan]
758 upvar #0 chan_nicks($lchan) nlist
759 lappend names_chans
$lchan
760 if {![info exists nlist
]} {
761 # We don't think we're on this channel, so ignore it !
762 # Unfortunately, because we don't get a reply to PART,
763 # we have to remember ourselves whether we're on a channel,
764 # and ignore stuff if we're not, to avoid races. Feh.
768 foreach user
[split $nicklist { }] {
769 regsub {^
[@+]} $user {} user
770 if {![string length
$user]} continue
772 set luser
[irctolower
$user]
773 upvar #0 nick_onchans($luser) oc
775 lappend nlist_new
$luser
781 proc msg_366
{p c args
} {
782 global names_chans nick_onchans
783 set lchan
[irctolower
$c]
784 foreach luser
[array names nick_onchans
] {
785 upvar #0 nick_onchans($luser) oc
786 if {[llength names_chans
] > 1} {
787 set oc
[grep tc
{[lsearch -exact $tc $names_chans] >= 0} $oc]
789 if {![llength $oc]} { lnick_forget
$n }
794 proc check_username
{target
} {
796 [string length
$target] > 8 ||
797 [regexp {[^
-0-9a-z
]} $target] ||
798 ![regexp {^
[a-z
]} $target]
799 } { error "invalid username" }
802 proc somedb__head
{} {
804 set idl
[irctolower
$id]
805 upvar #0 ${nickchan}db($idl) ndbe
806 binary scan $idl H
* idh
807 set idfn
$fprefix$idh
808 if {![info exists iddbe
] && [file exists
$idfn]} {
810 try_except_finally
{ set newval
[read $f] } {} { close $f }
811 if {[llength $newval] % 2} { error "invalid length" }
817 proc def_somedb
{name arglist body
} {
818 foreach {nickchan fprefix
} {
823 proc ${nickchan
}db_
$name $arglist \
824 "set nickchan $nickchan; set fprefix $fprefix; $body"
830 foreach path
[glob -nocomplain -path $fprefix *] {
831 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
832 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
833 lappend list [binary format H
* $thinghex]
838 proc def_somedb_id
{name arglist body
} {
839 def_somedb
$name [concat id
$arglist] "somedb__head; $body"
842 def_somedb_id exists
{} {
843 return [info exists iddbe
]
846 def_somedb_id delete
{} {
847 catch { unset iddbe
}
851 set default_settings_nick
{
855 tellrel
{remind
3600 30}
858 set default_settings_chan
{
867 set default_settings_msgs
{
871 # inbound -> [<nick> <time_t> <message>] ...
872 # outbound -> [<nick> <time_t(earliest)> <count>] ...
873 # neither are sorted particularly; only one entry per recipient in
874 # output; both sender and recipient are cased
876 def_somedb_id
set {args
} {
877 upvar #0 default_settings_$nickchan def
878 if {![info exists iddbe
]} { set iddbe
$def }
879 foreach {key value
} [concat $iddbe $args] { set a
($key) $value }
881 foreach {key value
} [array get a
] { lappend newval
$key $value }
882 set f
[open $idfn.new w
]
886 file rename -force $idfn.new
$idfn
894 def_somedb_id get
{key
} {
895 upvar #0 default_settings_$nickchan def
896 if {[info exists iddbe
]} {
897 set l
[concat $iddbe $def]
901 foreach {tkey value
} $l {
902 if {"$tkey" == "$key"} { return $value }
904 error "unset setting $key"
909 if {[info exists calling_nick
]} { set n
$calling_nick } { set n
{} }
910 return [nickdb_get
$n $key]
913 proc check_notonchan
{} {
915 if {[ischan
$dest]} { usererror
"That command must be sent privately." }
918 proc nick_securitycheck
{strict
} {
920 if {![nickdb_exists
$n]} {
921 usererror
"You are unknown to me, use `register'."
923 set wantu
[nickdb_get
$n username
]
924 if {![string length
$wantu]} {
926 usererror
"That feature is only available to secure users, sorry."
931 set luser
[irctolower
$n]
932 upvar #0 nick_username($luser) nu
933 if {![info exists nu
]} {
934 usererror
"Nick $n is secure, you must identify yourself first."
936 if {"$wantu" != "$nu"} {
937 usererror
"You are the wrong user -\
938 the nick $n belongs to $wantu, not $nu."
942 proc channel_ismanager
{channel n
} {
943 set mgrs
[chandb_get
$channel managers
]
944 return [expr {[lsearch -exact [irctolower
$mgrs] [irctolower
$n]] >= 0}]
947 proc channel_securitycheck
{channel
} {
949 if {![channel_ismanager
$channel $n]} {
950 usererror
"You are not a manager of $channel."
955 proc def_chancmd
{name body
} {
956 proc channel
/$name {} \
957 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
960 proc ta_listop
{findnow procvalue
} {
961 # findnow and procvalue are code fragments which will be executed
962 # in the caller's level. findnow should set ta_listop_ev to
963 # the current list, and procvalue should treat ta_listop_ev as
964 # a proposed value in the list and check and possibly modify
965 # (canonicalise?) it. After ta_listop, ta_listop_ev will
966 # be the new value of the list.
967 upvar 1 ta_listop_ev exchg
970 switch -exact _
$opcode {
974 foreach item
$exchg { set array($item) 1 }
977 error "list change opcode must be one of + - ="
980 foreach exchg
[split $text " "] {
981 if {![string length
$exchg]} continue
983 if {"$opcode" != "-"} {
986 catch { unset array($exchg) }
989 set exchg
[lsort [array names
array]]
992 def_chancmd manager
{
994 if {[chandb_exists
$chan]} {
995 set ta_listop_ev
[chandb_get
$chan managers
]
997 set ta_listop_ev
[list [irctolower
$n]]
1000 check_nick
$ta_listop_ev
1001 set ta_listop_ev
[irctolower
$ta_listop_ev]
1003 if {[llength $ta_listop_ev]} {
1004 chandb_set
$chan managers
$ta_listop_ev
1005 ucmdr
"Managers of $chan: $ta_listop_ev" {}
1008 ucmdr
{} {} "forgets about managing $chan." {}
1012 def_chancmd autojoin
{
1014 switch -exact [string tolower
$yesno] {
1017 default { error "channel autojoin must be `yes' or `no' }
1019 chandb_set $chan autojoin $nv
1020 ucmdr [expr {$nv ? "I will
join $chan when I'm restarted
" : \
1021 "I won't
join $chan when I'm restarted
"}] {}
1024 def_chancmd userinvite {
1025 set nv [string tolower [ta_word]]
1027 pub { set txt "!invite will work
for $chan, but it won't work by
/msg
" }
1028 here { set txt "!invite and
/msg invite will work
, but only
for users who are already on
$chan.
" }
1029 all { set txt "Any user will be able to invite themselves or anyone
else to
$chan.
" }
1030 none { set txt "I will not invite anyone to
$chan.
" }
1032 error "channel userinvite must be `pub'
, `here'
, `all' or `none'
1035 chandb_set
$chan userinvite
$nv
1041 switch -exact $what {
1044 chandb_set
$chan topicset
{}
1045 ucmdr
"I won't ever change the topic of $chan." {}
1048 set t
[string trim
$text]
1049 if {![string length
$t]} {
1050 error "you must specific the topic to set"
1052 chandb_set
$chan topicset
$t
1053 ucmdr
"Whenever I'm alone on $chan, I'll set the topic to $t." {}
1057 set ta_listop_ev
[chandb_get
$chan topic
$what]
1059 if {"$ta_listop_ev" != "*"} {
1060 if {![ischan
$ta_listop_ev]} {
1061 error "bad channel \`$ta_listop_ev' in topic $what"
1063 set ta_listop_ev
[irctolower
$ta_listop_ev]
1066 chandb_set
$chan topic
$what $ta_listop_ev
1067 ucmdr
"Topic $what list for $chan: $ta_listop_ev" {}
1070 usererror
"Unknown channel topic subcommand - see help channel."
1077 if {"$mode" != "*" && ![regexp {^
(([-+][imnpst
]+)+)$} $mode mode
]} {
1078 error {channel mode must be
* or match
([-+][imnpst
]+)+}
1080 chandb_set
$chan mode
$mode
1081 if {"$mode" == "*"} {
1082 ucmdr
"I won't ever change the mode of $chan." {}
1084 ucmdr
"Whenever I'm alone on $chan, I'll set the mode to $mode." {}
1089 if {[chandb_exists
$chan]} {
1090 set l
"Settings for $chan: autojoin "
1091 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
1092 append l
", mode " [chandb_get
$chan mode
]
1093 append l
", userinvite " [chandb_get
$chan userinvite
] "."
1094 append l
"\nManagers: "
1095 append l
[join [chandb_get
$chan managers
] " "]
1096 foreach {ts sep
} {see
"\n" tell " "} {
1097 set t
[chandb_get
$chan topic
$ts]
1100 append l
"Topic $ts list: $t."
1102 append l
"Topic $ts list is empty."
1106 set t
[chandb_get
$chan topicset
]
1107 if {[string length
$t]} {
1108 append l
"Topic to set: $t"
1110 append l
"I will not change the topic."
1114 ucmdr
{} "The channel $chan is not managed."
1118 proc channelmgr_monoop
{} {
1123 upvar 1 target target
1128 if {[ischan
$dest]} { set target
$dest }
1129 if {[ta_anymore
]} { set target
[ta_word
] }
1131 if {![info exists target
]} {
1132 usererror
"You must specify, or invoke me on, the relevant channel."
1134 if {![info exists chan_nicks
([irctolower
$target])]} {
1135 usererror
"I am not on $target."
1137 if {![ischan
$target]} { error "not a valid channel" }
1139 if {![chandb_exists
$target]} {
1140 usererror
"$target is not a managed channel."
1142 channel_securitycheck
$target
1147 sendout MODE
$target +o
$n
1156 global chan_nicks errorCode errorInfo
1159 if {[ischan
$dest]} {
1163 set target
[ta_word
]
1166 set ltarget
[irctolower
$target]
1167 if {![ischan
$target]} { error "$target is not a channel" }
1168 if {![info exists chan_nicks
($ltarget)]} {
1169 usererror
"I am not on $target."
1171 set ui
[chandb_get
$ltarget userinvite
]
1173 if {"$ui" == "pub" && !$onchan} {
1174 usererror
"Invitations to $target must be made there with !invite."
1176 if {"$ui" != "all"} {
1177 if {[lsearch -exact $chan_nicks($ltarget) [irctolower
$n]] < 0} {
1178 usererror
"Invitations to $target may only be made\
1179 by a user on the channel."
1182 if {"$ui" == "none"} {
1183 usererror
"Sorry, I've not been authorised\
1184 to invite people to $target."
1187 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager
$target $n]} {
1189 nick_securitycheck
1
1191 if {"$errorCode" == "BLIGHT USER"} {
1192 usererror
"$emsg2 Therefore you can't use your\
1193 channel manager privilege. $emsg"
1195 error $error $errorInfo $errorCode
1199 error $emsg $errorInfo $errorCode
1202 if {![ta_anymore
]} {
1203 usererror
"You have to say who to invite."
1206 while {[ta_anymore
]} {
1207 set invitee
[ta_nick
]
1208 lappend invitees
$invitee
1210 foreach invitee
$invitees {
1211 sendout INVITE
$invitee $ltarget
1213 set who
[lindex $invitees 0]
1214 switch -exact llength $invitees {
1215 0 { error "zero invitees" }
1217 2 { append who
" and [lindex $invitees 1]" }
1219 set who
[join [lreplace $invitees end end
] ", "]
1220 append who
" and [lindex $invitees [llength $invitees]]"
1223 ucmdr
{} {} {} "invites $who to $target."
1227 if {[ischan
$dest]} { set target
$dest }
1228 if {![ta_anymore
]} {
1231 set subcmd
[ta_word
]
1233 if {[ischan
$subcmd]} {
1235 if {![ta_anymore
]} {
1238 set subcmd
[ta_word
]
1241 if {![info exists target
]} { error "privately, you must specify a channel" }
1242 set procname channel
/$subcmd
1243 if {"$subcmd" != "show"} {
1244 if {[catch { info body
$procname }]} {
1245 usererror
"unknown channel setting $subcmd."
1248 if {[chandb_exists
$target]} {
1249 channel_securitycheck
$target
1251 nick_securitycheck
1
1252 upvar #0 chan_initialop([irctolower $target]) io
1253 upvar #0 nick_unique([irctolower $n]) u
1254 if {![info exists io
]} {
1255 usererror
"$target is not a managed channel."
1257 if {"$io" != "$u"} {
1258 usererror
"You are not the interim manager of $target."
1260 if {"$subcmd" != "manager"} {
1261 usererror
"Please use `channel manager' first."
1268 proc nickdb_get_username
{n
} {
1269 if {![nickdb_exists
$n]} { return "" }
1270 return [nickdb_get
$n username
]
1273 proc nickdb_get_sec_effective
{n
} {
1274 set l
[nickdb_get
$n tellsec
]
1275 set u
[nickdb_get_username
$n]
1276 if {"[lindex $l 0]" == "secure" && ![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 ninbound
$s $t $m
1312 msgsdb_set_maydelete
$lrecip inbound
$ninbound outbound
1313 if {![llength $ninbound]} {
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 {"[irctolower $r]" == "$lrecip"} continue
1321 lappend noutbound
$r $t $c
1323 msgsdb_set_maydelete
$s outbound
$noutbound inbound
1331 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)." {}
1344 global errorInfo errorCode
1346 set nl
[irctolower
$n]
1348 manyset
[nickdb_get_sec_effective
$n] sec secwhen
1349 switch -exact $sec {
1353 "There are no messages to delete\
1354 because your message disposition prevents them from being left."
1357 nick_securitycheck
1
1360 error "delmsg sec $sec"
1363 if {![llength [msgsdb_get
$n inbound
]]} {
1364 ucmdr
"No incoming messages to delete." {}
1367 if {![info exists u
]} {
1369 "I can't delete your messages unless I can see you on a channel with me.\
1370 Otherwise I might delete a message I hadn't told you about yet."
1372 if {"$stt" != "passed"} {
1373 set telling
[list $u undelivered
0]
1375 "There are message(s) you may not yet have seen;\
1376 I'll deliver them to you now.\
1377 If you actually want to delete them, just tell me `delmsg' again."
1379 set senders
[tell_peernicks
$text]
1380 set ndel
[tell_delete_msgs
[irctolower
$senders] [irctolower
$n]]
1382 if {[llength $senders]} {
1383 ucmdr
"No relevant incoming messages to delete." {}
1386 switch -exact [llength $senders] {
1387 0 { ucmdr
{} {} "deletes your $ndel message(s)." }
1388 1 { ucmdr
{} {} "deletes your $ndel message(s) from $senders." }
1390 ucmdr
{} {} "deletes your $ndel message(s) from\
1391 [lreplace $senders end end] and [lindex $senders end]."
1400 switch -exact [tell_event
[irctolower
$n] tellme
] {
1401 ERROR
- INVALID
{ ucmdr
{} {is ill. Help
!} }
1402 nomsgs
{ ucmdr
{You have no messages.
} {} }
1408 global nick_case ownmailaddr ownfullname
1411 set target
[ta_nick
]
1412 if {![string length
$text]} { error "tell them what?" }
1413 if {[string length
$text] > 400} { error "message too long" }
1415 set ltarget
[irctolower
$target]
1417 if {[info exists nick_case
($ltarget)]} { set ctarget
$nick_case($ltarget) }
1419 manyset
[nickdb_get_sec_effective
$target] sec mailtoint mailwhy
1420 manyset
[nickdb_get
$target tellrel
] rel relint relwithin
1421 switch -exact $sec {
1423 set now
[clock seconds
]
1424 set inbound
[msgsdb_get
$ltarget inbound
]
1425 lappend inbound
$n $now $text
1426 msgsdb_set
$ltarget inbound
$inbound
1428 set outbound
[msgsdb_get
$n outbound
]
1431 foreach {recip
time count
} $outbound {
1432 if {"[irctolower $recip]" == "$ltarget"} {
1437 lappend noutbound
$recip $time $count
1440 lappend noutbound
$ctarget $now 1
1442 msgsdb_set
$n outbound
$noutbound
1443 set msg
"OK, I'll tell $ctarget"
1444 if {$found} { append msg
" that too" }
1446 if {"$sec" != "secure"} {
1447 switch -exact $rel {
1448 unreliable
{ append msg
"neither reliably nor securely" }
1449 remind
{ append msg
"pretty reliably, but not securely" }
1450 pester
{ append msg
"reliably but not securely" }
1453 switch -exact $rel {
1454 unreliable
{ append msg
"securely but not reliably" }
1455 remind
{ append msg
"securely and pretty reliably" }
1456 pester
{ append msg
"reliably and securely" }
1460 tell_event
$ltarget msgsarrive
1464 set fmtmsg
[exec fmt
<< " $text"]
1465 exec /usr
/sbin
/sendmail
-odb -oi -t -oee -f $mailwhy \
1467 "From: $ownmailaddr ($ownfullname)
1469 Subject: IRC tell from $n
1471 $n asked me[expr {[ischan $dest] ? " on
$dest" : ""}] to tell you:
1472 [exec fmt << " $text"]
1474 (This message was for your nick $ctarget; your account $mailwhy
1475 arranged for it to be forwarded to $mailtoint.)
1478 "I've mailed $ctarget, which is what they prefer." \
1482 usererror
"Sorry, $ctarget does not want me to take messages."
1485 error "bad tellsec $sec"
1492 set target
[ta_nick
]; ta_nomore
1497 set myself
[expr {"$target" != "$n"}]
1499 set ltarget
[irctolower
$target]
1500 upvar #0 nick_case($ltarget) ctarget
1502 if {[info exists ctarget
]} {
1503 upvar #0 nick_onchans($ltarget) oc
1504 upvar #0 nick_username($ltarget) nu
1505 if {[info exists oc
]} { set nshow
$ctarget }
1507 if {![nickdb_exists
$ltarget]} {
1508 set ol
"$nshow is not a registered nick."
1509 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
1510 set ol
"The nick $nshow belongs to the user $username."
1512 set ol
"The nick $nshow is registered (but not to a username)."
1514 if {![info exists ctarget
] ||
![info exists oc
]} {
1516 append ol
"\nI can't see $nshow on anywhere."
1518 append ol
"\nYou aren't on any channels with me."
1520 } elseif
{![info exists nu
]} {
1521 append ol
"\n$nshow has not identified themselves."
1522 } elseif
{![info exists username
]} {
1523 append ol
"\n$nshow has identified themselves as the user $nu."
1524 } elseif
{"$nu" != "$username"} {
1525 append ol
"\nHowever, $nshow is being used by the user $nu."
1527 append ol
"\n$nshow has identified themselves to me."
1535 set old
[nickdb_exists
$n]
1536 if {$old} { nick_securitycheck
0 }
1537 set luser
[irctolower
$n]
1538 switch -exact [string tolower
[string trim
$text]] {
1540 upvar #0 nick_username($luser) nu
1541 if {![info exists nu
]} {
1543 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1545 nickdb_set
$n username
$nu
1546 ucmdr
{} {} "makes a note of your username." {}
1550 ucmdr
{} {} "forgets your nickname." {}
1553 nickdb_set
$n username
{}
1555 ucmdr
{} "Security is now disabled for your nickname !"
1557 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."
1561 error "you mean register / register delete / register insecure"
1566 proc timeformat_desc
{tf
} {
1568 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1569 hms
{ return "Times will be displayed in hours, minutes, etc." }
1570 beat
{ return "Times will be displayed in beats (1000B = 1d)." }
1571 default { error "invalid timeformat: $v" }
1576 proc def_setting
{opt show_body set_body
} {
1578 lappend settings
$opt
1579 proc set_show
/$opt {} "
1583 if {![string length
$set_body]} return
1584 proc set_set
/$opt {} "
1591 proc tellme_sec_desc
{v n
} {
1592 manyset
$v sec mailtoint
1593 switch -exact $sec {
1595 return "I'll tell you your messages whenever I see you."
1598 if {[string length
[nickdb_get_username
$n]]} {
1600 "I'll keep the bodies of your messages private until you identify yourself, reminding you every [showintervalsecs $mailtoint 1]."
1603 "I'll tell you your messages whenever I see you.\
1604 (Secure message delivery is enabled, but your nick is not registered\
1605 securely. See `help register'.)"
1609 return "I shan't accept messages for you."
1612 return "I'll forward your messages by email to $mailtoint."
1615 error "bad tellsec $sec"
1620 proc tellme_rel_desc
{v n
} {
1621 manyset
$v rel every within
1622 switch -exact $rel {
1624 return "As soon as I've told you message(s), I'll forget them\
1625 - note that this means messages can get lost !"
1631 set u
", or talk on channel within [showintervalsecs $within 1] of me having told you"
1634 error "bad tellrel $rel"
1637 return "After delivering messages, I'll remind you every\
1638 [showintervalsecs $every 1] until you say delmsg$u."
1641 def_setting timeformat
{
1642 set tf
[nickdb_get
$n timeformat
]
1643 return "$tf: [timeformat_desc $tf]"
1645 set tf
[string tolower
[ta_word
]]
1647 set desc
[timeformat_desc
$tf]
1648 nickdb_set
$n timeformat
$tf
1652 proc marktime_desc
{mt
} {
1653 if {"$mt" == "off"} {
1654 return "I will not send you periodic messages."
1655 } elseif
{"$mt" == "once"} {
1656 return "I will send you one informational message when I see you."
1658 return "I'll send you a message every [showintervalsecs $mt 0]."
1662 def_setting marktime
{
1663 set mt
[nickdb_get
$n marktime
]
1665 if {[string match
{[0-9]*} $mt]} { append p s
}
1667 append p
[marktime_desc
$mt]
1671 set mt
[string tolower
[ta_word
]]
1674 if {"$mt" == "off" ||
"$mt" == "once"} {
1676 set mt
[parse_interval
$mt $marktime_min]
1678 nickdb_set
$n marktime
$mt
1679 lnick_marktime_start
[irctolower
$n] "So:" 500 0
1680 ucmdr
{} [marktime_desc
$mt]
1683 def_setting security
{
1684 set s
[nickdb_get
$n username
]
1685 if {[string length
$s]} {
1686 return "Your nick, $n, is controlled by the user $s."
1688 return "Your nick, $n, is not secure."
1692 proc tellme_setting_sec_simple
{} {
1700 proc tellme_setting_neednomsgs
{} {
1702 if {[llength [msgsdb_get
$n inbound
]]} {
1703 usererror
"You must delete the incoming messages you have, first."
1708 def_setting tellme
{
1709 set secv
[nickdb_get
$n tellsec
]
1710 set ms
[tellme_sec_desc
$secv $n]
1712 switch -exact $sec {
1714 set mr
[tellme_rel_desc
[nickdb_get
$n tellrel
] $n]
1722 set setting
[string tolower
[ta_word
]]
1723 switch -exact $setting {
1725 tellme_setting_sec_simple
1728 set every
[ta_interval_optional
60 600]
1731 set v
[list secure
$every]
1734 tellme_setting_neednomsgs
1735 tellme_setting_sec_simple
1738 tellme_setting_neednomsgs
1740 if {![string length
[set u
[nickdb_get_username
$n]]]} {
1742 "Sorry, you must register securely to have your messages mailed\
1743 (to prevent the use of this feature for spamming). See `help register'."
1746 set v
[list mailto
[ta_word
] $u]
1748 unreliable
- pester
- remind
{
1749 manyset
[nickdb_get
$n tellsec
] sec
1750 switch -exact $sec {
1753 "You can't change your message delivery conditions when\
1754 your message disposition prevents messages from being left."
1759 if {"$setting" != "unreliable"} {
1760 set every
[ta_interval_optional
300 3600]
1763 if {"$setting" == "remind"} {
1764 set within
[ta_interval_optional
5 30]
1765 if {$within > $every} {
1766 error "remind interval must be at least time to respond"
1773 error "invalid tellme setting $setting"
1776 nickdb_set
$n tell$sr $v
1777 upvar #0 nick_telling([irctolower $n]) telling
1778 catch { unset telling
}
1779 ucmdr
[tellme_
${sr
}_desc
$v $n] {}
1782 proc lnick_checktold
{luser
} {
1783 set ml
[msgsdb_get
$luser outbound
]
1784 if {![llength $ml]} return
1785 set is1
[expr {[llength $ml]==3}]
1786 set m1
"FYI, I haven't yet delivered your"
1788 set now
[clock seconds
]
1789 while {[llength $ml]} {
1791 set ml
[lreplace $ml 0 2]
1792 set td
[expr {$now-$t}]
1794 set iv
[showinterval
$td]
1796 set if1
"message to $r, $iv."
1798 set iv
[showintervalsecs
$td 0]
1799 set ifo
"$r, $n messages, oldest $iv"
1800 set if1
"$n messages to $r, oldest $iv."
1803 sendprivmsg
$luser "$m1 $if1"
1806 lappend ol
" to $ifo[expr {[llength $ml] ? ";" : ".
"}]"
1809 sendprivmsg
$luser "$m1 messages:"
1810 msendprivmsg
$luser $ol
1817 if {![nickdb_exists
$n]} {
1818 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1820 if {![ta_anymore
]} {
1822 foreach opt
$settings {
1823 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1825 ucmdr
{} [join $ol "\n"]
1828 if {[catch { info body set_show
/$opt }]} {
1829 error "no setting $opt"
1831 if {![ta_anymore
]} {
1832 ucmdr
{} "$opt: [set_show/$opt]"
1834 nick_securitycheck
0
1835 if {[catch { info body set_set
/$opt }]} {
1836 error "setting $opt cannot be set with `set'"
1843 def_ucmd identpass
{
1846 set luser
[irctolower
$n]
1847 set username
[ta_word
]
1848 set passmd5
[md5sum
"[ta_word]\n"]
1850 upvar #0 nick_onchans($luser) onchans
1851 if {![info exists onchans
] ||
![llength $onchans]} {
1852 ucmdr
"You must be on a channel with me to identify yourself." {}
1854 check_username
$username
1855 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1857 upvar #0 nick_username($luser) rec_username
1858 set rec_username
$username
1859 after 50 [list tell_event
$luser ident
]
1860 ucmdr
"Pleased to see you, $username." {}
1866 set target
[ta_nick
]
1867 if {![nickdb_exists
$target]} { error "$target is not a registered nick." }
1868 set wantu
[nickdb_get
$target username
]
1869 if {![string length
$wantu]} { error "$target is insecurely registred." }
1870 upvar #0 nick_username([irctolower $n]) nu
1871 if {![info exists nu
]} { error "You must identify yourself first." }
1872 if {"$wantu" != "$nu"} {
1873 error "You are the wrong user, $nu - $target belongs to $wantu."
1875 set reason
"at request of user $nu"
1876 if {[ta_anymore
]} { append reason
"; $text" }
1877 sendout KILL
$target $reason
1881 set target
[ta_word
]
1883 # fixme would be nice if the rest of the text was passed on instead
1884 check_username
$target
1887 upvar #0 lastsummon($target) ls
1888 set now
[clock seconds
]
1889 if {[info exists ls
]} {
1890 set interval
[expr {$now - $ls}]
1891 if {$interval < 30} {
1893 "Please be patient; $target was summoned only [showinterval $interval]."
1896 regsub {^
[^
!]*!} $p {} path
1898 exec userv
--timeout 3 $target irc-summon
$n $path \
1899 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1902 regsub -all "\n" $rv { / } rv
1905 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1906 ucmdr
{} "The user `$target' $problem."
1907 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1908 set idletime
[expr {$now - $idlesince}]
1910 ucmdr
{} {} {} "invites $target ($tty[expr {
1911 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime 0]" : ""
1913 [ischan $dest] ? "join us here
" : "talk to you
"
1916 error "unexpected response from userv service: $rv"
1920 proc md5sum
{value
} { exec md5sum
<< $value }
1923 global lastseen nick
1926 set nlower
[irctolower
$ncase]
1928 set now
[clock seconds
]
1929 if {"$nlower" == "[irctolower $nick]"} {
1930 usererror
"I am not self-aware."
1931 } elseif
{![info exists lastseen
($nlower)]} {
1932 set rstr
"I've never seen $ncase."
1934 manyset
$lastseen($nlower) realnick
time what
1935 set howlong
[expr {$now - $time}]
1936 set string [showinterval
$howlong]
1937 set rstr
"I last saw $realnick $string, $what."
1939 if {[ischan
$dest]} {
1944 upvar #0 lookedfor($nlower) lf
1945 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1946 set lf
[list [list $now $n $where]]
1947 foreach v
$oldvalue {
1948 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1954 proc lnick_marktime_cancel
{luser
} {
1955 upvar #0 nick_markid($luser) mi
1956 if {![info exists mi
]} return
1957 catch { after cancel
$mi }
1961 proc lnick_marktime_doafter
{luser why ms mentiontold
} {
1962 lnick_marktime_cancel
$luser
1963 upvar #0 nick_markid($luser) mi
1964 set mi
[after $ms [list lnick_marktime_now
$luser $why 0]]
1967 proc lnick_marktime_reset
{luser
} {
1968 set mt
[nickdb_get
$luser marktime
]
1969 if {"$mt" == "off" ||
"$mt" == "once"} return
1970 lnick_marktime_doafter
$luser "Time passes." [expr {$mt*1000}] 0
1973 proc lnick_marktime_start
{luser why ms mentiontold
} {
1974 set mt
[nickdb_get
$luser marktime
]
1975 if {"$mt" == "off"} {
1976 lnick_marktime_cancel
$luser
1977 if {$mentiontold} { after $ms [list lnick_checktold
$luser] }
1979 lnick_marktime_doafter
$luser $why $ms $mentiontold
1983 proc lnick_marktime_now
{luser why mentiontold
} {
1984 upvar #0 nick_onchans($luser) oc
1986 set calling_nick
$luser
1987 sendprivmsg
$luser [lnick_pingstring
$why $oc ""]
1988 if {$mentiontold} { after 150 [list lnick_checktold
$luser] }
1989 lnick_marktime_reset
$luser
1992 proc lnick_pingstring
{why oc apstring
} {
1994 catch { exec uptime
} uptime
1995 set nnicks
[llength [array names nick_onchans
]]
1997 {^
*([0-9:apm
]+) +up.
*, +(\d
+) users?
, +load average
: +([0-9.
, ]+) *$} \
1998 $uptime dummy
time users
load]} {
1999 regsub -all , $load {} load
2000 set uptime
"$time $nnicks/$users $load"
2002 append uptime
", $nnicks nicks"
2004 if {[llength $oc]} {
2008 upvar #0 chan_lastactivity($ch) la
2009 if {![info exists la
]} continue
2010 if {$la <= $best_la} continue
2011 set since
[showintervalsecs
[expr {[clock seconds
]-$la}] 1]
2012 set activity
"$ch $since"
2019 append str
" " $uptime " " $activity
2020 if {[string length
$apstring]} { append str
" " $apstring }
2026 set ln
[irctolower
$n]
2027 if {[ischan
$dest]} {
2028 set oc
[irctolower
$dest]
2031 if {[info exists nick_onchans
($ln)]} {
2032 set oc
$nick_onchans($ln)
2036 if {[llength $oc]} { lnick_marktime_reset
$ln }
2038 after 150 [list lnick_checktold
$ln]
2039 ucmdr
{} [lnick_pingstring
"Pong!" $oc $text]
2042 proc ensure_globalsecret
{} {
2045 if {[info exists globalsecret
]} return
2046 set gsfile
[open /dev
/urandom r
]
2047 fconfigure $gsfile -translation binary
2048 set globalsecret
[read $gsfile 32]
2049 binary scan $globalsecret H
* globalsecret
2056 if {[info exists operuserpass
]} {
2057 eval sendout OPER
$operuserpass
2059 foreach chan
[chandb_list
] {
2060 if {[chandb_get
$chan autojoin
]} { dojoin
$chan }