3 proc defset
{varname val
} {
5 if {![info exists var
]} { set var
$val }
12 defset ownfullname
"testing bot"
13 defset ownmailaddr test-irc-bot
@example.com
15 defset musthaveping_ms
10000
17 defset out_interval
2100
18 defset out_lag_lag
5000
19 defset out_lag_very
25000
21 proc manyset
{list args
} {
22 foreach val
$list var
$args {
28 proc try_except_finally
{try except finally
} {
29 global errorInfo errorCode
30 set er
[catch { uplevel 1 $try } emsg
]
34 if {[catch { uplevel 1 $except } emsg3
]} {
35 append ei
"\nALSO ERROR HANDLING ERROR:\n$emsg3"
38 set er2
[catch { uplevel 1 $finally } emsg2
]
41 append ei
"\nALSO ERROR CLEANING UP:\n$emsg2"
43 return -code $er -errorinfo $ei -errorcode $ec $emsg
45 return -code $er2 -errorinfo $errorInfo -errorcode $errorCode $emsg2
53 global out_queue out_creditms out_creditat out_interval out_maxburst
54 global out_lag_lag out_lag_very
55 #set pr [lindex [info level 0] 0]
56 #puts $pr>[clock seconds]|$out_creditat|$out_creditms|[llength $out_queue]<
62 if {[llength $out_queue]*$out_interval > $out_lag_very} {
64 } elseif
{[llength $out_queue]*$out_interval > $out_lag_lag} {
74 set now
[clock seconds
]
75 incr out_creditms
[expr {($now - $out_creditat) * 1000}]
77 if {$out_creditms > $out_maxburst*$out_interval} {
78 set out_creditms
[expr {$out_maxburst*$out_interval}]
83 proc out_runqueue
{now
} {
87 while {[llength $out_queue] && $out_creditms >= $out_interval} {
88 #puts rq>$now|$out_creditat|$out_creditms|[llength $out_queue]<
89 manyset
[lindex $out_queue 0] orgwhen msg
90 set out_queue
[lrange $out_queue 1 end
]
91 if {[llength $out_queue]} {
92 append orgwhen
"+[expr {$now - $orgwhen}]"
93 append orgwhen
([llength $out_queue])"
95 puts "$orgwhen -> $msg"
97 incr out_creditms -$out_interval
99 if {[llength $out_queue]} {
100 after $out_interval out_nextmessage
104 proc out_nextmessage {} {
106 set now [clock seconds]
107 incr out_creditms $out_interval
108 set out_creditat $now
112 proc sendout_priority {priority command args} {
113 global sock out_queue
114 if {[llength $args]} {
115 set la [lindex $args end]
116 set args [lreplace $args end end]
118 if {[regexp {[: ]} $i]} {
119 error "bad argument in output
$i ($command $args)"
124 set args [lreplace $args 0 -1 $command]
125 set string [join $args { }]
126 set now [clock seconds]
127 set newe [list $now $string]
129 set out_queue [concat [list $newe] $out_queue]
131 lappend out_queue $newe
133 if {[llength $out_queue] == 1} {
138 proc sendout {command args} { eval sendout_priority [list 0 $command] $args }
144 proc logerror {data} {
149 global saveei saveec errorInfo errorCode
151 set saveei $errorInfo
152 set saveec $errorCode
154 puts ">$saveec|
$saveei<"
164 global sock nick calling_nick errorInfo errorCode
166 if {[gets $sock line] == -1} { fail "EOF
/error on input
" }
167 regsub -all "\[^
-\176\240-\376\]" $line ? line
172 catch { unset calling_nick }
176 if {[regexp -nocase {^:([^ ]+) (.*)} $line dummy prefix remain]} {
178 if {[regexp {^([^!]+)!} $prefix dummy maybenick]} {
179 set calling_nick $maybenick
180 if {"[irctolower
$maybenick]" == "[irctolower
$nick]"} return
185 if {![string length $line]} { return }
186 if {![regexp -nocase {^([0-9a-z]+) *(.*)} $line dummy command line]} {
187 log "bad command
: $org"
190 set command [string toupper $command]
192 while {[regexp {^([^ :]+) *(.*)} $line dummy thisword line]} {
193 lappend params $thisword
195 if {[regexp {^:(.*)} $line dummy thisword]} {
196 lappend params $thisword
197 } elseif {[string length $line]} {
198 log "junk at end
: $org"
201 if {"$command" == "PRIVMSG
" &&
202 [regexp {^[&#+!]} [lindex $params 0]] &&
203 ![regexp {^!} [lindex $params 1]]} {
204 # on-channel message, ignore
206 recordlastseen_p $prefix "talking on
[lindex $params 0]" 1
210 log "[clock seconds
] <- $org"
211 set procname msg_$command
212 if {[catch { info body $procname }]} { return }
214 eval [list $procname $prefix $command] $params
216 logerror "error: $emsg ($prefix $command $params)"
221 proc sendprivmsg {dest l} {
222 foreach v [split $l "\n"] {
223 sendout [expr {[ischan $dest] ? "PRIVMSG
" : "NOTICE
"}] $dest $v
226 proc sendaction_priority {priority dest what} {
227 sendout_priority $priority PRIVMSG $dest "\001ACTION
$what\001"
229 proc msendprivmsg {dest ll} { foreach l $ll { sendprivmsg $dest $l } }
230 proc msendprivmsg_delayed {delay dest ll} { after $delay [list msendprivmsg $dest $ll] }
232 proc prefix_none {} {
234 if {[string length $p]} { error "prefix specified
" }
237 proc msg_PING {p c s1} {
238 global musthaveping_after
241 if {[info exists musthaveping_after]} {
242 after cancel $musthaveping_after
243 unset musthaveping_after
247 proc check_nick {n} {
248 if {[regexp -nocase {[^][\\`_^{|}a-z0-9-]} $n]} { error "bad char in nick
" }
249 if {[regexp {^[-0-9]} $n]} { error "bad nick start
" }
253 return [regexp {^[&#+!]} $dest]
256 proc irctolower {v} {
257 foreach {from to} [list "\\\[" "{" \
261 regsub -all $from $v $to v
263 return [string tolower $v]
266 proc prefix_nick {} {
270 if {![regexp {^([^!]+)!} $p dummy n]} { error "not from nick
" }
272 if {"[irctolower
$n]" == "[irctolower
$nick]"} {
273 error "from myself
" {} {}
277 proc showintervalsecs {howlong} {
278 return [showintervalsecs/[opt timeformat] $howlong]
281 proc showintervalsecs/ks {howlong} {
282 if {$howlong < 1000} {
285 if {$howlong < 1000000} {
292 set value [expr "$howlong.0 / $scale"]
293 foreach {min format} {100 %.0f 10 %.1f 1 %.2f} {
294 if {$value < $min} continue
295 return [format "$format${pfx
}s
" $value]
300 proc format_qty {qty unit} {
304 if {$qty != 1} { append o s }
308 proc showintervalsecs/hms {qty} {
309 set ul {second 60 minute 60 hour 24 day 7 week}
311 while {[llength $ul] > 1 && $qty >= [set uv [lindex $ul 1]]} {
312 set remainu [lindex $ul 0]
313 set remainv [expr {$qty % $uv}]
314 set qty [expr {($qty-$remainv)/$uv}]
315 set ul [lreplace $ul 0 1]
317 set o [format_qty $qty [lindex $ul 0]]
320 append o [format_qty $remainv $remainu]
325 proc showinterval {howlong} {
329 return "[showintervalsecs
$howlong] ago
"
333 proc showtime {when} {
334 return [showinterval [expr {[clock seconds] - $when}]]
337 proc def_msgproc {name argl body} {
338 proc msg_$name "varbase
$argl" "\
339 upvar #0 msg/\$varbase/dest d\n\
340 upvar #0 msg/\$varbase/str s\n\
341 upvar #0 msg/\$varbase/accum a\n\
345 def_msgproc begin {dest str} {
351 def_msgproc append {str} {
353 if {[string length $s] && [string length $ns] > 65} {
354 msg__sendout $varbase
355 set s " [string trimleft
$str]"
361 def_msgproc finish {} {
362 msg__sendout $varbase
368 def_msgproc _sendout {} {
369 lappend a [string trimright $s]
373 proc looking_whenwhere {when where} {
374 set str [showtime [expr {$when-1}]]
375 if {[string length $where]} { append str " on
$where" }
379 proc recordlastseen_n {n how here} {
380 global lastseen lookedfor
381 set lastseen([irctolower $n]) [list $n [clock seconds] $how]
383 upvar #0 lookedfor([irctolower $n]) lf
384 if {[info exists lf]} {
385 switch -exact [llength $lf] {
390 manyset [lindex $lf 0] when who where
392 "FYI
, $who was looking
for you
[looking_whenwhere
$when $where].
"]
395 msg_begin tosend $n "FYI
, people have been looking
for you
:"
401 msg_append tosend " "
402 } elseif {$i == [llength $lf]} {
403 msg_append tosend " and
"
406 msg_append tosend ", "
408 manyset $e when who where
410 "$who ([looking_whenwhere
$when $where])$fin"
412 set ml [msg_finish tosend]
416 msendprivmsg_delayed 1000 $n $ml
420 proc recordlastseen_p {p how here} {
422 recordlastseen_n $n $how $here
425 proc chanmode_arg {} {
427 set rv [lindex $cm_args 0]
428 set cm_args [lreplace cm_args 0 0]
432 proc chanmode_o1 {m g p chan} {
433 global nick chan_initialop
435 set who [chanmode_arg]
436 recordlastseen_n $n "being nice to
$who" 1
437 if {"[irctolower
$who]" == "[irctolower
$nick]"} {
438 set nl [irctolower $n]
439 upvar #0 nick_unique($n) u
440 if {[chandb_exists $chan]} {
441 sendprivmsg $n Thanks.
442 } elseif {![info exists u]} {
443 sendprivmsg $n {Op me while not on the channel, why don't you ?}
445 set chan_initialop([irctolower $chan]) $u
447 "Thanks. You can use `channel manager ...' to register this channel.
"
448 if {![nickdb_exists $n] || ![string length [nickdb_get $n username]]} {
450 "(But to do that you must register your nick securely first.
)"
456 proc chanmode_o0 {m g p chan} {
459 set who [chanmode_arg]
460 recordlastseen_p $p "being mean to
$who" 1
461 if {"[irctolower
$who]" == "[irctolower
$nick]"} {
462 set chandeop($chan) [list [clock seconds] $p]
466 proc msg_MODE {p c dest modelist args} {
467 if {![ischan $dest]} return
468 if {[regexp {^\-(.+)$} $modelist dummy modelist]} {
470 } elseif {[regexp {^\+(.+)$} $modelist dummy modelist]} {
473 error "invalid modelist
"
475 foreach m [split $modelist] {
476 set procname chanmode_$m$give
477 if {[catch { info body $procname }]} {
478 recordlastseen_p $p "fiddling with
$dest" 1
480 $procname $m $give $p $dest
485 proc channel_noone_seen {chan} {
487 foreach n [array names nick_onchans] {
488 upvar #0 nick_onchans($n) oc
489 set oc [grep tc {"$tc" != "$chan"} $oc]
493 proc process_kickpart {chan user} {
496 if {![ischan $chan]} { error "not a channel
" }
497 if {"[irctolower
$user]" == "[irctolower
$nick]"} {
498 channel_noone_seen $chan
500 upvar #0 nick_onchans($user) oc
501 set lc [irctolower $chan]
502 set oc [grep tc {"$tc" != "$lc"} $oc]
503 if {![llength $oc]} { nick_forget $user }
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}
524 proc nick_forget {n} {
526 foreach ary $nick_arys {
527 upvar #0 nick_${ary}($n) av
535 set nick_case([irctolower $n]) $n
538 proc msg_NICK {p c newnick} {
539 global nick_arys nick_case
541 recordlastseen_n $n "changing nicks to
$newnick" 0
542 recordlastseen_n $newnick "changing nicks from
$n" 1
543 foreach ary $nick_arys {
544 upvar #0 nick_${ary}($n) old
545 upvar #0 nick_${ary}($newnick) new
546 if {[info exists new]} { error "nick collision ?
! $ary $n $newnick" }
547 if {[info exists old]} { set new $old; unset old }
552 proc nick_ishere {n} {
554 upvar #0 nick_unique($n) u
555 if {![info exists u]} { set u [incr nick_counter].$n.[clock seconds] }
559 proc msg_JOIN {p c chan} {
561 recordlastseen_n $n "joining
$chan" 1
562 upvar #0 nick_onchans($n) oc
563 lappend oc [irctolower $chan]
566 proc msg_PART {p c chan} {
568 recordlastseen_n $n "leaving
$chan" 1
569 process_kickpart $chan $n
571 proc msg_QUIT {p c why} {
573 recordlastseen_n $n "leaving
($why)" 0
577 proc msg_PRIVMSG {p c dest text} {
579 if {[ischan $dest]} {
580 recordlastseen_n $n "invoking me in
$dest" 1
583 recordlastseen_n $n "talking to me
" 1
589 regsub {^! *} $text {} text
591 set procname ucmd/[string tolower $ucmd]
592 if {[catch { info body $procname }]} {
593 error "unknown command
; try help
for help
"
597 sendprivmsg $n "error: $rv"
599 manyset $rv priv_msgs pub_msgs priv_acts pub_acts
600 foreach {td val} [list $n $priv_acts $output $pub_acts] {
601 foreach l [split $val "\n"] {
602 sendaction_priority 0 $td $l
605 foreach {td val} [list $n $priv_msgs $output $pub_msgs] {
606 foreach l [split $val "\n"] {
613 proc msg_INVITE {p c n chan} {
614 after 1000 [list sendout JOIN $chan]
617 proc grep {var predicate list} {
621 if {[uplevel 1 [list expr $predicate]]} { lappend o $v }
626 proc msg_353 {p c dest type chan nicklist} {
627 global names_chans nick_onchans
628 if {![info exists names_chans]} { set names_chans {} }
629 set chan [irctolower $chan]
630 lappend names_chans $chan
631 channel_noone_seen $chan
632 foreach n [split $nicklist { }] {
633 regsub {^[@+]} $n {} n
634 if {![string length $n]} continue
636 upvar #0 nick_onchans($n) oc
642 proc msg_366 {p c args} {
643 global names_chans nick_onchans
644 if {[llength names_chans] > 1} {
645 foreach n [array names nick_onchans] {
646 upvar #0 nick_onchans($n) oc
647 set oc [grep tc {[lsearch -exact $tc $names_chans] >= 0} $oc]
648 if {![llength $oc]} { nick_forget $n }
656 return [expr {!![string length $text]}]
661 if {[string length $text]} { error "too many parameters
" }
666 if {![regexp {^([^ ]+) *(.*)} $text dummy firstword text]} {
667 error "too few parameters
"
679 proc def_ucmd {cmdname body} {
680 proc ucmd/$cmdname {p dest} " upvar 1 text text\n$body"
683 proc ucmdr {priv pub args} {
684 return -code return [concat [list $priv $pub] $args]
690 catch { unset help_topics }
691 set f [open helpinfos r]
694 while {[gets $f l] >= 0} {
696 if {[regexp {^#.*} $l]} {
697 } elseif {[regexp {^ *$} $l]} {
698 if {[info exists topic]} {
699 set help_topics($topic) [join $lines "\n"]
703 } elseif {[regexp {^!([-+._0-9a-z]*)$} $l dummy newtopic]} {
704 if {[info exists topic]} {
705 error "help
$newtopic while in
$topic"
709 } elseif {[regexp {^[^!#]} $l]} {
711 lappend lines [string trimright $l]
713 error "eh ?
$lno: $l"
716 if {[info exists topic]} { error "unfinished topic
$topic" }
723 if {[set lag [out_lagged]]} {
724 if {[ischan $dest]} { set replyto $dest } else { set replyto $n }
726 sendaction_priority 1 $replyto \
727 "is very lagged. Please ask
for help again later.
"
730 sendaction_priority 1 $replyto \
731 "is lagged. Your help will arrive shortly ...
"
735 upvar #0 help_topics([irctolower [string trim $text]]) info
736 if {![info exists info]} { ucmdr "No help on
$text, sorry.
" {} }
742 ucmdr $help_topics() {}
745 proc check_username {target} {
747 [string length $target] > 8 ||
748 [regexp {[^-0-9a-z]} $target] ||
749 ![regexp {^[a-z]} $target]
750 } { error "invalid username
" }
753 proc somedb__head {} {
755 set idl [irctolower $id]
756 upvar #0 ${nickchan}db($idl) ndbe
757 binary scan $idl H* idh
758 set idfn $fprefix$idh
759 if {![info exists iddbe] && [file exists $idfn]} {
761 try_except_finally { set newval [read $f] } {} { close $f }
762 if {[llength $newval] % 2} { error "invalid length
" }
768 proc def_somedb {name arglist body} {
769 foreach {nickchan fprefix} {nick users/n chan chans/c} {
770 proc ${nickchan}db_$name $arglist \
771 "set nickchan
$nickchan; set fprefix
$fprefix; somedb__head
; $body"
775 def_somedb exists {id} {
776 return [info exists iddbe]
779 def_somedb delete {id} {
780 catch { unset iddbe }
784 set default_settings_nick {timeformat ks}
785 set default_settings_chan {autojoin 1}
787 def_somedb set {id args} {
788 upvar #0 default_settings_$nickchan def
789 if {![info exists iddbe]} { set iddbe $def }
790 foreach {key value} [concat $iddbe $args] { set a($key) $value }
792 foreach {key value} [array get a] { lappend newval $key $value }
793 set f [open $idfn.new w]
797 file rename -force $idfn.new $idfn
805 def_somedb get {id key} {
806 upvar #0 default_settings_$nickchan def
807 if {[info exists iddbe]} {
812 foreach {tkey value} $l {
813 if {"$tkey" == "$key"} { return $value }
815 error "unset setting
$key"
820 if {[info exists calling_nick]} { set n $calling_nick } { set n {} }
821 return [nickdb_get $n $key]
824 proc check_notonchan {} {
826 if {[ischan $dest]} { error "that command must be sent privately
" }
829 proc nick_securitycheck {strict} {
831 if {![nickdb_exists $n]} { error "you are
unknown to me
, use `register'.
" }
832 set wantu [nickdb_get $n username]
833 if {![string length $wantu]} {
835 error "that feature is only available to secure users
, sorry.
"
840 upvar #0 nick_username($n) nu
841 if {![info exists nu]} {
842 error "nick
$n is secure
, you must identify yourself first.
"
844 if {"$wantu" != "$nu"} {
845 error "you are the wrong user
- the nick
$n belongs to
$wantu, not
$nu"
849 proc channel_securitycheck {channel n} {
850 # You must also call `nick_securitycheck 1'
851 set mgrs [chandb_get $channel managers]
852 if {[lsearch -exact [irctolower $mgrs] [irctolower $n]] < 0} {
853 error "you are not a manager of
$channel"
857 proc def_chancmd {name body} {
858 proc channel/$name {} \
859 " upvar 1 target chan
; upvar 1 n n
; upvar 1 text text; $body"
862 def_chancmd manager {
864 switch -exact _$opcode {
867 if {[chandb_exists $chan]} {
868 set ml [chandb_get $chan managers]
870 set ml [list [irctolower $n]]
874 error "`channel manager' opcode must be one of
+ - ="
877 foreach nn [split $text " "] {
878 if {![string length $nn]} continue
880 set nn [irctolower $nn]
881 if {"$opcode" != "-"} {
884 set ml [grep nq {"$nq" != "$nn"} $ml]
888 chandb_set $chan managers $ml
889 ucmdr "Managers of
$chan: $ml" {}
892 ucmdr {} {} "forgets about managing
$chan.
" {}
896 def_chancmd autojoin {
898 switch -exact [string tolower $yesno] {
901 default { error "channel autojoin must be `yes' or `no'
}
903 chandb_set
$chan autojoin
$nv
907 if {[chandb_exists
$chan]} {
908 set l
"Settings for $chan: autojoin "
909 append l
[lindex {no yes
} [chandb_get
$chan autojoin
]]
910 append l
"\nManagers: "
911 append l
[join [chandb_get
$chan managers
] " "]
914 ucmdr
{} "The channel $chan is not managed."
919 if {[ischan
$dest]} { set target
$dest }
920 if {[ta_anymore
]} { set target
[ta_word
] }
922 if {![info exists target
]} { error "you must specify, or !... on, the channel" }
923 if {![ischan
$target]} { error "not a valid channel" }
924 if {![chandb_exists
$target]} { error "$target is not a managed channel." }
927 channel_securitycheck
$target $n
928 sendout MODE
$target +o
$n
932 if {[ischan
$dest]} { set target
$dest }
938 if {[ischan
$subcmd]} {
946 if {![info exists target
]} { error "privately, you must specify a channel" }
947 set procname channel
/$subcmd
948 if {"$subcmd" != "show"} {
949 if {[catch { info body
$procname }]} { error "unknown channel setting $subcmd" }
952 if {[chandb_exists
$target]} {
953 channel_securitycheck
$target $n
955 upvar #0 chan_initialop([irctolower $target]) io
956 upvar #0 nick_unique($n) u
957 if {![info exists io
]} { error "$target is not a managed channel" }
958 if {"$io" != "$u"} { error "you are not the interim manager of $target" }
959 if {"$subcmd" != "manager"} { error "use `channel manager' first" }
967 set target
[ta_word
]; ta_nomore
972 set myself
[expr {"$target" != "$n"}]
974 upvar #0 nick_case([irctolower $target]) nc
976 if {[info exists nc
]} {
977 upvar #0 nick_onchans($nc) oc
978 upvar #0 nick_username($nc) nu
979 if {[info exists oc
]} { set nshow
$nc }
981 if {![nickdb_exists
$target]} {
982 set ol
"$nshow is not a registered nick."
983 } elseif
{[string length
[set username
[nickdb_get
$target username
]]]} {
984 set ol
"The nick $nshow belongs to the user $username."
986 set ol
"The nick $nshow is registered (but not to a username)."
988 if {![info exists nc
] ||
![info exists oc
]} {
990 append ol
"\nI can't see $nshow on anywhere."
992 append ol
"\nYou aren't on any channels with me."
994 } elseif
{![info exists nu
]} {
995 append ol
"\n$nshow has not identified themselves."
996 } elseif
{![info exists username
]} {
997 append ol
"\n$nshow has identified themselves as the user $nu."
998 } elseif
{"$nu" != "$username"} {
999 append ol
"\nHowever, $nshow is being used by the user $nu."
1001 append ol
"\n$nshow has identified themselves to me."
1009 set old
[nickdb_exists
$n]
1010 if {$old} { nick_securitycheck
0 }
1011 switch -exact [string tolower
[string trim
$text]] {
1013 upvar #0 nick_username($n) nu
1014 if {![info exists nu
]} {
1016 "You must identify yourself before using `register'. See `help identify', or use `register insecure'."
1018 nickdb_set
$n username
$nu
1019 ucmdr
{} {} "makes a note of your username." {}
1023 ucmdr
{} {} "forgets your nickname." {}
1026 nickdb_set
$n username
{}
1028 ucmdr
{} "Security is now disabled for your nickname !"
1030 ucmdr
{} "This is fine, but bear in mind that people will be able to mess with your settings. Channel management features need a secure registration." "makes an insecure registration for your nick."
1036 proc timeformat_desc
{tf
} {
1038 ks
{ return "Times will be displayed in seconds or kiloseconds." }
1039 hms
{ return "Times will be displayed in hours, minutes, etc." }
1040 default { error "invalid timeformat: $v" }
1044 proc def_setting
{opt show_body set_body
} {
1045 proc set_show
/$opt {} "
1049 if {![string length
$set_body]} return
1050 proc set_set
/$opt {} "
1057 def_setting timeformat
{
1058 set tf
[nickdb_get
$n timeformat
]
1059 return "$tf: [timeformat_desc $tf]"
1061 set tf
[string tolower
[ta_word
]]
1063 set desc
[timeformat_desc
$tf]
1064 nickdb_set
$n timeformat
$tf
1068 def_setting security
{
1069 set s
[nickdb_get
$n username
]
1070 if {[string length
$s]} {
1071 return "Your nick, $n, is controlled by the user $s."
1073 return "Your nick, $n, is not secure."
1080 if {![nickdb_exists
$n]} {
1081 ucmdr
{} "You are unknown to me and so have no settings. (Use `register'.)"
1083 if {![ta_anymore
]} {
1085 foreach proc [lsort [info procs
]] {
1086 if {![regexp {^set_show
/(.
*)$} $proc dummy opt
]} continue
1087 lappend ol
[format "%-10s %s" $opt [set_show
/$opt]]
1089 ucmdr
{} [join $ol "\n"]
1092 if {[catch { info body set_show
/$opt }]} {
1093 error "no setting $opt"
1095 if {![ta_anymore
]} {
1096 ucmdr
{} "$opt [set_show/$opt]"
1098 nick_securitycheck
0
1099 if {[catch { info body set_set
/$opt }]} {
1100 error "setting $opt cannot be set with `set'"
1107 def_ucmd identpass
{
1108 set username
[ta_word
]
1109 set passmd5
[md5sum
"[ta_word]\n"]
1113 upvar #0 nick_onchans($n) onchans
1114 if {![info exists onchans
] ||
![llength $onchans]} {
1115 ucmdr
"You must be on a channel with me to identify yourself." {}
1117 check_username
$username
1118 exec userv
--timeout 3 $username << "$passmd5\n" > /dev
/null
\
1120 upvar #0 nick_username($n) rec_username
1121 set rec_username
$username
1122 ucmdr
"Pleased to see you, $username." {}
1126 set target
[ta_word
]
1128 check_username
$target
1131 upvar #0 lastsummon($target) ls
1132 set now
[clock seconds
]
1133 if {[info exists ls
]} {
1134 set interval
[expr {$now - $ls}]
1135 if {$interval < 30} {
1137 "Please be patient; $target was summoned only [showinterval $interval]."
1140 regsub {^
[^
!]*!} $p {} path
1142 exec userv
--timeout 3 $target irc-summon
$n $path \
1143 [expr {[ischan
$dest] ?
"$dest" : ""}] \
1146 regsub -all "\n" $rv { / } rv
1149 if {[regexp {^problem
(.
*)} $rv dummy problem
]} {
1150 ucmdr
{} "The user `$target' $problem."
1151 } elseif
{[regexp {^ok
([^
]+) ([0-9]+)$} $rv dummy tty idlesince
]} {
1152 set idletime
[expr {$now - $idlesince}]
1154 ucmdr
{} {} {} "invites $target ($tty[expr {
1155 $idletime > 10 ? ", idle
for [showintervalsecs
$idletime]" : ""
1157 [ischan $dest] ? "join us here
" : "talk to you
"
1160 error "unexpected response from userv service: $rv"
1164 proc md5sum
{value
} { exec md5sum
<< $value }
1167 global lastseen nick
1170 set nlower
[irctolower
$ncase]
1172 set now
[clock seconds
]
1173 if {"$nlower" == "[irctolower $nick]"} {
1174 error "I am not self-aware."
1175 } elseif
{![info exists lastseen
($nlower)]} {
1176 set rstr
"I've never seen $ncase."
1178 manyset
$lastseen($nlower) realnick
time what
1179 set howlong
[expr {$now - $time}]
1180 set string [showinterval
$howlong]
1181 set rstr
"I last saw $realnick $string, $what."
1183 if {[ischan
$dest]} {
1188 upvar #0 lookedfor($nlower) lf
1189 if {[info exists lf
]} { set oldvalue
$lf } else { set oldvalue
{} }
1190 set lf
[list [list $now $n $where]]
1191 foreach v
$oldvalue {
1192 if {"[irctolower [lindex $v 1]]" == "[irctolower $n]"} continue
1198 proc ensure_globalsecret
{} {
1201 if {[info exists globalsecret
]} return
1202 set gsfile
[open /dev
/urandom r
]
1203 fconfigure $gsfile -translation binary
1204 set globalsecret
[read $gsfile 32]
1205 binary scan $globalsecret H
* globalsecret
1210 proc ensure_outqueue
{} {
1212 if {[info exists out_queue
]} return
1213 set out_creditms
[expr {$out_maxburst*$out_interval}]
1214 set out_creditat
[clock seconds
]
1216 set out_lag_reported
0
1217 set out_lag_reportwhen
$out_creditat
1221 logerror
"failing: $msg"
1225 proc ensure_connecting
{} {
1226 global sock ownfullname host port nick
1227 global musthaveping_ms musthaveping_after
1229 if {[info exists sock
]} return
1230 set sock
[socket $host $port]
1231 fconfigure $sock -buffering line
1232 fconfigure $sock -translation crlf
1234 sendout USER blight
0 * $ownfullname
1236 fileevent $sock readable onread
1238 set musthaveping_after
[after $musthaveping_ms \
1239 {fail
"no ping within timeout"}]