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 tell_event
{nl
event} {
149 # For `act' we *haven't* yet done the 750ms delay; we implement
150 # that here. Also, here we turn `talk' into `talk' now and `act'
151 # later. We also support the psuedo-event `none'. The del msg
152 # and new msg events are handled by the command procedures, not here.
153 switch -exact $event {
156 tell_event_core
$nl talk
160 after 750 [list tell_event_core
$nl $event]
163 tell_event_core
$nl $event
166 error "tell_event $nl $event"
171 proc tell_event_core
{nl
event} {
172 # event is `talk', `act' or `ident'
173 # When user talks we actually get talk now and act later
174 FIXME
- implement all cmds
175 FIXME
- implement pass stuff
set stt
[list $u passed
$now]
176 FIXME
- implement tells_delete_msgs
catch { unset stt
} ?
177 FIXME
- document the extra param to recordlastseen
178 set iml
[msgdb_get
$nl inbound
]
179 if {![llength $iml]} return
181 upvar #0 nick_telling($nl) telling
182 upvar #0 nick_unique($nl) u
184 if {[info exists telling
]} {
185 manyset
$telling u_last stt telling_when
186 if {![info exists u
] ||
"$u_last" != "$u"} {
187 unset telling
; unset stt
; unset telling_when
191 if {![info exists stt
]} {
193 set telling_when
$now
196 set ago
[expr {$now - $telling_when}]
198 # Now we have the components of a telling state
199 # u - nick_unique (unset if not visible)
200 # stt - state: norecord, mentioned, passede
201 # ago - how long ago since we did anything
203 # We compute an evstate to dispatch on as follows:
205 # evstate is string of letters
207 # n NORECORD (MESSAGES)
214 # security level and timing
216 # ss Secure and soon (before interval)
217 # sl Secure and late (after interval)
218 # current identification
221 # reliability and timing
223 # rv Remind, very soon (before within-interval)
224 # rs Remind, soon (between)
225 # rl Remind, late (after every-interval)
226 # ps Pester, soon (before interval)
227 # pl Pester, late (after interval)
231 append evstate
[string range
$stt 0 0]
232 append evstate
[string range
$event 0 0]
234 manyset
[nickdb_get
$n tellsec
] sec secwhen
236 insecure
{ append evstate ii
}
237 secure
{ append evstate
[expr {$ago<$secwhen ?
"sl" : "ss"}] }
238 default { append evstate
"#$sec#" }
241 upvar #0 nick_username($nl) nu
242 if {[info exists nu
] && "$nu" == "[nickdb_get $nl username]"} {
248 manyset
[nickdb_set
$n tellrel
] rel relint relwithin
250 unreliable
{ append evstate uu
}
251 remind
{ append evstate
[expr {
252 $ago<$relwithin ?
"rv" : $ago<$relint ?
"rs" : "rl"
254 pester
{ append evstate
[expr {$ago<$relint ?
"ps" : "pl"}] }
255 default { append evstate
"#$rel#" }
258 switch -glob $evstate {
260 # consider delivered:
261 # (very recently passed, and the user talks)
262 tell_delete_msgs
{} $nl
266 pt???uu
- pt???rs
- pt???rl
- pt???p?
{
267 # ignore (any other `talk's) - act handles these
270 ni?????
- naii???
- nas?i??
- mi?????
- pa????l
{
271 # pass and then stuff
277 sendprivmsg
$nl {You have messages
(so identify yourself please
).
}]
281 sendprivmsg
$nl {Don't forget about your messages.
}]
286 mass???
- pa????v
- pa????s
{
291 error "tell_event_core nl=$nl evstate=$evstate ?"
294 if {![info exists u
]} {
295 catch { unset telling
}
297 set telling
[list $u $stt $now]
301 proc recordlastseen_n
{n how here
} {
302 global lastseen lookedfor
303 set nl
[irctolower
$n]
304 set now
[clock seconds
]
305 set lastseen
($nl) [list $n $now $how]
309 tell_event
$nl [lindex {none act talk
} $here]
311 upvar #0 lookedfor($nl) lf
312 if {[info exists lf
]} {
313 switch -exact [llength $lf] {
318 manyset
[lindex $lf 0] when who where
320 "FYI, $who was looking for you [looking_whenwhere $when $where]."]
323 msg_begin tosend
$n "FYI, people have been looking for you:"
329 msg_append tosend
" "
330 } elseif
{$i == [llength $lf]} {
331 msg_append tosend
" and "
334 msg_append tosend
", "
336 manyset
$e when who where
338 "$who ([looking_whenwhere $when $where])$fin"
340 set ml
[msg_finish tosend
]
344 msendprivmsg_delayed
1000 $n $ml
348 proc note_topic
{showoff whoby topic
} {
349 set msg
"FYI, $whoby has changed the topic on $showoff"
350 if {[string length
$topic] < 160} {
351 append msg
" to $topic"
353 append msg
" but it is too long to reproduce here !"
355 set showoff
[irctolower
$showoff]
356 set tell [chandb_get
$showoff topictell
]
357 if {[lsearch -exact $tell *] >= 0} {
358 set tryspies
[chandb_list
]
362 foreach spy
$tryspies {
363 set see
[chandb_get
$spy topicsee
]
364 if {[lsearch -exact $see $showoff] >= 0 ||
\
365 ([lsearch -exact $see *] >= 0 && \
366 [lsearch -exact $tell $spy] >= 0)} {
367 sendprivmsg
$spy $msg
372 proc recordlastseen_p
{p how here
} {
374 recordlastseen_n
$n $how $here
377 proc chanmode_arg
{} {
379 set rv
[lindex $cm_args 0]
380 set cm_args
[lreplace cm_args
0 0]
384 proc chanmode_o1
{m g p chan
} {
385 global nick chan_initialop
387 set who
[chanmode_arg
]
388 recordlastseen_n
$n "being nice to $who" 1
389 if {"[irctolower $who]" == "[irctolower $nick]"} {
390 set nlower
[irctolower
$n]
391 upvar #0 nick_unique($nlower) u
392 if {[chandb_exists
$chan]} {
393 sendprivmsg
$n Thanks.
394 } elseif
{![info exists u
]} {
395 sendprivmsg
$n {Op me
while not on the channel
, why don't you ?
}
397 set chan_initialop
([irctolower
$chan]) $u
399 "Thanks. You can use `channel manager ...' to register this channel."
400 if {![nickdb_exists
$n] ||
![string length
[nickdb_get
$n username
]]} {
402 "(But to do that you must register your nick securely first.)"
408 proc chanmode_o0
{m g p chan
} {
411 set who
[chanmode_arg
]
412 recordlastseen_p
$p "being mean to $who" 1
413 if {"[irctolower $who]" == "[irctolower $nick]"} {
414 set chandeop
($chan) [list [clock seconds
] $p]
418 proc msg_MODE
{p c dest modelist args
} {
419 if {![ischan
$dest]} return
420 if {[regexp {^
\-(.
+)$} $modelist dummy modelist
]} {
422 } elseif
{[regexp {^
\+(.
+)$} $modelist dummy modelist
]} {
425 error "invalid modelist"
427 foreach m
[split $modelist] {
428 set procname chanmode_
$m$give
429 if {[catch { info body
$procname }]} {
430 recordlastseen_p
$p "fiddling with $dest" 1
432 $procname $m $give $p $dest
437 proc leaving
{lchan
} {
438 foreach luser
[array names nick_onchans
] {
439 upvar #0 nick_onchans($luser) oc
440 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
442 upvar #0 chan_nicks($lchan) nlist
444 upvar #0 chan_lastactivity($lchan) la
448 proc doleave
{lchan
} {
453 proc dojoin
{lchan
} {
456 set chan_nicks
($lchan) {}
459 proc check_justme
{lchan
} {
461 upvar #0 chan_nicks($lchan) nlist
462 if {[llength $nlist] != 1} return
463 if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
464 if {[chandb_exists
$lchan]} {
465 set mode
[chandb_get
$lchan mode
]
466 if {"$mode" != "*"} {
467 sendout MODE
$lchan $mode
469 set topic
[chandb_get
$lchan topicset
]
470 if {[string length
$topic]} {
471 sendout TOPIC
$lchan $topic
478 proc process_kickpart
{chan user
} {
481 set luser
[irctolower
$user]
482 set lchan
[irctolower
$chan]
483 if {![ischan
$chan]} { error "not a channel" }
484 if {"$luser" == "[irctolower $nick]"} {
487 upvar #0 nick_onchans($luser) oc
488 upvar #0 chan_nicks($lchan) nlist
489 set oc
[grep tc
{"$tc" != "$lchan"} $oc]
490 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
492 if {![llength $oc]} {
500 proc msg_TOPIC
{p c dest topic
} {
502 if {![ischan
$dest]} return
503 recordlastseen_n
$n "changing the topic on $dest" 1
504 note_topic
[irctolower
$dest] $n $topic
507 proc msg_KICK
{p c chans users comment
} {
508 set chans
[split $chans ,]
509 set users
[split $users ,]
510 if {[llength $chans] > 1} {
511 foreach chan
$chans user
$users { process_kickpart
$chan $user }
513 foreach user
$users { process_kickpart
[lindex $chans 0] $user }
517 proc msg_KILL
{p c user why
} {
522 set nick_arys
{onchans username unique
}
523 # nick_onchans($luser) -> [list ... $lchan ...]
524 # nick_username($luser) -> <securely known local username>
525 # nick_unique($luser) -> <includes-counter>
526 # nick_case($luser) -> $user (valid even if no longer visible)
527 # nick_markid($luser) -> <after id for marktime>
528 # nick_telling($luser) -> <unique> mentioned|passed <when>
530 # chan_nicks($lchan) -> [list ... $luser ...]
531 # chan_lastactivity($lchan) -> [clock seconds]
533 proc lnick_forget
{luser
} {
534 global nick_arys chan_nicks
535 lnick_marktime_cancel
$luser
536 foreach ary
$nick_arys {
537 upvar #0 nick_${ary}($luser) av
540 foreach lch
[array names chan_nicks
] {
541 upvar #0 chan_nicks($lch) nlist
542 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
547 proc nick_forget
{user
} {
548 global nick_arys chan_nicks
549 lnick_forget
[irctolower
$user]
553 proc nick_case
{user
} {
555 set nick_case
([irctolower
$user]) $user
558 proc msg_NICK
{p c newnick
} {
559 global nick_arys nick_case calling_nick
561 recordlastseen_n
$n "changing nicks to $newnick" 0
562 set calling_nick
$newnick
563 recordlastseen_n
$newnick "changing nicks from $n" 1
564 set luser
[irctolower
$n]
565 lnick_marktime_cancel
$luser
566 set lusernew
[irctolower
$newnick]
567 foreach ary
$nick_arys {
568 upvar #0 nick_${ary}($luser) old
569 upvar #0 nick_${ary}($lusernew) new
570 if {[info exists new
]} { error "nick collision ?! $ary $n $newnick" }
571 if {[info exists old
]} { set new
$old; unset old
}
573 upvar #0 nick_onchans($lusernew) oc
575 upvar #0 chan_nicks($ch) nlist
576 set nlist
[grep tn
{"$tn" != "$luser"} $nlist]
577 lappend nlist
$lusernew
579 lnick_marktime_start
$lusernew "Hi." 500 1
583 proc nick_ishere
{n
} {
585 upvar #0 nick_unique([irctolower $n]) u
586 if {![info exists u
]} { set u
[incr nick_counter
].
$n.
[clock seconds
] }
590 proc msg_JOIN
{p c chan
} {
593 recordlastseen_n
$n "joining $chan" 1
594 set nl
[irctolower
$n]
595 set lchan
[irctolower
$chan]
596 upvar #0 nick_onchans($nl) oc
597 upvar #0 chan_nicks($lchan) nlist
598 if {![info exists oc
]} {
599 global marktime_join_startdelay
600 lnick_marktime_start
$nl "Welcome." $marktime_join_startdelay 1
605 proc msg_PART
{p c chan args
} {
607 set msg
"leaving $chan"
608 if {[llength $args]} {
609 set why
[lindex $args 0]
610 if {"[irctolower $why]" != "[irctolower $n]"} { append msg
" ($why)" }
612 recordlastseen_n
$n $msg 1
613 process_kickpart
$chan $n
615 proc msg_QUIT
{p c why
} {
617 recordlastseen_n
$n "leaving ($why)" 0
621 proc msg_PRIVMSG
{p c dest
text} {
625 if {[ischan
$dest]} {
626 recordlastseen_n
$n "invoking me in $dest" 1
629 recordlastseen_n
$n "talking to me" 1
634 execute_usercommand
$p $c $n $output $dest $text
637 proc msg_INVITE
{p c n chan
} {
638 after 1000 [list dojoin
[irctolower
$chan]]
641 proc grep
{var predicate
list} {
645 if {[uplevel 1 [list expr $predicate]]} { lappend o
$v }
650 proc msg_353
{p c dest type chan nicklist
} {
651 global names_chans nick_onchans
652 set lchan
[irctolower
$chan]
653 upvar #0 chan_nicks($lchan) nlist
654 lappend names_chans
$lchan
655 if {![info exists nlist
]} {
656 # We don't think we're on this channel, so ignore it !
657 # Unfortunately, because we don't get a reply to PART,
658 # we have to remember ourselves whether we're on a channel,
659 # and ignore stuff if we're not, to avoid races. Feh.
663 foreach user
[split $nicklist { }] {
664 regsub {^
[@+]} $user {} user
665 if {![string length
$user]} continue
667 set luser
[irctolower
$user]
668 upvar #0 nick_onchans($luser) oc
670 lappend nlist_new
$luser
676 proc msg_366
{p c args
} {
677 global names_chans nick_onchans
678 set lchan
[irctolower
$c]
679 foreach luser
[array names nick_onchans
] {
680 upvar #0 nick_onchans($luser) oc
681 if {[llength names_chans
] > 1} {
682 set oc
[grep tc
{[lsearch -exact $tc $names_chans] >= 0} $oc]
684 if {![llength $oc]} { lnick_forget
$n }
689 proc check_username
{target
} {
691 [string length
$target] > 8 ||
692 [regexp {[^
-0-9a-z
]} $target] ||
693 ![regexp {^
[a-z
]} $target]
694 } { error "invalid username" }
697 proc somedb__head
{} {
699 set idl
[irctolower
$id]
700 upvar #0 ${nickchan}db($idl) ndbe
701 binary scan $idl H
* idh
702 set idfn
$fprefix$idh
703 if {![info exists iddbe
] && [file exists
$idfn]} {
705 try_except_finally
{ set newval
[read $f] } {} { close $f }
706 if {[llength $newval] % 2} { error "invalid length" }
712 proc def_somedb
{name arglist body
} {
713 foreach {nickchan fprefix
} {
718 proc ${nickchan
}db_
$name $arglist \
719 "set nickchan $nickchan; set fprefix $fprefix; $body"
725 foreach path
[glob -nocomplain -path $fprefix *] {
726 binary scan $path "A[string length $fprefix]A*" afprefix thinghex
727 if {"$afprefix" != "$fprefix"} { error "wrong prefix $path $afprefix" }
728 lappend list [binary format H
* $thinghex]
733 proc def_somedb_id
{name arglist body
} {
734 def_somedb
$name [concat id
$arglist] "somedb__head; $body"
737 def_somedb_id exists
{} {
738 return [info exists iddbe
]
741 def_somedb_id delete
{} {
742 catch { unset iddbe
}
746 set default_settings_nick
{
750 tellrel
{remind
3600 30}
753 # inbound: concatenation of many sender time_t text
754 # outbound: concatenation of many recipient time_t count
755 # neither are sorted particularly; only one entry per recipient in
756 # output; both sender and recipient are cased
758 set default_settings_chan
{
767 set default_settings_msgs
{
771 # inbound -> [<nick> <time_t> <message>] ...
772 # outbound -> [<nick> <time_t(earliest)> <count>] ...
774 def_somedb_id
set {args
} {
775 upvar #0 default_settings_$nickchan def
776 if {![info exists iddbe
]} { set iddbe
$def }
777 foreach {key value
} [concat $iddbe $args] { set a
($key) $value }
779 foreach {key value
} [array get a
] { lappend newval
$key $value }
780 set f
[open $idfn.new w
]
784 file rename -force $idfn.new
$idfn
792 def_somedb_id get
{key
} {
793 upvar #0 default_settings_$nickchan def
794 if {[info exists iddbe
]} {
795 set l
[concat $iddbe $def]
799 foreach {tkey value
} $l {
800 if {"$tkey" == "$key"} { return $value }
802 error "unset setting $key"
807 if {[info exists calling_nick
]} { set n
$calling_nick } { set n
{} }
808 return [nickdb_get
$n $key]
811 proc check_notonchan
{} {
813 if {[ischan
$dest]} { usererror
"That command must be sent privately." }
816 proc nick_securitycheck
{strict
} {
818 if {![nickdb_exists
$n]} {
819 usererror
"You are unknown to me, use `register'."
821 set wantu
[nickdb_get
$n username
]
822 if {![string length
$wantu]} {
824 usererror
"That feature is only available to secure users, sorry."
829 set luser
[irctolower
$n]
830 upvar #0 nick_username($luser) nu
831 if {![info exists nu
]} {
832 usererror
"Nick $n is secure, you must identify yourself first."
834 if {"$wantu" != "$nu"} {
835 usererror
"You are the wrong user -\
836 the nick $n belongs to $wantu, not $nu."
840 proc channel_ismanager
{channel n
} {
841 set mgrs
[chandb_get
$channel managers
]
842 return [expr {[lsearch -exact [irctolower
$mgrs] [irctolower
$n]] >= 0}]
845 proc channel_securitycheck
{channel
} {
847 if {![channel_ismanager
$channel $n]} {
848 usererror
"You are not a manager of $channel."
853 proc def_chancmd
{name body
} {
854 proc channel
/$name {} \
855 " upvar 1 target chan; upvar 1 n n; upvar 1 text text; $body"
858 proc ta_listop
{findnow procvalue
} {
859 # findnow and procvalue are code fragments which will be executed
860 # in the caller's level. findnow should set ta_listop_ev to
861 # the current list, and procvalue should treat ta_listop_ev as
862 # a proposed value in the list and check and possibly modify
863 # (canonicalise?) it. After ta_listop, ta_listop_ev will
864 # be the new value of the list.
865 upvar 1 ta_listop_ev exchg
868 switch -exact _
$opcode {
872 foreach item
$exchg { set array($item) 1 }
875 error "list change opcode must be one of + - ="
878 foreach exchg
[split $text " "] {
879 if {![string length
$exchg]} continue
881 if {"$opcode" != "-"} {
884 catch { unset array($exchg) }
887 set exchg
[lsort [array names
array]]
890 def_chancmd manager
{
892 if {[chandb_exists
$chan]} {
893 set ta_listop_ev
[chandb_get
$chan managers
]
895 set ta_listop_ev
[list [irctolower
$n]]
898 check_nick
$ta_listop_ev
899 set ta_listop_ev
[irctolower
$ta_listop_ev]
901 if {[llength $ta_listop_ev]} {
902 chandb_set
$chan managers
$ta_listop_ev
903 ucmdr
"Managers of $chan: $ta_listop_ev" {}
906 ucmdr
{} {} "forgets about managing $chan." {}
910 def_chancmd autojoin
{
912 switch -exact [string tolower
$yesno] {
915 default { error "channel autojoin must be `yes' or `no' }
917 chandb_set $chan autojoin $nv
918 ucmdr [expr {$nv ? "I will
join $chan when I'm restarted
" : \
919 "I won't
join $chan when I'm restarted
"}] {}
922 def_chancmd userinvite {
923 set nv [string tolower [ta_word]]
925 pub { set txt "!invite will work
for $chan, but it won't work by
/msg
" }
926 here { set txt "!invite and
/msg invite will work
, but only
for users who are already on
$chan.
" }
927 all { set txt "Any user will be able to invite themselves or anyone
else to
$chan.
" }
928 none { set txt "I will not invite anyone to
$chan.
" }
930 error "channel userinvite must be `pub'
, `here'
, `all' or `none'
933 chandb_set
$chan userinvite
$nv
939 switch -exact $what {
942 chandb_set
$chan topicset
{}
943 ucmdr
"I won't ever change the topic of $chan." {}
946 set t
[string trim
$text]
947 if {![string length
$t]} {
948 error "you must specific the topic to set"
950 chandb_set
$chan topicset
$t
951 ucmdr
"Whenever I'm alone on $chan, I'll set the topic to $t." {}
955 set ta_listop_ev
[chandb_get
$chan topic
$what]
957 if {"$ta_listop_ev" != "*"} {
958 if {![ischan
$ta_listop_ev]} {
959 error "bad channel \`$ta_listop_ev' in topic $what"
961 set ta_listop_ev
[irctolower
$ta_listop_ev]
964 chandb_set
$chan topic
$what $ta_listop_ev
965 ucmdr
"Topic $what list for $chan: $ta_listop_ev" {}
968 usererror
"Unknown channel topic subcommand - see help channel."
975 if {"$mode" != "*" && ![regexp {^
(([-+][imnpst
]+)+)$} $mode mode
]} {
976 error {channel mode must be
* or match
([-+][imnpst
]+)+}
978 chandb_set
$chan mode
$mode
979 if {"$mode" == "*"} {
980 ucmdr
"I won't ever change the mode of $chan." {}
982 ucmdr
"Whenever I'm alone on $chan, I'll set the mode to $mode." {}
987 if {[chandb_exists
$chan]} {
988 set l
"Settings for $chan: autojoin "
989 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
990 append l
", mode " [chandb_get
$chan mode
]
991 append l
", userinvite " [chandb_get
$chan userinvite
] "."
992 append l
"\nManagers: "
993 append l
[join [chandb_get
$chan managers
] " "]
994 foreach {ts sep
} {see
"\n" tell " "} {
995 set t
[chandb_get
$chan topic
$ts]
998 append l
"Topic $ts list: $t."
1000 append l
"Topic $ts list is empty."
1004 set t
[chandb_get
$chan topicset
]
1005 if {[string length
$t]} {
1006 append l
"Topic to set: $t"
1008 append l
"I will not change the topic."
1012 ucmdr
{} "The channel $chan is not managed."
1016 proc channelmgr_monoop
{} {
1021 upvar 1 target target
1026 if {[ischan
$dest]} { set target
$dest }
1027 if {[ta_anymore
]} { set target
[ta_word
] }
1029 if {![info exists target
]} {
1030 usererror
"You must specify, or invoke me on, the relevant channel."
1032 if {![info exists chan_nicks
([irctolower
$target])]} {
1033 usererror
"I am not on $target."
1035 if {![ischan
$target]} { error "not a valid channel" }
1037 if {![chandb_exists
$target]} {
1038 usererror
"$target is not a managed channel."
1040 channel_securitycheck
$target
1045 sendout MODE
$target +o
$n
1054 global chan_nicks errorCode errorInfo
1057 if {[ischan
$dest]} {
1061 set target
[ta_word
]
1064 set ltarget
[irctolower
$target]
1065 if {![ischan
$target]} { error "$target is not a channel" }
1066 if {![info exists chan_nicks
($ltarget)]} {
1067 usererror
"I am not on $target."
1069 set ui
[chandb_get
$ltarget userinvite
]
1071 if {"$ui" == "pub" && !$onchan} {
1072 usererror
"Invitations to $target must be made there with !invite."
1074 if {"$ui" != "all"} {
1075 if {[lsearch -exact $chan_nicks($ltarget) [irctolower
$n]] < 0} {
1076 usererror
"Invitations to $target may only be made\
1077 by a user on the channel."
1080 if {"$ui" == "none"} {
1081 usererror
"Sorry, I've not been authorised\
1082 to invite people to $target."
1085 if {"$errorCode" == "BLIGHT USER" && [channel_ismanager
$target $n]} {
1087 nick_securitycheck
1
1089 if {"$errorCode" == "BLIGHT USER"} {
1090 usererror
"$emsg2 Therefore you can't use your\
1091 channel manager privilege. $emsg"
1093 error $error $errorInfo $errorCode
1097 error $emsg $errorInfo $errorCode
1100 if {![ta_anymore
]} {
1101 usererror
"You have to say who to invite."
1104 while {[ta_anymore
]} {
1105 set invitee
[ta_word
]
1107 lappend invitees
$invitee
1109 foreach invitee
$invitees {
1110 sendout INVITE
$invitee $ltarget
1112 set who
[lindex $invitees 0]
1113 switch -exact llength $invitees {
1114 0 { error "zero invitees" }
1116 2 { append who
" and [lindex $invitees 1]" }
1118 set who
[join [lreplace $invitees end end
] ", "]
1119 append who
" and [lindex $invitees [llength $invitees]]"
1122 ucmdr
{} {} {} "invites $who to $target."
1126 if {[ischan
$dest]} { set target
$dest }
1127 if {![ta_anymore
]} {
1130 set subcmd
[ta_word
]
1132 if {[ischan
$subcmd]} {
1134 if {![ta_anymore
]} {
1137 set subcmd
[ta_word
]
1140 if {![info exists target
]} { error "privately, you must specify a channel" }
1141 set procname channel
/$subcmd
1142 if {"$subcmd" != "show"} {
1143 if {[catch { info body
$procname }]} {
1144 usererror
"unknown channel setting $subcmd."
1147 if {[chandb_exists
$target]} {
1148 channel_securitycheck
$target
1150 nick_securitycheck
1
1151 upvar #0 chan_initialop([irctolower $target]) io
1152 upvar #0 nick_unique([irctolower $n]) u
1153 if {![info exists io
]} {
1154 usererror
"$target is not a managed channel."
1156 if {"$io" != "$u"} {
1157 usererror
"You are not the interim manager of $target."
1159 if {"$subcmd" != "manager"} {
1160 usererror
"Please use `channel manager' first."
1168 global nick_case ownmailaddr ownfullname
1171 set target
[ta_word
]
1172 if {![string length
$text]} { error "tell them what?" }
1174 set ltarget
[irctolower
$target]
1176 if {[info exists nick_case
($ltarget)]} { set ctarget
$nick_case($ltarget) }
1178 manyset
[nickdb_get
$target tellsec
] sec mailtoint mailwhy
1179 manyset
[nickdb_get
$target tellrel
] rel relint relwithin
1180 switch -exact $sec {
1182 set now
[clock seconds
]
1183 set inbound
[msgsdb_get
$ltarget inbound
]
1184 lappend inbound
$n $now $text
1185 msgsdb_set
$ltarget inbound
$inbound
1187 set outbound
[msgsdb_get
$n outbound
]
1190 foreach {recip
time count
} $outbound {
1191 if {"[irctolower $recip]" == "$ltarget"} {
1196 lappend noutbound
$recip $time $count
1199 lappend noutbound
$ctarget $now 1
1201 msgsdb_set
$n outbound
$noutbound
1202 set msg
"OK, I'll tell $ctarget"
1203 if {$found} { append msg
" that too" }
1205 if {"$sec" != "secure"} {
1206 switch -exact $rel {
1207 unreliable
{ append msg
"neither reliably nor securely" }
1208 remind
{ append msg
"pretty reliably, but not securely" }
1209 pester
{ append msg
"reliably but not securely" }
1212 switch -exact $rel {
1213 unreliable
{ append msg
"securely but not reliably" }
1214 remind
{ append msg
"securely and pretty reliably" }
1215 pester
{ append msg
"reliably and securely" }
1222 set fmtmsg
[exec fmt
<< " $text"]
1223 exec /usr
/sbin
/sendmail
-odb -oi -t -oee -f $mailwhy \
1225 "From: $ownmailaddr ($ownfullname)
1227 Subject: IRC tell from $n
1229 $n asked me[expr {[ischan $dest] ? " on
$dest" : ""}] to tell you:
1230 [exec fmt << " $text"]
1232 (This message was for your nick $ctarget; your account $mailwhy
1233 arranged for it to be forwarded to $mailtoint.)
1236 "I've mailed $ctarget, which is what they prefer." \
1240 usererror
"Sorry, $ctarget does not want me to take messages."
1243 error "bad tellsec $sec"
1250 set target
[ta_word
]; ta_nomore
1255 set myself
[expr {"$target" != "$n"}]
1257 set ltarget
[irctolower
$target]
1258 upvar #0 nick_case($ltarget) ctarget
1260 if {[info exists ctarget
]} {
1261 upvar #0 nick_onchans($ltarget) oc
1262 upvar #0 nick_username($ltarget) nu
1263 if {[info exists oc
]} { set nshow
$ctarget }
1265 if {![nickdb_exists
$ltarget]} {
1266 set ol
"$nshow is not a registered nick."
1267 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
1268 set ol
"The nick $nshow belongs to the user $username."
1270 set ol
"The nick $nshow is registered (but not to a username)."
1272 if {![info exists ctarget
] ||
![info exists oc
]} {
1274 append ol
"\nI can't see $nshow on anywhere."
1276 append ol
"\nYou aren't on any channels with me."
1278 } elseif
{![info exists nu
]} {
1279 append ol
"\n$nshow has not identified themselves."
1280 } elseif
{![info exists username
]} {
1281 append ol
"\n$nshow has identified themselves as the user $nu."
1282 } elseif
{"$nu" != "$username"} {
1283 append ol
"\nHowever, $nshow is being used by the user $nu."
1285 append ol
"\n$nshow has identified themselves to me."
1293 set old
[nickdb_exists
$n]
1294 if {$old} { nick_securitycheck
0 }
1295 set luser
[irctolower
$n]
1296 switch -exact [string tolower
[string trim
$text]] {
1298 upvar #0 nick_username($luser) nu
1299 if {![info exists nu
]} {
1301 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1303 nickdb_set
$n username
$nu
1304 ucmdr
{} {} "makes a note of your username." {}
1308 ucmdr
{} {} "forgets your nickname." {}
1311 nickdb_set
$n username
{}
1313 ucmdr
{} "Security is now disabled for your nickname !"
1315 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."
1319 error "you mean register / register delete / register insecure"
1324 proc timeformat_desc
{tf
} {
1326 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1327 hms
{ return "Times will be displayed in hours, minutes, etc." }
1328 default { error "invalid timeformat: $v" }
1333 proc def_setting
{opt show_body set_body
} {
1335 lappend settings
$opt
1336 proc set_show
/$opt {} "
1340 if {![string length
$set_body]} return
1341 proc set_set
/$opt {} "
1348 proc tellme_sec_desc
{v
} {
1349 manyset
$v sec mailtoint
1350 switch -exact $sec {
1352 return "I'll tell you your messages whenever I see you."
1356 "I'll keep the bodies of your messages private until you identify yourself, reminding you every [showintervalsecs $mailtoint 1]."
1359 return "I shan't accept messages for you."
1362 return "I'll forward your messages by email to $mailtoint."
1365 error "bad tellsec $sec"
1370 proc tellme_rel_desc
{v
} {
1371 manyset
$v rel every within
1372 switch -exact $rel {
1374 return "As soon as I've told you, I'll forget the message - note that this means messages can get lost !"
1380 set u
", or talk on channel within [showintervalsecs $within 1] of me having told you"
1383 error "bad tellrel $rel"
1386 return "I'll remind you every [showintervalsecs $every 1] until you say delmsg$u."
1389 def_setting timeformat
{
1390 set tf
[nickdb_get
$n timeformat
]
1391 return "$tf: [timeformat_desc $tf]"
1393 set tf
[string tolower
[ta_word
]]
1395 set desc
[timeformat_desc
$tf]
1396 nickdb_set
$n timeformat
$tf
1400 proc marktime_desc
{mt
} {
1401 if {"$mt" == "off"} {
1402 return "I will not send you periodic messages."
1403 } elseif
{"$mt" == "once"} {
1404 return "I will send you one informational message when I see you."
1406 return "I'll send you a message every [showintervalsecs $mt 0]."
1410 def_setting marktime
{
1411 set mt
[nickdb_get
$n marktime
]
1413 if {[string match
{[0-9]*} $mt]} { append p s
}
1415 append p
[marktime_desc
$mt]
1419 set mt
[string tolower
[ta_word
]]
1422 if {"$mt" == "off" ||
"$mt" == "once"} {
1424 set mt
[parse_interval
$mt $marktime_min]
1426 nickdb_set
$n marktime
$mt
1427 lnick_marktime_start
[irctolower
$n] "So:" 500 0
1428 ucmdr
{} [marktime_desc
$mt]
1431 def_setting security
{
1432 set s
[nickdb_get
$n username
]
1433 if {[string length
$s]} {
1434 return "Your nick, $n, is controlled by the user $s."
1436 return "Your nick, $n, is not secure."
1440 def_setting tellme
{
1441 set secv
[nickdb_get
$n tellsec
]
1442 set ms
[tellme_sec_desc
$secv]
1444 switch -exact $sec {
1446 set mr
[tellme_rel_desc
[nickdb_get
$n tellrel
]]
1454 set setting
[string tolower
[ta_word
]]
1455 switch -exact $setting {
1456 insecure
- secure
- refuse
{
1458 if {"$setting" == "refuse" && [llength [msgsdb_get
$n inbound
]]} {
1459 usererror
"You must delete the messages you have, first."
1465 set u
[nickdb_get
$n username
]
1466 if {![string length
$u]} {
1467 usererror
"Sorry, you must register secure to have your messages mailed (to prevent the use of this feature for spamming)."
1470 set v
[list mailto
[ta_word
] $u]
1472 unreliable
- pester
- remind
{
1473 manyset
[nickdb_get
$n tellsec
] sec
1474 switch -exact $sec {
1476 error "can't change message delivery conditions when message disposition prevents messages from being left"
1481 if {"$setting" != "unreliable"} {
1482 set every
[parse_interval
[ta_word
] 300]
1485 if {"$setting" == "remind"} {
1487 set within
[parse_interval
[ta_word
] 5]
1491 if {$within > $every} {
1492 error "remind interval must be at least time to respond"
1499 error "invalid tellme setting $setting"
1502 nickdb_set
$n tell$sr $v
1503 ucmdr
[tellme_
${sr
}_desc
$v] {}
1506 proc lnick_checktold
{luser
} {
1507 set ml
[msgsdb_get
$luser outbound
]
1508 if {![llength $ml]} return
1509 set is1
[expr {[llength $ml]==3}]
1510 set m1
"FYI, I haven't yet passed on your"
1512 set now
[clock seconds
]
1513 while {[llength $ml]} {
1515 set ml
[lreplace $ml 0 2]
1516 set td
[expr {$now-$t}]
1518 set iv
[showinterval
$td]
1520 set if1
"message to $r, $iv."
1522 set iv
[showintervalsecs
$td 0]
1523 set ifo
"$r, $n messages, oldest $iv"
1524 set if1
"$n messages to $r, oldest $iv."
1527 sendprivmsg
$luser "$m1 $if1"
1530 lappend ol
" to $ifo[expr {[llength $ml] ? ";" : ".
"}]"
1533 sendprivmsg
$luser "$m1 messages:"
1534 msendprivmsg
$luser $ol
1541 if {![nickdb_exists
$n]} {
1542 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1544 if {![ta_anymore
]} {
1546 foreach opt
$settings {
1547 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1549 ucmdr
{} [join $ol "\n"]
1552 if {[catch { info body set_show
/$opt }]} {
1553 error "no setting $opt"
1555 if {![ta_anymore
]} {
1556 ucmdr
{} "$opt: [set_show/$opt]"
1558 nick_securitycheck
0
1559 if {[catch { info body set_set
/$opt }]} {
1560 error "setting $opt cannot be set with `set'"
1567 def_ucmd identpass
{
1568 set username
[ta_word
]
1569 set passmd5
[md5sum
"[ta_word]\n"]
1573 set luser
[irctolower
$n]
1574 upvar #0 nick_onchans($luser) onchans
1575 if {![info exists onchans
] ||
![llength $onchans]} {
1576 ucmdr
"You must be on a channel with me to identify yourself." {}
1578 check_username
$username
1579 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1581 upvar #0 nick_username($luser) rec_username
1582 set rec_username
$username
1583 ucmdr
"Pleased to see you, $username." {}
1584 tell_event
$luser ident
1588 set target
[ta_word
]
1590 check_username
$target
1593 upvar #0 lastsummon($target) ls
1594 set now
[clock seconds
]
1595 if {[info exists ls
]} {
1596 set interval
[expr {$now - $ls}]
1597 if {$interval < 30} {
1599 "Please be patient; $target was summoned only [showinterval $interval]."
1602 regsub {^
[^
!]*!} $p {} path
1604 exec userv
--timeout 3 $target irc-summon
$n $path \
1605 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1608 regsub -all "\n" $rv { / } rv
1611 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1612 ucmdr
{} "The user `$target' $problem."
1613 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1614 set idletime
[expr {$now - $idlesince}]
1616 ucmdr
{} {} {} "invites $target ($tty[expr {
1617 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime 0]" : ""
1619 [ischan $dest] ? "join us here
" : "talk to you
"
1622 error "unexpected response from userv service: $rv"
1626 proc md5sum
{value
} { exec md5sum
<< $value }
1629 global lastseen nick
1632 set nlower
[irctolower
$ncase]
1634 set now
[clock seconds
]
1635 if {"$nlower" == "[irctolower $nick]"} {
1636 usererror
"I am not self-aware."
1637 } elseif
{![info exists lastseen
($nlower)]} {
1638 set rstr
"I've never seen $ncase."
1640 manyset
$lastseen($nlower) realnick
time what
1641 set howlong
[expr {$now - $time}]
1642 set string [showinterval
$howlong]
1643 set rstr
"I last saw $realnick $string, $what."
1645 if {[ischan
$dest]} {
1650 upvar #0 lookedfor($nlower) lf
1651 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1652 set lf
[list [list $now $n $where]]
1653 foreach v
$oldvalue {
1654 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1660 proc lnick_marktime_cancel
{luser
} {
1661 upvar #0 nick_markid($luser) mi
1662 if {![info exists mi
]} return
1663 catch { after cancel
$mi }
1667 proc lnick_marktime_doafter
{luser why ms mentiontold
} {
1668 lnick_marktime_cancel
$luser
1669 upvar #0 nick_markid($luser) mi
1670 set mi
[after $ms [list lnick_marktime_now
$luser $why 0]]
1673 proc lnick_marktime_reset
{luser
} {
1674 set mt
[nickdb_get
$luser marktime
]
1675 if {"$mt" == "off" ||
"$mt" == "once"} return
1676 lnick_marktime_doafter
$luser "Time passes." [expr {$mt*1000}] 0
1679 proc lnick_marktime_start
{luser why ms mentiontold
} {
1680 set mt
[nickdb_get
$luser marktime
]
1681 if {"$mt" == "off"} {
1682 lnick_marktime_cancel
$luser
1683 after $ms [list lnick_checktold
$luser]
1685 lnick_marktime_doafter
$luser $why $ms $mentiontold
1689 proc lnick_marktime_now
{luser why mentiontold
} {
1690 upvar #0 nick_onchans($luser) oc
1692 set calling_nick
$luser
1693 sendprivmsg
$luser [lnick_pingstring
$why $oc ""]
1694 if {$mentiontold} { lnick_checktold
$luser }
1695 lnick_marktime_reset
$luser
1698 proc lnick_pingstring
{why oc apstring
} {
1700 catch { exec uptime
} uptime
1701 set nnicks
[llength [array names nick_onchans
]]
1703 {^
*([0-9:apm
]+) +up.
*, +(\d
+) users?
, +load average
: +([0-9.
, ]+) *$} \
1704 $uptime dummy
time users
load]} {
1705 regsub -all , $load {} load
1706 set uptime
"$time $nnicks/$users $load"
1708 append uptime
", $nnicks nicks"
1710 if {[llength $oc]} {
1714 upvar #0 chan_lastactivity($ch) la
1715 if {![info exists la
]} continue
1716 if {$la <= $best_la} continue
1717 set since
[showintervalsecs
[expr {[clock seconds
]-$la}] 1]
1718 set activity
"$ch $since"
1725 append str
" " $uptime " " $activity
1726 if {[string length
$apstring]} { append str
" " $apstring }
1732 set ln
[irctolower
$n]
1733 if {[ischan
$dest]} {
1734 set oc
[irctolower
$dest]
1737 if {[info exists nick_onchans
($ln)]} {
1738 set oc
$nick_onchans($ln)
1742 if {[llength $oc]} { lnick_marktime_reset
$ln }
1745 ucmdr
{} [lnick_pingstring
"Pong!" $oc $text]
1748 proc ensure_globalsecret
{} {
1751 if {[info exists globalsecret
]} return
1752 set gsfile
[open /dev
/urandom r
]
1753 fconfigure $gsfile -translation binary
1754 set globalsecret
[read $gsfile 32]
1755 binary scan $globalsecret H
* globalsecret
1761 foreach chan
[chandb_list
] {
1762 if {[chandb_get
$chan autojoin
]} { dojoin
$chan }