X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/826964670ac56032443ea66986c5b87c5ef38a4c..db75daab8e080fef8e9dbe7796492b24945e8707:/erebus.py diff --git a/erebus.py b/erebus.py index b38820b..2c489f6 100644 --- a/erebus.py +++ b/erebus.py @@ -1,9 +1,12 @@ #!/usr/bin/python +# Erebus IRC bot - Author: John Runyon +# main startup code + #TODO: tons import os, sys, select, MySQLdb, MySQLdb.cursors -import bot, config +import bot, config, ctlmod class Erebus(object): bots = {} @@ -16,19 +19,28 @@ class Erebus(object): def __init__(self, nick, auth=None): self.nick = nick - self.auth = auth - - if auth is not None: - self.checklevel() + self.auth = nick #TEMP + self.checklevel() def authed(self, auth): self.auth = auth self.checklevel() - def checklevel(self): self.level = 9999 #TODO get level from db + def checklevel(self): + if self.auth is None: + self.level = -1 + else: + c = main.db.cursor() + c.execute("SELECT level FROM users WHERE auth = %s", (self.auth,)) + row = c.fetchone() + if row is not None: + self.level = row['level'] + else: + self.level = 0 + return self.level def __str__(self): return self.nick - def __repr__(self): return "" % (self.nick) + def __repr__(self): return "" % (self.nick,self.level) class Channel(object): users = [] @@ -100,23 +112,26 @@ class Erebus(object): if bot.conn.state == 0: bot.connect() - #module functions - def modlist(self): pass - def hasmod(self, name): pass - def loadmod(self, name): pass - def unloadmod(self, name): pass - def reloadmod(self, name): pass - #bind functions - def bind(self, word, handler): pass - def addbind(self, word, handler): pass - def rmbind(self, word, handler): pass - def getbind(self, word, handler): pass - -cfg = config.Config('bot.config') -main = Erebus() + def hook(self, word, handler): + self.msghandlers[word] = handler + def unhook(self, word): + del self.msghandlers[word] + def hashook(self, word): + return word in self.msghandlers + def gethook(self, word): + return self.msghandlers[word] def setup(): + global cfg, main + + cfg = config.Config('bot.config') + main = Erebus() + + autoloads = [mod for mod, yes in cfg.items('autoloads') if int(yes) == 1] + for mod in autoloads: + ctlmod.load(main, mod) + main.db = MySQLdb.connect(host=cfg.dbhost, user=cfg.dbuser, passwd=cfg.dbpass, db=cfg.dbname, cursorclass=MySQLdb.cursors.DictCursor) c = main.db.cursor() c.execute("SELECT nick, user, bind FROM bots WHERE active = 1")