#--------------------------------------------------------------------- # dalnetneedunban.tcl # TCL script for IRC bot eggdrop # # Example script requesting unban from Chanserv on DALnet when # the bot is banned. # # Once the bot gets banned (and kicked) from a channel, this # script will first request the banlist of the channels and then # find the ban that matches the bot. Then it will request the # matching ban(s) to be removed by Chanserv. # Note: channel must have +chanserv setting # (.chanset #channel +chanserv). # # v0: 05-Sep-2002 # v1: 08-Oct-2003 #--------------------------------------------------------------------- package require eggdrop 1.6.9 package require Tcl 8.0 #--------------------------------------------------------------------- # Bindings #--------------------------------------------------------------------- bind need - * dalnetneedunban bind RAW - 367 dalnetneedunban:raw367 bind RAW - 368 dalnetneedunban:raw368 setudef flag chanserv #--------------------------------------------------------------------- # Upon a need for unban, send a request for the list of bans # to the server. # Note that DALnet's chanserv allows a direct UNBAN command. # For demonstration purposes only, this script issues a request for # the banlist and requests an unban for each of the hostmasks # matching the bots nick!user@host. #--------------------------------------------------------------------- proc dalnetneedunban { channel type } { if { $type != "unban" } { return } putlog "Need unban: requesting list of bans for $channel" putserv "MODE $channel -b" } #--------------------------------------------------------------------- # Handle raw 367 RPL_BANLIST # RFC 1459: # DALNET: #--------------------------------------------------------------------- proc dalnetneedunban:raw367 { server keyword text } { global botname putlog "Received RAW 367: $server, $keyword, $text" set scancount [scan $text "%s %s %s %s %s" nick channel banhost\ banner bantime] # minimum nick, channel and banhost needed if { $scancount < 3 } { return 0 } # channel must valid, active and bot must be *off* chan if {![dalnetneedunban:channel $channel]} { return 0 } # only react on matching hosts if {![string match $banhost $botname]} { return 0 } # channel needs +chanserv setting set chaninfo [channel info $channel] if {[lsearch -exact $chaninfo +chanserv] != -1} { set chanserv chanserv@services.dal.net putlog "Need unban: attempting to UNBAN $banhost on $channel" putserv "PRIVMSG $chanserv :UNBAN $channel $banhost" } if { $scancount != 5 } { return 0 } # Action/punishment on $banner (i.e. the nick!user@host that # placed the ban on the bot) is possible. # For example: add the $banner to a handle having a the +d flag. # Or put a ban on the $banner. Etc. etc. } #--------------------------------------------------------------------- # Handle raw 368 RPL_ENDOFBANLIST # RFC 1459: " :End of channel ban list" #--------------------------------------------------------------------- proc dalnetneedunban:raw368 { server keyword text } { if {[scan $text "%s %s" nick channel] != 2 } { return 0 } if {![dalnetneedunban:channel $channel]} { return 0 } putlog "Need unban: attempting to JOIN $channel" putserv "JOIN $channel" } #--------------------------------------------------------------------- # Proc dalnetneedunban:channel checks if the channel is valid, # -inactive and the bot is not on the channel. #--------------------------------------------------------------------- proc dalnetneedunban:channel { channel } { if {![validchan $channel]} { return 0 } set chaninfo [channel info $channel] if {[lsearch -exact $chaninfo +inactive] != -1} { return 0 } if {[botonchan $channel]} { return 0 } return 1 } putlog "Loaded (version 1): Dalnet needunban."