7 set sock
[socket $host $port]
8 fconfigure $sock -buffering line
9 #fconfigure $sock -translation binary
10 fconfigure $sock -translation crlf
12 proc sendout
{prefix command args
} {
13 if {[llength $args]} {
14 set la
[lindex $args end
]
15 set args
[lreplace $args end end
]
17 if {[regexp {[: ]} $i]} {
18 error "bad argument in output $i ($prefix $command $args)"
23 set args
[lreplace $args 0 -1 $command]
24 if {[string length
$prefix]} {
25 set args
[lreplace $args
30 puts $sock "USER guest 0 * :chiark testing bot"
31 puts $sock "NICK $nick"
37 proc logerror
{data
} {
42 global sock saveei saveec errorInfo errorCode
45 regsub -all "\\[^ -\176\240-\376\\]" $line ? line
47 if {[regexp -nocase {^
:([^
]+) (.
*)} $line dummy prefix remain
]} {
52 if {![regexp -nocase {^
([0-9a-z
]+) *(.
*)} $line dummy command line
]} {
53 log
"bad command: $org"
56 set command
[string toupper command
]
58 while {[regexp {([^
:]+) *(.
*)} $line dummy thisword line
]} {
59 lappend params
$thisword
61 if {[regexp {^
:(.
*)} $line dummy thisword
]} {
62 lappend params
$thisword
63 } elseif
{[string length
$line]} {
64 log
"junk at end: $org"
67 set procname msg_
$command
69 eval [list $procname $prefix $command] $params
71 logerror
"error: $emsg ($prefix $command $params)"
72 if {![regexp {^invalid command name
} $emsg]} {
81 if {[string length
$p]} { error "prefix specified" }
83 proc msg_PING
{p s1
} {
88 fileevent $sock readable onread