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)." {}
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
[msgsdb_get
$n tellsec
] sec
1402 switch -exact $sec {
1403 refuse
{ ucmdr
"But, you asked me to refuse 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 {"[irctolower $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
} {
1659 if {"$mt" == "off"} {
1660 return "I will not send you periodic messages."
1661 } elseif
{"$mt" == "once"} {
1662 return "I will send you one informational message when I see you."
1664 return "I'll send you a message every [showintervalsecs $mt 0]."
1668 def_setting marktime
{
1669 set mt
[nickdb_get
$n marktime
]
1671 if {[string match
{[0-9]*} $mt]} { append p s
}
1673 append p
[marktime_desc
$mt]
1677 set mt
[string tolower
[ta_word
]]
1680 if {"$mt" == "off" ||
"$mt" == "once"} {
1682 set mt
[parse_interval
$mt $marktime_min]
1684 nickdb_set
$n marktime
$mt
1685 lnick_marktime_start
[irctolower
$n] "So:" 500 0
1686 ucmdr
{} [marktime_desc
$mt]
1689 def_setting security
{
1690 set s
[nickdb_get
$n username
]
1691 if {[string length
$s]} {
1692 return "Your nick, $n, is controlled by the user $s."
1694 return "Your nick, $n, is not secure."
1698 proc tellme_setting_sec_simple
{} {
1706 proc tellme_setting_neednomsgs
{} {
1708 if {[llength [msgsdb_get
$n inbound
]]} {
1709 usererror
"You must delete the incoming messages you have, first."
1714 def_setting tellme
{
1715 set secv
[nickdb_get
$n tellsec
]
1716 set ms
[tellme_sec_desc
$secv $n]
1718 switch -exact $sec {
1720 set mr
[tellme_rel_desc
[nickdb_get
$n tellrel
] $n]
1728 set setting
[string tolower
[ta_word
]]
1729 set nl
[irctolower
$n]
1730 switch -exact $setting {
1732 tellme_setting_sec_simple
1735 set every
[ta_interval_optional
60 600]
1738 set v
[list secure
$every]
1741 tellme_setting_neednomsgs
1742 tellme_setting_sec_simple
1745 tellme_setting_neednomsgs
1747 upvar #0 nick_username($nl) nu
1748 if {!([info exists nu
] && [string length
$nu])} {
1750 "Sorry, you must register securely to have your messages mailed\
1751 (to prevent the use of this feature for spamming). See `help register'."
1754 set v
[list mailto
[ta_word
] $nu]
1756 unreliable
- pester
- remind
{
1757 manyset
[nickdb_get
$n tellsec
] sec
1758 switch -exact $sec {
1761 "You can't change your message delivery conditions when\
1762 your message disposition prevents messages from being left."
1767 if {"$setting" != "unreliable"} {
1768 set every
[ta_interval_optional
300 3600]
1771 if {"$setting" == "remind"} {
1772 set within
[ta_interval_optional
5 30]
1773 if {$within > $every} {
1774 error "remind interval must be at least time to respond"
1781 error "invalid tellme setting $setting"
1784 nickdb_set
$n tell$sr $v
1785 upvar #0 nick_telling($nl) telling
1786 catch { unset telling
}
1787 ucmdr
[tellme_
${sr
}_desc
$v $n] {}
1790 proc lnick_checktold
{luser
} {
1791 set ml
[msgsdb_get
$luser outbound
]
1792 if {![llength $ml]} return
1793 set is1
[expr {[llength $ml]==3}]
1794 set m1
"FYI, I haven't yet delivered your"
1796 set now
[clock seconds
]
1797 while {[llength $ml]} {
1799 set ml
[lreplace $ml 0 2]
1800 set td
[expr {$now-$t}]
1802 set iv
[showinterval
$td]
1804 set if1
"message to $r, $iv."
1806 set iv
[showintervalsecs
$td 0]
1807 set ifo
"$r, $n messages, oldest $iv"
1808 set if1
"$n messages to $r, oldest $iv."
1811 sendprivmsg
$luser "$m1 $if1"
1814 lappend ol
" to $ifo[expr {[llength $ml] ? ";" : ".
"}]"
1817 sendprivmsg
$luser "$m1 messages:"
1818 msendprivmsg
$luser $ol
1825 if {![nickdb_exists
$n]} {
1826 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1828 if {![ta_anymore
]} {
1830 foreach opt
$settings {
1831 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1833 ucmdr
{} [join $ol "\n"]
1836 if {[catch { info body set_show
/$opt }]} {
1837 error "no setting $opt"
1839 if {![ta_anymore
]} {
1840 ucmdr
{} "$opt: [set_show/$opt]"
1842 nick_securitycheck
0
1843 if {[catch { info body set_set
/$opt }]} {
1844 error "setting $opt cannot be set with `set'"
1851 def_ucmd identpass
{
1854 set luser
[irctolower
$n]
1855 set username
[ta_word
]
1856 set passmd5
[md5sum
"[ta_word]\n"]
1858 upvar #0 nick_onchans($luser) onchans
1859 if {![info exists onchans
] ||
![llength $onchans]} {
1860 ucmdr
"You must be on a channel with me to identify yourself." {}
1862 check_username
$username
1863 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1865 upvar #0 nick_username($luser) rec_username
1866 set rec_username
$username
1867 after 50 [list tell_event
$luser ident
]
1868 ucmdr
"Pleased to see you, $username." {}
1874 set target
[ta_nick
]
1875 if {![nickdb_exists
$target]} { error "$target is not a registered nick." }
1876 set wantu
[nickdb_get
$target username
]
1877 if {![string length
$wantu]} { error "$target is insecurely registred." }
1878 upvar #0 nick_username([irctolower $n]) nu
1879 if {![info exists nu
]} { error "You must identify yourself first." }
1880 if {"$wantu" != "$nu"} {
1881 error "You are the wrong user, $nu - $target belongs to $wantu."
1883 set reason
"at request of user $nu"
1884 if {[ta_anymore
]} { append reason
"; $text" }
1885 sendout KILL
$target $reason
1889 set target
[ta_word
]
1891 # fixme would be nice if the rest of the text was passed on instead
1892 check_username
$target
1895 upvar #0 lastsummon($target) ls
1896 set now
[clock seconds
]
1897 if {[info exists ls
]} {
1898 set interval
[expr {$now - $ls}]
1899 if {$interval < 30} {
1901 "Please be patient; $target was summoned only [showinterval $interval]."
1904 regsub {^
[^
!]*!} $p {} path
1906 exec userv
--timeout 3 $target irc-summon
$n $path \
1907 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1910 regsub -all "\n" $rv { / } rv
1913 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1914 ucmdr
{} "The user `$target' $problem."
1915 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1916 set idletime
[expr {$now - $idlesince}]
1918 ucmdr
{} {} {} "invites $target ($tty[expr {
1919 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime 0]" : ""
1921 [ischan $dest] ? "join us here
" : "talk to you
"
1924 error "unexpected response from userv service: $rv"
1928 proc md5sum
{value
} { exec md5sum
<< $value }
1931 global lastseen nick
1934 set nlower
[irctolower
$ncase]
1936 set now
[clock seconds
]
1937 if {"$nlower" == "[irctolower $nick]"} {
1938 usererror
"I am not self-aware."
1939 } elseif
{![info exists lastseen
($nlower)]} {
1940 set rstr
"I've never seen $ncase."
1942 manyset
$lastseen($nlower) realnick
time what
1943 set howlong
[expr {$now - $time}]
1944 set string [showinterval
$howlong]
1945 set rstr
"I last saw $realnick $string, $what."
1947 if {[ischan
$dest]} {
1952 upvar #0 lookedfor($nlower) lf
1953 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1954 set lf
[list [list $now $n $where]]
1955 foreach v
$oldvalue {
1956 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1962 proc lnick_marktime_cancel
{luser
} {
1963 upvar #0 nick_markid($luser) mi
1964 if {![info exists mi
]} return
1965 catch { after cancel
$mi }
1969 proc lnick_marktime_doafter
{luser why ms mentiontold
} {
1970 lnick_marktime_cancel
$luser
1971 upvar #0 nick_markid($luser) mi
1972 set mi
[after $ms [list lnick_marktime_now
$luser $why 0]]
1975 proc lnick_marktime_reset
{luser
} {
1976 set mt
[nickdb_get
$luser marktime
]
1977 if {"$mt" == "off" ||
"$mt" == "once"} return
1978 lnick_marktime_doafter
$luser "Time passes." [expr {$mt*1000}] 0
1981 proc lnick_marktime_start
{luser why ms mentiontold
} {
1982 set mt
[nickdb_get
$luser marktime
]
1983 if {"$mt" == "off"} {
1984 lnick_marktime_cancel
$luser
1985 if {$mentiontold} { after $ms [list lnick_checktold
$luser] }
1987 lnick_marktime_doafter
$luser $why $ms $mentiontold
1991 proc lnick_marktime_now
{luser why mentiontold
} {
1992 upvar #0 nick_onchans($luser) oc
1994 set calling_nick
$luser
1995 sendprivmsg
$luser [lnick_pingstring
$why $oc ""]
1996 if {$mentiontold} { after 150 [list lnick_checktold
$luser] }
1997 lnick_marktime_reset
$luser
2000 proc lnick_pingstring
{why oc apstring
} {
2002 catch { exec uptime
} uptime
2003 set nnicks
[llength [array names nick_onchans
]]
2005 {^
*([0-9:apm
]+) +up.
*, +(\d
+) users?
, +load average
: +([0-9.
, ]+) *$} \
2006 $uptime dummy
time users
load]} {
2007 regsub -all , $load {} load
2008 set uptime
"$time $nnicks/$users $load"
2010 append uptime
", $nnicks nicks"
2012 if {[llength $oc]} {
2016 upvar #0 chan_lastactivity($ch) la
2017 if {![info exists la
]} continue
2018 if {$la <= $best_la} continue
2019 set since
[showintervalsecs
[expr {[clock seconds
]-$la}] 1]
2020 set activity
"$ch $since"
2027 append str
" " $uptime " " $activity
2028 if {[string length
$apstring]} { append str
" " $apstring }
2034 set ln
[irctolower
$n]
2035 if {[ischan
$dest]} {
2036 set oc
[irctolower
$dest]
2039 if {[info exists nick_onchans
($ln)]} {
2040 set oc
$nick_onchans($ln)
2044 if {[llength $oc]} { lnick_marktime_reset
$ln }
2046 after 150 [list lnick_checktold
$ln]
2047 ucmdr
{} [lnick_pingstring
"Pong!" $oc $text]
2050 proc ensure_globalsecret
{} {
2053 if {[info exists globalsecret
]} return
2054 set gsfile
[open /dev
/urandom r
]
2055 fconfigure $gsfile -translation binary
2056 set globalsecret
[read $gsfile 32]
2057 binary scan $globalsecret H
* globalsecret
2064 if {[info exists operuserpass
]} {
2065 eval sendout OPER
$operuserpass
2067 foreach chan
[chandb_list
] {
2068 if {[chandb_get
$chan autojoin
]} { dojoin
$chan }