circles/bot.py

54 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
import teambot, sys, os
class Circles(teambot.Handler):
def __init__(self, bot):
self._bot = bot
print('initilized')
self.modules = []
self.lm = []
self.cmd = {}
self.raw = {}
self.help = {}
self.prefix = "."
print('loading modules')
self.loadMods()
print('Ready!')
def loadMods(self):
for i in [s for s in os.listdir('modules') if ".py" in s]:
i = i[:-3]
print('loading',i)
m = __import__("modules."+i)
m = eval('m.'+i)
m.init(self)
self.lm.append(i)
self.modules.append(m)
def registerCommand(self, txt, func):
self.cmd[txt] = func
def registerRaw(self, txt, func):
self.raw[txt] = func
def registerHelp(self, cmd, ht):
self.help[cmd] = ht
def on_pubmsg(self,c,n,m):
if m.startswith(self.prefix):
args = m[len(self.prefix):].strip().split()
cmd = args.pop(0)
if cmd in self.cmd:
try:
self.cmd[cmd](self,c,n,m)
except TypeError:
self.say(c,n+": Usage: "+self.help[cmd])
try:
for i in self.raw:
self.raw[i](self,c,n,m)
except TypeError:
self.say(c,n+": Usage: "+self.help[cmd])
def say(self,target,message):
self._bot.conn.privmsg(target,message)
if __name__=="__main__":
chans = ['#chaos', '#lickthecheese', '#cminecraft', '#bots', '#mbgeneral']
bot = teambot.TeamBot(chans, "circles", "localhost", chandler=Circles)
bot.start()