]> jfr.im git - erebus.git/blobdiff - erebus.py
Fixed header
[erebus.git] / erebus.py
index c91e24cc49b0f1603eddaff8c1467b23a2d5d9e5..fb4239a97306f9c46963733e3aa7068e5bb4921d 100644 (file)
--- a/erebus.py
+++ b/erebus.py
@@ -12,6 +12,7 @@ class Erebus(object):
        bots = {}
        fds = {}
        mods = {}
+       numhandlers = {}
        msghandlers = {}
        users = {}
        chans = {}
@@ -29,7 +30,7 @@ class Erebus(object):
 
                def authed(self, auth):
                        if auth == '0': auth = None
-                       self.auth = auth
+                       self.auth = auth.lower()
                        self.checklevel()
 
                def checklevel(self):
@@ -54,15 +55,37 @@ class Erebus(object):
                def __repr__(self): return "<User %r (%d)>" % (self.nick,self.glevel)
 
        class Channel(object):
-               def __init__(self, name, bot, levels={}):
+               def __init__(self, name, bot):
                        self.name = name
                        self.bot = bot
-                       self.levels = levels
+                       self.levels = {}
 
                        self.users = []
                        self.voices = []
                        self.ops = []
 
+                       c = main.db.cursor()
+                       c.execute("SELECT user, level FROM chusers WHERE chan = %s", (self.name,))
+                       row = c.fetchone()
+                       while row is not None:
+                               self.levels[row['user']] = row['level']
+                               row = c.fetchone()
+
+
+               def levelof(self, auth):
+                       auth = auth.lower()
+                       if auth in self.levels:
+                               return self.levels[auth]
+                       else:
+                               return 0
+
+               def setlevel(self, auth, level, savetodb=True):
+                       auth = auth.lower()
+                       if savetodb:
+                               c = main.db.cursor()
+                               c.execute("REPLACE INTO chusers (chan, user, level) VALUES (%s, %s, %s)", (self.name, auth, level))
+                       self.levels[auth] = level
+
                def userjoin(self, user, level=None):
                        if user not in self.users: self.users.append(user)
                        if level == 'op' and user not in self.ops: self.ops.append(user)
@@ -130,8 +153,8 @@ class Erebus(object):
                else:
                        return None
 
-       def newchannel(self, bot, name, levels={}):
-               chan = self.Channel(name.lower(), bot, levels)
+       def newchannel(self, bot, name):
+               chan = self.Channel(name.lower(), bot)
                self.chans[name.lower()] = chan
                return chan
 
@@ -148,14 +171,34 @@ class Erebus(object):
 
        #bind functions
        def hook(self, word, handler):
-               self.msghandlers[word] = handler
-       def unhook(self, word):
-               del self.msghandlers[word]
+               try:
+                       self.msghandlers[word].append(handler)
+               except:
+                       self.msghandlers[word] = [handler]
+       def unhook(self, word, handler):
+               if word in self.msghandlers and handler in self.msghandlers[word]:
+                       self.msghandlers[word].remove(handler)
        def hashook(self, word):
-               return word in self.msghandlers
+               return word in self.msghandlers and len(self.msghandlers[word]) != 0
        def gethook(self, word):
                return self.msghandlers[word]
 
+       def hooknum(self, word, handler):
+               try:
+                       self.numhandlers[word].append(handler)
+               except:
+                       self.numhandlers[word] = [handler]
+       def unhooknum(self, word, handler):
+               if word in self.numhandlers and handler in self.numhandlers[word]:
+                       self.numhandlers[word].remove(handler)
+       def hasnumhook(self, word):
+               return word in self.numhandlers and len(self.numhandlers[word]) != 0
+       def getnumhook(self, word):
+               return self.numhandlers[word]
+
+
+
+
 def setup():
        global cfg, main