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.

47 lines
1.8 KiB

14 years ago
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import CommandHandler, protected
14 years ago
from oyoyo.parse import parse_nick
import logging
import botconfig
import wolfgame
14 years ago
class WolfBotHandler(CommandHandler):
14 years ago
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():
if msg.lower().startswith(x):
h = msg[len(x):]
if not h or h[0] == " " or not x:
wolfgame.COMMANDS[x](self.client, rawnick, chan, h.lstrip())
14 years ago
else:
for x in wolfgame.PM_COMMANDS.keys():
if msg.lower().startswith(x):
h = msg[len(x):]
if not h or h[0] == " " or not x:
wolfgame.PM_COMMANDS[x](self.client, rawnick, h.lstrip())
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 isinstance(arg, bytes): largs[i] = arg.decode('ascii')
14 years ago
wolfgame.HOOKS[cmd](self.client, *largs)
else:
logging.debug('Unhandled command {0}({1})'.format(cmd, [arg.decode('utf_8')
for arg in args
if isinstance(arg, bytes)]))
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
cli.mainLoop()
14 years ago
if __name__ == "__main__":
main()