From 05242e59870f0274831f2abb3ffb17c3ed5a3478 Mon Sep 17 00:00:00 2001 From: auscompgeek <david.vo2@gmail.com> Date: Wed, 17 Apr 2013 13:22:24 +1000 Subject: [PATCH] fix PEP8 W291 and W293 (trailing whitespace) Signed-off-by: Gryllida A <Gryllida@GMAIL.com> --- extra/example.py | 54 +++++++++--------- extra/games.py | 10 ++-- extra/rss.py | 6 +- extra/wikinews.py | 8 +-- guppy | 36 ++++++------ irc.py | 124 ++++++++++++++++++++--------------------- plugins/__init__.py | 28 +++++----- plugins/admintools.py | 12 ++-- plugins/auth.py | 68 +++++++++++----------- plugins/blockbot.py | 28 +++++----- plugins/ctcp.py | 6 +- plugins/ddg.py | 6 +- plugins/dns.py | 6 +- plugins/dynacode.py | 14 ++--- plugins/google.py | 10 ++-- plugins/help.py | 8 +-- plugins/isitup.py | 8 +-- plugins/karma.py | 34 +++++------ plugins/ping.py | 6 +- plugins/plugintools.py | 14 ++--- plugins/printer.py | 26 ++++----- plugins/rpn.py | 6 +- plugins/rss.py | 6 +- plugins/sed.py | 4 +- plugins/smack.py | 10 ++-- plugins/tinyurl.py | 8 +-- plugins/wikipedia.py | 12 ++-- plugins/yt.py | 6 +- 28 files changed, 282 insertions(+), 282 deletions(-) diff --git a/extra/example.py b/extra/example.py index 4c656c9..41dbe7a 100644 --- a/extra/example.py +++ b/extra/example.py @@ -1,4 +1,4 @@ -""" +""" We need the decorator, otherwise the bot doesn't see it's a plugin """ @@ -8,25 +8,25 @@ class Printer(object): """ Replace this comment with a help line for the plugin """ def __init__(self, server): """ - server is an instance of class IRC, + server is an instance of class IRC, you'll use it to do anything with the server, for example sending a message """ self.server = server - + """ You must use this to provide any helpful output, it automatically adds the [host] prefix for you """ self.prnt = server.prnt - + """ This is the array of commands that this plugin will handle. It doesn't need to be defined, it is passed as an argument to self.server.handle("command", function, ["command1", "command2"]) """ self.commands = [ "ping" ] - + """ this is just so that we don't have to hard-code every event (self.server.handlers has every type of event handle-able) @@ -39,80 +39,80 @@ class Printer(object): self.server.handle(h, func, self.commands) else: self.server.handle(h, func) - + """ any of the following functions will only be called if you set them up using server.handle(....) keep in mind, these function names are for example, you can use any names you'd like. - + Also, all arguments named "user" is actually a subclass of str, so that used normally, it provides the nickname, but you can also use the member fields user.ident and user.host """ - + def handle_command(self, channel, user, cmd, args): - """ + """ Called when we get a command It will be called when we are addressed, as well, - thus allowing "Guppy: <command>" without the + thus allowing "Guppy: <command>" without the comchar prefix. """ #in case we are handling a lot of commands if cmd == "ping": #send a response self.server.doMessage(channel, user[0]+": Pong") - + def handle_connect(self, server): """ Called when we connect to the server """ self.prnt("I have connected to %s" % server) - + def handle_disconnect(self, server): """ Called when we disconnect from the server """ self.prnt("I have disconnected from %s" % server) - + def handle_message(self, channel, user, message): """ Called when a message is received """ self.prnt("<%s> %s: %s" % (channel, user[0], message)) - + def handle_action(self, channel, user, action): """ Called when we see someone doing an action """ self.prnt("<%s> * %s %s" % (channel, user[0], action)) - + def handle_join(self, channel, user): """ Called when we see someone join a channel we're in """ self.prnt("%s has joined %s" % (user[0], channel)) - + def handle_part(self, channel, user, message): - """ - Called when someone parts a channel we're in + """ + Called when someone parts a channel we're in param message will be "" if there was no part message """ self.prnt("%s has left %s (%s)" % (user[0], channel, message)) - + def handle_quit(self, user, message): - """ - Called when someone quits IRC + """ + Called when someone quits IRC param message will be "" if there was no quit message """ self.prnt("%s has quit (%s)" % (user[0], message)) - + def handle_nick(self, oldnick, newnick): """ Called when someone changes their nick """ self.prnt("%s is now known as %s" % (oldnick, newnick)) - + def handle_kick(self, channel, user, userkicked, message): """ Called when someone is kicked from a channel we're in """ self.prnt("%s has kicked %s from %s (%s)" % (user, userkicked, channel, message)) - + def handle_notice(self, user, dest, message): """ Called when a notice is received """ self.prnt("(%s) -%s- %s" % (dest, user, message)) - + def handle_mode(self, channel, user, mode, otheruser): - """ + """ Called when someone sets a mode - param otheruser will be "" if the mode was set + param otheruser will be "" if the mode was set onto the channel, otherwise it will be the nickname of the user who had the mode set upon them """ diff --git a/extra/games.py b/extra/games.py index 0a32b3d..c35b51a 100644 --- a/extra/games.py +++ b/extra/games.py @@ -7,12 +7,12 @@ # 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, @@ -23,13 +23,13 @@ import random UNODECK = ['b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'g0', 'g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7', 'g8', 'g9', 'g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7', 'g8', 'g9', 'y0', 'y1', 'y2', 'y3', 'y4', 'y5', 'y6', 'y7', 'y8', 'y9', 'y1', 'y2', 'y3', 'y4', 'y5', 'y6', 'y7', 'y8', 'y9', 'r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'rS', 'gS', 'bS', 'yS', 'rD2', 'gD2', 'bD2', 'yD2', 'rR', 'gR', 'bR', 'yR', 'wW', 'wW', 'wW', 'wW', 'wWD4', 'wWD4', 'wWD4', 'wWD4', 'rS', 'gS', 'bS', 'yS', 'rD2', 'gD2', 'bD2', 'yD2', 'rR', 'gR', 'bR', 'yR'] #commented out the decorator, as the plugin is not yet made -#@plugin +#@plugin class Uno(object): def __init__(self, server): self.server = server self.commands = [] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): pass - + diff --git a/extra/rss.py b/extra/rss.py index 64b2b5b..1bdd125 100644 --- a/extra/rss.py +++ b/extra/rss.py @@ -70,7 +70,7 @@ class Rss(object): if len(cursor.fetchall()) == 0: cursor.execute('''INSERT INTO rss VALUES(?,?,?,?)''', ('', self.network, channel, url)) connection.commit() - self.server.doMessage(channel, "Done. RSS item %s added to %s.", (url, channel)) + self.server.doMessage(channel, "Done. RSS item %s added to %s.", (url, channel)) else: self.server.doMessage(channel, "Error: RSS item %s already exists at %s" % (url, channel)) elif (cmd == 'rss-list'): @@ -106,7 +106,7 @@ class Rss(object): for child in children: feed_id = child.find('guid').text if (feed_id == last_known_id): return - elif (bool_updated == 0): + elif (bool_updated == 0): # update the db connection = sqlite3.connect(self.db) cursor = connection.cursor() @@ -123,7 +123,7 @@ class Rss(object): msg += "["+child.find('category').text+"]" + " " msg += title self.server.doMessage(row[2], msg) - # print("%s [%s] %s" % (str(url), str(cat), str(title))) + # print("%s [%s] %s" % (str(url), str(cat), str(title))) def checkFeeds(self): connection = sqlite3.connect(self.db) cursor = connection.cursor() diff --git a/extra/wikinews.py b/extra/wikinews.py index d89c029..bea1d18 100644 --- a/extra/wikinews.py +++ b/extra/wikinews.py @@ -7,12 +7,12 @@ # 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, @@ -51,7 +51,7 @@ class wikinews(object): timeWaited += 10 def loop2(plugin,server): timeWaited = 0 - while self.loop: + while self.loop: if timeWaited >= self.timeCheckNewEntries: self.checkNewEntries() timeWaited = 0 @@ -63,7 +63,7 @@ class wikinews(object): if timeWaited >= self.timeCheckPublished: self.checkPublished() timeWaited = 0 - time.sleep(10) + time.sleep(10) timeWaited += 10 self.t1 = threading.Thread(target=loop, args=(self,server,)) self.t2 = threading.Thread(target=loop2, args=(self,server,)) diff --git a/guppy b/guppy index a9b4779..222c425 100755 --- a/guppy +++ b/guppy @@ -8,12 +8,12 @@ # 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, @@ -64,20 +64,20 @@ optional arguments: if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]: print(helptext) exit() - + if "-v" in sys.argv[1:] or "--version" in sys.argv[1:]: exit() - + if "-c" in sys.argv[1:] or "--makeconf" in sys.argv[1:]: self.makeconf() - if os.path.isfile(self.configpath) == False: + if os.path.isfile(self.configpath) == False: print("No configuration file found, running makeconf") self.makeconf() self.config = configparser.RawConfigParser() self.config.read(self.configpath) - + def start(self): self.clients = [] for section in self.config.sections(): @@ -87,7 +87,7 @@ optional arguments: server_config["confdir"] = self.directory for item,value in self.config.items(section): server_config[item] = value - + print("%s [%s] Connecting..." % (time.strftime("%Y-%m-%d %H:%M:%S"),server_config["network"])) self.clients.append(irc.IRC(server_config)) while(1): @@ -95,26 +95,26 @@ optional arguments: asyncore.loop() except: time.sleep(5) - + def stop(self): for client in self.clients: client.doQuit("Keyboard interrupt.") client.pluginManager.unloadAllPlugins() - + def my_raw(self,prompt="", default=""): ret = eval("'"+input("%s [%s]: "%(prompt,default))+"'") return default if ret == "" else ret - + def set(self,section,option,text,default=""): try: if default == "": default = self.config.get(section,option) except configparser.NoOptionError: pass - + value = self.my_raw(text,default) self.config.set(section,option,value) - + def makeconf(self): self.config = configparser.RawConfigParser() getting_servers = True @@ -126,11 +126,11 @@ optional arguments: overwrite = self.my_raw("Server already exists! Overwrite? (yes/no)", "no").lower() while overwrite != "yes" and overwrite != "y" and overwrite != "no" and overwrite != "n": overwrite = self.my_raw("Invalid option. Overwrite configuration for "+currentNetwork+"? (yes/no)", "no").lower() - + if overwrite.lower() == "no" or overwrite.lower() == "n": continue #go back to top of "while getting_servers:" #else continue out of try/except - + self.set(currentNetwork,'host',"What is the IRC network address (eg. irc.example.org)?") self.set(currentNetwork,'channels',"What channels to automatically join (comma-separated, no spaces)?") self.set(currentNetwork,'nickname',"What nickname should I use?") @@ -147,19 +147,19 @@ optional arguments: list2 = [item.replace(".py","") for item in list1 if not '__' in item] print("Available plugins are: "+" ".join(list2)) self.set(currentNetwork,"plugins","What plugins will I load on startup (comma-separated, no spaces)?", "auth,printer,pluginloader,ping_server") - + another_server = self.my_raw("All done with "+currentNetwork+". Add another server? (yes/no)", "no").lower() while another_server != "yes" and another_server != "y" and another_server != "no" and another_server != "n": another_server = self.my_raw("Invalid option. Do you want to add another server? (yes/no)", "no").lower() - + if another_server == "no" or another_server == "n": break #else no action needed - + self.writeconfig() print('Configuration file has been created.') exit() - + def writeconfig(self): configfile = open(self.configpath, 'w') self.config.write(configfile) diff --git a/irc.py b/irc.py index 303e048..5ec4b16 100644 --- a/irc.py +++ b/irc.py @@ -7,12 +7,12 @@ # 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, @@ -39,7 +39,7 @@ class PluginManager(object): self.server = server self.plugins = {} self.prnt = server.prnt - self.handlers = { + self.handlers = { "join" : [ ], "part" : [ ], "quit" : [ ], @@ -52,7 +52,7 @@ class PluginManager(object): "mode" : [ ], "command" : { }, } - + def handle(self, event, handler_func, handler_commands=None): event = event.lower() if event == "command": @@ -62,9 +62,9 @@ class PluginManager(object): else: if self.handlers.get(event, None) is None: self.handlers[event] = [] - + self.handlers[event].append(handler_func) - + def unhandle(self, event, handler_func, handler_commands=None): event = event.lower() if event == "command": @@ -72,59 +72,59 @@ class PluginManager(object): for command, handler in self.handlers[event]: if handler != handler_func and not command.lower() in handler_commands: handlers.insert(0, handler) - + self.handlers[event] = handlers else: handlers = [] for handler in self.handlers[event]: if handler != handler_func: handlers.insert(0, handler) - + self.handlers[event] = handlers - + def event(self, eventName, *args): eventName = eventName.lower() if self.handlers.get(eventName, None) is None: return - + if eventName == "command": handler = self.handlers[eventName].get(args[2].lower(), None) if handler is None: return #no such command - + handler(*args) else: for handler in self.handlers[eventName]: handler(*args) - + def loadedPlugin(self, pluginName): return pluginName.lower() in self.plugins - + def pluginExists(self, pluginName): return plugins.getPlugin(pluginName.lower()) is not None - + def loadPlugin(self, pluginName): plugins.refresh() if not self.loadedPlugin(pluginName.lower()): if not self.pluginExists(pluginName.lower()): self.prnt("No such plugin " + pluginName) return - + pClass = plugins.getPlugin(pluginName.lower()) - + self.plugins[pluginName.lower()] = pClass(self.server) - - def getPlugin(self, pluginName): + + def getPlugin(self, pluginName): try: return self.plugins[pluginName.lower()] except KeyError: return None - + def reloadPlugin(self, pluginName): self.unloadPlugin(pluginName.lower()) self.loadPlugin(pluginName.lower()) - + def unloadPlugin(self, pluginName): - if self.loadedPlugin(pluginName.lower()): + if self.loadedPlugin(pluginName.lower()): # the plugin is loaded inst = self.plugins[pluginName.lower()] # the plugin object del self.plugins[pluginName.lower()] # delete plugins object from self.plugins @@ -139,7 +139,7 @@ class PluginManager(object): destructors.append(destructor) else: newList[cmd] = func - + self.handlers[event] = newList for f in destructors: f() @@ -153,7 +153,7 @@ class PluginManager(object): destructors.append(destructor) else: newList.append(func) - + self.handlers[event] = newList for f in destructors: f() @@ -163,7 +163,7 @@ class PluginManager(object): for plugin in plugins: self.server.prnt("Loading "+plugin) self.loadPlugin(plugin.lower()) - + def unloadAllPlugins(self): for plugin in list(self.plugins.copy().keys()): self.unloadPlugin(plugin.lower()) @@ -182,7 +182,7 @@ class IRC(asynchat.async_chat): self.plugins = self.pluginManager.plugins self.getPlugin = self.pluginManager.getPlugin errs = self.pluginManager.loadAllPlugins() - + self.userlist = { } self.data = b"" self.set_terminator(b"\r\n") @@ -205,13 +205,13 @@ class IRC(asynchat.async_chat): return except socket.error as error: self.prnt('There was an error connecting to %s. %s' % (self.config["host"], error)) - return + return def _getData(self): ret = self.data self.data = b"" return ret - + def found_terminator(self): data = self._getData().decode("utf-8") self.pluginManager.event("data", self.config["network"], data) @@ -220,8 +220,8 @@ class IRC(asynchat.async_chat): # The server pinged us, we need to pong or we'll be disconnected # (make sure to send whatever follows the PING, in case they send a random hash) self.sendLine("PONG " + data[5:]) - return - + return + # Takes the ':Nick!Ident@Host' chunk and assigns (nick,ident,host) to user user = None if words[0].find("!") != -1: @@ -231,39 +231,39 @@ class IRC(asynchat.async_chat): else: #it's our nick, in the format ":NickName" user = User(words[0][words[0].find(":") + 1:]) - + if words[1] == "433": #There was a nick collision self.config["nickname"] = self.config["nickname"] + "_" self.sendLine("NICK "+self.config["nickname"]) - + elif words[1] == "422" or words[1] == "376": # We successfully logged in, do post-login procedures if self.config["ns_name"] != "" and self.config["ns_pwd"] != "": self.doMessage("NickServ", "IDENTIFY "+self.config["ns_name"]+" "+self.config["ns_pwd"]) - + self.pluginManager.event("connect", self.config["network"]) - + for chan in [k for k in self.config["channels"].split(",") if k != '']: self.doJoin(chan) - + elif words[1] == "353": #user list, if it's large, we only got part of it. words = [k for k in str(data).replace(" =", " ").replace(" @", " ").replace(" +", " ").replace(" %", " ").replace(" &", " ").replace(" @", " ").replace(" ~", " ").split(" ") if k != ''] if self.userlist.get(words[3], None) is None: self.userlist[words[3]] = [] - + self.userlist[words[3]] += [u.strip(":") for u in words[3:]] - + elif words[1] == "PRIVMSG": # We got a message channel = (words[2] if words[2] != self.config["nickname"] else user) - + # Checks to see if message is a PM or not isPrivate = False if words[2] == self.config["nickname"]: isPrivate = True - + message = data[data.find(":", data.find(channel[(channel.find("-") == -1 and 1 or channel.find("-")):]))+1:] if message.find("\x01ACTION") == 0: # String was found, it's an action @@ -293,35 +293,35 @@ class IRC(asynchat.async_chat): else: #Nothing was found, it has to be a message self.pluginManager.event("message", channel, user, message) - + elif words[1] == "JOIN": # Someone joined a channel that we're in if user != self.config["nickname"]: self.pluginManager.event("join", words[2].strip(":"), user) self.userlist[words[2].strip(":")].append(user) - + elif words[1] == "PART": if user != self.config["nickname"]: # Someone parted a channel we're in if user in self.userlist[words[2].strip(":")]: self.userlist[words[2]].remove(user) self.pluginManager.event("part", words[2].strip(":"), user, " ".join(words[3:])) - + elif words[1] == "QUIT": # Someone quit the server for k in list(self.userlist.keys()): if user in self.userlist[k]: self.userlist[k].remove(user) - self.pluginManager.event("quit", user, " ".join(words[2:])[1:]) - + self.pluginManager.event("quit", user, " ".join(words[2:])[1:]) + elif words[1] == "NICK": - # Someone changed their nickname + # Someone changed their nickname for k in list(self.userlist.keys()): if user in self.userlist[k]: self.userlist[k].remove(user) self.userlist[k].append(words[2].strip(":")) self.pluginManager.event("nick", user, words[2].strip(":")) - + elif words[1] == "MODE": if user != self.config["nickname"]: # Someone set a mode @@ -329,64 +329,64 @@ class IRC(asynchat.async_chat): self.pluginManager.event("mode", words[2], user, words[3], words[4]) except IndexError: # words[4] is not valid, it wasn't set on a user self.pluginManager.event("mode", words[2], user, words[3], "") - + elif words[1] == "KICK": #someone kicked someone if self.userlist.get(words[2].lower(), None) is not None: self.userlist[words[2].lower()].remove(words[3]) - + self.pluginManager.event("kick", words[2], user, words[3], words[4][1:]) - + elif words[1] == "NOTICE": self.pluginManager.event("notice", user, words[2], " ".join(words[3:]).strip(":")) - + else: self.pluginManager.event(words[1], data) - + def collect_incoming_data(self, data): self.data += data - + def handle_connect(self): self.config["ident"] = ident = self.config["ident"] if self.config["ident"] != "" else self.config["nickname"] # pass, nick, user - http://tools.ietf.org/html/rfc1459#section-4.1 if self.config["srpass"] != "": self.sendLine("PASS "+self.config["srpass"]) self.sendLine("NICK "+self.config["nickname"]) self.sendLine("USER "+ident+" * * *") - + def handle_disconnect(self): self.pluginManager.event("disconnect", self.config["network"]) - + def prnt(self, line): print(time.strftime("%Y-%m-%d %H:%M:%S") + (" ["+self.config["network"]+"] "+line)) - + def sendLine(self, line): #print("'"+line+"'") if line.endswith("\r\n"): self.push(bytes(line, "utf_8")) else: self.push(bytes(line + "\r\n", "utf_8")) - + def doMessage(self, channel, message): self.sendLine("PRIVMSG "+channel+" :"+message) self.pluginManager.event("message", channel, User(self.config["nickname"]), message) - + def doAction(self, channel, action): self.sendLine("PRIVMSG "+channel+" :\x01ACTION "+action+" \x01") self.pluginManager.event("action", channel, User(self.config["nickname"]), action) - + def doQuit(self, message=""): self.sendLine("QUIT :" + message) self.pluginManager.event("quit", User(self.config["nickname"]), message) self.close_when_done() - + def doNotice(self, user, message): self.sendLine("NOTICE "+user+" :"+message) - + def doNick(self, newnick): self.sendLine("NICK " + newnick) self.pluginManager.event("nick", User(self.config["nickname"]), User(newnick)) self.config["nickname"] = newnick - + def doJoin(self, channel): self.sendLine("JOIN "+channel) self.pluginManager.event("join", channel, User(self.config["nickname"])) @@ -394,13 +394,13 @@ class IRC(asynchat.async_chat): def doKick(self, channel, user, message=""): self.sendLine("KICK %s %s :%s" % (channel, user, message)) self.pluginManager.event("kick", channel, User(self.config["nickname"]), user, message) - + def doPart(self, channel, message=""): self.sendLine("PART "+channel) if channel in list(self.userlist.keys()): del self.userlist[channel] self.pluginManager.event("part", channel, User(self.config["nickname"]), message) - + def doMode(self, channel, mode, user=""): self.sendLine("MODE "+channel+" "+mode+" "+user) self.pluginManager.event("mode", channel, User(self.config["nickname"]), mode, user) diff --git a/plugins/__init__.py b/plugins/__init__.py index eb6230e..a8cfc9e 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -14,35 +14,35 @@ class NoSuchPluginError(Exception): pass def plugin(cls): #Using inspect, figure out what file is calling this function (using @plugin) clsFile = inspect.stack()[1][1] - + #Split the path, because it will be in the form "plugins" + os.sep + "*.py" modFile = clsFile.split(os.sep)[1] - + #Append the class name to the list indexed by module file name mList[modFile].append(cls.__name__.lower()) - + #Set class (plugin) name to the class (plugin) reference pList[cls.__name__.lower()] = cls - + #return cls, since decorators must return the "new" type return cls def refresh(pluginName = None): """ Refreshes the list of module/class pairs, and plugin/class pairs. - + If pluginName is not None, it can raise NoSuchPluginError. Regardless of the value of pluginName, it can raise any error a python file can raise, samme as using import. """ - + #if we are asked to do a general refresh of list if pluginName is None: #we were asked to refresh, so clear out our lists so we can start fresh pList.clear() mList.clear() - + #load every module in the plugins package - + current_dir = os.path.abspath(os.path.dirname(__file__)) _files = [] for f in os.listdir(current_dir): @@ -64,7 +64,7 @@ def refresh(pluginName = None): for f in _files: #Set "plugin" in the environment so that @plugin decorators work correctly env = {"plugin":plugin} - + #Execute the file. The file will automatically update the list of plugins, due to the @plugin decorator exec(compile(open(f).read(), f, 'exec'), env, env) else: @@ -74,9 +74,9 @@ def refresh(pluginName = None): if not found: refresh() found = __reload(pluginName) - + #if it's still not found, raise an error. - if not found: + if not found: raise NoSuchPluginError() @@ -87,13 +87,13 @@ def __reload(pluginName): if pluginName in classes: #Set "plugin" in the environment so that @plugin decorators work correctly env = {"plugin":plugin} - + #Execute the file. The file will automatically update the list of plugins, due to the @plugin decorator exec(compile(open(f).read(), f, 'exec'), env, env) - + #return True, indicating we have found and reloaded the module. return True - + #Else, we have not found it, so return False. return False diff --git a/plugins/admintools.py b/plugins/admintools.py index 79bd274..07a0955 100644 --- a/plugins/admintools.py +++ b/plugins/admintools.py @@ -7,12 +7,12 @@ # 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, @@ -26,7 +26,7 @@ class AdminTools(object): self.server.pluginManager.loadPlugin("auth") self.commands = [ "nick", "join", "part", "kick", "ban", "mute", "unban", "unmute", "op", "deop", "voice", "devoice", "unop", "unvoice","attrs" ] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if self.server.getPlugin("auth").isAdmin(user): if cmd == "op": @@ -50,11 +50,11 @@ class AdminTools(object): else: self.server.doMode(channel, "-v", args[0]) else: - + if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + if cmd == "join": self.server.doJoin(args[0]) elif cmd == "part": @@ -73,7 +73,7 @@ class AdminTools(object): self.server.doMode(channel, "-q", args[0]) elif cmd == "kick": self.server.doKick(channel, args[0], "Kicked!") - + if self.server.getPlugin("auth").isOwner(user): if cmd == "die": self.server.doMessage(channel, user + " wants me to leave, but I'll be back!") diff --git a/plugins/auth.py b/plugins/auth.py index 971f5bf..7aa03d1 100644 --- a/plugins/auth.py +++ b/plugins/auth.py @@ -7,12 +7,12 @@ # 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, @@ -35,13 +35,13 @@ class Auth(object): self.server.handle("nick", self.handle_nick) self.authfile = self.server.config["confdir"] + "auth.cfg" self._loadusers() - + def _checkAuth(self, user): stillOn = False for ch in list(self.server.userlist.keys()): if user in self.server.userlist[ch]: stillOn = True - + if not stillOn: if user.lower() in list(self.owners.keys()): self.owners[user.lower()][1] = False @@ -49,13 +49,13 @@ class Auth(object): self.admins[user.lower()][1] = False elif user.lower() in list(self.mods.keys()): self.mods[user.lower()][1] = False - + def handle_quit(self, user, message): self._checkAuth(user) - + def handle_part(self, channel, user, message): self._checkAuth(user) - + def handle_nick(self, oldnick, newnick): if self.isOwner(oldnick): self.owners[newnick.lower()] = self.owners[oldnick.lower()] @@ -66,7 +66,7 @@ class Auth(object): elif self.isMod(oldnick): self.mods[newnick.lower()] = self.mods[oldnick.lower()] del self.mods[oldnick.lower()] - + def handle_command(self, channel, user, cmd, args): if cmd == "owners": self.server.doMessage(channel, user+": My owners are: "+" ".join(self.owners)) @@ -81,40 +81,40 @@ class Auth(object): if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + if len(args) >= 2: self.owners[user.lower()][0] = args[1] self.server.doMessage(channel, user+": Password successfully changed.") else: self.owners[user.lower()][0] = args[0] self.server.doMessage(channel, user+": Password successfully changed.") - + elif user.lower() in list(self.admins.keys()): if self.admins[user.lower()][1]: if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + if len(args) >= 2: self.admins[user.lower()][0] = args[1] self.server.doMessage(channel, user+": Password successfully changed.") else: self.admins[user.lower()][0] = args[0] self.server.doMessage(channel, user+": Password successfully changed.") - + elif user.lower() in list(self.mods.keys()): if self.mods[user.lower()][1]: if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + if len(args) >= 2: self.mods[user.lower()][0] = args[1] self.server.doMessage(channel, user+": Password successfully changed.") else: self.mods[user.lower()][0] = args[0] self.server.doMessage(channel, user+": Password successfully changed.") - + else: self.server.doMessage(channel, user+": You are not in the owners/admins/mods lists.") return @@ -153,12 +153,12 @@ class Auth(object): else: self.server.doMessage(channel, user+": Please do that using private messaging.") return - + elif self.isOwner(user): if len(args) < 1: self.server.doMessage(channel, user+": What nick?") return - + if cmd == "addowner": if args[0].lower() in list(self.owners.keys()): return self.owners[args[0].lower()] = ['', True] @@ -177,33 +177,33 @@ class Auth(object): elif cmd == "delmod": if args[0].lower() in list(self.mods.keys()): del self.mods[args[0].lower()] - + #save users def destroy(self): self.configParser = configparser.RawConfigParser() - + if os.path.isfile(self.authfile): self.configParser.read(self.authfile) - + fh = open(self.authfile, "w") network = self.server.config["network"] if not self.configParser.has_section(network): self.configParser.add_section(network) - + self.configParser.set(self.server.config["network"],"owners",",".join( [k+":"+v[0] for k,v in list(self.owners.items())] )) self.configParser.set(self.server.config["network"],"admins",",".join( [k+":"+v[0] for k,v in list(self.admins.items())] )) self.configParser.set(self.server.config["network"],"mods",",".join( [k+":"+v[0] for k,v in list(self.mods.items())] )) - + self.configParser.write(fh) fh.close() - + def _loadusers(self): network = self.server.config["network"] - + if os.path.isfile(self.authfile): self.configParser = configparser.RawConfigParser() self.configParser.read(self.authfile) - + if self.configParser.has_section(network): if self.configParser.has_option(network, "owners"): olist = self.configParser.get(network, "owners").lower().split(",") @@ -211,39 +211,39 @@ class Auth(object): for user in olist: nick, pw = user.split(":") self.owners[nick] = [pw, pw == ''] - + if self.configParser.has_option(network, "admins"): alist = self.configParser.get(network, "admins").lower().split(",") alist = [a for a in alist if a != ''] for user in alist: nick, pw = user.split(":") self.admins[nick] = [pw, pw == ''] - + if self.configParser.has_option(network, "mods"): mlist = self.configParser.get(network, "mods").lower().split(",") mlist = [m for m in mlist if m != ''] for user in mlist: nick, pw = user.split(":") self.mods[nick] = [pw, pw == ''] - + else: onick = self.server.config["owner_nick"].lower() self.owners[onick] = ['', True] - + def isOwner(self, user): return user.lower() in self.owners and self.owners[user.lower()][1] - + def isAdmin(self, user): - if user.lower() in self.admins and self.admins[user.lower()][1]: + if user.lower() in self.admins and self.admins[user.lower()][1]: return True else: return self.isOwner(user) - + def isMod(self, user): - if user.lower() in self.mods and self.mods[user.lower()][1]: + if user.lower() in self.mods and self.mods[user.lower()][1]: return True - elif self.isAdmin(user): + elif self.isAdmin(user): return True else: return self.isOwner(user) - + diff --git a/plugins/blockbot.py b/plugins/blockbot.py index 526baab..36972ad 100644 --- a/plugins/blockbot.py +++ b/plugins/blockbot.py @@ -7,12 +7,12 @@ # 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, @@ -20,7 +20,7 @@ import re import time - + @plugin class Blockbot(object): """Automated channel flood/spam protection.""" @@ -28,7 +28,7 @@ class Blockbot(object): self.server = server self.commands = [] server.handle("message", self.handle_message) - + findlist = [ 'you will be unable to connect to freenode unless you are using sasl' ] @@ -36,17 +36,17 @@ class Blockbot(object): self.storage_time = 25 self.repeat_limit = 3 self.repeat_1word = 4 - - # Compile Spam Strings + + # Compile Spam Strings self.findlist = [] if findlist: for each in findlist: self.findlist.append(re.compile(each)) - + # Load Default Data self.msglist = [] #self.lastnot = ('BBot', time.time(), 'sdkljfls') - + def handle_message(self, channel, nick, message): # if the user is an owner, do nothing if self.server.getPlugin('auth').isOwner(nick): @@ -55,25 +55,25 @@ class Blockbot(object): """ Called when a message is received """ self.msglist.insert(0, (nick, channel, message, time.time())) - + # Check for spam strings ldata = message.lower() for each in self.findlist: if re.search(each, ldata): self.server.doKick(channel, nick, 'spam') return - + # Extract messages by this user user_msgs = [] for msg in self.msglist: if msg[0] == nick: user_msgs.append((nick, msg[1], msg[2], msg[3])) - + # Check for flooding if self.get_mps(user_msgs) > self.mps_limit: self.server.doKick(channel, nick,'flood') self.msglist.pop(0) - + # Check for repeats strings = [] repeats = 0 @@ -85,13 +85,13 @@ class Blockbot(object): if repeats > self.repeat_limit-1: self.server.doKick(channel, nick, 'flood/repetition') self.msglist.pop(0) - + # Clear out old messages now = time.time() for msg in self.msglist: if now - msg[3] > self.storage_time: self.msglist.remove(msg) - + def get_mps(self, user_msgs): '''Count the number of messages sent per second''' time_range = user_msgs[0][3] - user_msgs[-1][3] diff --git a/plugins/ctcp.py b/plugins/ctcp.py index e093ecc..fde9263 100644 --- a/plugins/ctcp.py +++ b/plugins/ctcp.py @@ -7,12 +7,12 @@ # 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, @@ -32,7 +32,7 @@ class ctcp(object): self.server = server self.commands = [] self.server.handle("message", self.handle_message) - + def handle_message(self, channel, nick, message): if message.find("\001") == -1: return message_array = message.replace("\001","",2).strip().lower().split() diff --git a/plugins/ddg.py b/plugins/ddg.py index 6b582d2..b019113 100644 --- a/plugins/ddg.py +++ b/plugins/ddg.py @@ -7,12 +7,12 @@ # 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, @@ -33,7 +33,7 @@ class ddg(object): self.server = server self.commands = ["ddg"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if len(args) < 1: self.server.doMessage(channel, user+": DuckDuckGo.com Zero-Click infoboxes search. Syntax: ddg <query>.") diff --git a/plugins/dns.py b/plugins/dns.py index e1db03b..67550a0 100644 --- a/plugins/dns.py +++ b/plugins/dns.py @@ -7,12 +7,12 @@ # 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, @@ -31,7 +31,7 @@ class dns(object): self.server = server self.commands = ["dns"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "dns": if len(args) < 1: diff --git a/plugins/dynacode.py b/plugins/dynacode.py index 01f77eb..4b5db21 100644 --- a/plugins/dynacode.py +++ b/plugins/dynacode.py @@ -7,12 +7,12 @@ # 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, @@ -28,13 +28,13 @@ class DynaCode(object): self.commands = [ "py" ] self.ownerOnly = 1 self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if self.server.getPlugin("auth").isOwner(user) and cmd == "py": if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + backup = sys.stdout myout = OutputBuffer() sys.stdout = myout @@ -43,7 +43,7 @@ class DynaCode(object): except Exception as e: sys.stdout = backup self.server.doMessage(channel, user+": "+e.__class__.__name__+": "+e.__str__()) - + sys.stdout = backup for line in myout.getOutput(): self.server.doMessage(channel, user+": "+line) @@ -51,10 +51,10 @@ class DynaCode(object): class OutputBuffer(object): def __init__(self): self.__output = [] - + def write(self, s): if s != "\n": self.__output.append(s) - + def getOutput(self): return self.__output diff --git a/plugins/google.py b/plugins/google.py index 76fded6..229c511 100644 --- a/plugins/google.py +++ b/plugins/google.py @@ -7,12 +7,12 @@ # 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, @@ -25,16 +25,16 @@ import urllib.request, urllib.parse @plugin class Google(object): - """Searches the web with Google. Google is an extremely popular search engine.""" + """Searches the web with Google. Google is an extremely popular search engine.""" def __init__(self, server): self.commands = ["google", "g"] self.server = server self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "google" or cmd == "g": search = " ".join(args) - req = urllib.request.Request("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + urllib.parse.quote(search) + "&key=ABQIAAAA4B16PYoznYWgfVLfNDV4fxRsamdul3hUHNYXnxki2eGK76NS_RQ795CTZZ3l-TuRCO2d5eibFI1WZA") + req = urllib.request.Request("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + urllib.parse.quote(search) + "&key=ABQIAAAA4B16PYoznYWgfVLfNDV4fxRsamdul3hUHNYXnxki2eGK76NS_RQ795CTZZ3l-TuRCO2d5eibFI1WZA") data = str(urllib.request.urlopen(req).read()) splitdata = data.split("\"") self.server.doMessage(channel, splitdata[31] + " - " + splitdata[11]) \ No newline at end of file diff --git a/plugins/help.py b/plugins/help.py index fec262c..4deebcb 100644 --- a/plugins/help.py +++ b/plugins/help.py @@ -7,12 +7,12 @@ # 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, @@ -28,12 +28,12 @@ class Help(object): self.commands = [ "help" ] self.server.handle("command", self.handle_command, self.commands) # self.server.handle("join", self.handle_join) - + def handle_command(self, channel, user, cmd, args): if cmd == "help": print(args) # ['FIRST', 'SECOND'] if args == []: - self.server.doMessage(user, "All commands can be sent in a private message to the bot, or a channel message beginning with " + self.server.doMessage(user, "All commands can be sent in a private message to the bot, or a channel message beginning with " + self.server.config["comchar"] + " or " + self.server.config["nickname"] + ":") # get command lists strings for each plugin strings=[] diff --git a/plugins/isitup.py b/plugins/isitup.py index baa0633..f92b5ba 100644 --- a/plugins/isitup.py +++ b/plugins/isitup.py @@ -7,12 +7,12 @@ # 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, @@ -29,7 +29,7 @@ class IsItUp(object): self.prnt = server.prnt self.commands = ["isitup"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") @@ -40,7 +40,7 @@ class IsItUp(object): elif args[0].startswith("https://"): url = args[0][8:] else: - url = args[0] + url = args[0] code = "".join(x.decode('utf8') for x in urllib.request.urlopen("http://isitup.org/"+url+".json").readlines()) #code = code.decode('utf8') print(code) diff --git a/plugins/karma.py b/plugins/karma.py index eba17d7..9964b83 100644 --- a/plugins/karma.py +++ b/plugins/karma.py @@ -7,12 +7,12 @@ # 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, @@ -25,58 +25,58 @@ class Karma(object): def __init__(self, server): self.server = server self.prnt = server.prnt - + self.commands = [ "karma", "points" ] - + self.server.handle("message", self.handle_message) self.server.handle("command", self.handle_command, self.commands) - + self.userpoints = { } self.karmadbfile = self.server.config["confdir"] + "karma.cfg" - + self.karma_re = re.compile("^.+(\+\+|\-\-).*$") - + self.configParser = configparser.RawConfigParser() if os.path.isfile(self.karmadbfile): self.configParser.read(self.karmadbfile) if self.configParser.has_section(self.server.config["network"]): for user,pts in self.configParser.items(self.server.config["network"]): self.userpoints[user] = int(pts) - + def destroy(self): self.configParser = configparser.RawConfigParser() if os.path.isfile(self.karmadbfile): self.configParser.read(self.karmadbfile) - + network = self.server.config["network"] if not self.configParser.has_section(network): self.configParser.add_section(network) - + for user,pts in list(self.userpoints.items()): self.configParser.set(network,user,str(pts)) - + fh = open(self.karmadbfile, "w") self.configParser.write(fh) fh.close() - + def handle_command(self, channel, user, cmd, args): if len(args) < 1: self.server.doMessage(channel, user+": Displays the amount of karma a user has. Usage: karma <nickname>") return - + if cmd == "karma" or cmd == "points": nick = args[0].lower() if self.userpoints.get(nick, None) is None: self.userpoints[nick] = 0 - + self.server.doMessage(channel, user+": "+args[0]+" has "+str(self.userpoints[nick])+" points.") - + def handle_message(self, channel, user, message): if self.karma_re.match(message): ulist = [u for u in message.split(";") if u != ''] addlist = [u[:-2].strip(" ") for u in ulist if u.endswith("++")] sublist = [u[:-2].strip(" ") for u in ulist if u.endswith("--")] - + for nick in addlist: lnick = nick.lower() if self.userpoints.get(lnick, None) is None: @@ -84,7 +84,7 @@ class Karma(object): else: total = self.userpoints[lnick] + 1 self.userpoints[lnick] = total - + for nick in sublist: lnick = nick.lower() if self.userpoints.get(lnick, None) is None: diff --git a/plugins/ping.py b/plugins/ping.py index 6e15499..b803c01 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -7,12 +7,12 @@ # 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, @@ -25,7 +25,7 @@ class Ping(object): self.server = server self.commands = [ "ping" ] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "ping": if len(args) > 0: diff --git a/plugins/plugintools.py b/plugins/plugintools.py index 8ef87b7..f9ffe52 100644 --- a/plugins/plugintools.py +++ b/plugins/plugintools.py @@ -7,12 +7,12 @@ # 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, @@ -28,7 +28,7 @@ class PluginLoader(object): self.commands = ["load", "unload", "reload", "reloadall", "loaded", "allplugins"] self.ownerOnly = 1 self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if self.server.getPlugin("auth").isMod(user): if cmd == "reloadall": @@ -39,12 +39,12 @@ class PluginLoader(object): elif cmd == "allplugins": self.server.doMessage(channel, user+": Available plugins: "+" ".join(list(sys.modules["irc"].plugins.pList.keys()))) return - + if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - - if cmd == "load": + + if cmd == "load": success, failed, dne = [], [], [] for arg in args: if self.server.pluginManager.pluginExists(arg): @@ -61,7 +61,7 @@ class PluginLoader(object): self.server.doMessage(channel, user+": Already loaded plugins: "+", ".join(failed)) if len(success): self.server.doMessage(channel, user+": Successfully loaded plugins: "+", ".join(success)) - + elif cmd == "unload": for arg in args: if self.server.pluginManager.pluginExists(arg): diff --git a/plugins/printer.py b/plugins/printer.py index e4204fa..8870230 100644 --- a/plugins/printer.py +++ b/plugins/printer.py @@ -7,12 +7,12 @@ # 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, @@ -24,7 +24,7 @@ class Printer(object): self.server = server self.commands = [] self.prnt = server.prnt - + self.server.handle("message", self.handle_message) self.server.handle("kick", self.handle_kick) self.server.handle("part", self.handle_part) @@ -38,22 +38,22 @@ class Printer(object): self.server.handle("nick", self.handle_nick) self.server.handle("error", self.handle_error) - + def handle_connect(self, server): self.prnt("I have connected to %s" % server) - + def handle_disconnect(self, server): self.prnt("I have disconnected from %s" % server) - + def handle_message(self, channel, user, message): self.prnt("<%s> %s: %s" % (channel, user, message)) - + def handle_action(self, channel, user, action): self.prnt("<%s> * %s %s" % (channel, user, action)) - + def handle_join(self, channel, user): self.prnt("%s has joined %s" % (user, channel)) - + def handle_part(self, channel, user, message): self.prnt("%s has left %s (%s)" % (user, channel, message)) @@ -62,15 +62,15 @@ class Printer(object): def handle_quit(self, user, message): self.prnt("%s has quit (%s)" % (user, message)) - + def handle_nick(self, oldnick, newnick): self.prnt("%s is now known as %s" % (oldnick, newnick)) - + def handle_kick(self, channel, user, userkicked, message): self.prnt("%s has kicked %s from %s (%s)" % (user, userkicked, channel, message)) - + def handle_notice(self, user, dest, message): self.prnt("(%s) -%s- %s" % (dest, user, message)) - + def handle_mode(self, channel, user, mode, otheruser): self.prnt("%s set mode %s on %s" % (user, mode, otheruser if otheruser != "" else channel)) diff --git a/plugins/rpn.py b/plugins/rpn.py index 7824779..1cc9fdd 100644 --- a/plugins/rpn.py +++ b/plugins/rpn.py @@ -7,12 +7,12 @@ # 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, @@ -29,7 +29,7 @@ class rpn(object): self.server = server self.commands = ["rpn"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "rpn": if len(args) < 1: diff --git a/plugins/rss.py b/plugins/rss.py index 7f275ae..966faf8 100644 --- a/plugins/rss.py +++ b/plugins/rss.py @@ -70,7 +70,7 @@ class Rss(object): if len(cursor.fetchall()) == 0: cursor.execute('''INSERT INTO rss VALUES(?,?,?,?)''', ('', self.network, channel, url)) connection.commit() - self.server.doMessage(channel, "Done. RSS item %s added to %s." % (url, channel)) + self.server.doMessage(channel, "Done. RSS item %s added to %s." % (url, channel)) else: self.server.doMessage(channel, "Error: RSS item %s already exists at %s" % (url, channel)) elif (cmd == 'rss-list'): @@ -106,7 +106,7 @@ class Rss(object): for child in children: feed_id = child.find('guid').text if (feed_id == last_known_id): return - elif (bool_updated == 0): + elif (bool_updated == 0): # update the db connection = sqlite3.connect(self.db) cursor = connection.cursor() @@ -122,7 +122,7 @@ class Rss(object): msg += "["+child.find('category').text+"]" + " " msg += title self.server.doMessage(row[2], msg) - # print("%s [%s] %s" % (str(url), str(cat), str(title))) + # print("%s [%s] %s" % (str(url), str(cat), str(title))) def checkFeeds(self): connection = sqlite3.connect(self.db) cursor = connection.cursor() diff --git a/plugins/sed.py b/plugins/sed.py index dabe259..7a87604 100644 --- a/plugins/sed.py +++ b/plugins/sed.py @@ -7,12 +7,12 @@ # 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, diff --git a/plugins/smack.py b/plugins/smack.py index 99f79e2..28c4493 100644 --- a/plugins/smack.py +++ b/plugins/smack.py @@ -7,12 +7,12 @@ # 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, @@ -20,7 +20,7 @@ import random -@plugin +@plugin class Smack(object): def __init__(self, server): self.server = server @@ -33,8 +33,8 @@ class Smack(object): "keyboard", "fly swatter" ] - + def handle_command(self, channel, user, cmd, args): if cmd == "smack" and len(args) > 0: self.server.doAction(channel, "smacks "+args[0]+" with a "+self.objects[random.Random().randint(0, len(self.objects)-1)]+"!") - + diff --git a/plugins/tinyurl.py b/plugins/tinyurl.py index 86750ae..3cbe886 100644 --- a/plugins/tinyurl.py +++ b/plugins/tinyurl.py @@ -7,12 +7,12 @@ # 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, @@ -26,12 +26,12 @@ class TinyURL(object): self.server = server self.commands = ["tinyurl"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "tinyurl": if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + url = args[0] if args[0].startswith("http://") else "http://"+args[0] self.server.doMessage(channel, user+": "+urllib.request.urlopen("http://tinyurl.com/api-create.php?url="+url).readline().decode('utf8')) diff --git a/plugins/wikipedia.py b/plugins/wikipedia.py index bac7f01..3ee8f1f 100644 --- a/plugins/wikipedia.py +++ b/plugins/wikipedia.py @@ -7,12 +7,12 @@ # 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, @@ -28,17 +28,17 @@ class Wikipedia(object): self.server = server self.commands = ["wp"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "wp": - if len(args) < 1: + if len(args) < 1: self.server.doMessage(channel, user+": Not enough arguments.") return - + url = "http://en.wikipedia.org/w/api.php?action=opensearch&limit=3&namespace=0&format=xml&search=" query = " ".join(args) search = url + urllib.parse.quote_plus(query, "/") - + try: # get the data data = urllib.request.urlopen(search).readlines() diff --git a/plugins/yt.py b/plugins/yt.py index 8de4c26..e2a1997 100644 --- a/plugins/yt.py +++ b/plugins/yt.py @@ -7,12 +7,12 @@ # 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, @@ -32,7 +32,7 @@ class yt(object): self.server = server self.commands = ["yt"] self.server.handle("command", self.handle_command, self.commands) - + def handle_command(self, channel, user, cmd, args): if cmd == "yt": if len(args) < 1: -- GitLab