chiark / gitweb /
Nick tracking.
authorijackson <ijackson>
Tue, 5 Sep 2000 13:02:56 +0000 (13:02 +0000)
committerijackson <ijackson>
Tue, 5 Sep 2000 13:02:56 +0000 (13:02 +0000)
bot.tcl
test.tcl [new file with mode: 0644]

diff --git a/bot.tcl b/bot.tcl
index bef0eadd4aef50b18d33245a94578210cf3b2b9d..f17134479b3ef3a4cf04c0c150e8c1292ccb4845 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -57,13 +57,15 @@ proc bgerror {msg} {
 }
 
 proc onread {args} {
-    global sock
+    global sock nick
     
     if {[gets $sock line] == -1} { set terminate 1; return }
     regsub -all "\[^ -\176\240-\376\]" $line ? line
     set org $line
     if {[regexp -nocase {^:([^ ]+) (.*)} $line dummy prefix remain]} {
        set line $remain
+       if {[regexp {^([^!]+)!} $prefix dummy maybenick] &&
+           "[irctolower $maybenick]" == "[irctolower $nick]"} return
     } else {
        set prefix {}
     }
@@ -145,7 +147,9 @@ proc prefix_nick {} {
     upvar 1 n n
     if {![regexp {^([^!]+)!} $p dummy n]} { error "not from nick" }
     check_nick $n
-    if {"[irctolower $n]" == "[irctolower $nick]"} { error "from myself" }
+    if {"[irctolower $n]" == "[irctolower $nick]"} {
+       error "from myself" {} {}
+    }
 }
 
 proc showintervalsecs {howlong} {
@@ -313,15 +317,68 @@ proc msg_MODE {p c dest modelist args} {
     }
 }
 
+proc process_kickpart {chan user} {
+    check_nick $user
+    if {![ischan $chan]} { error "not a channel" }
+
+    upvar #0 nick_onchans($user) oc
+    set lc [irctolower $chan]
+    set oc [grep tc {"$tc" != "$lc"} $oc]
+}    
+
+proc msg_KICK {p c chans users comment} {
+    set chans [split $chans ,]
+    set users [split $users ,]
+    if {[llength $chans] > 1} {
+       foreach chan $chans user $users { process_kickpart $chan $user }
+    } else {
+       foreach user $users { process_kickpart [lindex $chans 0] $user }
+    }
+}
+
+proc msg_KILL {p c user why} {
+    nick_forget $user
+}
+
+set nick_arys {onchans username}
+
+proc nick_forget {n} {
+    global nick_arys
+    foreach ary $nick_arys {
+       upvar #0 nick_${ary}($n) av
+       catch { unset av }
+    }
+}
+
 proc msg_NICK {p c newnick} {
+    global nick_arys
     prefix_nick
     recordlastseen_n $n "changing nicks to $newnick" 0
     recordlastseen_n $newnick "changing nicks from $n" 1
+    foreach ary $nick_arys {
+       upvar #0 nick_${ary}($n) old
+       upvar #0 nick_${ary}($newnick) new
+       if {[info exists new]} { error "nick collision ?! $ary $n $newnick" }
+       if {[info exists old]} { set new $old; unset old }
+    }
 }
 
-proc msg_JOIN {p c chan} { recordlastseen_p $p "joining $chan" 1 }
-proc msg_PART {p c chan} { recordlastseen_p $p "leaving $chan" 1 }
-proc msg_QUIT {p c why} { recordlastseen_p $p "leaving ($why)" 0 }
+proc msg_JOIN {p c chan} {
+    prefix_nick
+    recordlastseen_n $n "joining $chan" 1
+    upvar #0 nick_onchans($n) oc
+    lappend oc [irctolower $chan]
+}
+proc msg_PART {p c chan} {
+    prefix_nick
+    recordlastseen_n $n "leaving $chan" 1
+    process_kickpart $chan $n
+}
+proc msg_QUIT {p c why} {
+    prefix_nick
+    recordlastseen_n $n "leaving ($why)" 0
+    nick_forget $n
+}
 
 proc msg_PRIVMSG {p c dest text} {
     prefix_nick
@@ -358,6 +415,49 @@ proc msg_PRIVMSG {p c dest text} {
     }
 }
 
+proc msg_INVITE {p c n chan} {
+    after 1000 [list sendout JOIN $chan]
+}
+
+proc grep {var predicate list} {
+    set o {}
+    upvar 1 $var v
+    foreach v $list {
+       if {[uplevel 1 [list expr $predicate]]} { lappend o $v }
+    }
+    return $o
+}
+
+proc msg_353 {p c dest type chan nicklist} {
+    global names_chans nick_onchans
+    if {![info exists names_chans]} { set names_chans {} }
+    set chan [irctolower $chan]
+    lappend names_chans $chan
+    foreach n [array names nick_onchans] {
+       upvar #0 nick_onchans($n) oc
+       set oc [grep tc {"$tc" != "$chan"} $oc]
+    }
+    foreach n [split $nicklist { }] {
+       regsub {^[@+]} $n {} n
+       check_nick $n
+       if {![string length $n]} continue
+       upvar #0 nick_onchans($n) oc
+       lappend oc $chan
+    }
+}
+
+proc msg_366 {p c args} {
+    global names_chans nick_onchans
+    if {[llength names_chans] > 1} {
+       foreach n [array names nick_onchans] {
+           upvar #0 nick_onchans($n) oc
+           set oc [grep tc {[lsearch -exact $tc $names_chans] >= 0} $oc]
+           if {![llength $oc]} { nick_forget $n }
+       }
+    }
+    unset names_chans
+}
+
 proc ta_nomore {} {
     upvar 1 text text
     if {[string length $text]} { error "too many parameters" }
@@ -392,7 +492,10 @@ proc ucmd_sendhelp {} {
  help              get this list of commands
  seen <nick>       ask after someone (I'll tell them you asked)
  summon <username> invite a logged-on user onto IRC
-Send commands to be by /msg, or say them in channel with ! in front.} {}
+Send commands to me by /msg, or say them in channel with ! in front.} {}
+#
+# register          register your nick (you must auth[*] first)
+#[*]auth: /blight in ircII, or /msg blight authuser <username> <pass>
 }
 
 def_ucmd help { ta_nomore; ucmd_sendhelp }
diff --git a/test.tcl b/test.tcl
new file mode 100644 (file)
index 0000000..d54d29e
--- /dev/null
+++ b/test.tcl
@@ -0,0 +1,2 @@
+set nick testbot
+set ownfullname confused