circles/bot.py

65 lines
2.1 KiB
Python
Raw Permalink Normal View History

2020-01-31 16:32:17 +00:00
#!/usr/bin/env python3
2020-02-05 01:41:32 +00:00
import teambot, sys, os, traceback
2020-01-31 16:32:17 +00:00
2020-01-31 22:17:11 +00:00
class Circles(teambot.Handler):
def __init__(self, bot):
2020-02-01 00:57:06 +00:00
self._bot = bot
2020-01-31 23:00:47 +00:00
print('initilized')
2020-01-31 22:17:11 +00:00
self.modules = []
2020-02-01 13:16:35 +00:00
self.lm = []
2020-01-31 22:17:11 +00:00
self.cmd = {}
2020-01-31 23:00:47 +00:00
self.raw = {}
2020-01-31 22:34:37 +00:00
self.help = {}
self.prefix = "?"
print('loading modules')
self.loadMods()
print('Ready!')
2020-01-31 22:17:11 +00:00
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)
2020-01-31 22:34:37 +00:00
m.init(self)
2020-02-01 13:16:35 +00:00
self.lm.append(i)
2020-01-31 22:17:11 +00:00
self.modules.append(m)
def registerCommand(self, txt, func):
self.cmd[txt] = func
def registerRaw(self, txt, func):
2020-01-31 23:00:47 +00:00
self.raw[txt] = func
2020-01-31 22:34:37 +00:00
def registerHelp(self, cmd, ht):
self.help[cmd] = ht
2020-02-01 00:39:41 +00:00
def on_pubmsg(self,c,n,m):
2020-01-31 22:17:11 +00:00
if m.startswith(self.prefix):
args = m[len(self.prefix):].strip().split()
try:
cmd = args.pop(0)
except:
return
2020-01-31 22:17:11 +00:00
if cmd in self.cmd:
2020-01-31 22:34:37 +00:00
try:
self.cmd[cmd](self,c,n,m)
2020-02-04 16:48:26 +00:00
except BaseException as e:
2020-02-05 01:41:32 +00:00
self.say(c,"Invalid Input, do {}help {} to see syntax".format(self.prefix, cmd))
2020-02-04 16:48:26 +00:00
print('error', e)
2020-02-05 01:41:32 +00:00
n = sys.exc_info()
print(n, "Inp:", m)
traceback.print_tb(n[2])
2020-03-06 16:13:25 +00:00
return
2020-02-01 00:47:42 +00:00
try:
for i in self.raw:
self.raw[i](self,c,n,m)
except TypeError:
2020-03-05 11:27:09 +00:00
print('raw error')
2020-02-01 13:05:44 +00:00
def say(self,target,message):
self._bot.conn.privmsg(target,message)
2020-01-31 22:34:37 +00:00
2020-01-31 23:00:47 +00:00
if __name__=="__main__":
chans = ['#chaos', '#team', '#chaoss', '#lickthecheese', '#cminecraft', '#bots', '#casino', '#windowsloser']
2020-02-05 01:35:20 +00:00
if '-dev' in sys.argv:
print("WARN Starting in development mode")
2020-03-05 15:39:32 +00:00
chans = ['#bots'] # only go in bots while under development
2020-01-31 23:00:47 +00:00
bot = teambot.TeamBot(chans, "circles", "localhost", chandler=Circles)
bot.start()
2020-01-31 16:32:17 +00:00