Add people to the relevant chan_nicks when they join. New leave channel manager...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Jan 2001 17:40:52 +0000 (17:40 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Jan 2001 17:40:52 +0000 (17:40 +0000)
bot.tcl
helpinfos

diff --git a/bot.tcl b/bot.tcl
index ad5c908..5bbaeb0 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -200,7 +200,7 @@ proc onread {args} {
     }
     if {"$command" == "PRIVMSG" &&
         [regexp {^[&#+!]} [lindex $params 0]] &&
-        ![regexp {^!} [lindex $params 1]]} {
+        ![regexp {^![a-z][-a-z]*[a-z]( .*)?$} [lindex $params 1]]} {
        # on-channel message, ignore
        catch {
            recordlastseen_p $prefix "talking on [lindex $params 0]" 1
@@ -512,6 +512,11 @@ proc leaving {lchan} {
     unset nlist
 }
 
+proc doleave {lchan} {
+    sendout PART $lchan
+    leaving $lchan
+}
+
 proc dojoin {lchan} {
     global chan_nicks
     sendout JOIN $lchan
@@ -533,8 +538,7 @@ proc check_justme {lchan} {
            sendout TOPIC $lchan $topic
        }
     } else {
-       sendout PART $lchan
-       leaving $lchan
+       doleave $lchan
     }
 }
 
@@ -646,8 +650,12 @@ proc nick_ishere {n} {
 proc msg_JOIN {p c chan} {
     prefix_nick
     recordlastseen_n $n "joining $chan" 1
-    upvar #0 nick_onchans([irctolower $n]) oc
-    lappend oc [irctolower $chan]
+    set nl [irctolower $n]
+    set lchan [irctolower $chan]
+    upvar #0 nick_onchans($nl) oc
+    upvar #0 chan_nicks($lchan) nlist
+    lappend oc $lchan
+    lappend nlist $nl
     nick_ishere $n
 }
 proc msg_PART {p c chan} {
@@ -824,20 +832,28 @@ proc loadhelp {} {
 }
 
 def_ucmd help {
+    upvar 1 n n
+
+    set topic [irctolower [string trim $text]]
+    if {[string length $topic]} {
+       set ontopic " on `$topic'"
+    } else {
+       set ontopic ""
+    }
     if {[set lag [out_lagged]]} {
        if {[ischan $dest]} { set replyto $dest } else { set replyto $n }
        if {$lag > 1} {
            sendaction_priority 1 $replyto \
-               "is very lagged.  Please ask for help again later."
+               "is very lagged.  Please ask for help$ontopic again later."
            ucmdr {} {}
        } else {
            sendaction_priority 1 $replyto \
-               "is lagged.  Your help will arrive shortly ..."
+               "is lagged.  Your help$ontopic will arrive shortly ..."
        }
     }
     
-    upvar #0 help_topics([irctolower [string trim $text]]) info
-    if {![info exists info]} { ucmdr "No help on $text, sorry." {} }
+    upvar #0 help_topics($topic) info
+    if {![info exists info]} { ucmdr "No help on $topic, sorry." {} }
     ucmdr $info {}
 }
 
@@ -1143,19 +1159,40 @@ def_chancmd show {
     }
 }
 
-def_ucmd op {
+proc channelmgr_monoop {} {
+    upvar 1 dest dest
+    upvar 1 text text
+    upvar 1 n n
+    upvar 1 p p
+    upvar 1 target target
+    global chan_nicks
+
     if {[ischan $dest]} { set target $dest }
     if {[ta_anymore]} { set target [ta_word] }
     ta_nomore
-    if {![info exists target]} { error "you must specify, or !... on, the channel" }
+    if {![info exists target]} {
+       error "you must specify, or invoke me on, the relevant channel"
+    }
+    if {![info exists chan_nicks([irctolower $target])]} {
+       error "I am not on $target."
+    }
     if {![ischan $target]} { error "not a valid channel" }
     if {![chandb_exists $target]} { error "$target is not a managed channel." }
     prefix_nick
     nick_securitycheck 1
     channel_securitycheck $target $n
+}
+
+def_ucmd op {
+    channelmgr_monoop
     sendout MODE $target +o $n
 }
 
+def_ucmd leave {
+    channelmgr_monoop
+    doleave $target
+}
+
 def_ucmd invite {
     global chan_nicks
     
index 4a55aa4..e801bd3 100644 (file)
--- a/helpinfos
+++ b/helpinfos
@@ -12,6 +12,7 @@ General commands:           Registration and user settings:
  !summon <username>           (See `help !identify', `help !blight-id')
  !invite [<chan>] <nick>...  Channel settings (see `help channel'):
  !op [<chan>]                 !channel [<chan>] <setting> [....]
+ !leave [<chan>]
 Options:                    Additional help topics:
  !timeformat ks|hms           !identify !identpass !invite !blight-id
 Send commands to me by /msg, or say them in channel with \! in front.
@@ -54,6 +55,12 @@ op <channel>       (privately)
  I'll give you channel operator privilege, if you're a manager.
  See `help !manager'.
 
+:leave
+leave [<channel>]     on channel
+leave <channel>       (privately)
+ I'll leave the channel, if you're a manager.  For an unmanaged
+ channel, I'll leave when I'm the last one on the channel.
+
 :channel
 channel [<chan>] [show]                       show settings
 channel [<chan>] !manager +|-|= <nick> ...     set manager list