You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

14 years ago
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler, protected
14 years ago
from oyoyo.parse import parse_nick
import logging
import botconfig
import wolfgame
14 years ago
def cmd(s, pm = False):
14 years ago
def dec(f):
if s is None and pm:
G_PM_COMMAND.append(f)
elif s is None and not pm:
G_COMMAND.append(f)
elif pm:
PM_COMMANDS[s] = f
14 years ago
else:
COMMANDS[s] = f
14 years ago
return f
return dec
def hook(s):
def dec(f):
HOOKS[s] = f
return f
return dec
class WolfBotHandler(DefaultCommandHandler):
def __init__(self, client):
super().__init__(client)
def privmsg(self, rawnick, chan, msg):
14 years ago
if chan != botconfig.NICK: #not a PM
for x in wolfgame.COMMANDS.keys():
14 years ago
if msg.startswith(x):
msg = msg.replace(x, "", 1)
wolfgame.COMMANDS[x](self.client, rawnick, chan, msg.lstrip())
14 years ago
else:
for x in wolfgame.PM_COMMANDS.keys():
14 years ago
if msg.startswith(x):
msg = msg.replace(x, "", 1)
wolfgame.PM_COMMANDS[x](self.client, rawnick, msg.lstrip())
print(wolfgame.COMMANDS)
14 years ago
@protected
def __unhandled__(self, cmd, *args):
if cmd in wolfgame.HOOKS.keys():
largs = list(args)
for i,arg in enumerate(largs):
if arg: largs[i] = arg.decode('ascii')
wolfgame.HOOKS[cmd](*largs)
else:
logging.debug('unhandled command %s(%s)' % (cmd, args))
14 years ago
def main():
logging.basicConfig(level=logging.DEBUG)
cli = IRCClient(WolfBotHandler, host=botconfig.HOST, port=botconfig.PORT, nickname=botconfig.NICK,
connect_cb=wolfgame.connect_callback)
14 years ago
conn = cli.connect()
while True:
next(conn)
14 years ago
if __name__ == "__main__":
main()