# # Unbanner - Automatically unban yourself from a channel # ----------------------------------------------- # # 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ----------------------------------------------- # # Author: Simone Economo (aka eKoeS) (http://www.lineheight.net) # Email: my.ekoes@gmail.com # # http://www.gnu.org/licenses/gpl.html # __module_name__ = "Unbanner" __module_version__ = "0.1" __module_description__ = "Automatically unban yourself from a channel" import xchat from threading import Thread class Task(Thread): def __init__(self): Thread.__init__(self) self.activeChannel = None def run(self, mode, args): def Unban(): channel, mask = args[0], args[1] for user in xchat.get_list("users"): if user.nick == xchat.get_info("nick") \ and (user.prefix == "@" \ or user.prefix == "%" \ or user.prefix == "+"): return Class["Parser"].Mask(mask, user.host, user.nick) \ and xchat.command("cs unban %s me" % channel) \ or None def Join(): channel, usernick = args[0], args[1] if channel.lower()[1:] == self.activeChannel and usernick == xchat.get_info("nick"): xchat.command("join %s" % channel) return def Invite(): channel, usernick = args[0], args[1] #if usernick == xchat.get_info("nick"): #for user in xchat.get_list("users"): #if user.nick == xchat.get_info("nick") \ #and (user.prefix == "@" \ #or user.prefix == "%" \ #or user.prefix == "+"): #xchat.command("cs invite %s" % channel) #break #xchat.command("join %s" % channel) #return xchat.command("cs invite %s" % channel) self.activeChannel = channel.lower() return def Opme(): channel, usernick = args[0], args[1] if usernick == xchat.get_info("nick"): for user in xchat.get_list("users"): if user.nick == xchat.get_info("nick") \ and (user.prefix == "@" \ or user.prefix == "%" \ or user.prefix == "+"): xchat.command("cs op %s %s " % (channel, usernick)) return xchat.EAT_ALL eval("%s()" % mode) or None return class Parser: def Invite(self, word, word_eol, userdata): aliases = { "channel": word[3], "user": word[2] } Class["Task"].run("Join", (aliases["channel"], aliases["user"])) return xchat.EAT_NONE def Modes(self, word, word_eol, userdata): aliases = { "channel": word[2], "mode" : word[3], #"mask" : word[4], "user" : word[0].split("!")[0][1:] } # Well, so let me parse modes.. if aliases["mode"] == "+b" or aliases["mode"].startswith("+b"): aliases["mask"] = word[4] Class["Task"].run("Unban", (aliases["channel"], aliases["mask"])) elif aliases["mode"] == "-o": self.Deop(word, word_eol, userdata) else: if aliases["mode"] == "-o+b": aliases["mask"], aliases["user"] = word[5], word[4] elif aliases["mode"] == "+b-o": aliases["mask"], aliases["user"] = word[4], word[5] else: return Class["Task"].run("Opme", (aliases["channel"], aliases["user"])) Class["Task"].run("Unban", (aliases["channel"], aliases["mask"])) return xchat.EAT_NONE def Kick(self, word, word_eol, userdata): aliases = { "channel": word[2], "user" : word[3], "kicker" : word[0].split("!")[0][1:], "reason" : word_eol[4] } if aliases["user"] == xchat.get_info("nick"): xchat.emit_print("You Kicked", aliases["user"], aliases["channel"], \ aliases["kicker"], aliases["reason"]) Class["Task"].run("Invite", (aliases["channel"], aliases["user"])) # This prevents creation of a new ugly tab :/ return xchat.EAT_XCHAT else: return def Deop(self, word, word_eol, userdata): aliases = { "channel": word[2], "user" : word[4], } Class["Task"].run("Opme", (aliases["channel"], aliases["user"])) return xchat.EAT_NONE def Mask(self, banmask, usermask, usernick): try: user = usermask.split("@")[0] domain = usermask.split("@")[1] #host = domain.replace(domain.split(".")[0],"") host = domain.split(".", 1)[1] if (host in banmask) or (domain in banmask) or (user in banmask) or (usernick in banmask): return True except IndexError: pass return False Class = { "Task" : Task(), "Parser": Parser() } xchat.hook_server("MODE", Class["Parser"].Modes) xchat.hook_server("KICK", Class["Parser"].Kick) xchat.hook_server("INVITE", Class["Parser"].Invite) print "%s version %s loaded correctly." % (__module_name__, __module_version__) print """ 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. """