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
/beat
{howlong abbrev
} {
27 return [format "%g B" [expr {$howlong/86.4}]]
30 proc showintervalsecs
/ks
{howlong abbrev
} {
31 if {$howlong < 1000} {
34 if {$howlong < 1000000} {
41 set value
[expr "$howlong.0 / $scale"]
42 foreach {min
format} {100 %.0f
10 %.1f
1 %.2f
} {
43 if {$value < $min} continue
44 return [format "$format${pfx}s" $value]
49 proc format_qty
{qty unit abbrev
} {
52 append o
[string range
$unit 0 0]
56 if {$qty != 1} { append o s
}
61 proc showintervalsecs
/hms
{qty abbrev
} {
62 set ul
{second
60 minute
60 hour
24 day
7 week
}
64 while {[llength $ul] > 1 && $qty >= [set uv
[lindex $ul 1]]} {
65 set remainu
[lindex $ul 0]
66 set remainv
[expr {$qty % $uv}]
67 set qty
[expr {($qty-$remainv)/$uv}]
68 set ul
[lreplace $ul 0 1]
70 set o
[format_qty
$qty [lindex $ul 0] $abbrev]
72 if {!$abbrev} { append o
" " }
73 append o
[format_qty
$remainv $remainu $abbrev]
78 proc showinterval
{howlong
} {
82 return "[showintervalsecs $howlong 0] ago"
86 proc showtime
{when
} {
87 return [showinterval
[expr {[clock seconds
] - $when}]]
90 proc def_msgproc
{name argl body
} {
91 proc msg_
$name "varbase $argl" "\
92 upvar #0 msg/\$varbase/dest d\n\
93 upvar #0 msg/\$varbase/str s\n\
94 upvar #0 msg/\$varbase/accum a\n\
98 def_msgproc begin
{dest str
} {
104 def_msgproc
append {str
} {
106 if {[string length
$s] && [string length
$ns] > 65} {
107 msg__sendout
$varbase
108 set s
" [string trimleft $str]"
114 def_msgproc finish
{} {
115 msg__sendout
$varbase
121 def_msgproc _sendout
{} {
122 lappend a
[string trimright
$s]
126 proc looking_whenwhere
{when where
} {
127 set str
[showtime
[expr {$when-1}]]
128 if {[string length
$where]} { append str
" on $where" }
132 proc recordlastseen_n
{n how here
} {
133 global lastseen lookedfor
134 set lastseen
([irctolower
$n]) [list $n [clock seconds
] $how]
136 upvar #0 lookedfor([irctolower $n]) lf
137 if {[info exists lf
]} {
138 switch -exact [llength $lf] {
143 manyset
[lindex $lf 0] when who where
145 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
148 msg_begin tosend
$n "FYI, people have been looking for you:"
154 msg_append tosend
" "
155 } elseif
{$i == [llength $lf]} {
156 msg_append tosend
" and "
159 msg_append tosend
", "
161 manyset
$e when who where
163 "$who ([looking_whenwhere $when $where])$fin"
165 set ml
[msg_finish tosend
]
169 msendprivmsg_delayed
1000 $n $ml
173 proc note_topic
{showoff whoby topic
} {
174 set msg
"FYI, $whoby has changed the topic on $showoff"
175 if {[string length
$topic] < 160} {
176 append msg
" to $topic"
178 append msg
" but it is too long to reproduce here !"
180 set showoff
[irctolower
$showoff]
181 set tell [chandb_get
$showoff topictell
]
182 if {[lsearch -exact $tell *] >= 0} {
183 set tryspies
[chandb_list
]
187 foreach spy
$tryspies {
188 set see
[chandb_get
$spy topicsee
]
189 if {[lsearch -exact $see $showoff] >= 0 ||
\
190 ([lsearch -exact $see *] >= 0 && \
191 [lsearch -exact $tell $spy] >= 0)} {
192 sendprivmsg
$spy $msg
197 proc recordlastseen_p
{p how here
} {
199 recordlastseen_n
$n $how $here
202 proc chanmode_arg
{} {
204 set rv
[lindex $cm_args 0]
205 set cm_args
[lreplace cm_args
0 0]
209 proc chanmode_o1
{m g p chan
} {
210 global nick chan_initialop
212 set who
[chanmode_arg
]
213 recordlastseen_n
$n "being nice to $who" 1
214 if {"[irctolower $who]" == "[irctolower $nick]"} {
215 set nlower
[irctolower
$n]
216 upvar #0 nick_unique($nlower) u
217 if {[chandb_exists
$chan]} {
218 sendprivmsg
$n Thanks.
219 } elseif
{![info exists u
]} {
220 sendprivmsg
$n {Op me
while not on the channel
, why don't you ?
}
222 set chan_initialop
([irctolower
$chan]) $u
224 "Thanks. You can use `channel manager ...' to register this channel."
225 if {![nickdb_exists
$n] ||
![string length
[nickdb_get
$n username
]]} {
227 "(But to do that you must register your nick securely first.)"
233 proc chanmode_o0
{m g p chan
} {
236 set who
[chanmode_arg
]
237 recordlastseen_p
$p "being mean to $who" 1
238 if {"[irctolower $who]" == "[irctolower $nick]"} {
239 set chandeop
($chan) [list [clock seconds
] $p]
243 proc msg_MODE
{p c dest modelist args
} {
244 if {![ischan
$dest]} return
245 if {[regexp {^
\-(.
+)$} $modelist dummy modelist
]} {
247 } elseif
{[regexp {^
\+(.
+)$} $modelist dummy modelist
]} {
250 error "invalid modelist"
252 foreach m
[split $modelist] {
253 set procname chanmode_
$m$give
254 if {[catch { info body
$procname }]} {
255 recordlastseen_p
$p "fiddling with $dest" 1
257 $procname $m $give $p $dest
262 proc leaving
{lchan
} {
263 foreach luser
[array names nick_onchans
] {
264 upvar #0 nick_onchans($luser) oc
265 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
267 upvar #0 chan_nicks($lchan) nlist
269 upvar #0 chan_lastactivity($lchan) la
273 proc doleave
{lchan
} {
278 proc dojoin
{lchan
} {
281 set chan_nicks
($lchan) {}
284 proc check_justme
{lchan
} {
286 upvar #0 chan_nicks($lchan) nlist
287 if {[llength $nlist] != 1} return
288 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
289 if {[chandb_exists
$lchan]} {
290 set mode
[chandb_get
$lchan mode
]
291 if {"$mode" != "*"} {
292 sendout MODE
$lchan $mode
294 set topic
[chandb_get
$lchan topicset
]
295 if {[string length
$topic]} {
296 sendout TOPIC
$lchan $topic
303 proc process_kickpart
{chan user
} {
306 set luser
[irctolower
$user]
307 set lchan
[irctolower
$chan]
308 if {![ischan
$chan]} { error "not a channel" }
309 if {"$luser" == "[irctolower $nick]"} {
312 upvar #0 nick_onchans($luser) oc
313 upvar #0 chan_nicks($lchan) nlist
314 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
315 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
317 if {![llength $oc]} {
325 proc msg_TOPIC
{p c dest topic
} {
327 if {![ischan
$dest]} return
328 recordlastseen_n
$n "changing the topic on $dest" 1
329 note_topic
[irctolower
$dest] $n $topic
332 proc msg_KICK
{p c chans users comment
} {
333 set chans
[split $chans ,]
334 set users
[split $users ,]
335 if {[llength $chans] > 1} {
336 foreach chan
$chans user
$users { process_kickpart
$chan $user }
338 foreach user
$users { process_kickpart
[lindex $chans 0] $user }
342 proc msg_KILL
{p c user why
} {
347 set nick_arys
{onchans username unique
}
348 # nick_onchans($luser) -> [list ... $lchan ...]
349 # nick_username($luser) -> <securely known local username>
350 # nick_unique($luser) -> <counter>
351 # nick_case($luser) -> $user (valid even if no longer visible)
352 # nick_markid($luser) -> <after id for marktime>
354 # chan_nicks($lchan) -> [list ... $luser ...]
355 # chan_lastactivity($lchan) -> [clock seconds]
357 proc lnick_forget
{luser
} {
358 global nick_arys chan_nicks
359 lnick_marktime_cancel
$luser
360 foreach ary
$nick_arys {
361 upvar #0 nick_${ary}($luser) av
364 foreach lch
[array names chan_nicks
] {
365 upvar #0 chan_nicks($lch) nlist
366 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
371 proc nick_forget
{user
} {
372 global nick_arys chan_nicks
373 lnick_forget
[irctolower
$user]
377 proc nick_case
{user
} {
379 set nick_case
([irctolower
$user]) $user
382 proc msg_NICK
{p c newnick
} {
383 global nick_arys nick_case calling_nick
385 recordlastseen_n
$n "changing nicks to $newnick" 0
386 set calling_nick
$newnick
387 recordlastseen_n
$newnick "changing nicks from $n" 1
388 set luser
[irctolower
$n]
389 lnick_marktime_cancel
$luser
390 set lusernew
[irctolower
$newnick]
391 foreach ary
$nick_arys {
392 upvar #0 nick_${ary}($luser) old
393 upvar #0 nick_${ary}($lusernew) new
394 if {[info exists new
]} { error "nick collision ?! $ary $n $newnick" }
395 if {[info exists old
]} { set new
$old; unset old
}
397 upvar #0 nick_onchans($lusernew) oc
399 upvar #0 chan_nicks($ch) nlist
400 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
401 lappend nlist
$lusernew
403 lnick_marktime_start
$lusernew "Hi." 500
407 proc nick_ishere
{n
} {
409 upvar #0 nick_unique([irctolower $n]) u
410 if {![info exists u
]} { set u
[incr nick_counter
].
$n.
[clock seconds
] }
414 proc msg_JOIN
{p c chan
} {
416 recordlastseen_n
$n "joining $chan" 1
417 set nl
[irctolower
$n]
418 set lchan
[irctolower
$chan]
419 upvar #0 nick_onchans($nl) oc
420 upvar #0 chan_nicks($lchan) nlist
421 if {![info exists oc
]} {
422 global marktime_join_startdelay
423 lnick_marktime_start
$nl "Welcome." $marktime_join_startdelay
429 proc msg_PART
{p c chan args
} {
431 set msg
"leaving $chan"
432 if {[llength $args]} {
433 set why
[lindex $args 0]
434 if {"[irctolower $why]" != "[irctolower $n]"} { append msg
" ($why)" }
436 recordlastseen_n
$n $msg 1
437 process_kickpart
$chan $n
439 proc msg_QUIT
{p c why
} {
441 recordlastseen_n
$n "leaving ($why)" 0
445 proc msg_PRIVMSG
{p c dest
text} {
449 if {[ischan
$dest]} {
450 recordlastseen_n
$n "invoking me in $dest" 1
453 recordlastseen_n
$n "talking to me" 1
458 execute_usercommand
$p $c $n $output $dest $text
461 proc msg_INVITE
{p c n chan
} {
462 after 1000 [list dojoin
[irctolower
$chan]]
465 proc grep
{var predicate
list} {
469 if {[uplevel 1 [list expr $predicate]]} { lappend o
$v }
474 proc msg_353
{p c dest type chan nicklist
} {
475 global names_chans nick_onchans
476 set lchan
[irctolower
$chan]
477 upvar #0 chan_nicks($lchan) nlist
478 lappend names_chans
$lchan
479 if {![info exists nlist
]} {
480 # We don't think we're on this channel, so ignore it !
481 # Unfortunately, because we don't get a reply to PART,
482 # we have to remember ourselves whether we're on a channel,
483 # and ignore stuff if we're not, to avoid races. Feh.
487 foreach user
[split $nicklist { }] {
488 regsub {^
[@+]} $user {} user
489 if {![string length
$user]} continue
491 set luser
[irctolower
$user]
492 upvar #0 nick_onchans($luser) oc
494 lappend nlist_new
$luser
500 proc msg_366
{p c args
} {
501 global names_chans nick_onchans
502 set lchan
[irctolower
$c]
503 foreach luser
[array names nick_onchans
] {
504 upvar #0 nick_onchans($luser) oc
505 if {[llength names_chans
] > 1} {
506 set oc
[grep tc
{[lsearch -exact $tc $names_chans] >= 0} $oc]
508 if {![llength $oc]} { lnick_forget
$n }
513 proc check_username
{target
} {
515 [string length
$target] > 8 ||
516 [regexp {[^
-0-9a-z
]} $target] ||
517 ![regexp {^
[a-z
]} $target]
518 } { error "invalid username" }
521 proc somedb__head
{} {
523 set idl
[irctolower
$id]
524 upvar #0 ${nickchan}db($idl) ndbe
525 binary scan $idl H
* idh
526 set idfn
$fprefix$idh
527 if {![info exists iddbe
] && [file exists
$idfn]} {
529 try_except_finally
{ set newval
[read $f] } {} { close $f }
530 if {[llength $newval] % 2} { error "invalid length" }
536 proc def_somedb
{name arglist body
} {
537 foreach {nickchan fprefix
} {nick users
/n chan chans
/c
} {
538 proc ${nickchan
}db_
$name $arglist \
539 "set nickchan $nickchan; set fprefix $fprefix; $body"
545 foreach path
[glob -nocomplain -path $fprefix *] {
546 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
547 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
548 lappend list [binary format H
* $thinghex]
553 proc def_somedb_id
{name arglist body
} {
554 def_somedb
$name [concat id
$arglist] "somedb__head; $body"
557 def_somedb_id exists
{} {
558 return [info exists iddbe
]
561 def_somedb_id delete
{} {
562 catch { unset iddbe
}
566 set default_settings_nick
{timeformat ks marktime off
}
567 set default_settings_chan
{
576 def_somedb_id
set {args
} {
577 upvar #0 default_settings_$nickchan def
578 if {![info exists iddbe
]} { set iddbe
$def }
579 foreach {key value
} [concat $iddbe $args] { set a
($key) $value }
581 foreach {key value
} [array get a
] { lappend newval
$key $value }
582 set f
[open $idfn.new w
]
586 file rename -force $idfn.new
$idfn
594 def_somedb_id get
{key
} {
595 upvar #0 default_settings_$nickchan def
596 if {[info exists iddbe
]} {
597 set l
[concat $iddbe $def]
601 foreach {tkey value
} $l {
602 if {"$tkey" == "$key"} { return $value }
604 error "unset setting $key"
609 if {[info exists calling_nick
]} { set n
$calling_nick } { set n
{} }
610 return [nickdb_get
$n $key]
613 proc check_notonchan
{} {
615 if {[ischan
$dest]} { usererror
"That command must be sent privately." }
618 proc nick_securitycheck
{strict
} {
620 if {![nickdb_exists
$n]} {
621 usererror
"You are unknown to me, use `register'."
623 set wantu
[nickdb_get
$n username
]
624 if {![string length
$wantu]} {
626 usererror
"That feature is only available to secure users, sorry."
631 set luser
[irctolower
$n]
632 upvar #0 nick_username($luser) nu
633 if {![info exists nu
]} {
634 usererror
"Nick $n is secure, you must identify yourself first."
636 if {"$wantu" != "$nu"} {
637 usererror
"You are the wrong user -\
638 the nick $n belongs to $wantu, not $nu."
642 proc channel_ismanager
{channel n
} {
643 set mgrs
[chandb_get
$channel managers
]
644 return [expr {[lsearch -exact [irctolower
$mgrs] [irctolower
$n]] >= 0}]
647 proc channel_securitycheck
{channel
} {
649 if {![channel_ismanager
$channel $n]} {
650 usererror
"You are not a manager of $channel."
655 proc def_chancmd
{name body
} {
656 proc channel
/$name {} \
657 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
660 proc ta_listop
{findnow procvalue
} {
661 # findnow and procvalue are code fragments which will be executed
662 # in the caller's level. findnow should set ta_listop_ev to
663 # the current list, and procvalue should treat ta_listop_ev as
664 # a proposed value in the list and check and possibly modify
665 # (canonicalise?) it. After ta_listop, ta_listop_ev will
666 # be the new value of the list.
667 upvar 1 ta_listop_ev exchg
670 switch -exact _
$opcode {
674 foreach item
$exchg { set array($item) 1 }
677 error "list change opcode must be one of + - ="
680 foreach exchg
[split $text " "] {
681 if {![string length
$exchg]} continue
683 if {"$opcode" != "-"} {
686 catch { unset array($exchg) }
689 set exchg
[lsort [array names
array]]
692 def_chancmd manager
{
694 if {[chandb_exists
$chan]} {
695 set ta_listop_ev
[chandb_get
$chan managers
]
697 set ta_listop_ev
[list [irctolower
$n]]
700 check_nick
$ta_listop_ev
701 set ta_listop_ev
[irctolower
$ta_listop_ev]
703 if {[llength $ta_listop_ev]} {
704 chandb_set
$chan managers
$ta_listop_ev
705 ucmdr
"Managers of $chan: $ta_listop_ev" {}
708 ucmdr
{} {} "forgets about managing $chan." {}
712 def_chancmd autojoin
{
714 switch -exact [string tolower
$yesno] {
717 default { error "channel autojoin must be `yes' or `no' }
719 chandb_set $chan autojoin $nv
720 ucmdr [expr {$nv ? "I will
join $chan when I'm restarted
" : \
721 "I won't
join $chan when I'm restarted
"}] {}
724 def_chancmd userinvite {
725 set nv [string tolower [ta_word]]
727 pub { set txt "!invite will work
for $chan, but it won't work by
/msg
" }
728 here { set txt "!invite and
/msg invite will work
, but only
for users who are already on
$chan.
" }
729 all { set txt "Any user will be able to invite themselves or anyone
else to
$chan.
" }
730 none { set txt "I will not invite anyone to
$chan.
" }
732 error "channel userinvite must be `pub'
, `here'
, `all' or `none'
735 chandb_set
$chan userinvite
$nv
741 switch -exact $what {
744 chandb_set
$chan topicset
{}
745 ucmdr
"I won't ever change the topic of $chan." {}
748 set t
[string trim
$text]
749 if {![string length
$t]} {
750 error "you must specific the topic to set"
752 chandb_set
$chan topicset
$t
753 ucmdr
"Whenever I'm alone on $chan, I'll set the topic to $t." {}
757 set ta_listop_ev
[chandb_get
$chan topic
$what]
759 if {"$ta_listop_ev" != "*"} {
760 if {![ischan
$ta_listop_ev]} {
761 error "bad channel \`$ta_listop_ev' in topic $what"
763 set ta_listop_ev
[irctolower
$ta_listop_ev]
766 chandb_set
$chan topic
$what $ta_listop_ev
767 ucmdr
"Topic $what list for $chan: $ta_listop_ev" {}
770 usererror
"Unknown channel topic subcommand - see help channel."
777 if {"$mode" != "*" && ![regexp {^
(([-+][imnpst
]+)+)$} $mode mode
]} {
778 error {channel mode must be
* or match
([-+][imnpst
]+)+}
780 chandb_set
$chan mode
$mode
781 if {"$mode" == "*"} {
782 ucmdr
"I won't ever change the mode of $chan." {}
784 ucmdr
"Whenever I'm alone on $chan, I'll set the mode to $mode." {}
789 if {[chandb_exists
$chan]} {
790 set l
"Settings for $chan: autojoin "
791 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
792 append l
", mode " [chandb_get
$chan mode
]
793 append l
", userinvite " [chandb_get
$chan userinvite
] "."
794 append l
"\nManagers: "
795 append l
[join [chandb_get
$chan managers
] " "]
796 foreach {ts sep
} {see
"\n" tell " "} {
797 set t
[chandb_get
$chan topic
$ts]
800 append l
"Topic $ts list: $t."
802 append l
"Topic $ts list is empty."
806 set t
[chandb_get
$chan topicset
]
807 if {[string length
$t]} {
808 append l
"Topic to set: $t"
810 append l
"I will not change the topic."
814 ucmdr
{} "The channel $chan is not managed."
818 proc channelmgr_monoop
{} {
823 upvar 1 target target
828 if {[ischan
$dest]} { set target
$dest }
829 if {[ta_anymore
]} { set target
[ta_word
] }
831 if {![info exists target
]} {
832 usererror
"You must specify, or invoke me on, the relevant channel."
834 if {![info exists chan_nicks
([irctolower
$target])]} {
835 usererror
"I am not on $target."
837 if {![ischan
$target]} { error "not a valid channel" }
839 if {![chandb_exists
$target]} {
840 usererror
"$target is not a managed channel."
842 channel_securitycheck
$target
847 sendout MODE
$target +o
$n
856 global chan_nicks errorCode errorInfo
859 if {[ischan
$dest]} {
866 set ltarget
[irctolower
$target]
867 if {![ischan
$target]} { error "$target is not a channel" }
868 if {![info exists chan_nicks
($ltarget)]} {
869 usererror
"I am not on $target."
871 set ui
[chandb_get
$ltarget userinvite
]
873 if {"$ui" == "pub" && !$onchan} {
874 usererror
"Invitations to $target must be made there with !invite."
876 if {"$ui" != "all"} {
877 if {[lsearch -exact $chan_nicks($ltarget) [irctolower
$n]] < 0} {
878 usererror
"Invitations to $target may only be made\
879 by a user on the channel."
882 if {"$ui" == "none"} {
883 usererror
"Sorry, I've not been authorised\
884 to invite people to $target."
887 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager
$target $n]} {
891 if {"$errorCode" == "BLIGHT USER"} {
892 usererror
"$emsg2 Therefore you can't use your\
893 channel manager privilege. $emsg"
895 error $error $errorInfo $errorCode
899 error $emsg $errorInfo $errorCode
903 usererror
"You have to say who to invite."
906 while {[ta_anymore
]} {
907 set invitee
[ta_word
]
909 lappend invitees
$invitee
911 foreach invitee
$invitees {
912 sendout INVITE
$invitee $ltarget
914 set who
[lindex $invitees 0]
915 switch -exact llength $invitees {
916 0 { error "zero invitees" }
918 2 { append who
" and [lindex $invitees 1]" }
920 set who
[join [lreplace $invitees end end
] ", "]
921 append who
" and [lindex $invitees [llength $invitees]]"
924 ucmdr
{} {} {} "invites $who to $target."
928 if {[ischan
$dest]} { set target
$dest }
934 if {[ischan
$subcmd]} {
942 if {![info exists target
]} { error "privately, you must specify a channel" }
943 set procname channel
/$subcmd
944 if {"$subcmd" != "show"} {
945 if {[catch { info body
$procname }]} {
946 usererror
"unknown channel setting $subcmd."
949 if {[chandb_exists
$target]} {
950 channel_securitycheck
$target
953 upvar #0 chan_initialop([irctolower $target]) io
954 upvar #0 nick_unique([irctolower $n]) u
955 if {![info exists io
]} {
956 usererror
"$target is not a managed channel."
959 usererror
"You are not the interim manager of $target."
961 if {"$subcmd" != "manager"} {
962 usererror
"Please use `channel manager' first."
971 set target
[ta_word
]; ta_nomore
976 set myself
[expr {"$target" != "$n"}]
978 set ltarget
[irctolower
$target]
979 upvar #0 nick_case($ltarget) ctarget
981 if {[info exists ctarget
]} {
982 upvar #0 nick_onchans($ltarget) oc
983 upvar #0 nick_username($ltarget) nu
984 if {[info exists oc
]} { set nshow
$ctarget }
986 if {![nickdb_exists
$ltarget]} {
987 set ol
"$nshow is not a registered nick."
988 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
989 set ol
"The nick $nshow belongs to the user $username."
991 set ol
"The nick $nshow is registered (but not to a username)."
993 if {![info exists ctarget
] ||
![info exists oc
]} {
995 append ol
"\nI can't see $nshow on anywhere."
997 append ol
"\nYou aren't on any channels with me."
999 } elseif
{![info exists nu
]} {
1000 append ol
"\n$nshow has not identified themselves."
1001 } elseif
{![info exists username
]} {
1002 append ol
"\n$nshow has identified themselves as the user $nu."
1003 } elseif
{"$nu" != "$username"} {
1004 append ol
"\nHowever, $nshow is being used by the user $nu."
1006 append ol
"\n$nshow has identified themselves to me."
1014 set old
[nickdb_exists
$n]
1015 if {$old} { nick_securitycheck
0 }
1016 set luser
[irctolower
$n]
1017 switch -exact [string tolower
[string trim
$text]] {
1019 upvar #0 nick_username($luser) nu
1020 if {![info exists nu
]} {
1022 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1024 nickdb_set
$n username
$nu
1025 ucmdr
{} {} "makes a note of your username." {}
1029 ucmdr
{} {} "forgets your nickname." {}
1032 nickdb_set
$n username
{}
1034 ucmdr
{} "Security is now disabled for your nickname !"
1036 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."
1040 error "you mean register / register delete / register insecure"
1045 proc timeformat_desc
{tf
} {
1047 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1048 hms
{ return "Times will be displayed in hours, minutes, etc." }
1049 beat
{ return "Times will be displayed in beats (1000B = 1d)." }
1050 default { error "invalid timeformat: $v" }
1054 proc def_setting
{opt show_body set_body
} {
1055 proc set_show
/$opt {} "
1059 if {![string length
$set_body]} return
1060 proc set_set
/$opt {} "
1067 def_setting timeformat
{
1068 set tf
[nickdb_get
$n timeformat
]
1069 return "$tf: [timeformat_desc $tf]"
1071 set tf
[string tolower
[ta_word
]]
1073 set desc
[timeformat_desc
$tf]
1074 nickdb_set
$n timeformat
$tf
1078 proc marktime_desc
{mt
} {
1079 if {"$mt" == "off"} {
1080 return "I will not send you periodic messages."
1081 } elseif
{"$mt" == "once"} {
1082 return "I will send you one informational message when I see you."
1084 return "I'll send you a message every [showintervalsecs $mt 0]."
1088 def_setting marktime
{
1089 set mt
[nickdb_get
$n marktime
]
1091 if {[string match
{[0-9]*} $mt]} { append p s
}
1093 append p
[marktime_desc
$mt]
1097 set mt
[string tolower
[ta_word
]]
1100 if {"$mt" == "off" ||
"$mt" == "once"} {
1101 } elseif
{[regexp {^
([0-9]+)([a-z
]+)$} $mt dummy value unit
]} {
1102 switch -exact $unit {
1109 default { error "unknown unit of time $unit" }
1111 if {$value > 86400*21/$u} { error "marktime interval too large" }
1112 set mt
[expr {round
($value*$u)}]
1113 if {$mt < $marktime_min} { error "marktime interval too small" }
1115 error "invalid syntax for marktime"
1117 nickdb_set
$n marktime
$mt
1118 lnick_marktime_start
[irctolower
$n] "So:" 500
1119 ucmdr
{} [marktime_desc
$mt]
1122 def_setting security
{
1123 set s
[nickdb_get
$n username
]
1124 if {[string length
$s]} {
1125 return "Your nick, $n, is controlled by the user $s."
1127 return "Your nick, $n, is not secure."
1134 if {![nickdb_exists
$n]} {
1135 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1137 if {![ta_anymore
]} {
1139 foreach proc [lsort [info procs
]] {
1140 if {![regexp {^set_show
/(.
*)$} $proc dummy opt
]} continue
1141 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1143 ucmdr
{} [join $ol "\n"]
1146 if {[catch { info body set_show
/$opt }]} {
1147 error "no setting $opt"
1149 if {![ta_anymore
]} {
1150 ucmdr
{} "$opt [set_show/$opt]"
1152 nick_securitycheck
0
1153 if {[catch { info body set_set
/$opt }]} {
1154 error "setting $opt cannot be set with `set'"
1161 def_ucmd identpass
{
1162 set username
[ta_word
]
1163 set passmd5
[md5sum
"[ta_word]\n"]
1167 set luser
[irctolower
$n]
1168 upvar #0 nick_onchans($luser) onchans
1169 if {![info exists onchans
] ||
![llength $onchans]} {
1170 ucmdr
"You must be on a channel with me to identify yourself." {}
1172 check_username
$username
1173 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1175 upvar #0 nick_username($luser) rec_username
1176 set rec_username
$username
1177 ucmdr
"Pleased to see you, $username." {}
1181 set target
[ta_word
]
1183 check_username
$target
1186 upvar #0 lastsummon($target) ls
1187 set now
[clock seconds
]
1188 if {[info exists ls
]} {
1189 set interval
[expr {$now - $ls}]
1190 if {$interval < 30} {
1192 "Please be patient; $target was summoned only [showinterval $interval]."
1195 regsub {^
[^
!]*!} $p {} path
1197 exec userv
--timeout 3 $target irc-summon
$n $path \
1198 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1201 regsub -all "\n" $rv { / } rv
1204 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1205 ucmdr
{} "The user `$target' $problem."
1206 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1207 set idletime
[expr {$now - $idlesince}]
1209 ucmdr
{} {} {} "invites $target ($tty[expr {
1210 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime 0]" : ""
1212 [ischan $dest] ? "join us here
" : "talk to you
"
1215 error "unexpected response from userv service: $rv"
1219 proc md5sum
{value
} { exec md5sum
<< $value }
1222 global lastseen nick
1225 set nlower
[irctolower
$ncase]
1227 set now
[clock seconds
]
1228 if {"$nlower" == "[irctolower $nick]"} {
1229 usererror
"I am not self-aware."
1230 } elseif
{![info exists lastseen
($nlower)]} {
1231 set rstr
"I've never seen $ncase."
1233 manyset
$lastseen($nlower) realnick
time what
1234 set howlong
[expr {$now - $time}]
1235 set string [showinterval
$howlong]
1236 set rstr
"I last saw $realnick $string, $what."
1238 if {[ischan
$dest]} {
1243 upvar #0 lookedfor($nlower) lf
1244 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1245 set lf
[list [list $now $n $where]]
1246 foreach v
$oldvalue {
1247 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1253 proc lnick_marktime_cancel
{luser
} {
1254 upvar #0 nick_markid($luser) mi
1255 if {![info exists mi
]} return
1256 catch { after cancel
$mi }
1260 proc lnick_marktime_doafter
{luser why ms
} {
1261 lnick_marktime_cancel
$luser
1262 upvar #0 nick_markid($luser) mi
1263 set mi
[after $ms [list lnick_marktime_now
$luser $why]]
1266 proc lnick_marktime_reset
{luser
} {
1267 set mt
[nickdb_get
$luser marktime
]
1268 if {"$mt" == "off" ||
"$mt" == "once"} return
1269 lnick_marktime_doafter
$luser "Time passes." [expr {$mt*1000}]
1272 proc lnick_marktime_start
{luser why ms
} {
1273 set mt
[nickdb_get
$luser marktime
]
1274 if {"$mt" == "off"} {
1275 lnick_marktime_cancel
$luser
1277 lnick_marktime_doafter
$luser $why $ms
1281 proc lnick_marktime_now
{luser why
} {
1282 upvar #0 nick_onchans($luser) oc
1284 set calling_nick
$luser
1285 sendprivmsg
$luser [lnick_pingstring
$why $oc ""]
1286 lnick_marktime_reset
$luser
1289 proc lnick_pingstring
{why oc apstring
} {
1291 catch { exec uptime
} uptime
1292 set nnicks
[llength [array names nick_onchans
]]
1294 {^
*([0-9:apm
]+) +up.
*, +(\d
+) users?
, +load average
: +([0-9.
, ]+) *$} \
1295 $uptime dummy
time users
load]} {
1296 regsub -all , $load {} load
1297 set uptime
"$time $nnicks/$users $load"
1299 append uptime
", $nnicks nicks"
1301 if {[llength $oc]} {
1305 upvar #0 chan_lastactivity($ch) la
1306 if {![info exists la
]} continue
1307 if {$la <= $best_la} continue
1308 set since
[showintervalsecs
[expr {[clock seconds
]-$la}] 1]
1309 set activity
"$ch $since"
1316 append str
" " $uptime " " $activity
1317 if {[string length
$apstring]} { append str
" " $apstring }
1322 if {[ischan
$dest]} {
1323 set oc
[irctolower
$dest]
1327 set ln
[irctolower
$n]
1328 if {[info exists nick_onchans
($ln)]} {
1329 set oc
$nick_onchans($ln)
1333 if {[llength $oc]} { lnick_marktime_reset
$ln }
1335 ucmdr
{} [lnick_pingstring
"Pong!" $oc $text]
1338 proc ensure_globalsecret
{} {
1341 if {[info exists globalsecret
]} return
1342 set gsfile
[open /dev
/urandom r
]
1343 fconfigure $gsfile -translation binary
1344 set globalsecret
[read $gsfile 32]
1345 binary scan $globalsecret H
* globalsecret
1351 foreach chan
[chandb_list
] {
1352 if {[chandb_get
$chan autojoin
]} { dojoin
$chan }