1 # Battle.net server bridge thingy
3 set helpfile bridgehelp
4 set bnbot_callervars
{nicks
}
11 proc privmsg_unlogged
{p ischan params
} {
12 global bots errorCode errorInfo line_org_endchar
16 set text [lindex $params 1]
17 if {"$line_org_endchar" == "\001"} {
18 if {[regexp {^
\?ACTION
(.
*)\?$} $text dummy
text]} {
19 set towrite
"* $n $text"
24 set towrite
"\[$n] [lindex $params 1]"
27 upvar #0 bot/$botid/chan ch
31 log
"error: $emsg $errorCode $errorInfo"
36 execute_usercommand
$p PRIVMSG
$n $n \
37 [lindex $params 0] [lindex $params 1]
47 proc bnnick_clean
{n
} {
48 if {[regexp {^
[-+_0-9a-zA-Z
]} $n]} { return $n }
53 global channel errorCode
54 if {[regexp {^
1002 JOIN
([^
]+) \w
+} $l dummy n
]} {
56 sendprivmsg
$channel "[bnnick_clean $n] has joined $bnchanfn."
57 } elseif
{[regexp {^
1003 LEAVE
([^
]+) \w
+$} $l dummy n
]} {
58 if {"$n" == "$bnnick"} return
59 catch { unset bnnicks
($n) }
60 sendprivmsg
$channel "[bnnick_clean $n] has left $bnchanfn."
61 } elseif
{[regexp {^
1004 WHISPER
([^
]+) \w
+ "(.*)"$} $l dummy n
text]} {
63 go_usercommand
"$botid $n" $bnchanfn $n $n $text
65 if {"$errorCode" != "BLIGHT USER"} { set rv
"error: $rv" }
66 bnbot_write
$botid "/msg $n $rv"
69 foreach mt
$rv { lappend rvl
[split $mt "\n"] }
70 manyset
$rvl priv_msgs pub_msgs priv_acts pub_acts
71 foreach m
$priv_acts { bnbot_write
$botid "/msg $n The bot $m" }
72 foreach m
$pub_acts { bnbot_write
$botid "/me $m" }
73 foreach m
$priv_msgs { bnbot_write
$botid "/msg $n $m" }
74 foreach m
$pub_msgs { bnbot_writemsg
$botid "$n $m" }
76 } elseif
{[regexp {^
1001 USER
([^
]+) \w
+} $l dummy n
]} {
77 if {"$n" == "$bnnick"} return
84 proc msg_353
{p c dest type chan nicklist
} {
85 global onchan_nicks channel nick
86 catch { unset onchan_nicks
}
88 regsub {^
[@+]} $n {} n
89 if {"$n" == "$nick"} continue
90 set onchan_nicks
($n) 1
96 foreach botid
$bots { bnbot_writemsg
$botid $msg }
99 proc msg_JOIN
{p c chan
} {
102 tellall
"$n has joined $chan."
103 set onchan_nicks
($n) 1
106 proc msg_NICK
{p c newnick
} {
110 set onchan_nicks
($newnick) 1
111 tellall
"$n has changed nicks to $newnick."
114 proc kill_nick
{n
} { global onchan_nicks
; catch { unset onchan_nicks
($n) } }
116 proc msg_KICK
{p c chans users comment
} {
117 foreach n
[split $users ,] {
118 tellall
"$user was kicked off $chans ($comment)"
122 proc msg_KILL
{p c user why
} {
123 tellall
"$user was killed ($why)"
126 proc msg_PART
{p c chan
} {
128 tellall
"$n has left $chan."
131 proc msg_QUIT
{p c why
} {
133 tellall
"$n has signed off ($why)"
137 proc who_res
{thing l
} {
139 return "$thing: [lsort -dictionary $l]"
141 return "$thing - empty."
145 def_bnbot who
{} { who_res
$bnchanfn [array names bnnicks
] }
148 global bots channel onchan_nicks
150 set o
[who_res
"$channel (IRC)" [array names onchan_nicks
]]
151 foreach botid
$bots { append o
"\n" [bnbot_who
$botid] }
158 foreach botid
$bots { bnbot_ensure_connecting
$botid }
160 fail
"startup: $emsg"