9 proc privmsg_unlogged {prefix ischan params} {
11 [regexp {^![a-z][-a-z]*[a-z]( .*)?$} [lindex $params 1]]} {
14 # on-channel message, ignore
15 set chan [lindex $params 0]
16 upvar #0 chan_lastactivity([irctolower $chan]) la
17 set la [clock seconds]
18 catch { recordlastseen_p $prefix "talking on $chan" 1 }
22 proc showintervalsecs {howlong abbrev} {
23 return [showintervalsecs/[opt timeformat] $howlong $abbrev]
26 proc formatsf {pfx value} {
27 foreach {min format} { 100 %.0f 10 %.1f 0 %.2f} {
28 set fval [format $format $value]
29 if {$fval < $min} continue
30 return [format "$fval${pfx}" $value]
34 proc showintervalsecs/beat {howlong abbrev} {
35 # We split in two to avoid overflow problems.
39 return [format "%.0fmB" [expr {round($howlong * 1.157)*10} ]]
41 if {$howlong < 86400 } {
44 set value [expr {$howlong / 86.4}]
48 set value [expr {$howlong / 86400.0}]
51 return [formatsf $pfx $value]
54 proc showintervalsecs/ks {howlong abbrev} {
55 if {$howlong < 1000} {
58 if {$howlong < 1000000} {
65 set value [expr "$howlong.0 / $scale"]
66 return [formatsf $pfx $value]
70 proc format_qty {qty unit abbrev} {
73 append o [string range $unit 0 0]
77 if {$qty != 1} { append o s }
82 proc showintervalsecs/hms {qty abbrev} {
83 set ul {second 60 minute 60 hour 24 day 7 week}
85 while {[llength $ul] > 1 && $qty >= [set uv [lindex $ul 1]]} {
86 set remainu [lindex $ul 0]
87 set remainv [expr {$qty % $uv}]
88 set qty [expr {($qty-$remainv)/$uv}]
89 set ul [lreplace $ul 0 1]
91 set o [format_qty $qty [lindex $ul 0] $abbrev]
93 if {!$abbrev} { append o " " }
94 append o [format_qty $remainv $remainu $abbrev]
99 proc showinterval {howlong} {
103 return "[showintervalsecs $howlong 0] ago"
107 proc showtime {when} {
108 return [showinterval [expr {[clock seconds] - $when}]]
111 proc def_msgproc {name argl body} {
112 proc msg_$name "varbase $argl" "\
113 upvar #0 msg/\$varbase/dest d\n\
114 upvar #0 msg/\$varbase/str s\n\
115 upvar #0 msg/\$varbase/accum a\n\
119 def_msgproc begin {dest str} {
125 def_msgproc append {str} {
127 if {[string length $s] && [string length $ns] > 65} {
128 msg__sendout $varbase
129 set s " [string trimleft $str]"
135 def_msgproc finish {} {
136 msg__sendout $varbase
142 def_msgproc _sendout {} {
143 lappend a [string trimright $s]
147 proc looking_whenwhere {when where} {
148 set str [showtime [expr {$when-1}]]
149 if {[string length $where]} { append str " on $where" }
153 proc recordlastseen_n {n how here} {
154 global lastseen lookedfor
155 set lastseen([irctolower $n]) [list $n [clock seconds] $how]
157 upvar #0 lookedfor([irctolower $n]) lf
158 if {[info exists lf]} {
159 switch -exact [llength $lf] {
164 manyset [lindex $lf 0] when who where
166 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
169 msg_begin tosend $n "FYI, people have been looking for you:"
175 msg_append tosend " "
176 } elseif {$i == [llength $lf]} {
177 msg_append tosend " and "
180 msg_append tosend ", "
182 manyset $e when who where
184 "$who ([looking_whenwhere $when $where])$fin"
186 set ml [msg_finish tosend]
190 msendprivmsg_delayed 1000 $n $ml
194 proc note_topic {showoff whoby topic} {
195 set msg "FYI, $whoby has changed the topic on $showoff"
196 if {[string length $topic] < 160} {
197 append msg " to $topic"
199 append msg " but it is too long to reproduce here !"
201 set showoff [irctolower $showoff]
202 set tell [chandb_get $showoff topictell]
203 if {[lsearch -exact $tell *] >= 0} {
204 set tryspies [chandb_list]
208 foreach spy $tryspies {
209 set see [chandb_get $spy topicsee]
210 if {[lsearch -exact $see $showoff] >= 0 || \
211 ([lsearch -exact $see *] >= 0 && \
212 [lsearch -exact $tell $spy] >= 0)} {
213 sendprivmsg $spy $msg
218 proc recordlastseen_p {p how here} {
220 recordlastseen_n $n $how $here
223 proc chanmode_arg {} {
225 set rv [lindex $cm_args 0]
226 set cm_args [lreplace cm_args 0 0]
230 proc chanmode_o1 {m g p chan} {
231 global nick chan_initialop
233 set who [chanmode_arg]
234 recordlastseen_n $n "being nice to $who" 1
235 if {"[irctolower $who]" == "[irctolower $nick]"} {
236 set nlower [irctolower $n]
237 upvar #0 nick_unique($nlower) u
238 if {[chandb_exists $chan]} {
239 sendprivmsg $n Thanks.
240 } elseif {![info exists u]} {
241 sendprivmsg $n {Op me while not on the channel, why don't you ?}
243 set chan_initialop([irctolower $chan]) $u
245 "Thanks. You can use `channel manager ...' to register this channel."
246 if {![nickdb_exists $n] || ![string length [nickdb_get $n username]]} {
248 "(But to do that you must register your nick securely first.)"
254 proc chanmode_o0 {m g p chan} {
257 set who [chanmode_arg]
258 recordlastseen_p $p "being mean to $who" 1
259 if {"[irctolower $who]" == "[irctolower $nick]"} {
260 set chandeop($chan) [list [clock seconds] $p]
264 proc msg_MODE {p c dest modelist args} {
265 if {![ischan $dest]} return
266 if {[regexp {^\-(.+)$} $modelist dummy modelist]} {
268 } elseif {[regexp {^\+(.+)$} $modelist dummy modelist]} {
271 error "invalid modelist"
273 foreach m [split $modelist] {
274 set procname chanmode_$m$give
275 if {[catch { info body $procname }]} {
276 recordlastseen_p $p "fiddling with $dest" 1
278 $procname $m $give $p $dest
283 proc leaving {lchan} {
285 foreach luser [array names nick_onchans] {
286 upvar #0 nick_onchans($luser) oc
287 set oc [grep tc {"$tc" != "$lchan"} $oc]
289 upvar #0 chan_nicks($lchan) nlist
291 upvar #0 chan_lastactivity($lchan) la
295 proc doleave {lchan} {
300 proc dojoin {lchan} {
303 set chan_nicks($lchan) {}
306 proc check_justme {lchan} {
308 upvar #0 chan_nicks($lchan) nlist
309 if {[llength $nlist] != 1} return
310 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
311 if {[chandb_exists $lchan]} {
312 set mode [chandb_get $lchan mode]
313 if {"$mode" != "*"} {
314 sendout MODE $lchan $mode
316 set topic [chandb_get $lchan topicset]
317 if {[string length $topic]} {
318 sendout TOPIC $lchan $topic
325 proc process_kickpart {chan user} {
328 set luser [irctolower $user]
329 set lchan [irctolower $chan]
330 if {![ischan $chan]} { error "not a channel" }
331 if {"$luser" == "[irctolower $nick]"} {
334 upvar #0 nick_onchans($luser) oc
335 upvar #0 chan_nicks($lchan) nlist
336 set oc [grep tc {"$tc" != "$lchan"} $oc]
337 set nlist [grep tn {"$tn" != "$luser"} $nlist]
339 if {![llength $oc]} {
347 proc msg_TOPIC {p c dest topic} {
349 if {![ischan $dest]} return
350 recordlastseen_n $n "changing the topic on $dest" 1
351 note_topic [irctolower $dest] $n $topic
354 proc msg_KICK {p c chans users comment} {
355 set chans [split $chans ,]
356 set users [split $users ,]
357 if {[llength $chans] > 1} {
358 foreach chan $chans user $users { process_kickpart $chan $user }
360 foreach user $users { process_kickpart [lindex $chans 0] $user }
364 proc msg_KILL {p c user why} {
369 set nick_arys {onchans username unique}
370 # nick_onchans($luser) -> [list ... $lchan ...]
371 # nick_username($luser) -> <securely known local username>
372 # nick_unique($luser) -> <counter>
373 # nick_case($luser) -> $user (valid even if no longer visible)
374 # nick_markid($luser) -> <after id for marktime>
376 # chan_nicks($lchan) -> [list ... $luser ...]
377 # chan_lastactivity($lchan) -> [clock seconds]
379 proc lnick_forget {luser} {
380 global nick_arys chan_nicks
381 lnick_marktime_cancel $luser
382 foreach ary $nick_arys {
383 upvar #0 nick_${ary}($luser) av
386 foreach lch [array names chan_nicks] {
387 upvar #0 chan_nicks($lch) nlist
388 set nlist [grep tn {"$tn" != "$luser"} $nlist]
393 proc nick_forget {user} {
394 global nick_arys chan_nicks
395 lnick_forget [irctolower $user]
399 proc nick_case {user} {
401 set nick_case([irctolower $user]) $user
404 proc msg_NICK {p c newnick} {
405 global nick_arys nick_case calling_nick
407 recordlastseen_n $n "changing nicks to $newnick" 0
408 set calling_nick $newnick
409 recordlastseen_n $newnick "changing nicks from $n" 1
410 set luser [irctolower $n]
411 lnick_marktime_cancel $luser
412 set lusernew [irctolower $newnick]
413 foreach ary $nick_arys {
414 upvar #0 nick_${ary}($luser) old
415 upvar #0 nick_${ary}($lusernew) new
416 if {[info exists new]} { error "nick collision ?! $ary $n $newnick" }
417 if {[info exists old]} { set new $old; unset old }
419 upvar #0 nick_onchans($lusernew) oc
421 upvar #0 chan_nicks($ch) nlist
422 set nlist [grep tn {"$tn" != "$luser"} $nlist]
423 lappend nlist $lusernew
425 lnick_marktime_start $lusernew "Hi." 500
429 proc nick_ishere {n} {
431 upvar #0 nick_unique([irctolower $n]) u
432 if {![info exists u]} { set u [incr nick_counter].$n.[clock seconds] }
436 proc msg_JOIN {p c chan} {
438 recordlastseen_n $n "joining $chan" 1
439 set nl [irctolower $n]
440 set lchan [irctolower $chan]
441 upvar #0 nick_onchans($nl) oc
442 upvar #0 chan_nicks($lchan) nlist
443 if {![info exists oc]} {
444 global marktime_join_startdelay
445 lnick_marktime_start $nl "Welcome." $marktime_join_startdelay
451 proc msg_PART {p c chan args} {
453 set msg "leaving $chan"
454 if {[llength $args]} {
455 set why [lindex $args 0]
456 if {"[irctolower $why]" != "[irctolower $n]"} { append msg " ($why)" }
458 recordlastseen_n $n $msg 1
459 process_kickpart $chan $n
461 proc msg_QUIT {p c why} {
463 recordlastseen_n $n "leaving ($why)" 0
467 proc msg_PRIVMSG {p c dest text} {
471 if {[ischan $dest]} {
472 recordlastseen_n $n "invoking me in $dest" 1
475 recordlastseen_n $n "talking to me" 1
480 execute_usercommand $p $c $n $output $dest $text
483 proc msg_INVITE {p c n chan} {
484 after 1000 [list dojoin [irctolower $chan]]
487 proc grep {var predicate list} {
491 if {[uplevel 1 [list expr $predicate]]} { lappend o $v }
496 proc msg_353 {p c dest type chan nicklist} {
497 global names_chans nick_onchans
498 set lchan [irctolower $chan]
499 upvar #0 chan_nicks($lchan) nlist
500 lappend names_chans $lchan
501 if {![info exists nlist]} {
502 # We don't think we're on this channel, so ignore it !
503 # Unfortunately, because we don't get a reply to PART,
504 # we have to remember ourselves whether we're on a channel,
505 # and ignore stuff if we're not, to avoid races. Feh.
509 foreach user [split $nicklist { }] {
510 regsub {^[@+]} $user {} user
511 if {![string length $user]} continue
513 set luser [irctolower $user]
514 upvar #0 nick_onchans($luser) oc
516 lappend nlist_new $luser
522 proc msg_366 {p c args} {
523 global names_chans nick_onchans
524 set lchan [irctolower $c]
525 foreach luser [array names nick_onchans] {
526 upvar #0 nick_onchans($luser) oc
527 if {[llength names_chans] > 1} {
528 set oc [grep tc {[lsearch -exact $tc $names_chans] >= 0} $oc]
530 if {![llength $oc]} { lnick_forget $luser }
535 proc check_username {target} {
537 [string length $target] > 8 ||
538 [regexp {[^-0-9a-z]} $target] ||
539 ![regexp {^[a-z]} $target]
540 } { error "invalid username" }
543 proc somedb__head {} {
545 set idl [irctolower $id]
546 upvar #0 ${nickchan}db($idl) ndbe
547 binary scan $idl H* idh
548 set idfn $fprefix$idh
549 if {![info exists iddbe] && [file exists $idfn]} {
551 try_except_finally { set newval [read $f] } {} { close $f }
552 if {[llength $newval] % 2} { error "invalid length" }
558 proc def_somedb {name arglist body} {
559 foreach {nickchan fprefix} {nick users/n chan chans/c} {
560 proc ${nickchan}db_$name $arglist \
561 "set nickchan $nickchan; set fprefix $fprefix; $body"
567 foreach path [glob -nocomplain -path $fprefix *] {
568 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
569 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
570 lappend list [binary format H* $thinghex]
575 proc def_somedb_id {name arglist body} {
576 def_somedb $name [concat id $arglist] "somedb__head; $body"
579 def_somedb_id exists {} {
580 return [info exists iddbe]
583 def_somedb_id delete {} {
584 catch { unset iddbe }
588 set default_settings_nick {timeformat ks marktime off}
589 set default_settings_chan {
598 def_somedb_id set {args} {
599 upvar #0 default_settings_$nickchan def
600 if {![info exists iddbe]} { set iddbe $def }
601 foreach {key value} [concat $iddbe $args] { set a($key) $value }
603 foreach {key value} [array get a] { lappend newval $key $value }
604 set f [open $idfn.new w]
608 file rename -force $idfn.new $idfn
616 def_somedb_id get {key} {
617 upvar #0 default_settings_$nickchan def
618 if {[info exists iddbe]} {
619 set l [concat $iddbe $def]
623 foreach {tkey value} $l {
624 if {"$tkey" == "$key"} { return $value }
626 error "unset setting $key"
631 if {[info exists calling_nick]} { set n $calling_nick } { set n {} }
632 return [nickdb_get $n $key]
635 proc check_notonchan {} {
637 if {[ischan $dest]} { usererror "That command must be sent privately." }
640 proc nick_securitycheck {strict} {
642 if {![nickdb_exists $n]} {
643 usererror "You are unknown to me, use `register'."
645 set wantu [nickdb_get $n username]
646 if {![string length $wantu]} {
648 usererror "That feature is only available to secure users, sorry."
653 set luser [irctolower $n]
654 upvar #0 nick_username($luser) nu
655 if {![info exists nu]} {
656 usererror "Nick $n is secure, you must identify yourself first."
658 if {"$wantu" != "$nu"} {
659 usererror "You are the wrong user -\
660 the nick $n belongs to $wantu, not $nu."
664 proc channel_ismanager {channel n} {
665 set mgrs [chandb_get $channel managers]
666 return [expr {[lsearch -exact [irctolower $mgrs] [irctolower $n]] >= 0}]
669 proc channel_securitycheck {channel} {
671 if {![channel_ismanager $channel $n]} {
672 usererror "You are not a manager of $channel."
677 proc def_chancmd {name body} {
678 proc channel/$name {} \
679 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
682 proc ta_listop {findnow procvalue} {
683 # findnow and procvalue are code fragments which will be executed
684 # in the caller's level. findnow should set ta_listop_ev to
685 # the current list, and procvalue should treat ta_listop_ev as
686 # a proposed value in the list and check and possibly modify
687 # (canonicalise?) it. After ta_listop, ta_listop_ev will
688 # be the new value of the list.
689 upvar 1 ta_listop_ev exchg
692 switch -exact _$opcode {
696 foreach item $exchg { set array($item) 1 }
699 error "list change opcode must be one of + - ="
702 foreach exchg [split $text " "] {
703 if {![string length $exchg]} continue
705 if {"$opcode" != "-"} {
708 catch { unset array($exchg) }
711 set exchg [lsort [array names array]]
714 def_chancmd manager {
716 if {[chandb_exists $chan]} {
717 set ta_listop_ev [chandb_get $chan managers]
719 set ta_listop_ev [list [irctolower $n]]
722 check_nick $ta_listop_ev
723 set ta_listop_ev [irctolower $ta_listop_ev]
725 if {[llength $ta_listop_ev]} {
726 chandb_set $chan managers $ta_listop_ev
727 ucmdr "Managers of $chan: $ta_listop_ev" {}
730 ucmdr {} {} "forgets about managing $chan." {}
734 def_chancmd autojoin {
736 switch -exact [string tolower $yesno] {
739 default { error "channel autojoin must be `yes' or `no' }
741 chandb_set $chan autojoin $nv
742 ucmdr [expr {$nv ? "I will join $chan when I'm restarted " : \
743 "I won't join $chan when I'm restarted "}] {}
746 def_chancmd userinvite {
747 set nv [string tolower [ta_word]]
749 pub { set txt "!invite will work for $chan, but it won't work by /msg" }
750 here { set txt "!invite and /msg invite will work, but only for users who are already on $chan." }
751 all { set txt "Any user will be able to invite themselves or anyone else to $chan." }
752 none { set txt "I will not invite anyone to $chan." }
754 error "channel userinvite must be `pub', `here', `all' or `none'
757 chandb_set $chan userinvite $nv
763 switch -exact $what {
766 chandb_set $chan topicset {}
767 ucmdr "I won't ever change the topic of $chan." {}
770 set t [string trim $text]
771 if {![string length $t]} {
772 error "you must specific the topic to set"
774 chandb_set $chan topicset $t
775 ucmdr "Whenever I'm alone on $chan, I'll set the topic to $t." {}
779 set ta_listop_ev [chandb_get $chan topic$what]
781 if {"$ta_listop_ev" != "*"} {
782 if {![ischan $ta_listop_ev]} {
783 error "bad channel \`$ta_listop_ev' in topic $what"
785 set ta_listop_ev [irctolower $ta_listop_ev]
788 chandb_set $chan topic$what $ta_listop_ev
789 ucmdr "Topic $what list for $chan: $ta_listop_ev" {}
792 usererror "Unknown channel topic subcommand - see help channel."
799 if {"$mode" != "*" && ![regexp {^(([-+][imnpst]+)+)$} $mode mode]} {
800 error {channel mode must be * or match ([-+][imnpst]+)+}
802 chandb_set $chan mode $mode
803 if {"$mode" == "*"} {
804 ucmdr "I won't ever change the mode of $chan." {}
806 ucmdr "Whenever I'm alone on $chan, I'll set the mode to $mode." {}
811 if {[chandb_exists $chan]} {
812 set l "Settings for $chan: autojoin "
813 append l [lindex {no yes} [chandb_get $chan autojoin]]
814 append l ", mode " [chandb_get $chan mode]
815 append l ", userinvite " [chandb_get $chan userinvite] "."
816 append l "\nManagers: "
817 append l [join [chandb_get $chan managers] " "]
818 foreach {ts sep} {see "\n" tell " "} {
819 set t [chandb_get $chan topic$ts]
822 append l "Topic $ts list: $t."
824 append l "Topic $ts list is empty."
828 set t [chandb_get $chan topicset]
829 if {[string length $t]} {
830 append l "Topic to set: $t"
832 append l "I will not change the topic."
836 ucmdr {} "The channel $chan is not managed."
840 proc channelmgr_monoop {} {
845 upvar 1 target target
850 if {[ischan $dest]} { set target $dest }
851 if {[ta_anymore]} { set target [ta_word] }
853 if {![info exists target]} {
854 usererror "You must specify, or invoke me on, the relevant channel."
856 if {![info exists chan_nicks([irctolower $target])]} {
857 usererror "I am not on $target."
859 if {![ischan $target]} { error "not a valid channel" }
861 if {![chandb_exists $target]} {
862 usererror "$target is not a managed channel."
864 channel_securitycheck $target
869 sendout MODE $target +o $n
878 global chan_nicks errorCode errorInfo
881 if {[ischan $dest]} {
888 set ltarget [irctolower $target]
889 if {![ischan $target]} { error "$target is not a channel" }
890 if {![info exists chan_nicks($ltarget)]} {
891 usererror "I am not on $target."
893 set ui [chandb_get $ltarget userinvite]
895 if {"$ui" == "pub" && !$onchan} {
896 usererror "Invitations to $target must be made there with !invite."
898 if {"$ui" != "all"} {
899 if {[lsearch -exact $chan_nicks($ltarget) [irctolower $n]] < 0} {
900 usererror "Invitations to $target may only be made\
901 by a user on the channel."
904 if {"$ui" == "none"} {
905 usererror "Sorry, I've not been authorised\
906 to invite people to $target."
909 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager $target $n]} {
913 if {"$errorCode" == "BLIGHT USER"} {
914 usererror "$emsg2 Therefore you can't use your\
915 channel manager privilege. $emsg"
917 error $error $errorInfo $errorCode
921 error $emsg $errorInfo $errorCode
925 usererror "You have to say who to invite."
928 while {[ta_anymore]} {
929 set invitee [ta_word]
931 lappend invitees $invitee
933 foreach invitee $invitees {
934 sendout INVITE $invitee $ltarget
936 set who [lindex $invitees 0]
937 switch -exact llength $invitees {
938 0 { error "zero invitees" }
940 2 { append who " and [lindex $invitees 1]" }
942 set who [join [lreplace $invitees end end] ", "]
943 append who " and [lindex $invitees [llength $invitees]]"
946 ucmdr {} {} {} "invites $who to $target."
950 if {[ischan $dest]} { set target $dest }
956 if {[ischan $subcmd]} {
964 if {![info exists target]} { error "privately, you must specify a channel" }
965 set procname channel/$subcmd
966 if {"$subcmd" != "show"} {
967 if {[catch { info body $procname }]} {
968 usererror "unknown channel setting $subcmd."
971 if {[chandb_exists $target]} {
972 channel_securitycheck $target
975 upvar #0 chan_initialop([irctolower $target]) io
976 upvar #0 nick_unique([irctolower $n]) u
977 if {![info exists io]} {
978 usererror "$target is not a managed channel."
981 usererror "You are not the interim manager of $target."
983 if {"$subcmd" != "manager"} {
984 usererror "Please use `channel manager' first."
993 set target [ta_word]; ta_nomore
998 set myself [expr {"$target" != "$n"}]
1000 set ltarget [irctolower $target]
1001 upvar #0 nick_case($ltarget) ctarget
1003 if {[info exists ctarget]} {
1004 upvar #0 nick_onchans($ltarget) oc
1005 upvar #0 nick_username($ltarget) nu
1006 if {[info exists oc]} { set nshow $ctarget }
1008 if {![nickdb_exists $ltarget]} {
1009 set ol "$nshow is not a registered nick."
1010 } elseif {[string length [set username [nickdb_get $target username]]]} {
1011 set ol "The nick $nshow belongs to the user $username."
1013 set ol "The nick $nshow is registered (but not to a username)."
1015 if {![info exists ctarget] || ![info exists oc]} {
1017 append ol "\nI can't see $nshow on anywhere."
1019 append ol "\nYou aren't on any channels with me."
1021 } elseif {![info exists nu]} {
1022 append ol "\n$nshow has not identified themselves."
1023 } elseif {![info exists username]} {
1024 append ol "\n$nshow has identified themselves as the user $nu."
1025 } elseif {"$nu" != "$username"} {
1026 append ol "\nHowever, $nshow is being used by the user $nu."
1028 append ol "\n$nshow has identified themselves to me."
1036 set old [nickdb_exists $n]
1037 if {$old} { nick_securitycheck 0 }
1038 set luser [irctolower $n]
1039 switch -exact [string tolower [string trim $text]] {
1041 upvar #0 nick_username($luser) nu
1042 if {![info exists nu]} {
1044 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1046 nickdb_set $n username $nu
1047 ucmdr {} {} "makes a note of your username." {}
1051 ucmdr {} {} "forgets your nickname." {}
1054 nickdb_set $n username {}
1056 ucmdr {} "Security is now disabled for your nickname !"
1058 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."
1062 error "you mean register / register delete / register insecure"
1067 proc timeformat_desc {tf} {
1069 ks { return "Times will be displayed in seconds or kiloseconds." }
1070 hms { return "Times will be displayed in hours, minutes, etc." }
1071 beat { return "Times will be displayed in beats (1000B = 1d)." }
1072 default { error "invalid timeformat: $v" }
1076 proc def_setting {opt show_body set_body} {
1077 proc set_show/$opt {} "
1081 if {![string length $set_body]} return
1082 proc set_set/$opt {} "
1089 def_setting timeformat {
1090 set tf [nickdb_get $n timeformat]
1091 return "$tf: [timeformat_desc $tf]"
1093 set tf [string tolower [ta_word]]
1095 set desc [timeformat_desc $tf]
1096 nickdb_set $n timeformat $tf
1100 proc marktime_desc {mt} {
1101 if {"$mt" == "off"} {
1102 return "I will not send you periodic messages."
1103 } elseif {"$mt" == "once"} {
1104 return "I will send you one informational message when I see you."
1106 return "I'll send you a message every [showintervalsecs $mt 0]."
1110 def_setting marktime {
1111 set mt [nickdb_get $n marktime]
1113 if {[string match {[0-9]*} $mt]} { append p s }
1115 append p [marktime_desc $mt]
1119 set mt [string tolower [ta_word]]
1122 if {"$mt" == "off" || "$mt" == "once"} {
1123 } elseif {[regexp {^([0-9]+)([a-z]+)$} $mt dummy value unit]} {
1124 switch -exact $unit {
1131 default { error "unknown unit of time $unit" }
1133 if {$value > 86400*21/$u} { error "marktime interval too large" }
1134 set mt [expr {round($value*$u)}]
1135 if {$mt < $marktime_min} { error "marktime interval too small" }
1137 error "invalid syntax for marktime"
1139 nickdb_set $n marktime $mt
1140 lnick_marktime_start [irctolower $n] "So:" 500
1141 ucmdr {} [marktime_desc $mt]
1144 def_setting security {
1145 set s [nickdb_get $n username]
1146 if {[string length $s]} {
1147 return "Your nick, $n, is controlled by the user $s."
1149 return "Your nick, $n, is not secure."
1156 if {![nickdb_exists $n]} {
1157 ucmdr {} "You are unknown to me and so have no settings. (Use `register'.)"
1159 if {![ta_anymore]} {
1161 foreach proc [lsort [info procs]] {
1162 if {![regexp {^set_show/(.*)$} $proc dummy opt]} continue
1163 lappend ol [format "%-10s %s" $opt [set_show/$opt]]
1165 ucmdr {} [join $ol "\n"]
1168 if {[catch { info body set_show/$opt }]} {
1169 error "no setting $opt"
1171 if {![ta_anymore]} {
1172 ucmdr {} "$opt [set_show/$opt]"
1174 nick_securitycheck 0
1175 if {[catch { info body set_set/$opt }]} {
1176 error "setting $opt cannot be set with `set'"
1183 def_ucmd identpass {
1184 set username [ta_word]
1185 set passmd5 [md5sum "[ta_word]\n"]
1189 set luser [irctolower $n]
1190 upvar #0 nick_onchans($luser) onchans
1191 if {![info exists onchans] || ![llength $onchans]} {
1192 ucmdr "You must be on a channel with me to identify yourself." {}
1194 check_username $username
1195 exec userv --timeout 3 $username << "$passmd5\n" > /dev/null \
1197 upvar #0 nick_username($luser) rec_username
1198 set rec_username $username
1199 ucmdr "Pleased to see you, $username." {}
1205 set target [ta_nick]
1206 if {![nickdb_exists $target]} { error "$target is not a registered nick." }
1207 set wantu [nickdb_get $target username]
1208 if {![string length $wantu]} { error "$target is insecurely registred." }
1209 upvar #0 nick_username([irctolower $n]) nu
1210 if {![info exists nu]} { error "You must identify yourself first." }
1211 if {"$wantu" != "$nu"} {
1212 error "You are the wrong user, $nu - $target belongs to $wantu."
1214 set reason "at request of user $nu"
1215 if {[ta_anymore]} { append reason "; $text" }
1216 sendout KILL $target $reason
1220 set target [ta_word]
1222 # fixme would be nice if the rest of the text was passed on instead
1223 check_username $target
1226 upvar #0 lastsummon($target) ls
1227 set now [clock seconds]
1228 if {[info exists ls]} {
1229 set interval [expr {$now - $ls}]
1230 if {$interval < 30} {
1232 "Please be patient; $target was summoned only [showinterval $interval]."
1235 regsub {^[^!]*!} $p {} path
1237 exec userv --timeout 3 $target irc-summon $n $path \
1238 [expr {[ischan $dest] ? "$dest" : ""}] \
1241 regsub -all "\n" $rv { / } rv
1244 if {[regexp {^problem (.*)} $rv dummy problem]} {
1245 ucmdr {} "The user `$target' $problem."
1246 } elseif {[regexp {^ok ([^ ]+) ([0-9]+)$} $rv dummy tty idlesince]} {
1247 set idletime [expr {$now - $idlesince}]
1249 ucmdr {} {} {} "invites $target ($tty[expr {
1250 $idletime > 10 ? ", idle for [showintervalsecs $idletime 0]" : ""
1252 [ischan $dest] ? "join us here" : "talk to you"
1255 error "unexpected response from userv service: $rv"
1259 proc md5sum {value} { exec md5sum << $value }
1262 global lastseen nick
1265 set nlower [irctolower $ncase]
1267 set now [clock seconds]
1268 if {"$nlower" == "[irctolower $nick]"} {
1269 usererror "I am not self-aware."
1270 } elseif {![info exists lastseen($nlower)]} {
1271 set rstr "I've never seen $ncase."
1273 manyset $lastseen($nlower) realnick time what
1274 set howlong [expr {$now - $time}]
1275 set string [showinterval $howlong]
1276 set rstr "I last saw $realnick $string, $what."
1278 if {[ischan $dest]} {
1283 upvar #0 lookedfor($nlower) lf
1284 if {[info exists lf]} { set oldvalue $lf } else { set oldvalue {} }
1285 set lf [list [list $now $n $where]]
1286 foreach v $oldvalue {
1287 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1293 proc lnick_marktime_cancel {luser} {
1294 upvar #0 nick_markid($luser) mi
1295 if {![info exists mi]} return
1296 catch { after cancel $mi }
1300 proc lnick_marktime_doafter {luser why ms} {
1301 lnick_marktime_cancel $luser
1302 upvar #0 nick_markid($luser) mi
1303 set mi [after $ms [list lnick_marktime_now $luser $why]]
1306 proc lnick_marktime_reset {luser} {
1307 set mt [nickdb_get $luser marktime]
1308 if {"$mt" == "off" || "$mt" == "once"} return
1309 lnick_marktime_doafter $luser "Time passes." [expr {$mt*1000}]
1312 proc lnick_marktime_start {luser why ms} {
1313 set mt [nickdb_get $luser marktime]
1314 if {"$mt" == "off"} {
1315 lnick_marktime_cancel $luser
1317 lnick_marktime_doafter $luser $why $ms
1321 proc lnick_marktime_now {luser why} {
1322 upvar #0 nick_onchans($luser) oc
1324 set calling_nick $luser
1325 sendprivmsg $luser [lnick_pingstring $why $oc ""]
1326 lnick_marktime_reset $luser
1329 proc lnick_pingstring {why oc apstring} {
1331 catch { exec uptime } uptime
1332 set nnicks [llength [array names nick_onchans]]
1334 {^ *([0-9:apm]+) +up.*, +(\d+) users?, +load average: +([0-9., ]+) *$} \
1335 $uptime dummy time users load]} {
1336 regsub -all , $load {} load
1337 set uptime "$time $nnicks/$users $load"
1339 append uptime ", $nnicks nicks"
1341 if {[llength $oc]} {
1345 upvar #0 chan_lastactivity($ch) la
1346 if {![info exists la]} continue
1347 if {$la <= $best_la} continue
1348 set since [showintervalsecs [expr {[clock seconds]-$la}] 1]
1349 set activity "$ch $since"
1356 append str " " $uptime " " $activity
1357 if {[string length $apstring]} { append str " " $apstring }
1362 if {[ischan $dest]} {
1363 set oc [irctolower $dest]
1367 set ln [irctolower $n]
1368 if {[info exists nick_onchans($ln)]} {
1369 set oc $nick_onchans($ln)
1373 if {[llength $oc]} { lnick_marktime_reset $ln }
1375 ucmdr {} [lnick_pingstring "Pong!" $oc $text]
1378 proc ensure_globalsecret {} {
1381 if {[info exists globalsecret]} return
1382 set gsfile [open /dev/urandom r]
1383 fconfigure $gsfile -translation binary
1384 set globalsecret [read $gsfile 32]
1385 binary scan $globalsecret H* globalsecret
1392 if {[info exists operuserpass]} {
1393 eval sendout OPER $operuserpass
1395 foreach chan [chandb_list] {
1396 if {[chandb_get $chan autojoin]} { dojoin $chan }