bots = {}
fds = {}
mods = {}
+ numhandlers = {}
msghandlers = {}
users = {}
chans = {}
return self.bots[name.lower()]
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
- def user(self, nick):
+ def user(self, nick, justjoined=False):
nick = nick.lower()
if nick in self.users:
return self.users[nick]
else:
user = self.User(nick)
self.users[nick] = user
+
+ if justjoined:
+ self.randbot().conn.send("WHO %s %%ant,2" % (nick))
+
return user
def channel(self, name): #get Channel() by name
if name.lower() in self.chans:
#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
autoloads = [mod for mod, yes in cfg.items('autoloads') if int(yes) == 1]
for mod in autoloads:
+ print "Loading %s" % (mod)
ctlmod.load(main, mod)
main.db = MySQLdb.connect(host=cfg.dbhost, user=cfg.dbuser, passwd=cfg.dbpass, db=cfg.dbname, cursorclass=MySQLdb.cursors.DictCursor)