chiark / gitweb /
who command. correctly forget people when we are kicked.
authorijackson <ijackson>
Wed, 6 Sep 2000 12:51:13 +0000 (12:51 +0000)
committerijackson <ijackson>
Wed, 6 Sep 2000 12:51:13 +0000 (12:51 +0000)
bot.tcl
helpinfos

diff --git a/bot.tcl b/bot.tcl
index dff9ab30618223234ac6fd18ac3feec6186a341c..ff5e8b74c6c2c91310738b3528f632b077da43ed 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -85,14 +85,15 @@ proc onread {args} {
     if {[gets $sock line] == -1} { set terminate 1; return }
     regsub -all "\[^ -\176\240-\376\]" $line ? line
     set org $line
+    catch { unset calling_nick }
     if {[regexp -nocase {^:([^ ]+) (.*)} $line dummy prefix remain]} {
        set line $remain
-       if {[regexp {^([^!]+)!} $prefix dummy maybenick] &&
-           "[irctolower $maybenick]" == "[irctolower $nick]"} return
-       set calling_nick $maybenick
+       if {[regexp {^([^!]+)!} $prefix dummy maybenick]} {
+           set calling_nick $maybenick
+           if {"[irctolower $maybenick]" == "[irctolower $nick]"} return
+       }
     } else {
        set prefix {}
-       catch { unset calling_nick }
     }
     if {![string length $line]} { return }
     if {![regexp -nocase {^([0-9a-z]+) *(.*)} $line dummy command line]} {
@@ -371,14 +372,26 @@ proc msg_MODE {p c dest modelist args} {
     }
 }
 
+proc channel_noone_seen {chan} {
+    global nick_onchans
+    foreach n [array names nick_onchans] {
+       upvar #0 nick_onchans($n) oc
+       set oc [grep tc {"$tc" != "$chan"} $oc]
+    }
+}
+
 proc process_kickpart {chan user} {
+    global nick
     check_nick $user
     if {![ischan $chan]} { error "not a channel" }
-
+    if {"[irctolower $user]" == "[irctolower $nick]"} {
+       channel_noone_seen $chan
+    }
     upvar #0 nick_onchans($user) oc
     set lc [irctolower $chan]
     set oc [grep tc {"$tc" != "$lc"} $oc]
     if {![llength $oc]} { nick_forget $user }
+    nick_case $user
 }    
 
 proc msg_KICK {p c chans users comment} {
@@ -403,10 +416,16 @@ proc nick_forget {n} {
        upvar #0 nick_${ary}($n) av
        catch { unset av }
     }
+    nick_case $n
+}
+
+proc nick_case {n} {
+    global nick_case
+    set nick_case([irctolower $n]) $n
 }
 
 proc msg_NICK {p c newnick} {
-    global nick_arys
+    global nick_arys nick_case
     prefix_nick
     recordlastseen_n $n "changing nicks to $newnick" 0
     recordlastseen_n $newnick "changing nicks from $n" 1
@@ -416,6 +435,7 @@ proc msg_NICK {p c newnick} {
        if {[info exists new]} { error "nick collision ?! $ary $n $newnick" }
        if {[info exists old]} { set new $old; unset old }
     }
+    nick_case $newnick
 }
 
 proc msg_JOIN {p c chan} {
@@ -423,6 +443,7 @@ proc msg_JOIN {p c chan} {
     recordlastseen_n $n "joining $chan" 1
     upvar #0 nick_onchans($n) oc
     lappend oc [irctolower $chan]
+    nick_case $n
 }
 proc msg_PART {p c chan} {
     prefix_nick
@@ -444,6 +465,7 @@ proc msg_PRIVMSG {p c dest text} {
        recordlastseen_n $n "talking to me" 1
        set output $n
     }
+    nick_case $n
 
     if {[catch {
        regsub {^! *} $text {} text
@@ -488,16 +510,14 @@ proc msg_353 {p c dest type chan nicklist} {
     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]
-    }
+    channel_noone_seen $chan
     foreach n [split $nicklist { }] {
        regsub {^[@+]} $n {} n
-       check_nick $n
        if {![string length $n]} continue
+       check_nick $n
        upvar #0 nick_onchans($n) oc
        lappend oc $chan
+       nick_case $n
     }
 }
 
@@ -699,6 +719,47 @@ proc nick_securitycheck {strict} {
     }
 }
 
+def_ucmd who {
+    if {[ta_anymore]} {
+       set target [ta_word]; ta_nomore
+       set myself 1
+    } else {
+       prefix_nick
+       set target $n
+       set myself [expr {"$target" != "$n"}]
+    }
+    upvar #0 nick_case([irctolower $target]) nc
+    set nshow $target
+    if {[info exists nc]} {
+       upvar #0 nick_onchans($nc) oc
+       upvar #0 nick_username($nc) nu
+       if {[info exists oc]} { set nshow $nc }
+    }
+    if {![nickdb_exists $target]} {
+       set ol "$nshow is not a registered nick."
+    } elseif {[string length [set username [nickdb_opt $target username]]]} {
+       set ol "The nick $nshow belongs to the user $username."
+    } else {
+       set ol "The nick $nshow is registered (but not to a username)."
+    }
+    if {![info exists nc] || ![info exists oc]} {
+       if {$myself} {
+           append ol "\nI can't see $nshow on anywhere."
+       } else {
+           append ol "\nYou aren't on any channels with me."
+       }
+    } elseif {![info exists nu]} {
+       append ol "\n$nshow has not identified themselves."
+    } elseif {![info exists username]} {
+       append ol "\n$nshow has identified themselves as the user $nu."
+    } elseif {"$nu" != "$username"} {
+       append ol "\nHowever, $nshow is being used by the user $nu."
+    } else {
+       append ol "\n$nshow has identified themselves to me."
+    }
+    ucmdr {} $ol
+}
+
 def_ucmd register {
     prefix_nick
     check_notonchan
@@ -709,7 +770,7 @@ def_ucmd register {
            upvar #0 nick_username($n) nu
            if {![info exists nu]} {
                ucmdr {} \
- "You must identify yourself before using `register'.  See `help identify'."
+ "You must identify yourself before using `register'.  See `help identify', or use `register insecure'."
            }
            nickdb_set $n username $nu
            ucmdr {} {} "makes a note of your username." {}
index 896e6be69b6022d2f4d8098dceff2e87fc35d36c..1ae3a765001f583cf2a6735a3dfb80c8b1b2cba2 100644 (file)
--- a/helpinfos
+++ b/helpinfos
@@ -1,7 +1,7 @@
 !
 General commands:           Registration and user settings:
  help [<cmd>|<opt>|<topic>]  register [insecure|delete]
- seen <nick>                 set [<opt> [<value>]]
+ seen <nick>                 set [<opt> [<value>]]      who [<nick>]
  summon <username>           (See `help identify', `help blight-id')
  convert <number> <unit>    Channel settings:
  ops                         oplist [<chan>] [+|-|= [?]<nick> ...]
@@ -26,6 +26,13 @@ summon <username>
  you'll be told.  Target users can change this (eg, to disable it)
  by reconfiguring the userv service `irc-summon'.  See ~ian/.userv.
 
+!who
+who [<nick>]
+ Gives information about who I think the nick is (or who I think you
+ are), including whether the nick is registered, whether it is
+ associated with a username and if so who, and whether the current
+ user of the nick has identified themselves to me.
+
 !convert
 convert <number> <unit>
  Converts the specified quantity into SI units.  Units that are