#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 = {}
- mods = {}
numhandlers = {}
msghandlers = {}
chanhandlers = {}
def levelof(self, auth):
+ if auth is None:
+ return 0
auth = auth.lower()
if auth in self.levels:
return self.levels[auth]
def __str__(self): return self.name
def __repr__(self): return "<Channel %r>" % (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()
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()
self.users[nick] = user
if justjoined:
- self.randbot().conn.send("WHO %s %%ant,2" % (nick))
+ self.randbot().conn.send("WHO %s n%%ant,2" % (nick))
return user
def channel(self, name): #get Channel() by name
if bot.conn.state == 0:
bot.connect()
+ def module(self, name):
+ return ctlmod.modules[name]
+
#bind functions
def hook(self, word, handler):
try:
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: