]> jfr.im git - erebus.git/blobdiff - erebus.py
trivia - updated example json
[erebus.git] / erebus.py
index 7386df2bea82efd5644e93a773830f8210a0e29b..190c4ba2301b0eeb39efe9cb83a7982717b8f150 100644 (file)
--- 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