From 613c7fca05747aff553c0604008e7000568b7862 Mon Sep 17 00:00:00 2001 From: Jimmy Cao Date: Thu, 29 Dec 2011 17:41:25 -0600 Subject: [PATCH] various tweaks --- modules/common.py | 2 +- modules/sabotage.py | 10 ++++++++++ modules/wolfgame.py | 16 ++++++++-------- oyoyo/client.py | 6 +++++- tools/decorators.py | 8 ++++---- tools/moduleloader.py | 3 +++ 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/modules/common.py b/modules/common.py index 6936cf4..7e276f4 100644 --- a/modules/common.py +++ b/modules/common.py @@ -93,7 +93,7 @@ def connect_callback(cli): ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli) if botconfig.JOIN_AFTER_CLOAKED: - prepare_stuff = hook("event_hosthidden", id=294)(prepare_stuff) + prepare_stuff = hook("event_hosthidden", hookid=294)(prepare_stuff) @hook("nicknameinuse") diff --git a/modules/sabotage.py b/modules/sabotage.py index 7cd4e0d..5eaaec5 100644 --- a/modules/sabotage.py +++ b/modules/sabotage.py @@ -1,3 +1,13 @@ +# Copyright (c) 2011, Jimmy Cao +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +# Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + from tools import decorators import settings.sabotage as var import time diff --git a/modules/wolfgame.py b/modules/wolfgame.py index af25c94..ea9624a 100644 --- a/modules/wolfgame.py +++ b/modules/wolfgame.py @@ -38,7 +38,7 @@ hook = decorators.generate(HOOKS, raw_nick=True, permissions=False) def connect_callback(cli): to_be_devoiced = [] - @hook("whospcrpl", id=294) + @hook("whospcrpl", hookid=294) def on_whoreply(cli, server, nick, ident, cloak, user, status, acc): if user in var.USERS: return # Don't add someone who is already there if user == botconfig.NICK: @@ -51,19 +51,19 @@ def connect_callback(cli): to_be_devoiced.append(user) var.USERS[user] = dict(cloak=cloak,account=acc) - @hook("endofwho", id=294) + @hook("endofwho", hookid=294) def afterwho(*args): cmodes = [] for nick in to_be_devoiced: cmodes.append(("-v", nick)) # devoice all on connect - @hook("quietlist", id=294) + @hook("quietlist", hookid=294) def on_quietlist(cli, server, botnick, channel, q, quieted, by, something): if re.match(".+\!\*@\*", quieted): # only unquiet people quieted by bot cmodes.append(("-q", quieted)) - @hook("quietlistend", id=294) + @hook("quietlistend", hookid=294) def on_quietlistend(cli, *rest): decorators.unhook(HOOKS, 294) mass_mode(cli, cmodes) @@ -252,7 +252,7 @@ def pinger(cli, nick, chan, rest): - @hook("whoreply", id=800) + @hook("whoreply", hookid=800) def on_whoreply(cli, server, dunno, chan, dunno1, cloak, dunno3, user, status, dunno4): if not var.PINGING: return @@ -264,7 +264,7 @@ def pinger(cli, nick, chan, rest): - @hook("endofwho", id=800) + @hook("endofwho", hookid=800) def do_ping(*args): if not var.PINGING: return @@ -2404,7 +2404,7 @@ def show_admins(cli, nick, chan, rest): return var.ADMIN_PINGING = True - @hook("whoreply", id = 4) + @hook("whoreply", hookid = 4) def on_whoreply(cli, server, dunno, chan, dunno1, cloak, dunno3, user, status, dunno4): if not var.ADMIN_PINGING: @@ -2413,7 +2413,7 @@ def show_admins(cli, nick, chan, rest): user != botconfig.NICK and cloak not in var.AWAY): admins.append(user) - @hook("endofwho", id = 4) + @hook("endofwho", hookid = 4) def show(*args): if not var.ADMIN_PINGING: return diff --git a/oyoyo/client.py b/oyoyo/client.py index ccda636..545f78a 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -185,7 +185,11 @@ class IRCClient(object): self.user(self.nickname, self.real_name) if self.connect_cb: - self.connect_cb(self) + try: + self.connect_cb(self) + except Exception as e: + traceback.print_exc() + raise e buffer = bytes() while not self._end: diff --git a/tools/decorators.py b/tools/decorators.py index cca1601..1289017 100644 --- a/tools/decorators.py +++ b/tools/decorators.py @@ -14,7 +14,7 @@ import botconfig def generate(fdict, permissions=True, **kwargs): """Generates a decorator generator. Always use this""" - def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, id=-1): + def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, hookid=-1): def dec(f): def innerf(*args): largs = list(args) @@ -76,7 +76,7 @@ def generate(fdict, permissions=True, **kwargs): innerf.owner_only = owner_only innerf.raw_nick = raw_nick innerf.admin_only = admin_only - innerf.id = id + innerf.hookid = hookid innerf.__doc__ = f.__doc__ return innerf @@ -85,10 +85,10 @@ def generate(fdict, permissions=True, **kwargs): return lambda *args, **kwarargs: cmd(*args, **kwarargs) if kwarargs else cmd(*args, **kwargs) -def unhook(hdict, id): +def unhook(hdict, hookid): for cmd in list(hdict.keys()): for x in hdict[cmd]: - if x.id == id: + if x.hookid == hookid: hdict[cmd].remove(x) if not hdict[cmd]: del hdict[cmd] diff --git a/tools/moduleloader.py b/tools/moduleloader.py index 10f802d..39603ab 100644 --- a/tools/moduleloader.py +++ b/tools/moduleloader.py @@ -14,6 +14,9 @@ for modfile in os.listdir("modules"): continue # not a file modfile = modfile[:-3] + + print("Loading module "+modfile) + MODULES[modfile] = getattr(__import__("modules."+modfile), modfile) if botconfig.DEFAULT_MODULE in MODULES.keys():