circles/bot.py

65 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
import teambot, sys, os, traceback
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()
try:
cmd = args.pop(0)
except:
return
if cmd in self.cmd:
try:
self.cmd[cmd](self,c,n,m)
except BaseException as e:
self.say(c,"Invalid Input, do {}help {} to see syntax".format(self.prefix, cmd))
print('error', e)
n = sys.exc_info()
print(n, "Inp:", m)
traceback.print_tb(n[2])
return
try:
for i in self.raw:
self.raw[i](self,c,n,m)
except TypeError:
print('raw error')
def say(self,target,message):
self._bot.conn.privmsg(target,message)
if __name__=="__main__":
chans = ['#chaos', '#team', '#chaoss', '#lickthecheese', '#cminecraft', '#bots', '#casino', '#windowsloser']
if '-dev' in sys.argv:
print("WARN Starting in development mode")
chans = ['#bots'] # only go in bots while under development
bot = teambot.TeamBot(chans, "circles", "localhost", chandler=Circles)
bot.start()