chiark / gitweb /
Settings setting seems to work.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 6 Sep 2000 00:11:46 +0000 (00:11 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 6 Sep 2000 00:11:46 +0000 (00:11 +0000)
bot.tcl

diff --git a/bot.tcl b/bot.tcl
index 967b095dbf8575b15b70f3c5a2a71f23d61736ee..b52e1395e812018c7ba748034d0db6089fb7369c 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -481,6 +481,11 @@ proc msg_366 {p c args} {
     unset names_chans
 }
 
+proc ta_anymore {} {
+    upvar 1 text text
+    return [expr {!![string length $text]}]
+}
+
 proc ta_nomore {} {
     upvar 1 text text
     if {[string length $text]} { error "too many parameters" }
@@ -678,14 +683,84 @@ def_ucmd register {
            }
        }
     }
-}          
+}
+
+proc timeformat_desc {tf} {
+    switch -exact $tf {
+       ks { return "Times will be displayed in kiloseconds or seconds." }
+       hms { return "Times will be displayed in hours, minutes, etc." }
+       default { error "invalid timeformat: $v" }
+    }
+}
+
+proc def_setting {opt show_body set_body} {
+    proc set_show/$opt {} "
+        upvar 1 n n
+        set opt $opt
+        $show_body"
+    if {![string length $set_body]} return
+    proc set_set/$opt {} "
+        upvar 1 n n
+        upvar 1 text text
+        set opt $opt
+        $set_body"
+}
+
+def_setting timeformat {
+    set tf [nickdb_opt $n timeformat]
+    return "$tf: [timeformat_desc $tf]"
+} {
+    set tf [string tolower [ta_word]]
+    ta_nomore
+    set desc [timeformat_desc $tf]
+    nickdb_set $n timeformat $tf
+    ucmdr {} $desc
+}
+
+def_setting security {
+    set s [nickdb_opt $n username]
+    if {[string length $s]} {
+       return "Your nick, $n, is controlled by the user $s."
+    } else {
+       return "Your nick, $n, is not secure."
+    }
+} {}
+
+def_ucmd set {
+    prefix_nick
+    check_notonchan
+    if {![nickdb_exists $n]} {
+       ucmdr {} "You are unknown to me and so have no settings."
+    }
+    if {![ta_anymore]} {
+       set ol {}
+       foreach proc [lsort [info procs]] {
+           if {![regexp {^set_show/(.*)$} $proc dummy opt]} continue
+           lappend ol [format "%-10s %s" $opt [set_show/$opt]]
+       }
+       ucmdr {} [join $ol "\n"]
+    } else {
+       set opt [ta_word]
+       if {[catch { info body set_show/$opt }]} {
+           error "no setting $opt"
+       }
+       if {![ta_anymore]} {
+           ucmdr {} "$opt [set_show/$opt]"
+       } else {
+           if {[catch { info body set_set/$opt }]} {
+               error "setting $opt cannot be set with `set'"
+           }
+           set_set/$opt
+       }
+    }
+}
 
 def_ucmd identpass {
     set username [ta_word]
     set passmd5 [md5sum [ta_word]]
     ta_nomore
     prefix_nick
-    check_isprivmsg
+    check_notonchan
     upvar #0 nick_onchans($n) onchans
     if {![info exists onchans] || ![llength $onchans]} {
        ucmdr "You must be on a channel with me to identify yourself." {}