X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/a9ce8d6ae47ce34389bae9441bb83526ff582195..fd52fb165f70d0b10f123ac9468fbf66d45f92f8:/erebus.py diff --git a/erebus.py b/erebus.py index 07fef14..2783bd5 100644 --- a/erebus.py +++ b/erebus.py @@ -5,10 +5,13 @@ #TODO: tons -import os, sys, select, MySQLdb, MySQLdb.cursors, time +import os, sys, select, MySQLdb, MySQLdb.cursors, time, random import bot, config, ctlmod class Erebus(object): + APIVERSION = 1 + RELEASE = 0 + bots = {} fds = {} numhandlers = {} @@ -77,6 +80,9 @@ class Erebus(object): row = c.fetchone() + def msg(self, *args, **kwargs): + self.bot.msg(self.name, *args, **kwargs) + def levelof(self, auth): if auth is None: return 0 @@ -117,8 +123,9 @@ class Erebus(object): def __str__(self): return self.name def __repr__(self): return "" % (self.name) - def __init__(self, trigger): - self.trigger = trigger + def __init__(self, cfg): + self.cfg = cfg + self.trigger = cfg.trigger if os.name == "posix": self.potype = "poll" self.po = select.poll() @@ -126,9 +133,9 @@ class Erebus(object): self.potype = "select" self.fdlist = [] - def newbot(self, nick, user, bind, server, port, realname): + def newbot(self, nick, user, bind, authname, authpass, server, port, realname): if bind is None: bind = '' - obj = bot.Bot(self, nick, user, bind, server, port, realname) + obj = bot.Bot(self, nick, user, bind, authname, authpass, server, port, realname) self.bots[nick.lower()] = obj def newfd(self, obj, fileno): @@ -143,7 +150,7 @@ class Erebus(object): def fd(self, fileno): #get Bot() by fd/fileno return self.fds[fileno] def randbot(self): #get Bot() randomly - for b in self.bots.itervalues(): return b #TODO + return self.bots[random.choice(self.bots.keys())] def user(self, _nick, justjoined=False): nick = _nick.lower() @@ -243,7 +250,7 @@ def setup(): global cfg, main cfg = config.Config('bot.config') - main = Erebus(cfg.trigger) + main = Erebus(cfg) autoloads = [mod for mod, yes in cfg.items('autoloads') if int(yes) == 1] for mod in autoloads: @@ -252,11 +259,11 @@ def setup(): dbsetup() c = main.db.cursor() - if c.execute("SELECT nick, user, bind FROM bots WHERE active = 1"): + if c.execute("SELECT nick, user, bind, authname, authpass FROM bots WHERE active = 1"): rows = c.fetchall() c.close() for row in rows: - main.newbot(row['nick'], row['user'], row['bind'], cfg.host, cfg.port, cfg.realname) + main.newbot(row['nick'], row['user'], row['bind'], row['authname'], row['authpass'], cfg.host, cfg.port, cfg.realname) main.connectall() def loop():