/usr/share/sbnc/scripts/bind.tcl is in sbnc-tcl 1.3.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | # shroudBNC - an object-oriented framework for IRC
# Copyright (C) 2005-2014 Gunnar Beutner
# 2010 Sandro Hummel
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
internalbind modec sbnc:modechange
internalbind svrconnect sbnc:svrconnect
internalbind svrdisconnect sbnc:svrdisconnect
internalbind svrlogon sbnc:svrlogon
internalbind prerehash sbnc:prerehash
internalbind postrehash sbnc:postrehash
internalbind channelsort sbnc:channelsort
internalbind server sbnc:need-limit 471 *
internalbind server sbnc:need-invite 473 *
internalbind server sbnc:need-unban 474 *
internalbind server sbnc:need-key 475 *
internalbind server sbnc:need-op 482 *
if {![info exists ::channelsorthandler]} {
set ::channelsorthandler "stricmp"
}
proc sbnc:nickfromhost {host} {
return [lindex [split $host "!"] 0]
}
proc sbnc:sitefromhost {host} {
return [lindex [split $host "!"] 1]
}
proc sbnc:svrconnect {client} {
callevent "connect-server"
}
proc sbnc:svrdisconnect {client} {
callevent "disconnect-server"
}
proc sbnc:svrlogon {client} {
callevent "init-server"
}
proc sbnc:prerehash {} {
foreach user [bncuserlist] {
setctx $user
callevent "prerehash"
}
}
proc sbnc:postrehash {} {
foreach user [bncuserlist] {
setctx $user
callevent "postrehash"
}
}
proc sbnc:bindpulse {} {
foreach user [bncuserlist] {
setctx $user
foreach chan [channels] {
if {[botonchan $chan] && ![botisop $chan]} {
sbnc:callbinds "need" - $chan "$chan op" $chan "op"
}
}
set time [unixtime]
set minute [clock format $time -format "%M"]
set hour [clock format $time -format "%H"]
set day [clock format $time -format "%d"]
set month [clock format $time -format "%m"]
set year [clock format $time -format "%Y"]
sbnc:callbinds "time" - {} "$minute $hour $day $month $year" $minute $hour $day $month $year
}
}
proc sbnc:modechange {client parameters} {
set source [lindex $parameters 0]
set channel [lindex $parameters 1]
set mode [lindex $parameters 2]
set targ [lindex $parameters 3]
set hand [finduser $source]
set flags $hand
set nick [sbnc:nickfromhost $source]
set host [sbnc:sitefromhost $source]
if {![onchan $nick $channel]} {
set nick ""
set host $source
set hand "*"
set flags $hand
}
sbnc:callbinds "mode" $flags $channel "$channel $mode" $nick $host $hand $channel $mode $targ
}
proc sbnc:rawserver {client parameters} {
if {[llength [binds]] == 0} { return }
set source [lindex $parameters 0]
set nick [sbnc:nickfromhost $source]
set site [sbnc:sitefromhost $source]
set verb [string tolower [lindex $parameters 1]]
set targ [lindex $parameters 2]
set opt [lindex $parameters 3]
# todo: implement
set hand [finduser $source]
set flags $hand
if {[llength [split [lindex $parameters end]]] > 1} {
set last ":[lindex $parameters end]"
} else {
set last [lindex $parameters end]
}
sbnc:callbinds "raw" - "" $verb $source $verb "[join [lrange $parameters 2 end-1]] $last"
switch $verb {
"privmsg" {
if {[regexp "\001(\[^ \]+)(| (.*?))\001" $opt foo verb text]} {
sbnc:callbinds "ctcp" $flags $targ $verb $nick $site $hand $targ $verb $text
} else {
if {[validchan $targ] || [botonchan $targ]} {
sbnc:callbinds "pub" $flags $targ [lindex [split $opt] 0] $nick $site $hand $targ [join [lrange [split $opt] 1 end]]
sbnc:callbinds "pubm" $flags $targ "$targ $opt" $nick $site $hand $targ $opt
} else {
sbnc:callbinds "msg" $flags "" [lindex [split $opt] 0] $nick $site $hand [join [lrange [split $opt] 1 end]]
sbnc:callbinds "msgm" $flags "" $opt $nick $site $hand $opt
}
}
}
"notice" {
if {[regexp "\001(\[^ \]+)(| (.*?))\001" $opt foo verb text]} {
sbnc:callbinds "ctcr" $flags $targ $verb $nick $site $hand $targ $verb $text
} else {
sbnc:callbinds "notc" $flags $targ $opt $nick $site $hand $opt $targ
}
}
"join" {
sbnc:callbinds "join" $flags $targ "$targ $source" $nick $site $hand $targ
}
"part" {
sbnc:callbinds "part" $flags $targ "$targ $source" $nick $site $hand $targ $opt
}
"quit" {
if {![regexp {^\S+\.\S+ \S+\.\S+$} $targ]} {
foreach c [internalchannels] {
if {[onchan $nick $c]} {
sbnc:callbinds "sign" $flags $c "$c $source" $nick $site $hand $c $targ
}
}
}
}
"topic" {
sbnc:callbinds "topc" $flags $targ "$targ $opt" $nick $site $hand $targ $opt
}
"kick" {
sbnc:callbinds "kick" $flags $targ "$targ $opt" $nick $site $hand $targ $opt [lindex $parameters 4]
}
"nick" {
foreach c [internalchannels] {
if {[onchan $targ $c]} {
sbnc:callbinds "nick" $flags $c "$c $targ" $nick $site $hand $c $targ
}
}
}
"wallops" {
sbnc:callbinds "wall" - "" $targ $source [join [lrange $parameters 2 end]]
}
"471" {
sbnc:callbinds "need" - $opt "$opt limit" $opt "limit"
}
"473" {
sbnc:callbinds "need" - $opt "$opt invite" $opt "invite"
}
"474" {
sbnc:callbinds "need" - $opt "$opt unban" $opt "unban"
}
"475" {
sbnc:callbinds "need" - $opt "$opt key" $opt "key"
}
"477" {
sbnc:callbinds "need" - $opt "$opt register" $opt "register"
}
"invite" {
if {[lsearch -exact [string tolower [channels]] [string tolower $opt]] != -1} {
puthelp "JOIN $opt"
}
}
}
}
proc sbnc:callbinds {type flags chan mask args} {
namespace eval [getns] {
if {![info exists binds]} { set binds "" }
if {![info exists binds]} { set clastbind "" }
}
upvar [getns]::binds binds
upvar [getns]::clastbind clastbind
set allbinds $binds
set old [getctx]
setctx ":any"
namespace eval [getns] {
if {![info exists binds]} { set binds "" }
}
upvar [getns]::binds binds
setctx $old
foreach bind $binds {
lappend allbinds $bind
}
set count 0
foreach bind $allbinds {
set t [lindex $bind 0]
set f [lindex $bind 1]
set m [lindex $bind 2]
set u [lindex $bind 3]
set p [lindex $bind 4]
if {[string equal -nocase $t $type] && [string match -nocase $m $mask] && [matchattr $flags $f $chan]} {
set clastbind $m
set errcode [catch [list eval $p $args] error]
if {$errcode} {
bncnotc "Error in tcl bind $t $f $m called: $p ($args)"
foreach line [split $error \n] {
bncnotc $line
}
}
incr count
}
}
return $count
}
proc bind {type flags mask {procname ""}} {
set nonstackable [list msg dcc fil pub bot note]
set result [list]
namespace eval [getns] {
if {![info exists binds]} { set binds "" }
}
upvar [getns]::binds binds
foreach bind $binds {
if {$procname != ""} {
if {[lsearch -exact $nonstackable [string tolower $type]] != -1 && [string equal -nocase $mask [lindex $bind 2]]} {
unbind [lindex $bind 0] [lindex $bind 1] [lindex $bind 2] [lindex $bind 4]
}
if {[string equal -nocase $type [lindex $bind 0]] && [string equal -nocase $mask [lindex $bind 2]] && [string equal -nocase $procname [lindex $bind 4]]} {
unbind [lindex $bind 0] [lindex $bind 1] [lindex $bind 2] [lindex $bind 4]
}
} elseif {$procname == "" && [string equal -nocase $type [lindex $bind 0]] && [string equal -nocase $mask [lindex $bind 2]]} {
lappend result $bind
}
}
if {$procname == ""} {
return $result
}
unbind $type $flags $mask $procname
lappend binds [list $type $flags $mask 0 $procname]
internalbind server sbnc:rawserver * [getctx]
if {[string equal -nocase $type "need"] || [string equal -nocase $type "time"]} {
internaltimer 60 1 sbnc:bindpulse
}
return $mask
}
proc bindall {type flags mask {procname ""}} {
set old [getctx]
setctx ":any"
set result [bind $type $flags $mask $procname]
setctx $old
return $result
}
proc unbind {type flags mask procname} {
namespace eval [getns] {
if {![info exists binds]} { set binds "" }
}
upvar [getns]::binds binds
if {$procname == ""} {
set list ""
foreach bind $binds {
if {[lindex $bind 0]} {
lappend list $bind
}
}
return $list
}
set newbinds ""
foreach bind $binds {
set t [lindex $bind 0]
set f [lindex $bind 1]
set m [lindex $bind 2]
set u [lindex $bind 3]
set p [lindex $bind 4]
if {![string equal -nocase $t $type] || ![string equal -nocase $f $flags] || ![string equal -nocase $m $mask] || ![string equal -nocase $p $procname]} {
lappend newbinds $bind
}
}
set binds $newbinds
if {[llength $binds] == 0} {
internalunbind server sbnc:rawserver * [getctx]
}
return $mask
}
proc unbindall {type flags mask procname} {
set old [getctx]
setctx ":any"
set result [unbind $type $flags $mask $procname]
setctx $old
return $result
}
proc binds {{pattern ""}} {
namespace eval [getns] {
if {![info exists binds]} { set binds "" }
}
upvar [getns]::binds binds
if {$pattern == ""} {
return $binds
} else {
set out ""
foreach bind $binds {
set type [lindex $bind 0]
set mask [lindex $bind 2]
if {[string match -nocase $pattern $mask] || [string match -nocase $pattern $type]} {
lappend out $bind
}
}
return $out
}
}
proc bindsall {{pattern ""}} {
set old [getctx]
setctx ":any"
set result [binds $pattern]
setctx $old
return $result
}
proc callevent {event} {
sbnc:callbinds "evnt" - {} $event $event
}
proc sbnc:channelsort {client params} {
setchannelsortvalue [$::channelsorthandler [lindex $params 0] [lindex $params 1]]
}
proc setchannelsorthandler {handler} {
set ::channelsorthandler $handler
}
proc getchannelsorthandler {} {
return $::channelsorthandler
}
proc sbnc:need-op {client parameters} {
set chan [lindex $parameters 3]
if {[validchan $chan] && ![string equal [channel get $chan need-op] ""]} {
eval [channel get $chan need-op]
}
}
proc sbnc:need-key {client parameters} {
set chan [lindex $parameters 3]
if {[validchan $chan] && ![string equal [channel get $chan need-key] ""]} {
eval [channel get $chan need-key]
}
}
proc sbnc:need-unban {client parameters} {
set chan [lindex $parameters 3]
if {[validchan $chan] && ![string equal [channel get $chan need-unban] ""]} {
eval [channel get $chan need-unban]
}
}
proc sbnc:need-invite {client parameters} {
set chan [lindex $parameters 3]
if {[validchan $chan] && ![string equal [channel get $chan need-invite] ""]} {
eval [channel get $chan need-invite]
}
}
proc sbnc:need-limit {client parameters} {
set chan [lindex $parameters 3]
if {[validchan $chan] && ![string equal [channel get $chan need-limit] ""]} {
eval [channel get $chan need-limit]
}
}
|