chiark / gitweb /
Figured out what to do about tellme secure but register insecure. Implementing untel...
[ircbot] / bot.tcl
diff --git a/bot.tcl b/bot.tcl
index 29c000788ad2492e57cab2adb4febf8b336d9040..0fd2b75deb6513795f07d4546663c8746c9fda3e 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -235,7 +235,7 @@ FIXME - document the extra param to recordlastseen
     append evstate [string range $stt 0 0]
     append evstate [string range $event 0 0]
 
-    manyset [nickdb_get $n tellsec] sec secwhen
+    manyset [tell_effective_sec $n] sec secwhen
     switch -exact $sec {
        insecure { append evstate ii }
        secure { append evstate [expr {$ago<$secwhen ? "sl" : "ss"}] }
@@ -417,7 +417,7 @@ proc chanmode_o1 {m g p chan} {
        } else {
            set chan_initialop([irctolower $chan]) $u
            sendprivmsg $n \
- "Thanks. You can use `channel manager ...' to register this channel."
+ "Thanks.  You can use `channel manager ...' to register this channel."
            if {![nickdb_exists $n] || ![string length [nickdb_get $n username]]} {
                sendprivmsg $n \
  "(But to do that you must register your nick securely first.)"
@@ -767,7 +767,7 @@ def_somedb_id delete {} {
 set default_settings_nick {
     timeformat ks
     marktime off
-    tellsec insecure
+    tellsec {secure 600}
     tellrel {remind 3600 30}
 }
 
@@ -1182,14 +1182,57 @@ def_ucmd channel {
     channel/$subcmd
 }
 
+proc tell_effective_sec {n} {
+    set l [nickdb_get $n tellsec]
+    set u [nickdb_get $n username]
+    if {"[lindex $l 0]" == "secure" && ![string length $u]} { set l insecure }
+    return $l
+}
+
+proc tell_peernicks {
+-- FIXME HERE
+
+def_ucmd untell {
+    prefix_nick
+    check_notonchan
+    nick_securitycheck 0
+    set peernicks
+
 def_ucmd delmsg {
+    global errorInfo errorCode
     prefix_nick
     check_notonchan
-    manyset [nickdb_get $n tellsec] sec
+    manyset [tell_effective_sec $n] sec secwhen
     switch -exact $sec {
        insecure { }
-       refuse - mailto { error "you cannot 
-    if {"$sec" == "
+       refuse - mailto {
+           usererror \
+ "There are no messages to delete\
+ because your message disposition prevents them from being left."
+       }
+       secure {
+           nick_securitycheck 1
+       }
+       default {
+           error "delmsg sec $sec"
+       }
+    }
+    set text [irctolower [string trim $text]]
+    set senders [split $text " "]
+    foreach sender $senders {
+       if {[catch { check_nick $sender } emsg]} {
+           error "invalid sender nick `$sender': $emsg" $errorInfo $errorCode
+       }
+    }
+    tell_delete_msgs [irctolower $senders] [irctolower $n]
+    switch -exact [llength $senders] {
+       0 { ucmdr {} {} "deletes your message(s)." }
+       1 { ucmdr {} {} "deletes your message(s) from $senders." }
+       default {
+           ucmdr {} {} "deletes your message(s) from\
+ [lreplace $senders end end] and [lindex $senders end]."
+       }
+    }
 }
 
 def_ucmd tell {
@@ -1204,7 +1247,7 @@ def_ucmd tell {
     set ctarget $target
     if {[info exists nick_case($ltarget)]} { set ctarget $nick_case($ltarget) }
 
-    manyset [nickdb_get $target tellsec] sec mailtoint mailwhy
+    manyset [tell_effective_sec $target] sec mailtoint mailwhy
     manyset [nickdb_get $target tellrel] rel relint relwithin
     switch -exact $sec {
        insecure - secure {
@@ -1374,15 +1417,22 @@ proc def_setting {opt show_body set_body} {
         $set_body"
 }
 
-proc tellme_sec_desc {v} {
+proc tellme_sec_desc {v n} {
     manyset $v sec mailtoint
     switch -exact $sec {
        insecure {
            return "I'll tell you your messages whenever I see you."
        }
        secure {
-           return \
+           if {[string length [nickdb_get $n username]]} {
+               return \
  "I'll keep the bodies of your messages private until you identify yourself, reminding you every [showintervalsecs $mailtoint 1]."
+           } else {
+               return \
+ "I'll tell you your messages whenever I see you.\
+  (Secure message delivery is enabled, but your nick is not registered\
+ securely.  See `help register'.)"
+           }
        }
        refuse {
            return "I shan't accept messages for you."
@@ -1466,13 +1516,7 @@ def_setting security {
     }
 } {}
 
-proc tellme_setting_needsecure {n ue} {
-    set u [nickdb_get $n username]
-    if {[string length $u]} { usererror $ue }
-    return $u
-}
-
-proc telling_setting_sec_simple {} {
+proc tellme_setting_sec_simple {} {
     uplevel 1 {
        ta_nomore
        set sr sec
@@ -1480,16 +1524,17 @@ proc telling_setting_sec_simple {} {
     }
 }
 
-proc telling_setting_neednomsgs {} {
+proc tellme_setting_neednomsgs {} {
     uplevel 1 {
        if {[llength [msgsdb_get $n inbound]]} {
            usererror "You must delete the messages you have, first."
        }
     }
+}
 
 def_setting tellme {
     set secv [nickdb_get $n tellsec]
-    set ms [tellme_sec_desc $secv]
+    set ms [tellme_sec_desc $secv $n]
     manyset $secv sec
     switch -exact $sec {
        insecure - secure {
@@ -1504,22 +1549,26 @@ def_setting tellme {
     set setting [string tolower [ta_word]]
     switch -exact $setting {
        insecure {
-           telling_setting_sec_simple
+           tellme_setting_sec_simple
        }
        secure {
-           telling_setting_sec_simple
+           set every [ta_interval_optional 60 600]
+           ta_nomore
+           set sr sec
+           set v [list secure $every]
        }
        refuse {
            telling_setting_neednomsgs
            telling_setting_sec_simple
        }
        mailto {
-FIXME - working here, check needsecure for secure
-FIXME - what if user makes themselves insecure or deletes themselves while they have msgs ?
            telling_setting_neednomsgs
-           set u [tellme_setting_needsecure $n \
- "Sorry, you must register secure to have your messages mailed\
- (to prevent the use of this feature for spamming)."]
+            set u [nickdb_get $n username]
+           if {[string length $u]} {
+               usererror \
+ "Sorry, you must register securely to have your messages mailed\
+ (to prevent the use of this feature for spamming).  See `help register'."
+           }
            set sr sec
            set v [list mailto [ta_word] $u]
        }
@@ -1527,21 +1576,19 @@ FIXME - what if user makes themselves insecure or deletes themselves while they
            manyset [nickdb_get $n tellsec] sec
            switch -exact $sec {
                refuse - mailto {
-                   error "can't change message delivery conditions when message disposition prevents messages from being left"
+                   usererror \
+ "You can't change your message delivery conditions when\
+ your message disposition prevents messages from being left."
                }
            }
            set sr rel
            set v $setting
            if {"$setting" != "unreliable"} {
-               set every [parse_interval [ta_word] 300]
+               set every [parse_interval_optional 300 3600]
                lappend v $every
            }
            if {"$setting" == "remind"} {
-               if {[ta_anymore]} {
-                   set within [parse_interval [ta_word] 5]
-               } else {
-                   set within 30
-               }
+               set within [ta_interval_optional 5 30]
                if {$within > $every} {
                    error "remind interval must be at least time to respond"
                }