circles/bot.py

51 lines
1.5 KiB
Python
Raw Normal View History

2020-01-31 16:32:17 +00:00
#!/usr/bin/env python3
import teambot, sys, os
2020-01-31 22:17:11 +00:00
class Circles(teambot.Handler):
def __init__(self, bot):
2020-01-31 23:00:47 +00:00
print('initilized')
2020-01-31 22:17:11 +00:00
self.modules = []
self.cmd = {}
2020-01-31 23:00:47 +00:00
self.raw = {}
2020-01-31 22:34:37 +00:00
self.help = {}
2020-01-31 22:17:11 +00:00
self.prefix = "."
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-01-31 22:17:11 +00:00
self.modules.append(m)
def registerCommand(self, txt, func):
self.cmd[txt] = func
2020-01-31 23:00:47 +00:00
def regosterRaw(self, txt, func):
self.raw[txt] = func
2020-01-31 22:34:37 +00:00
def registerHelp(self, cmd, ht):
self.help[cmd] = ht
2020-01-31 22:17:11 +00:00
def on_connection_established(self):
2020-01-31 23:00:47 +00:00
print('Connected!')
2020-01-31 22:17:11 +00:00
self.loadMods()
2020-01-31 23:00:47 +00:00
print('Ready!')
2020-01-31 22:17:11 +00:00
def on_pubmessage(self,c,n,m):
2020-01-31 23:11:01 +00:00
print(m)
2020-01-31 22:17:11 +00:00
if m.startswith(self.prefix):
args = m[len(self.prefix):].strip().split()
2020-01-31 22:34:37 +00:00
cmd = args.pop()
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)
except TypeError:
self.say(c,n+": Usage: "+self.help[cmd])
2020-01-31 23:00:47 +00:00
if cmd in self.raw:
try:
self.raw[cmd](self,c,n,m)
except TypeError:
self.say(c,n+": Usage: "+self.help[cmd])
2020-01-31 22:34:37 +00:00
2020-01-31 23:00:47 +00:00
if __name__=="__main__":
chans = ['#chaos']
bot = teambot.TeamBot(chans, "circles", "localhost", chandler=Circles)
bot.start()
2020-01-31 16:32:17 +00:00