numhandlers = {}
msghandlers = {}
chanhandlers = {}
+ exceptionhandlers = [] # list of (Exception_class, handler_function) tuples
users = {}
chans = {}
class User(object):
def __init__(self, nick, auth=None):
self.nick = nick
- self.auth = auth
+ if auth is None:
+ self.auth = None
+ else:
+ self.auth = auth.lower()
self.checklevel()
self.chans = []
self.glevel = 0
return self.glevel
+ def setlevel(self, level, savetodb=True):
+ if savetodb:
+ if level != 0:
+ c = main.query("REPLACE INTO users (auth, level) VALUES (%s, %s)", (self.auth, level))
+ else:
+ c = main.query("DELETE FROM users WHERE auth = %s", (self.auth,))
+ if c == 0: # no rows affected
+ c = True # is fine
+ if c:
+ self.glevel = level
+ return True
+ else:
+ return False
+ else:
+ self.glevel = level
+ return True
+
def join(self, chan):
if chan not in self.chans: self.chans.append(chan)
def part(self, chan):
return True
else:
return False
+ else:
+ self.levels[auth] = level
+ return True
def userjoin(self, user, level=None):
if user not in self.users: self.users.append(user)
def getchanhook(self, chan):
return self.chanhandlers[chan]
+ def hookexception(self, exc, handler):
+ self.exceptionhandlers.append((exc, handler))
+ def unhookexception(self, exc, handler):
+ self.exceptionhandlers.remove((exc, handler))
+ def hasexceptionhook(self, exc):
+ return any((True for x,h in self.exceptionhandlers if isinstance(exc, x)))
+ def getexceptionhook(self, exc):
+ return (h for x,h in self.exceptionhandlers if isinstance(exc, x))
+
def dbsetup():
main.db = None