]> jfr.im git - erebus.git/blobdiff - erebus.py
added code to AUTH and +x
[erebus.git] / erebus.py
index 66f6cd2532a38695b7c178765e0a58b70dead2b7..94e9c3ae99027573ffa77f0f4afc07f148ecc5a6 100644 (file)
--- a/erebus.py
+++ b/erebus.py
@@ -5,13 +5,15 @@
 
 #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 = {}
@@ -53,6 +55,9 @@ class Erebus(object):
                        self.chans.append(chan)
                def part(self, chan):
                        self.chans.remove(chan)
+               def quit(self):
+                       for chan in self.chans:
+                               self.chans.remove(chan)
 
                def __str__(self): return self.nick
                def __repr__(self): return "<User %r (%d)>" % (self.nick,self.glevel)
@@ -76,6 +81,8 @@ class Erebus(object):
 
 
                def levelof(self, auth):
+                       if auth is None:
+                               return 0
                        auth = auth.lower()
                        if auth in self.levels:
                                return self.levels[auth]
@@ -113,8 +120,9 @@ class Erebus(object):
                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()
@@ -122,9 +130,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):
@@ -139,18 +147,18 @@ 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()
+       def user(self, _nick, justjoined=False):
+               nick = _nick.lower()
                if nick in self.users:
                        return self.users[nick]
                else:
-                       user = self.User(nick)
+                       user = self.User(_nick)
                        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
@@ -175,6 +183,9 @@ class Erebus(object):
                        if bot.conn.state == 0:
                                bot.connect()
 
+       def module(self, name):
+               return ctlmod.modules[name]
+
        #bind functions
        def hook(self, word, handler):
                try:
@@ -236,7 +247,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:
@@ -245,11 +256,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():