Browse Source

various tweaks

master
Jimmy Cao 13 years ago
parent
commit
613c7fca05
  1. 2
      modules/common.py
  2. 10
      modules/sabotage.py
  3. 16
      modules/wolfgame.py
  4. 6
      oyoyo/client.py
  5. 8
      tools/decorators.py
  6. 3
      tools/moduleloader.py

2
modules/common.py

@ -93,7 +93,7 @@ def connect_callback(cli): @@ -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")

10
modules/sabotage.py

@ -1,3 +1,13 @@ @@ -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

16
modules/wolfgame.py

@ -38,7 +38,7 @@ hook = decorators.generate(HOOKS, raw_nick=True, permissions=False) @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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

6
oyoyo/client.py

@ -185,7 +185,11 @@ class IRCClient(object): @@ -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:

8
tools/decorators.py

@ -14,7 +14,7 @@ import botconfig @@ -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): @@ -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): @@ -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]

3
tools/moduleloader.py

@ -14,6 +14,9 @@ for modfile in os.listdir("modules"): @@ -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():

Loading…
Cancel
Save