X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/3d724d3a4b12e184c8973a129a18191add52243e..8a9b8a6cd0379efd7b343bceb1fc4feed7347111:/erebus.py diff --git a/erebus.py b/erebus.py index 7386df2..190c4ba 100644 --- a/erebus.py +++ b/erebus.py @@ -6,7 +6,7 @@ import os, sys, select, MySQLdb, MySQLdb.cursors, time, random import bot, config, ctlmod -class Erebus(object): +class Erebus(object): #singleton to pass around APIVERSION = 1 RELEASE = 0 @@ -57,14 +57,14 @@ class Erebus(object): return self.glevel def join(self, chan): - self.chans.append(chan) + if chan not in self.chans: self.chans.append(chan) def part(self, chan): try: self.chans.remove(chan) except: pass + return len(self.chans) == 0 def quit(self): - for chan in self.chans: - self.chans.remove(chan) + pass def nickchange(self, newnick): self.nick = newnick @@ -174,7 +174,7 @@ class Erebus(object): self.users[nick] = user if justjoined: - self.randbot().conn.send("WHO %s n%%ant,2" % (nick)) + self.randbot().conn.send("WHO %s n%%ant,1" % (nick)) return user else: @@ -204,6 +204,9 @@ class Erebus(object): def module(self, name): return ctlmod.modules[name] + def log(self, source, level, message): + print "%09.3f %s [%s] %s" % (time.time() % 100000, source, level, message) + #bind functions def hook(self, word, handler): try: @@ -247,11 +250,13 @@ class Erebus(object): class MyCursor(MySQLdb.cursors.DictCursor): def execute(self, *args, **kwargs): - print "%09.3f [SQL] [#] MyCursor.execute(self, %s, %s)" % (time.time() % 100000, ', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs])) + main.log("[SQL]", "?", "MyCursor.execute(self, %s, %s)" % (', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs]))) +# print "%09.3f [SQL] [#] MyCursor.execute(self, %s, %s)" % (time.time() % 100000, ', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs])) try: - super(self.__class__, self).execute(*args, **kwargs) + return super(self.__class__, self).execute(*args, **kwargs) except MySQLdb.MySQLError as e: - print "%09.3f [SQL] [!] MySQL error! %r" % (time.time() % 100000, e) + main.log("[SQL]", "!", "MySQL error! %r" % (e)) +# print "%09.3f [SQL] [!] MySQL error! %r" % (time.time() % 100000, e) dbsetup() return False return True