chiark / gitweb /
handle eof on stdin
[ircbot.git] / irccore.tcl
index 069743e54f046cfc938e192f803909289151ef82..545446cac3e464c1dd99a4c26d5ca64dc59983e3 100644 (file)
@@ -5,6 +5,7 @@ proc defset {varname val} {
 
 # must set host
 defset port 6667
+defset socketargs {}
 
 defset nick testbot
 defset ident blight
@@ -180,7 +181,7 @@ proc onread {args} {
        set line $remain
        if {[regexp {^([^!]+)!} $prefix dummy maybenick]} {
            set calling_nick $maybenick
-           if {"[irctolower $maybenick]" == "[irctolower $nick]"} return
+           if {![ircnick_compare $maybenick $nick]} return
        }
     } else {
        set prefix {}
@@ -201,7 +202,7 @@ proc onread {args} {
        log "junk at end: $org"
        return
     }
-    if {"$command" == "PRIVMSG" && \
+    if {![string compare $command "PRIVMSG"] && \
         [privmsg_unlogged $prefix [ischan [lindex $params 0]] $params]} {
        return
     }
@@ -247,6 +248,13 @@ proc check_nick {n} {
     if {[string length $n] > 18} { error "nick too long" }
 }
 
+proc check_chan {n} {
+    if {![regsub {^\#} $n {} n]} { error "bad chan start" }
+    if {[regexp -nocase {[^][\\`_^{|}a-z0-9-]} $n]} { error "bad char in chan" }
+    if {[regexp {^[-0-9]} $n]} { error "bad chan name start" }
+    if {[string length $n] > 18} { error "chan name too long" }
+}
+
 proc ischan {dest} {
     return [regexp {^[&#+!]} $dest]
 }
@@ -261,6 +269,10 @@ proc irctolower {v} {
     return [string tolower $v]
 }
 
+proc ircnick_compare {a b} {
+    return [string compare [irctolower $a] [irctolower $b]]
+}
+
 proc prefix_none {} {
     upvar 1 p p
     if {[string length $p]} { error "prefix specified" }
@@ -272,7 +284,7 @@ proc prefix_nick {} {
     upvar 1 n n
     if {![regexp {^([^!]+)!} $p dummy n]} { error "not from nick" }
     check_nick $n
-    if {"[irctolower $n]" == "[irctolower $nick]"} {
+    if {![ircnick_compare $n $nick]} {
        error "from myself" {} {}
     }
 }