7 proc sendout {command args} {
10 set la [lindex $args end]
11 set args [lreplace $args end end]
13 if {[regexp {[: ]} $i]} {
14 error "bad argument in output $i ($command $args)"
19 set args [lreplace $args 0 -1 $command]
20 set string [join $args { }]
29 proc logerror {data} {
34 global saveei saveec errorInfo errorCode
39 puts ">$saveec|$saveei<"
51 if {[gets $sock line] == -1} { set terminate 1; return }
52 regsub -all "\[^ -\176\240-\376\]" $line ? line
54 if {[regexp -nocase {^:([^ ]+) (.*)} $line dummy prefix remain]} {
59 if {![string length $line]} { return }
60 if {![regexp -nocase {^([0-9a-z]+) *(.*)} $line dummy command line]} {
61 log "bad command: $org"
64 set command [string toupper $command]
66 while {[regexp {^([^ :]+) *(.*)} $line dummy thisword line]} {
67 lappend params $thisword
69 if {[regexp {^:(.*)} $line dummy thisword]} {
70 lappend params $thisword
71 } elseif {[string length $line]} {
72 log "junk at end: $org"
75 if {"$command" == "PRIVMSG" &&
76 [regexp {^[&#+!]} [lindex $params 0]] &&
77 ![regexp {^!} [lindex $params 1]]} {
78 # on-channel message, ignore
82 set procname msg_$command
83 if {[catch { info body $procname }]} { return }
85 eval [list $procname $prefix $command] $params
87 logerror "error: $emsg ($prefix $command $params)"
94 if {[string length $p]} { error "prefix specified" }
97 proc msg_PING {p c s1} {
102 proc check_nick {n} {
103 if {[regexp -nocase {[^][\\`_^{|}a-z0-9-]} $n]} { error "bad char in nick" }
104 if {[regexp {^[-0-9]} $n]} { error "bad nick start" }
107 proc prefix_nick {} {
111 if {![regexp {^([^!]+)!} $p dummy n]} { error "not from nick" }
113 if {"[string tolower $n]" == "$nick"} { error "from myself" }
116 proc msg_PRIVMSG {p c dest text} {
118 if {[regexp {^[&#+!]} $dest]} {
122 set what "private messages"
126 "I will respond to $what at some point; for now I just log $them."
129 if {![info exists sock]} {
130 set sock [socket $host $port]
131 fconfigure $sock -buffering line
132 #fconfigure $sock -translation binary
133 fconfigure $sock -translation crlf
135 sendout USER guest 0 * ":chiark testing bot"
137 fileevent $sock readable onread
140 if {![regexp {tclsh} $argv0]} {