diff --git a/extra/example.py b/extra/example.py index 4c656c92cdc4b5c21db86417e1615189b0ecda2d..41dbe7a67d66c8e6e5645543c9f1b0dd240229a2 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 0a32b3ddaedda516bb12d65d32ae9abf5af7ae7f..c35b51af8a50327535e2278e6fc5cd0a97267539 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 64b2b5b9d88884952ef6a408f03c87d79e1d2f0a..1bdd12591284358decc82204faa677887a55f21c 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 d89c0295300c4b1e877b28f32ff8a22ae5661732..bea1d1876d4d6087e96660793ec84a6cc8e8b36c 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 a9b4779e2f67590ea22d294ea98a62300755f5fe..222c425beb21af7043df0497115bd19efcd41446 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 303e048609da054cd85169a85a02385610424752..5ec4b1692147c2fb5e0ab484df867e727594edb3 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 eb6230ef9d1d647c0e511cde415617d9927fa45e..a8cfc9ea32cc5b32169a1afff8b0e28e25efbe53 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 79bd2747913cf2a7897d58ac45cc0e8e4a123bef..07a095546616f65593ac9e38a5d0bd888a402ca0 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 971f5bf8399f5844fd7b84091d0e235cc4bff39f..7aa03d1da95b8f7b36029b1e41e38cb82d092089 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 526baab7e3486e12c9263a260174566fe263ce5b..36972adb2c366e35db8e432318b66940f3e65f9b 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 e093eccbae1f992a7aa627c075c4b4e03c679725..fde9263d0397c3286521bf96b9fdfd9019f3fb5c 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 6b582d2d25feaaf3416705443cc1b450d3e4f29f..b01911387a63555fe25becc240685aba29284af9 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 e1db03bd3abc30b295bb6f3a947336417f8eb3c4..67550a08f1419805ea01e1d0da6c07fcf7ad439d 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 01f77ebd509c204655d49ab9cb092dd86c461810..4b5db213276e7e2b57938e3ea1407c652035e141 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 76fded652946f764d7a5e9f6129d758cf7a7cdfc..229c5119e124b9446a9368d2dec887fa21586720 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 fec262cd0a449a5938b8edbd8df2d2ee3ea98a65..4deebcb09632658d1f37d9e4a81232f2f61a00f8 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 baa0633b22ffefb976bd39c5d92e39ea8e76a353..f92b5ba102d721ea5765830203b1c443c55a7cd7 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 eba17d7458dd84d822f92208c1d00b65651660ce..9964b836b8878b2d105f57873b2d61870f704faf 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 6e15499db091dfd101698ef6951489bec99d986d..b803c01e430f496b1a897ac329640caed9950a4c 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 8ef87b77155b3bbc779ef8af4e6ec91703f0b94e..f9ffe52d15440f227be19ed78c6463e9b48eb6eb 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 e4204fa2ded41789e0fa11f583f1dc71434defea..88702304af1eb750ff3e28b5dd62be887f0a3139 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 782477917881f2c7c17f39be734e9b2d94e53a7c..1cc9fddb6d2aadc9ba7e7f1725d220f2a5fdc7e0 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 7f275ae053ac22ef00ebff5ceefe50fd5637a99d..966faf83d1a11676d764fa03fcf66bf946e6689b 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 dabe2590564830cd475a1836df3a3946f392493e..7a87604b90ec2f06aafe661e7160874a6fecdb22 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 99f79e25b958d36b2c8fe15b52b762800268d347..28c44936b3db1a84903ad46f47289931ab5902e3 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 86750ae857cb38df77816bdd92e03f8a135b5a8d..3cbe88686863b98d14f1788966ef9e57f2933db5 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 bac7f0122c6a8d626279a2bdd73b0d12625d431a..3ee8f1f19aeaf902102d3ecd1e770645ded0ad96 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 8de4c268db48a6ca0ef1597bec7a5e520846bd52..e2a199779fad0f5fc299d32193ff03dab89debe5 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: