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 showintervalsecs
/ks
{howlong abbrev
} {
30 if {$howlong < 1000} {
33 if {$howlong < 1000000} {
40 set value
[expr "$howlong.0 / $scale"]
41 foreach {min
format} {100 %.0f
10 %.1f
1 %.2f
} {
42 if {$value < $min} continue
43 return [format "$format${pfx}s" $value]
48 proc format_qty
{qty unit abbrev
} {
51 append o
[string range
$unit 0 0]
55 if {$qty != 1} { append o s
}
60 proc showintervalsecs
/hms
{qty abbrev
} {
61 set ul
{second
60 minute
60 hour
24 day
7 week
}
63 while {[llength $ul] > 1 && $qty >= [set uv
[lindex $ul 1]]} {
64 set remainu
[lindex $ul 0]
65 set remainv
[expr {$qty % $uv}]
66 set qty
[expr {($qty-$remainv)/$uv}]
67 set ul
[lreplace $ul 0 1]
69 set o
[format_qty
$qty [lindex $ul 0] $abbrev]
71 if {!$abbrev} { append o
" " }
72 append o
[format_qty
$remainv $remainu $abbrev]
77 proc showinterval
{howlong
} {
81 return "[showintervalsecs $howlong 0] ago"
85 proc showtime
{when
} {
86 return [showinterval
[expr {[clock seconds
] - $when}]]
89 proc parse_interval
{specified min
} {
90 if {![regexp {^
([0-9]+)([a-z
]+)$} $specified dummy value unit
]} {
91 error "invalid syntax for interval"
98 default { error "unknown unit of time $unit" }
100 if {$value > 86400*21/$u} { error "interval too large" }
101 set result
[expr {$value*$u}]
102 if {$result < $min} { error "interval too small (<${min}s)" }
106 proc def_msgproc
{name argl body
} {
107 proc msg_
$name "varbase $argl" "\
108 upvar #0 msg/\$varbase/dest d\n\
109 upvar #0 msg/\$varbase/str s\n\
110 upvar #0 msg/\$varbase/accum a\n\
114 def_msgproc begin
{dest str
} {
120 def_msgproc
append {str
} {
122 if {[string length
$s] && [string length
$ns] > 65} {
123 msg__sendout
$varbase
124 set s
" [string trimleft $str]"
130 def_msgproc finish
{} {
131 msg__sendout
$varbase
137 def_msgproc _sendout
{} {
138 lappend a
[string trimright
$s]
142 proc looking_whenwhere
{when where
} {
143 set str
[showtime
[expr {$when-1}]]
144 if {[string length
$where]} { append str
" on $where" }
148 proc check_telling
{nl
event} {
149 # event is `talk', `act' or `come'
151 set iml
[msgdb_get
$nl inbound
]
152 if {![llength $iml]} return
154 upvar #0 nick_telling($nl) telling
155 upvar #0 nick_unique($nl) u
157 if {[info exists telling
]} {
158 manyset
$telling u2 stt telling_when
159 if {"$u2" != "$u"} { unset telling
; unset stt
; unset telling_when
}
162 if {![info exists stt
]} {
164 set telling_when
$now
167 set ago
[expr {$now - $telling_when}]
169 # evstate is string of letters
178 # security level and timing
180 # ss Secure and soon (before interval)
181 # sl Secure and late (after interval)
182 # reliability and timing
184 # rv Remind, very soon (before within-interval)
185 # rs Remind, soon (between)
186 # rl Remind, late (aftr every-interval)
187 # ps Pester, soon (before interval)
188 # pl Pester, late (after interval)
189 # current identification
194 # h Hidden (invisible, no unique)
196 set evstate
[string range
$stt 0 0]
198 manyset
[nickdb_get
$n tellsec
] sec secwhen
200 insecure
{ append evstate ii
}
201 secure
{ append evstate
[expr {$ago<$secwhen ?
"sl" : "ss"}] }
202 default { append evstate
"#$sec#" }
205 manyset
[nickdb_set
$n tellrel
] rel relint relwithin
207 unreliable
{ append evstate uu
}
208 remind
{ append evstate
[expr {
209 $ago<$relwithin ?
"rv" : $ago<$relint ?
"rs" : "rl"
211 pester
{ append evstate
[expr {$ago<$relint ?
"ps" : "pl"}] }
212 default { append evstate
"#$rel#" }
215 upvar #0 nick_username($nl) nu
216 if {[info exists nu
] && "$nu" == "[nickdb_get $nl username]"} {
222 append evstate
[expr {[info exists u
] ?
"v" : "h"}]
224 switch -glob $evstate {
234 if {![info exists u
]} { catch { unset telling
} }
235 && [info exists telling
]} {
240 if {![info exists telling
]} {
243 proc recordlastseen_n
{n how here
} {
244 global lastseen lookedfor
245 set nl
[irctolower
$n]
246 set now
[clock seconds
]
247 set lastseen
($nl) [list $n $now $how]
251 check_telling
$nl [lindex {x act talk
} $here]
253 upvar #0 lookedfor($nl) lf
254 if {[info exists lf
]} {
255 switch -exact [llength $lf] {
260 manyset
[lindex $lf 0] when who where
262 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
265 msg_begin tosend
$n "FYI, people have been looking for you:"
271 msg_append tosend
" "
272 } elseif
{$i == [llength $lf]} {
273 msg_append tosend
" and "
276 msg_append tosend
", "
278 manyset
$e when who where
280 "$who ([looking_whenwhere $when $where])$fin"
282 set ml
[msg_finish tosend
]
286 msendprivmsg_delayed
1000 $n $ml
290 proc note_topic
{showoff whoby topic
} {
291 set msg
"FYI, $whoby has changed the topic on $showoff"
292 if {[string length
$topic] < 160} {
293 append msg
" to $topic"
295 append msg
" but it is too long to reproduce here !"
297 set showoff
[irctolower
$showoff]
298 set tell [chandb_get
$showoff topictell
]
299 if {[lsearch -exact $tell *] >= 0} {
300 set tryspies
[chandb_list
]
304 foreach spy
$tryspies {
305 set see
[chandb_get
$spy topicsee
]
306 if {[lsearch -exact $see $showoff] >= 0 ||
\
307 ([lsearch -exact $see *] >= 0 && \
308 [lsearch -exact $tell $spy] >= 0)} {
309 sendprivmsg
$spy $msg
314 proc recordlastseen_p
{p how here
} {
316 recordlastseen_n
$n $how $here
319 proc chanmode_arg
{} {
321 set rv
[lindex $cm_args 0]
322 set cm_args
[lreplace cm_args
0 0]
326 proc chanmode_o1
{m g p chan
} {
327 global nick chan_initialop
329 set who
[chanmode_arg
]
330 recordlastseen_n
$n "being nice to $who" 1
331 if {"[irctolower $who]" == "[irctolower $nick]"} {
332 set nlower
[irctolower
$n]
333 upvar #0 nick_unique($nlower) u
334 if {[chandb_exists
$chan]} {
335 sendprivmsg
$n Thanks.
336 } elseif
{![info exists u
]} {
337 sendprivmsg
$n {Op me
while not on the channel
, why don't you ?
}
339 set chan_initialop
([irctolower
$chan]) $u
341 "Thanks. You can use `channel manager ...' to register this channel."
342 if {![nickdb_exists
$n] ||
![string length
[nickdb_get
$n username
]]} {
344 "(But to do that you must register your nick securely first.)"
350 proc chanmode_o0
{m g p chan
} {
353 set who
[chanmode_arg
]
354 recordlastseen_p
$p "being mean to $who" 1
355 if {"[irctolower $who]" == "[irctolower $nick]"} {
356 set chandeop
($chan) [list [clock seconds
] $p]
360 proc msg_MODE
{p c dest modelist args
} {
361 if {![ischan
$dest]} return
362 if {[regexp {^
\-(.
+)$} $modelist dummy modelist
]} {
364 } elseif
{[regexp {^
\+(.
+)$} $modelist dummy modelist
]} {
367 error "invalid modelist"
369 foreach m
[split $modelist] {
370 set procname chanmode_
$m$give
371 if {[catch { info body
$procname }]} {
372 recordlastseen_p
$p "fiddling with $dest" 1
374 $procname $m $give $p $dest
379 proc leaving
{lchan
} {
380 foreach luser
[array names nick_onchans
] {
381 upvar #0 nick_onchans($luser) oc
382 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
384 upvar #0 chan_nicks($lchan) nlist
386 upvar #0 chan_lastactivity($lchan) la
390 proc doleave
{lchan
} {
395 proc dojoin
{lchan
} {
398 set chan_nicks
($lchan) {}
401 proc check_justme
{lchan
} {
403 upvar #0 chan_nicks($lchan) nlist
404 if {[llength $nlist] != 1} return
405 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
406 if {[chandb_exists
$lchan]} {
407 set mode
[chandb_get
$lchan mode
]
408 if {"$mode" != "*"} {
409 sendout MODE
$lchan $mode
411 set topic
[chandb_get
$lchan topicset
]
412 if {[string length
$topic]} {
413 sendout TOPIC
$lchan $topic
420 proc process_kickpart
{chan user
} {
423 set luser
[irctolower
$user]
424 set lchan
[irctolower
$chan]
425 if {![ischan
$chan]} { error "not a channel" }
426 if {"$luser" == "[irctolower $nick]"} {
429 upvar #0 nick_onchans($luser) oc
430 upvar #0 chan_nicks($lchan) nlist
431 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
432 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
434 if {![llength $oc]} {
442 proc msg_TOPIC
{p c dest topic
} {
444 if {![ischan
$dest]} return
445 recordlastseen_n
$n "changing the topic on $dest" 1
446 note_topic
[irctolower
$dest] $n $topic
449 proc msg_KICK
{p c chans users comment
} {
450 set chans
[split $chans ,]
451 set users
[split $users ,]
452 if {[llength $chans] > 1} {
453 foreach chan
$chans user
$users { process_kickpart
$chan $user }
455 foreach user
$users { process_kickpart
[lindex $chans 0] $user }
459 proc msg_KILL
{p c user why
} {
464 set nick_arys
{onchans username unique
}
465 # nick_onchans($luser) -> [list ... $lchan ...]
466 # nick_username($luser) -> <securely known local username>
467 # nick_unique($luser) -> <includes-counter>
468 # nick_case($luser) -> $user (valid even if no longer visible)
469 # nick_markid($luser) -> <after id for marktime>
470 # nick_telling($luser) -> <unique> mentioned|passed <when>
472 # chan_nicks($lchan) -> [list ... $luser ...]
473 # chan_lastactivity($lchan) -> [clock seconds]
475 proc lnick_forget
{luser
} {
476 global nick_arys chan_nicks
477 lnick_marktime_cancel
$luser
478 foreach ary
$nick_arys {
479 upvar #0 nick_${ary}($luser) av
482 foreach lch
[array names chan_nicks
] {
483 upvar #0 chan_nicks($lch) nlist
484 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
489 proc nick_forget
{user
} {
490 global nick_arys chan_nicks
491 lnick_forget
[irctolower
$user]
495 proc nick_case
{user
} {
497 set nick_case
([irctolower
$user]) $user
500 proc msg_NICK
{p c newnick
} {
501 global nick_arys nick_case calling_nick
503 recordlastseen_n
$n "changing nicks to $newnick" 0
504 set calling_nick
$newnick
505 recordlastseen_n
$newnick "changing nicks from $n" 1
506 set luser
[irctolower
$n]
507 lnick_marktime_cancel
$luser
508 set lusernew
[irctolower
$newnick]
509 foreach ary
$nick_arys {
510 upvar #0 nick_${ary}($luser) old
511 upvar #0 nick_${ary}($lusernew) new
512 if {[info exists new
]} { error "nick collision ?! $ary $n $newnick" }
513 if {[info exists old
]} { set new
$old; unset old
}
515 upvar #0 nick_onchans($lusernew) oc
517 upvar #0 chan_nicks($ch) nlist
518 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
519 lappend nlist
$lusernew
521 lnick_marktime_start
$lusernew "Hi." 500 1
525 proc nick_ishere
{n
} {
527 upvar #0 nick_unique([irctolower $n]) u
528 if {![info exists u
]} { set u
[incr nick_counter
].
$n.
[clock seconds
] }
532 proc msg_JOIN
{p c chan
} {
535 recordlastseen_n
$n "joining $chan" 1
536 set nl
[irctolower
$n]
537 set lchan
[irctolower
$chan]
538 upvar #0 nick_onchans($nl) oc
539 upvar #0 chan_nicks($lchan) nlist
540 if {![info exists oc
]} {
541 global marktime_join_startdelay
542 lnick_marktime_start
$nl "Welcome." $marktime_join_startdelay 1
547 proc msg_PART
{p c chan args
} {
549 set msg
"leaving $chan"
550 if {[llength $args]} {
551 set why
[lindex $args 0]
552 if {"[irctolower $why]" != "[irctolower $n]"} { append msg
" ($why)" }
554 recordlastseen_n
$n $msg 1
555 process_kickpart
$chan $n
557 proc msg_QUIT
{p c why
} {
559 recordlastseen_n
$n "leaving ($why)" 0
563 proc msg_PRIVMSG
{p c dest
text} {
567 if {[ischan
$dest]} {
568 recordlastseen_n
$n "invoking me in $dest" 1
571 recordlastseen_n
$n "talking to me" 1
576 execute_usercommand
$p $c $n $output $dest $text
579 proc msg_INVITE
{p c n chan
} {
580 after 1000 [list dojoin
[irctolower
$chan]]
583 proc grep
{var predicate
list} {
587 if {[uplevel 1 [list expr $predicate]]} { lappend o
$v }
592 proc msg_353
{p c dest type chan nicklist
} {
593 global names_chans nick_onchans
594 set lchan
[irctolower
$chan]
595 upvar #0 chan_nicks($lchan) nlist
596 lappend names_chans
$lchan
597 if {![info exists nlist
]} {
598 # We don't think we're on this channel, so ignore it !
599 # Unfortunately, because we don't get a reply to PART,
600 # we have to remember ourselves whether we're on a channel,
601 # and ignore stuff if we're not, to avoid races. Feh.
605 foreach user
[split $nicklist { }] {
606 regsub {^
[@+]} $user {} user
607 if {![string length
$user]} continue
609 set luser
[irctolower
$user]
610 upvar #0 nick_onchans($luser) oc
612 lappend nlist_new
$luser
618 proc msg_366
{p c args
} {
619 global names_chans nick_onchans
620 set lchan
[irctolower
$c]
621 foreach luser
[array names nick_onchans
] {
622 upvar #0 nick_onchans($luser) oc
623 if {[llength names_chans
] > 1} {
624 set oc
[grep tc
{[lsearch -exact $tc $names_chans] >= 0} $oc]
626 if {![llength $oc]} { lnick_forget
$n }
631 proc check_username
{target
} {
633 [string length
$target] > 8 ||
634 [regexp {[^
-0-9a-z
]} $target] ||
635 ![regexp {^
[a-z
]} $target]
636 } { error "invalid username" }
639 proc somedb__head
{} {
641 set idl
[irctolower
$id]
642 upvar #0 ${nickchan}db($idl) ndbe
643 binary scan $idl H
* idh
644 set idfn
$fprefix$idh
645 if {![info exists iddbe
] && [file exists
$idfn]} {
647 try_except_finally
{ set newval
[read $f] } {} { close $f }
648 if {[llength $newval] % 2} { error "invalid length" }
654 proc def_somedb
{name arglist body
} {
655 foreach {nickchan fprefix
} {
660 proc ${nickchan
}db_
$name $arglist \
661 "set nickchan $nickchan; set fprefix $fprefix; $body"
667 foreach path
[glob -nocomplain -path $fprefix *] {
668 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
669 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
670 lappend list [binary format H
* $thinghex]
675 proc def_somedb_id
{name arglist body
} {
676 def_somedb
$name [concat id
$arglist] "somedb__head; $body"
679 def_somedb_id exists
{} {
680 return [info exists iddbe
]
683 def_somedb_id delete
{} {
684 catch { unset iddbe
}
688 set default_settings_nick
{
692 tellrel
{remind
3600 30}
695 set default_settings_chan
{
704 set default_settings_msgs
{
708 # inbound -> [<nick> <time_t> <message>] ...
709 # outbound -> [<nick> <time_t(earliest)> <count>] ...
711 def_somedb_id
set {args
} {
712 upvar #0 default_settings_$nickchan def
713 if {![info exists iddbe
]} { set iddbe
$def }
714 foreach {key value
} [concat $iddbe $args] { set a
($key) $value }
716 foreach {key value
} [array get a
] { lappend newval
$key $value }
717 set f
[open $idfn.new w
]
721 file rename -force $idfn.new
$idfn
729 def_somedb_id get
{key
} {
730 upvar #0 default_settings_$nickchan def
731 if {[info exists iddbe
]} {
732 set l
[concat $iddbe $def]
736 foreach {tkey value
} $l {
737 if {"$tkey" == "$key"} { return $value }
739 error "unset setting $key"
744 if {[info exists calling_nick
]} { set n
$calling_nick } { set n
{} }
745 return [nickdb_get
$n $key]
748 proc check_notonchan
{} {
750 if {[ischan
$dest]} { usererror
"That command must be sent privately." }
753 proc nick_securitycheck
{strict
} {
755 if {![nickdb_exists
$n]} {
756 usererror
"You are unknown to me, use `register'."
758 set wantu
[nickdb_get
$n username
]
759 if {![string length
$wantu]} {
761 usererror
"That feature is only available to secure users, sorry."
766 set luser
[irctolower
$n]
767 upvar #0 nick_username($luser) nu
768 if {![info exists nu
]} {
769 usererror
"Nick $n is secure, you must identify yourself first."
771 if {"$wantu" != "$nu"} {
772 usererror
"You are the wrong user -\
773 the nick $n belongs to $wantu, not $nu."
777 proc channel_ismanager
{channel n
} {
778 set mgrs
[chandb_get
$channel managers
]
779 return [expr {[lsearch -exact [irctolower
$mgrs] [irctolower
$n]] >= 0}]
782 proc channel_securitycheck
{channel
} {
784 if {![channel_ismanager
$channel $n]} {
785 usererror
"You are not a manager of $channel."
790 proc def_chancmd
{name body
} {
791 proc channel
/$name {} \
792 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
795 proc ta_listop
{findnow procvalue
} {
796 # findnow and procvalue are code fragments which will be executed
797 # in the caller's level. findnow should set ta_listop_ev to
798 # the current list, and procvalue should treat ta_listop_ev as
799 # a proposed value in the list and check and possibly modify
800 # (canonicalise?) it. After ta_listop, ta_listop_ev will
801 # be the new value of the list.
802 upvar 1 ta_listop_ev exchg
805 switch -exact _
$opcode {
809 foreach item
$exchg { set array($item) 1 }
812 error "list change opcode must be one of + - ="
815 foreach exchg
[split $text " "] {
816 if {![string length
$exchg]} continue
818 if {"$opcode" != "-"} {
821 catch { unset array($exchg) }
824 set exchg
[lsort [array names
array]]
827 def_chancmd manager
{
829 if {[chandb_exists
$chan]} {
830 set ta_listop_ev
[chandb_get
$chan managers
]
832 set ta_listop_ev
[list [irctolower
$n]]
835 check_nick
$ta_listop_ev
836 set ta_listop_ev
[irctolower
$ta_listop_ev]
838 if {[llength $ta_listop_ev]} {
839 chandb_set
$chan managers
$ta_listop_ev
840 ucmdr
"Managers of $chan: $ta_listop_ev" {}
843 ucmdr
{} {} "forgets about managing $chan." {}
847 def_chancmd autojoin
{
849 switch -exact [string tolower
$yesno] {
852 default { error "channel autojoin must be `yes' or `no' }
854 chandb_set $chan autojoin $nv
855 ucmdr [expr {$nv ? "I will
join $chan when I'm restarted
" : \
856 "I won't
join $chan when I'm restarted
"}] {}
859 def_chancmd userinvite {
860 set nv [string tolower [ta_word]]
862 pub { set txt "!invite will work
for $chan, but it won't work by
/msg
" }
863 here { set txt "!invite and
/msg invite will work
, but only
for users who are already on
$chan.
" }
864 all { set txt "Any user will be able to invite themselves or anyone
else to
$chan.
" }
865 none { set txt "I will not invite anyone to
$chan.
" }
867 error "channel userinvite must be `pub'
, `here'
, `all' or `none'
870 chandb_set
$chan userinvite
$nv
876 switch -exact $what {
879 chandb_set
$chan topicset
{}
880 ucmdr
"I won't ever change the topic of $chan." {}
883 set t
[string trim
$text]
884 if {![string length
$t]} {
885 error "you must specific the topic to set"
887 chandb_set
$chan topicset
$t
888 ucmdr
"Whenever I'm alone on $chan, I'll set the topic to $t." {}
892 set ta_listop_ev
[chandb_get
$chan topic
$what]
894 if {"$ta_listop_ev" != "*"} {
895 if {![ischan
$ta_listop_ev]} {
896 error "bad channel \`$ta_listop_ev' in topic $what"
898 set ta_listop_ev
[irctolower
$ta_listop_ev]
901 chandb_set
$chan topic
$what $ta_listop_ev
902 ucmdr
"Topic $what list for $chan: $ta_listop_ev" {}
905 usererror
"Unknown channel topic subcommand - see help channel."
912 if {"$mode" != "*" && ![regexp {^
(([-+][imnpst
]+)+)$} $mode mode
]} {
913 error {channel mode must be
* or match
([-+][imnpst
]+)+}
915 chandb_set
$chan mode
$mode
916 if {"$mode" == "*"} {
917 ucmdr
"I won't ever change the mode of $chan." {}
919 ucmdr
"Whenever I'm alone on $chan, I'll set the mode to $mode." {}
924 if {[chandb_exists
$chan]} {
925 set l
"Settings for $chan: autojoin "
926 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
927 append l
", mode " [chandb_get
$chan mode
]
928 append l
", userinvite " [chandb_get
$chan userinvite
] "."
929 append l
"\nManagers: "
930 append l
[join [chandb_get
$chan managers
] " "]
931 foreach {ts sep
} {see
"\n" tell " "} {
932 set t
[chandb_get
$chan topic
$ts]
935 append l
"Topic $ts list: $t."
937 append l
"Topic $ts list is empty."
941 set t
[chandb_get
$chan topicset
]
942 if {[string length
$t]} {
943 append l
"Topic to set: $t"
945 append l
"I will not change the topic."
949 ucmdr
{} "The channel $chan is not managed."
953 proc channelmgr_monoop
{} {
958 upvar 1 target target
963 if {[ischan
$dest]} { set target
$dest }
964 if {[ta_anymore
]} { set target
[ta_word
] }
966 if {![info exists target
]} {
967 usererror
"You must specify, or invoke me on, the relevant channel."
969 if {![info exists chan_nicks
([irctolower
$target])]} {
970 usererror
"I am not on $target."
972 if {![ischan
$target]} { error "not a valid channel" }
974 if {![chandb_exists
$target]} {
975 usererror
"$target is not a managed channel."
977 channel_securitycheck
$target
982 sendout MODE
$target +o
$n
991 global chan_nicks errorCode errorInfo
994 if {[ischan
$dest]} {
1001 set ltarget
[irctolower
$target]
1002 if {![ischan
$target]} { error "$target is not a channel" }
1003 if {![info exists chan_nicks
($ltarget)]} {
1004 usererror
"I am not on $target."
1006 set ui
[chandb_get
$ltarget userinvite
]
1008 if {"$ui" == "pub" && !$onchan} {
1009 usererror
"Invitations to $target must be made there with !invite."
1011 if {"$ui" != "all"} {
1012 if {[lsearch -exact $chan_nicks($ltarget) [irctolower
$n]] < 0} {
1013 usererror
"Invitations to $target may only be made\
1014 by a user on the channel."
1017 if {"$ui" == "none"} {
1018 usererror
"Sorry, I've not been authorised\
1019 to invite people to $target."
1022 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager
$target $n]} {
1024 nick_securitycheck
1
1026 if {"$errorCode" == "BLIGHT USER"} {
1027 usererror
"$emsg2 Therefore you can't use your\
1028 channel manager privilege. $emsg"
1030 error $error $errorInfo $errorCode
1034 error $emsg $errorInfo $errorCode
1037 if {![ta_anymore
]} {
1038 usererror
"You have to say who to invite."
1041 while {[ta_anymore
]} {
1042 set invitee
[ta_word
]
1044 lappend invitees
$invitee
1046 foreach invitee
$invitees {
1047 sendout INVITE
$invitee $ltarget
1049 set who
[lindex $invitees 0]
1050 switch -exact llength $invitees {
1051 0 { error "zero invitees" }
1053 2 { append who
" and [lindex $invitees 1]" }
1055 set who
[join [lreplace $invitees end end
] ", "]
1056 append who
" and [lindex $invitees [llength $invitees]]"
1059 ucmdr
{} {} {} "invites $who to $target."
1063 if {[ischan
$dest]} { set target
$dest }
1064 if {![ta_anymore
]} {
1067 set subcmd
[ta_word
]
1069 if {[ischan
$subcmd]} {
1071 if {![ta_anymore
]} {
1074 set subcmd
[ta_word
]
1077 if {![info exists target
]} { error "privately, you must specify a channel" }
1078 set procname channel
/$subcmd
1079 if {"$subcmd" != "show"} {
1080 if {[catch { info body
$procname }]} {
1081 usererror
"unknown channel setting $subcmd."
1084 if {[chandb_exists
$target]} {
1085 channel_securitycheck
$target
1087 nick_securitycheck
1
1088 upvar #0 chan_initialop([irctolower $target]) io
1089 upvar #0 nick_unique([irctolower $n]) u
1090 if {![info exists io
]} {
1091 usererror
"$target is not a managed channel."
1093 if {"$io" != "$u"} {
1094 usererror
"You are not the interim manager of $target."
1096 if {"$subcmd" != "manager"} {
1097 usererror
"Please use `channel manager' first."
1105 global nick_case ownmailaddr ownfullname
1108 set target
[ta_word
]
1109 if {![string length
$text]} { error "tell them what?" }
1111 set ltarget
[irctolower
$target]
1113 if {[info exists nick_case
($ltarget)]} { set ctarget
$nick_case($ltarget) }
1115 manyset
[nickdb_get
$target tellsec
] sec mailtoint mailwhy
1116 manyset
[nickdb_get
$target tellrel
] rel relint relwithin
1117 switch -exact $sec {
1119 set now
[clock seconds
]
1120 set inbound
[msgsdb_get
$ltarget inbound
]
1121 lappend inbound
$n $now $text
1122 msgsdb_set
$ltarget inbound
$inbound
1124 set outbound
[msgsdb_get
$n outbound
]
1127 foreach {recip
time count
} $outbound {
1128 if {"[irctolower $recip]" == "$ltarget"} {
1133 lappend noutbound
$recip $time $count
1136 lappend noutbound
$ctarget $now 1
1138 msgsdb_set
$n outbound
$noutbound
1139 set msg
"OK, I'll tell $ctarget"
1140 if {$found} { append msg
" that too" }
1142 if {"$sec" != "secure"} {
1143 switch -exact $rel {
1144 unreliable
{ append msg
"neither reliably nor securely" }
1145 remind
{ append msg
"pretty reliably, but not securely" }
1146 pester
{ append msg
"reliably but not securely" }
1149 switch -exact $rel {
1150 unreliable
{ append msg
"securely but not reliably" }
1151 remind
{ append msg
"securely and pretty reliably" }
1152 pester
{ append msg
"reliably and securely" }
1159 set fmtmsg
[exec fmt
<< " $text"]
1160 exec /usr
/sbin
/sendmail
-odb -oi -t -oee -f $mailwhy \
1162 "From: $ownmailaddr ($ownfullname)
1164 Subject: IRC tell from $n
1166 $n asked me[expr {[ischan $dest] ? " on
$dest" : ""}] to tell you:
1167 [exec fmt << " $text"]
1169 (This message was for your nick $ctarget; your account $mailwhy
1170 arranged for it to be forwarded to $mailtoint.)
1173 "I've mailed $ctarget, which is what they prefer." \
1177 usererror
"Sorry, $ctarget does not want me to take messages."
1180 error "bad tellsec $sec"
1187 set target
[ta_word
]; ta_nomore
1192 set myself
[expr {"$target" != "$n"}]
1194 set ltarget
[irctolower
$target]
1195 upvar #0 nick_case($ltarget) ctarget
1197 if {[info exists ctarget
]} {
1198 upvar #0 nick_onchans($ltarget) oc
1199 upvar #0 nick_username($ltarget) nu
1200 if {[info exists oc
]} { set nshow
$ctarget }
1202 if {![nickdb_exists
$ltarget]} {
1203 set ol
"$nshow is not a registered nick."
1204 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
1205 set ol
"The nick $nshow belongs to the user $username."
1207 set ol
"The nick $nshow is registered (but not to a username)."
1209 if {![info exists ctarget
] ||
![info exists oc
]} {
1211 append ol
"\nI can't see $nshow on anywhere."
1213 append ol
"\nYou aren't on any channels with me."
1215 } elseif
{![info exists nu
]} {
1216 append ol
"\n$nshow has not identified themselves."
1217 } elseif
{![info exists username
]} {
1218 append ol
"\n$nshow has identified themselves as the user $nu."
1219 } elseif
{"$nu" != "$username"} {
1220 append ol
"\nHowever, $nshow is being used by the user $nu."
1222 append ol
"\n$nshow has identified themselves to me."
1230 set old
[nickdb_exists
$n]
1231 if {$old} { nick_securitycheck
0 }
1232 set luser
[irctolower
$n]
1233 switch -exact [string tolower
[string trim
$text]] {
1235 upvar #0 nick_username($luser) nu
1236 if {![info exists nu
]} {
1238 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1240 nickdb_set
$n username
$nu
1241 ucmdr
{} {} "makes a note of your username." {}
1245 ucmdr
{} {} "forgets your nickname." {}
1248 nickdb_set
$n username
{}
1250 ucmdr
{} "Security is now disabled for your nickname !"
1252 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."
1256 error "you mean register / register delete / register insecure"
1261 proc timeformat_desc
{tf
} {
1263 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1264 hms
{ return "Times will be displayed in hours, minutes, etc." }
1265 default { error "invalid timeformat: $v" }
1270 proc def_setting
{opt show_body set_body
} {
1272 lappend settings
$opt
1273 proc set_show
/$opt {} "
1277 if {![string length
$set_body]} return
1278 proc set_set
/$opt {} "
1285 proc tellme_sec_desc
{v
} {
1286 manyset
$v sec mailtoint
1287 switch -exact $sec {
1289 return "I'll tell you your messages whenever I see you."
1293 "I'll keep the bodies of your messages private until you identify yourself, reminding you every [showintervalsecs $mailtoint 1]."
1296 return "I shan't accept messages for you."
1299 return "I'll forward your messages by email to $mailtoint."
1302 error "bad tellsec $sec"
1307 proc tellme_rel_desc
{v
} {
1308 manyset
$v rel every within
1309 switch -exact $rel {
1311 return "As soon as I've told you, I'll forget the message - note that this means messages can get lost !"
1317 set u
", or talk on channel within [showintervalsecs $within 1] of me having told you"
1320 error "bad tellrel $rel"
1323 return "I'll remind you every [showintervalsecs $every 1] until you say delmsg$u."
1326 def_setting timeformat
{
1327 set tf
[nickdb_get
$n timeformat
]
1328 return "$tf: [timeformat_desc $tf]"
1330 set tf
[string tolower
[ta_word
]]
1332 set desc
[timeformat_desc
$tf]
1333 nickdb_set
$n timeformat
$tf
1337 proc marktime_desc
{mt
} {
1338 if {"$mt" == "off"} {
1339 return "I will not send you periodic messages."
1340 } elseif
{"$mt" == "once"} {
1341 return "I will send you one informational message when I see you."
1343 return "I'll send you a message every [showintervalsecs $mt 0]."
1347 def_setting marktime
{
1348 set mt
[nickdb_get
$n marktime
]
1350 if {[string match
{[0-9]*} $mt]} { append p s
}
1352 append p
[marktime_desc
$mt]
1356 set mt
[string tolower
[ta_word
]]
1359 if {"$mt" == "off" ||
"$mt" == "once"} {
1361 set mt
[parse_interval
$mt $marktime_min]
1363 nickdb_set
$n marktime
$mt
1364 lnick_marktime_start
[irctolower
$n] "So:" 500 0
1365 ucmdr
{} [marktime_desc
$mt]
1368 def_setting security
{
1369 set s
[nickdb_get
$n username
]
1370 if {[string length
$s]} {
1371 return "Your nick, $n, is controlled by the user $s."
1373 return "Your nick, $n, is not secure."
1377 def_setting tellme
{
1378 set secv
[nickdb_get
$n tellsec
]
1379 set ms
[tellme_sec_desc
$secv]
1381 switch -exact $sec {
1383 set mr
[tellme_rel_desc
[nickdb_get
$n tellrel
]]
1391 set setting
[string tolower
[ta_word
]]
1392 switch -exact $setting {
1393 insecure
- secure
- refuse
{
1395 if {"$setting" == "refuse" && [llength [msgsdb_get
$n inbound
]]} {
1396 usererror
"You must delete the messages you have, first."
1402 set u
[nickdb_get
$n username
]
1403 if {![string length
$u]} {
1404 usererror
"Sorry, you must register secure to have your messages mailed (to prevent the use of this feature for spamming)."
1407 set v
[list mailto
[ta_word
] $u]
1409 unreliable
- pester
- remind
{
1410 manyset
[nickdb_get
$n tellsec
] sec
1411 switch -exact $sec {
1413 error "can't change message delivery conditions when message disposition prevents messages from being left"
1418 if {"$setting" != "unreliable"} {
1419 set every
[parse_interval
[ta_word
] 300]
1422 if {"$setting" == "remind"} {
1424 set within
[parse_interval
[ta_word
] 5]
1428 if {$within > $every} {
1429 error "remind interval must be at least time to respond"
1436 error "invalid tellme setting $setting"
1439 nickdb_set
$n tell$sr $v
1440 ucmdr
[tellme_
${sr
}_desc
$v] {}
1443 proc lnick_checktold
{luser
} {
1444 set ml
[msgsdb_get
$luser outbound
]
1445 if {![llength $ml]} return
1446 set is1
[expr {[llength $ml]==3}]
1447 set m1
"FYI, I haven't yet passed on your"
1449 set now
[clock seconds
]
1450 while {[llength $ml]} {
1452 set ml
[lreplace $ml 0 2]
1453 set td
[expr {$now-$t}]
1455 set iv
[showinterval
$td]
1457 set if1
"message to $r, $iv."
1459 set iv
[showintervalsecs
$td 0]
1460 set ifo
"$r, $n messages, oldest $iv"
1461 set if1
"$n messages to $r, oldest $iv."
1464 sendprivmsg
$luser "$m1 $if1"
1467 lappend ol
" to $ifo[expr {[llength $ml] ? ";" : ".
"}]"
1470 sendprivmsg
$luser "$m1 messages:"
1471 msendprivmsg
$luser $ol
1478 if {![nickdb_exists
$n]} {
1479 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1481 if {![ta_anymore
]} {
1483 foreach opt
$settings {
1484 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1486 ucmdr
{} [join $ol "\n"]
1489 if {[catch { info body set_show
/$opt }]} {
1490 error "no setting $opt"
1492 if {![ta_anymore
]} {
1493 ucmdr
{} "$opt: [set_show/$opt]"
1495 nick_securitycheck
0
1496 if {[catch { info body set_set
/$opt }]} {
1497 error "setting $opt cannot be set with `set'"
1504 def_ucmd identpass
{
1505 set username
[ta_word
]
1506 set passmd5
[md5sum
"[ta_word]\n"]
1510 set luser
[irctolower
$n]
1511 upvar #0 nick_onchans($luser) onchans
1512 if {![info exists onchans
] ||
![llength $onchans]} {
1513 ucmdr
"You must be on a channel with me to identify yourself." {}
1515 check_username
$username
1516 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1518 upvar #0 nick_username($luser) rec_username
1519 set rec_username
$username
1520 ucmdr
"Pleased to see you, $username." {}
1524 set target
[ta_word
]
1526 check_username
$target
1529 upvar #0 lastsummon($target) ls
1530 set now
[clock seconds
]
1531 if {[info exists ls
]} {
1532 set interval
[expr {$now - $ls}]
1533 if {$interval < 30} {
1535 "Please be patient; $target was summoned only [showinterval $interval]."
1538 regsub {^
[^
!]*!} $p {} path
1540 exec userv
--timeout 3 $target irc-summon
$n $path \
1541 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1544 regsub -all "\n" $rv { / } rv
1547 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1548 ucmdr
{} "The user `$target' $problem."
1549 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1550 set idletime
[expr {$now - $idlesince}]
1552 ucmdr
{} {} {} "invites $target ($tty[expr {
1553 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime 0]" : ""
1555 [ischan $dest] ? "join us here
" : "talk to you
"
1558 error "unexpected response from userv service: $rv"
1562 proc md5sum
{value
} { exec md5sum
<< $value }
1565 global lastseen nick
1568 set nlower
[irctolower
$ncase]
1570 set now
[clock seconds
]
1571 if {"$nlower" == "[irctolower $nick]"} {
1572 usererror
"I am not self-aware."
1573 } elseif
{![info exists lastseen
($nlower)]} {
1574 set rstr
"I've never seen $ncase."
1576 manyset
$lastseen($nlower) realnick
time what
1577 set howlong
[expr {$now - $time}]
1578 set string [showinterval
$howlong]
1579 set rstr
"I last saw $realnick $string, $what."
1581 if {[ischan
$dest]} {
1586 upvar #0 lookedfor($nlower) lf
1587 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1588 set lf
[list [list $now $n $where]]
1589 foreach v
$oldvalue {
1590 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1596 proc lnick_marktime_cancel
{luser
} {
1597 upvar #0 nick_markid($luser) mi
1598 if {![info exists mi
]} return
1599 catch { after cancel
$mi }
1603 proc lnick_marktime_doafter
{luser why ms mentiontold
} {
1604 lnick_marktime_cancel
$luser
1605 upvar #0 nick_markid($luser) mi
1606 set mi
[after $ms [list lnick_marktime_now
$luser $why 0]]
1609 proc lnick_marktime_reset
{luser
} {
1610 set mt
[nickdb_get
$luser marktime
]
1611 if {"$mt" == "off" ||
"$mt" == "once"} return
1612 lnick_marktime_doafter
$luser "Time passes." [expr {$mt*1000}] 0
1615 proc lnick_marktime_start
{luser why ms mentiontold
} {
1616 set mt
[nickdb_get
$luser marktime
]
1617 if {"$mt" == "off"} {
1618 lnick_marktime_cancel
$luser
1619 after $ms [list lnick_checktold
$luser]
1621 lnick_marktime_doafter
$luser $why $ms $mentiontold
1625 proc lnick_marktime_now
{luser why mentiontold
} {
1626 upvar #0 nick_onchans($luser) oc
1628 set calling_nick
$luser
1629 sendprivmsg
$luser [lnick_pingstring
$why $oc ""]
1630 if {$mentiontold} { lnick_checktold
$luser }
1631 lnick_marktime_reset
$luser
1634 proc lnick_pingstring
{why oc apstring
} {
1636 catch { exec uptime
} uptime
1637 set nnicks
[llength [array names nick_onchans
]]
1639 {^
*([0-9:apm
]+) +up.
*, +(\d
+) users?
, +load average
: +([0-9.
, ]+) *$} \
1640 $uptime dummy
time users
load]} {
1641 regsub -all , $load {} load
1642 set uptime
"$time $nnicks/$users $load"
1644 append uptime
", $nnicks nicks"
1646 if {[llength $oc]} {
1650 upvar #0 chan_lastactivity($ch) la
1651 if {![info exists la
]} continue
1652 if {$la <= $best_la} continue
1653 set since
[showintervalsecs
[expr {[clock seconds
]-$la}] 1]
1654 set activity
"$ch $since"
1661 append str
" " $uptime " " $activity
1662 if {[string length
$apstring]} { append str
" " $apstring }
1668 set ln
[irctolower
$n]
1669 if {[ischan
$dest]} {
1670 set oc
[irctolower
$dest]
1673 if {[info exists nick_onchans
($ln)]} {
1674 set oc
$nick_onchans($ln)
1678 if {[llength $oc]} { lnick_marktime_reset
$ln }
1681 ucmdr
{} [lnick_pingstring
"Pong!" $oc $text]
1684 proc ensure_globalsecret
{} {
1687 if {[info exists globalsecret
]} return
1688 set gsfile
[open /dev
/urandom r
]
1689 fconfigure $gsfile -translation binary
1690 set globalsecret
[read $gsfile 32]
1691 binary scan $globalsecret H
* globalsecret
1697 foreach chan
[chandb_list
] {
1698 if {[chandb_get
$chan autojoin
]} { dojoin
$chan }