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 showintervalsecs
/ks
{howlong abbrev
} {
27 if {$howlong < 1000} {
30 if {$howlong < 1000000} {
37 set value
[expr "$howlong.0 / $scale"]
38 foreach {min
format} {100 %.0f
10 %.1f
1 %.2f
} {
39 if {$value < $min} continue
40 return [format "$format${pfx}s" $value]
45 proc format_qty
{qty unit abbrev
} {
48 append o
[string range
$unit 0 0]
52 if {$qty != 1} { append o s
}
57 proc showintervalsecs
/hms
{qty abbrev
} {
58 set ul
{second
60 minute
60 hour
24 day
7 week
}
60 while {[llength $ul] > 1 && $qty >= [set uv
[lindex $ul 1]]} {
61 set remainu
[lindex $ul 0]
62 set remainv
[expr {$qty % $uv}]
63 set qty
[expr {($qty-$remainv)/$uv}]
64 set ul
[lreplace $ul 0 1]
66 set o
[format_qty
$qty [lindex $ul 0] $abbrev]
68 if {!$abbrev} { append o
" " }
69 append o
[format_qty
$remainv $remainu $abbrev]
74 proc showinterval
{howlong
} {
78 return "[showintervalsecs $howlong 0] ago"
82 proc showtime
{when
} {
83 return [showinterval
[expr {[clock seconds
] - $when}]]
86 proc def_msgproc
{name argl body
} {
87 proc msg_
$name "varbase $argl" "\
88 upvar #0 msg/\$varbase/dest d\n\
89 upvar #0 msg/\$varbase/str s\n\
90 upvar #0 msg/\$varbase/accum a\n\
94 def_msgproc begin
{dest str
} {
100 def_msgproc
append {str
} {
102 if {[string length
$s] && [string length
$ns] > 65} {
103 msg__sendout
$varbase
104 set s
" [string trimleft $str]"
110 def_msgproc finish
{} {
111 msg__sendout
$varbase
117 def_msgproc _sendout
{} {
118 lappend a
[string trimright
$s]
122 proc looking_whenwhere
{when where
} {
123 set str
[showtime
[expr {$when-1}]]
124 if {[string length
$where]} { append str
" on $where" }
128 proc recordlastseen_n
{n how here
} {
129 global lastseen lookedfor
130 set lastseen
([irctolower
$n]) [list $n [clock seconds
] $how]
132 upvar #0 lookedfor([irctolower $n]) lf
133 if {[info exists lf
]} {
134 switch -exact [llength $lf] {
139 manyset
[lindex $lf 0] when who where
141 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
144 msg_begin tosend
$n "FYI, people have been looking for you:"
150 msg_append tosend
" "
151 } elseif
{$i == [llength $lf]} {
152 msg_append tosend
" and "
155 msg_append tosend
", "
157 manyset
$e when who where
159 "$who ([looking_whenwhere $when $where])$fin"
161 set ml
[msg_finish tosend
]
165 msendprivmsg_delayed
1000 $n $ml
169 proc note_topic
{showoff whoby topic
} {
170 set msg
"FYI, $whoby has changed the topic on $showoff"
171 if {[string length
$topic] < 160} {
172 append msg
" to $topic"
174 append msg
" but it is too long to reproduce here !"
176 set showoff
[irctolower
$showoff]
177 set tell [chandb_get
$showoff topictell
]
178 if {[lsearch -exact $tell *] >= 0} {
179 set tryspies
[chandb_list
]
183 foreach spy
$tryspies {
184 set see
[chandb_get
$spy topicsee
]
185 if {[lsearch -exact $see $showoff] >= 0 ||
\
186 ([lsearch -exact $see *] >= 0 && \
187 [lsearch -exact $tell $spy] >= 0)} {
188 sendprivmsg
$spy $msg
193 proc recordlastseen_p
{p how here
} {
195 recordlastseen_n
$n $how $here
198 proc chanmode_arg
{} {
200 set rv
[lindex $cm_args 0]
201 set cm_args
[lreplace cm_args
0 0]
205 proc chanmode_o1
{m g p chan
} {
206 global nick chan_initialop
208 set who
[chanmode_arg
]
209 recordlastseen_n
$n "being nice to $who" 1
210 if {"[irctolower $who]" == "[irctolower $nick]"} {
211 set nlower
[irctolower
$n]
212 upvar #0 nick_unique($nlower) u
213 if {[chandb_exists
$chan]} {
214 sendprivmsg
$n Thanks.
215 } elseif
{![info exists u
]} {
216 sendprivmsg
$n {Op me
while not on the channel
, why don't you ?
}
218 set chan_initialop
([irctolower
$chan]) $u
220 "Thanks. You can use `channel manager ...' to register this channel."
221 if {![nickdb_exists
$n] ||
![string length
[nickdb_get
$n username
]]} {
223 "(But to do that you must register your nick securely first.)"
229 proc chanmode_o0
{m g p chan
} {
232 set who
[chanmode_arg
]
233 recordlastseen_p
$p "being mean to $who" 1
234 if {"[irctolower $who]" == "[irctolower $nick]"} {
235 set chandeop
($chan) [list [clock seconds
] $p]
239 proc msg_MODE
{p c dest modelist args
} {
240 if {![ischan
$dest]} return
241 if {[regexp {^
\-(.
+)$} $modelist dummy modelist
]} {
243 } elseif
{[regexp {^
\+(.
+)$} $modelist dummy modelist
]} {
246 error "invalid modelist"
248 foreach m
[split $modelist] {
249 set procname chanmode_
$m$give
250 if {[catch { info body
$procname }]} {
251 recordlastseen_p
$p "fiddling with $dest" 1
253 $procname $m $give $p $dest
258 proc leaving
{lchan
} {
259 foreach luser
[array names nick_onchans
] {
260 upvar #0 nick_onchans($luser) oc
261 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
263 upvar #0 chan_nicks($lchan) nlist
265 upvar #0 chan_lastactivity($lchan) la
269 proc doleave
{lchan
} {
274 proc dojoin
{lchan
} {
277 set chan_nicks
($lchan) {}
280 proc check_justme
{lchan
} {
282 upvar #0 chan_nicks($lchan) nlist
283 if {[llength $nlist] != 1} return
284 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
285 if {[chandb_exists
$lchan]} {
286 set mode
[chandb_get
$lchan mode
]
287 if {"$mode" != "*"} {
288 sendout MODE
$lchan $mode
290 set topic
[chandb_get
$lchan topicset
]
291 if {[string length
$topic]} {
292 sendout TOPIC
$lchan $topic
299 proc process_kickpart
{chan user
} {
302 set luser
[irctolower
$user]
303 set lchan
[irctolower
$chan]
304 if {![ischan
$chan]} { error "not a channel" }
305 if {"$luser" == "[irctolower $nick]"} {
308 upvar #0 nick_onchans($luser) oc
309 upvar #0 chan_nicks($lchan) nlist
310 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
311 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
313 if {![llength $oc]} {
321 proc msg_TOPIC
{p c dest topic
} {
323 if {![ischan
$dest]} return
324 recordlastseen_n
$n "changing the topic on $dest" 1
325 note_topic
[irctolower
$dest] $n $topic
328 proc msg_KICK
{p c chans users comment
} {
329 set chans
[split $chans ,]
330 set users
[split $users ,]
331 if {[llength $chans] > 1} {
332 foreach chan
$chans user
$users { process_kickpart
$chan $user }
334 foreach user
$users { process_kickpart
[lindex $chans 0] $user }
338 proc msg_KILL
{p c user why
} {
343 set nick_arys
{onchans username unique
}
344 # nick_onchans($luser) -> [list ... $lchan ...]
345 # nick_username($luser) -> <securely known local username>
346 # nick_unique($luser) -> <counter>
347 # nick_case($luser) -> $user (valid even if no longer visible)
348 # nick_markid($luser) -> <after id for marktime>
350 # chan_nicks($lchan) -> [list ... $luser ...]
351 # chan_lastactivity($lchan) -> [clock seconds]
353 proc lnick_forget
{luser
} {
354 global nick_arys chan_nicks
355 lnick_marktime_cancel
$luser
356 foreach ary
$nick_arys {
357 upvar #0 nick_${ary}($luser) av
360 foreach lch
[array names chan_nicks
] {
361 upvar #0 chan_nicks($lch) nlist
362 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
367 proc nick_forget
{user
} {
368 global nick_arys chan_nicks
369 lnick_forget
[irctolower
$user]
373 proc nick_case
{user
} {
375 set nick_case
([irctolower
$user]) $user
378 proc msg_NICK
{p c newnick
} {
379 global nick_arys nick_case calling_nick
381 recordlastseen_n
$n "changing nicks to $newnick" 0
382 set calling_nick
$newnick
383 recordlastseen_n
$newnick "changing nicks from $n" 1
384 set luser
[irctolower
$n]
385 lnick_marktime_cancel
$luser
386 set lusernew
[irctolower
$newnick]
387 foreach ary
$nick_arys {
388 upvar #0 nick_${ary}($luser) old
389 upvar #0 nick_${ary}($lusernew) new
390 if {[info exists new
]} { error "nick collision ?! $ary $n $newnick" }
391 if {[info exists old
]} { set new
$old; unset old
}
393 upvar #0 nick_onchans($lusernew) oc
395 upvar #0 chan_nicks($ch) nlist
396 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
397 lappend nlist
$lusernew
399 lnick_marktime_start
$lusernew "Hi." 500
403 proc nick_ishere
{n
} {
405 upvar #0 nick_unique([irctolower $n]) u
406 if {![info exists u
]} { set u
[incr nick_counter
].
$n.
[clock seconds
] }
410 proc msg_JOIN
{p c chan
} {
412 recordlastseen_n
$n "joining $chan" 1
413 set nl
[irctolower
$n]
414 set lchan
[irctolower
$chan]
415 upvar #0 nick_onchans($nl) oc
416 upvar #0 chan_nicks($lchan) nlist
417 if {![info exists oc
]} {
418 global marktime_join_startdelay
419 lnick_marktime_start
$nl "Welcome." $marktime_join_startdelay
425 proc msg_PART
{p c chan args
} {
427 set msg
"leaving $chan"
428 if {[llength $args]} {
429 set why
[lindex $args 0]
430 if {"[irctolower $why]" != "[irctolower $n]"} { append msg
" ($why)" }
432 recordlastseen_n
$n $msg 1
433 process_kickpart
$chan $n
435 proc msg_QUIT
{p c why
} {
437 recordlastseen_n
$n "leaving ($why)" 0
441 proc msg_PRIVMSG
{p c dest
text} {
445 if {[ischan
$dest]} {
446 recordlastseen_n
$n "invoking me in $dest" 1
449 recordlastseen_n
$n "talking to me" 1
454 execute_usercommand
$p $c $n $output $dest $text
457 proc msg_INVITE
{p c n chan
} {
458 after 1000 [list dojoin
[irctolower
$chan]]
461 proc grep
{var predicate
list} {
465 if {[uplevel 1 [list expr $predicate]]} { lappend o
$v }
470 proc msg_353
{p c dest type chan nicklist
} {
471 global names_chans nick_onchans
472 set lchan
[irctolower
$chan]
473 upvar #0 chan_nicks($lchan) nlist
474 lappend names_chans
$lchan
475 if {![info exists nlist
]} {
476 # We don't think we're on this channel, so ignore it !
477 # Unfortunately, because we don't get a reply to PART,
478 # we have to remember ourselves whether we're on a channel,
479 # and ignore stuff if we're not, to avoid races. Feh.
483 foreach user
[split $nicklist { }] {
484 regsub {^
[@+]} $user {} user
485 if {![string length
$user]} continue
487 set luser
[irctolower
$user]
488 upvar #0 nick_onchans($luser) oc
490 lappend nlist_new
$luser
496 proc msg_366
{p c args
} {
497 global names_chans nick_onchans
498 set lchan
[irctolower
$c]
499 foreach luser
[array names nick_onchans
] {
500 upvar #0 nick_onchans($luser) oc
501 if {[llength names_chans
] > 1} {
502 set oc
[grep tc
{[lsearch -exact $tc $names_chans] >= 0} $oc]
504 if {![llength $oc]} { lnick_forget
$n }
509 proc check_username
{target
} {
511 [string length
$target] > 8 ||
512 [regexp {[^
-0-9a-z
]} $target] ||
513 ![regexp {^
[a-z
]} $target]
514 } { error "invalid username" }
517 proc somedb__head
{} {
519 set idl
[irctolower
$id]
520 upvar #0 ${nickchan}db($idl) ndbe
521 binary scan $idl H
* idh
522 set idfn
$fprefix$idh
523 if {![info exists iddbe
] && [file exists
$idfn]} {
525 try_except_finally
{ set newval
[read $f] } {} { close $f }
526 if {[llength $newval] % 2} { error "invalid length" }
532 proc def_somedb
{name arglist body
} {
533 foreach {nickchan fprefix
} {nick users
/n chan chans
/c
} {
534 proc ${nickchan
}db_
$name $arglist \
535 "set nickchan $nickchan; set fprefix $fprefix; $body"
541 foreach path
[glob -nocomplain -path $fprefix *] {
542 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
543 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
544 lappend list [binary format H
* $thinghex]
549 proc def_somedb_id
{name arglist body
} {
550 def_somedb
$name [concat id
$arglist] "somedb__head; $body"
553 def_somedb_id exists
{} {
554 return [info exists iddbe
]
557 def_somedb_id delete
{} {
558 catch { unset iddbe
}
562 set default_settings_nick
{timeformat ks marktime off
}
563 set default_settings_chan
{
572 def_somedb_id
set {args
} {
573 upvar #0 default_settings_$nickchan def
574 if {![info exists iddbe
]} { set iddbe
$def }
575 foreach {key value
} [concat $iddbe $args] { set a
($key) $value }
577 foreach {key value
} [array get a
] { lappend newval
$key $value }
578 set f
[open $idfn.new w
]
582 file rename -force $idfn.new
$idfn
590 def_somedb_id get
{key
} {
591 upvar #0 default_settings_$nickchan def
592 if {[info exists iddbe
]} {
593 set l
[concat $iddbe $def]
597 foreach {tkey value
} $l {
598 if {"$tkey" == "$key"} { return $value }
600 error "unset setting $key"
605 if {[info exists calling_nick
]} { set n
$calling_nick } { set n
{} }
606 return [nickdb_get
$n $key]
609 proc check_notonchan
{} {
611 if {[ischan
$dest]} { usererror
"That command must be sent privately." }
614 proc nick_securitycheck
{strict
} {
616 if {![nickdb_exists
$n]} {
617 usererror
"You are unknown to me, use `register'."
619 set wantu
[nickdb_get
$n username
]
620 if {![string length
$wantu]} {
622 usererror
"That feature is only available to secure users, sorry."
627 set luser
[irctolower
$n]
628 upvar #0 nick_username($luser) nu
629 if {![info exists nu
]} {
630 usererror
"Nick $n is secure, you must identify yourself first."
632 if {"$wantu" != "$nu"} {
633 usererror
"You are the wrong user -\
634 the nick $n belongs to $wantu, not $nu."
638 proc channel_ismanager
{channel n
} {
639 set mgrs
[chandb_get
$channel managers
]
640 return [expr {[lsearch -exact [irctolower
$mgrs] [irctolower
$n]] >= 0}]
643 proc channel_securitycheck
{channel
} {
645 if {![channel_ismanager
$channel $n]} {
646 usererror
"You are not a manager of $channel."
651 proc def_chancmd
{name body
} {
652 proc channel
/$name {} \
653 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
656 proc ta_listop
{findnow procvalue
} {
657 # findnow and procvalue are code fragments which will be executed
658 # in the caller's level. findnow should set ta_listop_ev to
659 # the current list, and procvalue should treat ta_listop_ev as
660 # a proposed value in the list and check and possibly modify
661 # (canonicalise?) it. After ta_listop, ta_listop_ev will
662 # be the new value of the list.
663 upvar 1 ta_listop_ev exchg
666 switch -exact _
$opcode {
670 foreach item
$exchg { set array($item) 1 }
673 error "list change opcode must be one of + - ="
676 foreach exchg
[split $text " "] {
677 if {![string length
$exchg]} continue
679 if {"$opcode" != "-"} {
682 catch { unset array($exchg) }
685 set exchg
[lsort [array names
array]]
688 def_chancmd manager
{
690 if {[chandb_exists
$chan]} {
691 set ta_listop_ev
[chandb_get
$chan managers
]
693 set ta_listop_ev
[list [irctolower
$n]]
696 check_nick
$ta_listop_ev
697 set ta_listop_ev
[irctolower
$ta_listop_ev]
699 if {[llength $ta_listop_ev]} {
700 chandb_set
$chan managers
$ta_listop_ev
701 ucmdr
"Managers of $chan: $ta_listop_ev" {}
704 ucmdr
{} {} "forgets about managing $chan." {}
708 def_chancmd autojoin
{
710 switch -exact [string tolower
$yesno] {
713 default { error "channel autojoin must be `yes' or `no' }
715 chandb_set $chan autojoin $nv
716 ucmdr [expr {$nv ? "I will
join $chan when I'm restarted
" : \
717 "I won't
join $chan when I'm restarted
"}] {}
720 def_chancmd userinvite {
721 set nv [string tolower [ta_word]]
723 pub { set txt "!invite will work
for $chan, but it won't work by
/msg
" }
724 here { set txt "!invite and
/msg invite will work
, but only
for users who are already on
$chan.
" }
725 all { set txt "Any user will be able to invite themselves or anyone
else to
$chan.
" }
726 none { set txt "I will not invite anyone to
$chan.
" }
728 error "channel userinvite must be `pub'
, `here'
, `all' or `none'
731 chandb_set
$chan userinvite
$nv
737 switch -exact $what {
740 chandb_set
$chan topicset
{}
741 ucmdr
"I won't ever change the topic of $chan." {}
744 set t
[string trim
$text]
745 if {![string length
$t]} {
746 error "you must specific the topic to set"
748 chandb_set
$chan topicset
$t
749 ucmdr
"Whenever I'm alone on $chan, I'll set the topic to $t." {}
753 set ta_listop_ev
[chandb_get
$chan topic
$what]
755 if {"$ta_listop_ev" != "*"} {
756 if {![ischan
$ta_listop_ev]} {
757 error "bad channel \`$ta_listop_ev' in topic $what"
759 set ta_listop_ev
[irctolower
$ta_listop_ev]
762 chandb_set
$chan topic
$what $ta_listop_ev
763 ucmdr
"Topic $what list for $chan: $ta_listop_ev" {}
766 usererror
"Unknown channel topic subcommand - see help channel."
773 if {"$mode" != "*" && ![regexp {^
(([-+][imnpst
]+)+)$} $mode mode
]} {
774 error {channel mode must be
* or match
([-+][imnpst
]+)+}
776 chandb_set
$chan mode
$mode
777 if {"$mode" == "*"} {
778 ucmdr
"I won't ever change the mode of $chan." {}
780 ucmdr
"Whenever I'm alone on $chan, I'll set the mode to $mode." {}
785 if {[chandb_exists
$chan]} {
786 set l
"Settings for $chan: autojoin "
787 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
788 append l
", mode " [chandb_get
$chan mode
]
789 append l
", userinvite " [chandb_get
$chan userinvite
] "."
790 append l
"\nManagers: "
791 append l
[join [chandb_get
$chan managers
] " "]
792 foreach {ts sep
} {see
"\n" tell " "} {
793 set t
[chandb_get
$chan topic
$ts]
796 append l
"Topic $ts list: $t."
798 append l
"Topic $ts list is empty."
802 set t
[chandb_get
$chan topicset
]
803 if {[string length
$t]} {
804 append l
"Topic to set: $t"
806 append l
"I will not change the topic."
810 ucmdr
{} "The channel $chan is not managed."
814 proc channelmgr_monoop
{} {
819 upvar 1 target target
824 if {[ischan
$dest]} { set target
$dest }
825 if {[ta_anymore
]} { set target
[ta_word
] }
827 if {![info exists target
]} {
828 usererror
"You must specify, or invoke me on, the relevant channel."
830 if {![info exists chan_nicks
([irctolower
$target])]} {
831 usererror
"I am not on $target."
833 if {![ischan
$target]} { error "not a valid channel" }
835 if {![chandb_exists
$target]} {
836 usererror
"$target is not a managed channel."
838 channel_securitycheck
$target
843 sendout MODE
$target +o
$n
852 global chan_nicks errorCode errorInfo
855 if {[ischan
$dest]} {
862 set ltarget
[irctolower
$target]
863 if {![ischan
$target]} { error "$target is not a channel" }
864 if {![info exists chan_nicks
($ltarget)]} {
865 usererror
"I am not on $target."
867 set ui
[chandb_get
$ltarget userinvite
]
869 if {"$ui" == "pub" && !$onchan} {
870 usererror
"Invitations to $target must be made there with !invite."
872 if {"$ui" != "all"} {
873 if {[lsearch -exact $chan_nicks($ltarget) [irctolower
$n]] < 0} {
874 usererror
"Invitations to $target may only be made\
875 by a user on the channel."
878 if {"$ui" == "none"} {
879 usererror
"Sorry, I've not been authorised\
880 to invite people to $target."
883 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager
$target $n]} {
887 if {"$errorCode" == "BLIGHT USER"} {
888 usererror
"$emsg2 Therefore you can't use your\
889 channel manager privilege. $emsg"
891 error $error $errorInfo $errorCode
895 error $emsg $errorInfo $errorCode
899 usererror
"You have to say who to invite."
902 while {[ta_anymore
]} {
903 set invitee
[ta_word
]
905 lappend invitees
$invitee
907 foreach invitee
$invitees {
908 sendout INVITE
$invitee $ltarget
910 set who
[lindex $invitees 0]
911 switch -exact llength $invitees {
912 0 { error "zero invitees" }
914 2 { append who
" and [lindex $invitees 1]" }
916 set who
[join [lreplace $invitees end end
] ", "]
917 append who
" and [lindex $invitees [llength $invitees]]"
920 ucmdr
{} {} {} "invites $who to $target."
924 if {[ischan
$dest]} { set target
$dest }
930 if {[ischan
$subcmd]} {
938 if {![info exists target
]} { error "privately, you must specify a channel" }
939 set procname channel
/$subcmd
940 if {"$subcmd" != "show"} {
941 if {[catch { info body
$procname }]} {
942 usererror
"unknown channel setting $subcmd."
945 if {[chandb_exists
$target]} {
946 channel_securitycheck
$target
949 upvar #0 chan_initialop([irctolower $target]) io
950 upvar #0 nick_unique([irctolower $n]) u
951 if {![info exists io
]} {
952 usererror
"$target is not a managed channel."
955 usererror
"You are not the interim manager of $target."
957 if {"$subcmd" != "manager"} {
958 usererror
"Please use `channel manager' first."
967 set target
[ta_word
]; ta_nomore
972 set myself
[expr {"$target" != "$n"}]
974 set ltarget
[irctolower
$target]
975 upvar #0 nick_case($ltarget) ctarget
977 if {[info exists ctarget
]} {
978 upvar #0 nick_onchans($ltarget) oc
979 upvar #0 nick_username($ltarget) nu
980 if {[info exists oc
]} { set nshow
$ctarget }
982 if {![nickdb_exists
$ltarget]} {
983 set ol
"$nshow is not a registered nick."
984 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
985 set ol
"The nick $nshow belongs to the user $username."
987 set ol
"The nick $nshow is registered (but not to a username)."
989 if {![info exists ctarget
] ||
![info exists oc
]} {
991 append ol
"\nI can't see $nshow on anywhere."
993 append ol
"\nYou aren't on any channels with me."
995 } elseif
{![info exists nu
]} {
996 append ol
"\n$nshow has not identified themselves."
997 } elseif
{![info exists username
]} {
998 append ol
"\n$nshow has identified themselves as the user $nu."
999 } elseif
{"$nu" != "$username"} {
1000 append ol
"\nHowever, $nshow is being used by the user $nu."
1002 append ol
"\n$nshow has identified themselves to me."
1010 set old
[nickdb_exists
$n]
1011 if {$old} { nick_securitycheck
0 }
1012 set luser
[irctolower
$n]
1013 switch -exact [string tolower
[string trim
$text]] {
1015 upvar #0 nick_username($luser) nu
1016 if {![info exists nu
]} {
1018 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1020 nickdb_set
$n username
$nu
1021 ucmdr
{} {} "makes a note of your username." {}
1025 ucmdr
{} {} "forgets your nickname." {}
1028 nickdb_set
$n username
{}
1030 ucmdr
{} "Security is now disabled for your nickname !"
1032 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."
1036 error "you mean register / register delete / register insecure"
1041 proc timeformat_desc
{tf
} {
1043 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1044 hms
{ return "Times will be displayed in hours, minutes, etc." }
1045 default { error "invalid timeformat: $v" }
1049 proc def_setting
{opt show_body set_body
} {
1050 proc set_show
/$opt {} "
1054 if {![string length
$set_body]} return
1055 proc set_set
/$opt {} "
1062 def_setting timeformat
{
1063 set tf
[nickdb_get
$n timeformat
]
1064 return "$tf: [timeformat_desc $tf]"
1066 set tf
[string tolower
[ta_word
]]
1068 set desc
[timeformat_desc
$tf]
1069 nickdb_set
$n timeformat
$tf
1073 proc marktime_desc
{mt
} {
1074 if {"$mt" == "off"} {
1075 return "I will not send you periodic messages."
1076 } elseif
{"$mt" == "once"} {
1077 return "I will send you one informational message when I see you."
1079 return "I'll send you a message every [showintervalsecs $mt 0]."
1083 def_setting marktime
{
1084 set mt
[nickdb_get
$n marktime
]
1086 if {[string match
{[0-9]*} $mt]} { append p s
}
1088 append p
[marktime_desc
$mt]
1092 set mt
[string tolower
[ta_word
]]
1095 if {"$mt" == "off" ||
"$mt" == "once"} {
1096 } elseif
{[regexp {^
([0-9]+)([a-z
]+)$} $mt dummy value unit
]} {
1097 switch -exact $unit {
1102 default { error "unknown unit of time $unit" }
1104 if {$value > 86400*21/$u} { error "marktime interval too large" }
1105 set mt
[expr {$value*$u}]
1106 if {$mt < $marktime_min} { error "marktime interval too small" }
1108 error "invalid syntax for marktime"
1110 nickdb_set
$n marktime
$mt
1111 lnick_marktime_start
[irctolower
$n] "So:" 500
1112 ucmdr
{} [marktime_desc
$mt]
1115 def_setting security
{
1116 set s
[nickdb_get
$n username
]
1117 if {[string length
$s]} {
1118 return "Your nick, $n, is controlled by the user $s."
1120 return "Your nick, $n, is not secure."
1127 if {![nickdb_exists
$n]} {
1128 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1130 if {![ta_anymore
]} {
1132 foreach proc [lsort [info procs
]] {
1133 if {![regexp {^set_show
/(.
*)$} $proc dummy opt
]} continue
1134 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1136 ucmdr
{} [join $ol "\n"]
1139 if {[catch { info body set_show
/$opt }]} {
1140 error "no setting $opt"
1142 if {![ta_anymore
]} {
1143 ucmdr
{} "$opt [set_show/$opt]"
1145 nick_securitycheck
0
1146 if {[catch { info body set_set
/$opt }]} {
1147 error "setting $opt cannot be set with `set'"
1154 def_ucmd identpass
{
1155 set username
[ta_word
]
1156 set passmd5
[md5sum
"[ta_word]\n"]
1160 set luser
[irctolower
$n]
1161 upvar #0 nick_onchans($luser) onchans
1162 if {![info exists onchans
] ||
![llength $onchans]} {
1163 ucmdr
"You must be on a channel with me to identify yourself." {}
1165 check_username
$username
1166 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1168 upvar #0 nick_username($luser) rec_username
1169 set rec_username
$username
1170 ucmdr
"Pleased to see you, $username." {}
1174 set target
[ta_word
]
1176 check_username
$target
1179 upvar #0 lastsummon($target) ls
1180 set now
[clock seconds
]
1181 if {[info exists ls
]} {
1182 set interval
[expr {$now - $ls}]
1183 if {$interval < 30} {
1185 "Please be patient; $target was summoned only [showinterval $interval]."
1188 regsub {^
[^
!]*!} $p {} path
1190 exec userv
--timeout 3 $target irc-summon
$n $path \
1191 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1194 regsub -all "\n" $rv { / } rv
1197 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1198 ucmdr
{} "The user `$target' $problem."
1199 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1200 set idletime
[expr {$now - $idlesince}]
1202 ucmdr
{} {} {} "invites $target ($tty[expr {
1203 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime 0]" : ""
1205 [ischan $dest] ? "join us here
" : "talk to you
"
1208 error "unexpected response from userv service: $rv"
1212 proc md5sum
{value
} { exec md5sum
<< $value }
1215 global lastseen nick
1218 set nlower
[irctolower
$ncase]
1220 set now
[clock seconds
]
1221 if {"$nlower" == "[irctolower $nick]"} {
1222 usererror
"I am not self-aware."
1223 } elseif
{![info exists lastseen
($nlower)]} {
1224 set rstr
"I've never seen $ncase."
1226 manyset
$lastseen($nlower) realnick
time what
1227 set howlong
[expr {$now - $time}]
1228 set string [showinterval
$howlong]
1229 set rstr
"I last saw $realnick $string, $what."
1231 if {[ischan
$dest]} {
1236 upvar #0 lookedfor($nlower) lf
1237 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1238 set lf
[list [list $now $n $where]]
1239 foreach v
$oldvalue {
1240 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1246 proc lnick_marktime_cancel
{luser
} {
1247 upvar #0 nick_markid($luser) mi
1248 if {![info exists mi
]} return
1249 catch { after cancel
$mi }
1253 proc lnick_marktime_doafter
{luser why ms
} {
1254 lnick_marktime_cancel
$luser
1255 upvar #0 nick_markid($luser) mi
1256 set mi
[after $ms [list lnick_marktime_now
$luser $why]]
1259 proc lnick_marktime_reset
{luser
} {
1260 set mt
[nickdb_get
$luser marktime
]
1261 if {"$mt" == "off" ||
"$mt" == "once"} return
1262 lnick_marktime_doafter
$luser "Time passes." [expr {$mt*1000}]
1265 proc lnick_marktime_start
{luser why ms
} {
1266 set mt
[nickdb_get
$luser marktime
]
1267 if {"$mt" == "off"} {
1268 lnick_marktime_cancel
$luser
1270 lnick_marktime_doafter
$luser $why $ms
1274 proc lnick_marktime_now
{luser why
} {
1275 upvar #0 nick_onchans($luser) oc
1277 set calling_nick
$luser
1278 sendprivmsg
$luser [lnick_pingstring
$why $oc ""]
1279 lnick_marktime_reset
$luser
1282 proc lnick_pingstring
{why oc apstring
} {
1284 catch { exec uptime
} uptime
1285 set nnicks
[llength [array names nick_onchans
]]
1287 {^
*([0-9:apm
]+) +up.
*, +(\d
+) users?
, +load average
: +([0-9.
, ]+) *$} \
1288 $uptime dummy
time users
load]} {
1289 regsub -all , $load {} load
1290 set uptime
"$time $nnicks/$users $load"
1292 append uptime
", $nnicks nicks"
1294 if {[llength $oc]} {
1298 upvar #0 chan_lastactivity($ch) la
1299 if {![info exists la
]} continue
1300 if {$la <= $best_la} continue
1301 set since
[showintervalsecs
[expr {[clock seconds
]-$la}] 1]
1302 set activity
"$ch $since"
1309 append str
" " $uptime " " $activity
1310 if {[string length
$apstring]} { append str
" " $apstring }
1315 if {[ischan
$dest]} {
1316 set oc
[irctolower
$dest]
1320 set ln
[irctolower
$n]
1321 if {[info exists nick_onchans
($ln)]} {
1322 set oc
$nick_onchans($ln)
1326 if {[llength $oc]} { lnick_marktime_reset
$ln }
1328 ucmdr
{} [lnick_pingstring
"Pong!" $oc $text]
1331 proc ensure_globalsecret
{} {
1334 if {[info exists globalsecret
]} return
1335 set gsfile
[open /dev
/urandom r
]
1336 fconfigure $gsfile -translation binary
1337 set globalsecret
[read $gsfile 32]
1338 binary scan $globalsecret H
* globalsecret
1344 foreach chan
[chandb_list
] {
1345 if {[chandb_get
$chan autojoin
]} { dojoin
$chan }