chiark / gitweb /
Set socketargs to {}.
[ircbot] / bot.tcl
diff --git a/bot.tcl b/bot.tcl
index 0b12a54d1dcf2049be684f4f00f0dda95407a55a..ad5c908b336f6954fb997381a4c44dbea4f8a3c5 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -90,7 +90,7 @@ proc out_runqueue {now} {
        set out_queue [lrange $out_queue 1 end]
        if {[llength $out_queue]} {
            append orgwhen "+[expr {$now - $orgwhen}]"
-           append orgwhen ([llength $out_queue])"
+           append orgwhen "([llength $out_queue])"
        }
        puts "$orgwhen -> $msg"
        puts $sock $msg
@@ -415,11 +415,7 @@ proc recordlastseen_n {n how here} {
 }
 
 proc note_topic {showoff whoby topic} {
-    if {[string length $whoby]} {
-       set msg "FYI, $whoby has changed the topic on $showoff"
-    } else {
-       set msg "FYI, I have reset the topic on $showoff"
-    }
+    set msg "FYI, $whoby has changed the topic on $showoff"
     if {[string length $topic] < 160} {
        append msg " to $topic"
     } else {
@@ -432,10 +428,8 @@ proc note_topic {showoff whoby topic} {
     } else {
        set tryspies $tell
     }
-puts "NT>showoff $showoff|whoby $whoby|topic $topic|tell $tell|tryspies $tryspies|msg $msg<"
     foreach spy $tryspies {
        set see [chandb_get $spy topicsee]
-puts "NT>spy $spy|see $see<"
        if {[lsearch -exact $see $showoff] >= 0 || \
                ([lsearch -exact $see *] >= 0 && \
                [lsearch -exact $tell $spy] >= 0)} {
@@ -528,7 +522,7 @@ proc check_justme {lchan} {
     global nick
     upvar #0 chan_nicks($lchan) nlist
     if {[llength $nlist] != 1} return
-    if {"[lindex $nlist 0]" != "$nick"} return
+    if {"[lindex $nlist 0]" != "[irctolower $nick]"} return
     if {[chandb_exists $lchan]} {
        set mode [chandb_get $lchan mode]
        if {"$mode" != "*"} {
@@ -537,7 +531,6 @@ proc check_justme {lchan} {
        set topic [chandb_get $lchan topicset]
        if {[string length $topic]} {
            sendout TOPIC $lchan $topic
-           note_topic $lchan {} $topic
        }
     } else {
        sendout PART $lchan
@@ -626,15 +619,15 @@ proc msg_NICK {p c newnick} {
     prefix_nick
     recordlastseen_n $n "changing nicks to $newnick" 0
     recordlastseen_n $newnick "changing nicks from $n" 1
+    set luser [irctolower $n]
+    set lusernew [irctolower $newnick]
     foreach ary $nick_arys {
-       upvar #0 nick_${ary}($n) old
-       upvar #0 nick_${ary}($newnick) new
+       upvar #0 nick_${ary}($luser) old
+       upvar #0 nick_${ary}($lusernew) new
        if {[info exists new]} { error "nick collision ?! $ary $n $newnick" }
        if {[info exists old]} { set new $old; unset old }
     }
-    upvar #0 nick_onchans($new)
-    set luser [irctolower $n]
-    set lusernew [irctolower $newnick]
+    upvar #0 nick_onchans($lusernew) oc
     foreach ch $oc {
        upvar #0 chan_nicks($ch) nlist
        set nlist [grep tn {"$tn" != "$luser"} $nlist]
@@ -1052,8 +1045,8 @@ def_chancmd autojoin {
        default { error "channel autojoin must be `yes' or `no' }
     }
     chandb_set $chan autojoin $nv
-    ucmdr [expr {$nv ? "I will join #chan when I'm restarted " : \
-           "I won't join #chan when I'm restarted "}] {}
+    ucmdr [expr {$nv ? "I will join $chan when I'm restarted " : \
+           "I won't join $chan when I'm restarted "}] {}
 }
 
 def_chancmd userinvite {
@@ -1085,7 +1078,7 @@ def_chancmd topic {
                error "you must specific the topic to set"
            }
            chandb_set $chan topicset $t
-           ucmdr "Whenever I'm alone on #chan, I'll set the topic to $t." {}
+           ucmdr "Whenever I'm alone on $chan, I'll set the topic to $t." {}
        }
        see - tell {
            ta_listop {
@@ -1127,13 +1120,7 @@ def_chancmd show {
        append l ", mode " [chandb_get $chan mode]
        append l ", userinvite " [chandb_get $chan userinvite] "."
        append l "\nManagers: "
-       append l [join [chandb_get $chan managers] " "] "\n"
-       set t [chandb_get $chan topicset]
-       if {[string length $t]} {
-           append l "Topic to set: $t"
-       } else {
-           append l "I will not change the topic."
-       }
+       append l [join [chandb_get $chan managers] " "]
        foreach {ts sep} {see "\n" tell "  "} {
            set t [chandb_get $chan topic$ts]
            append l $sep
@@ -1143,6 +1130,13 @@ def_chancmd show {
                append l "Topic $ts list is empty."
            }
        }
+       append l "\n"
+       set t [chandb_get $chan topicset]
+       if {[string length $t]} {
+           append l "Topic to set: $t"
+       } else {
+           append l "I will not change the topic."
+       }
        ucmdr {} $l
     } else {
        ucmdr {} "The channel $chan is not managed."
@@ -1511,11 +1505,11 @@ proc fail {msg} {
 }
 
 proc ensure_connecting {} {
-    global sock ownfullname host port nick
+    global sock ownfullname host port nick socketargs
     global musthaveping_ms musthaveping_after
     
     if {[info exists sock]} return
-    set sock [socket $host $port]
+    set sock [eval socket $socketargs [list $host $port]]
     fconfigure $sock -buffering line
     fconfigure $sock -translation crlf