register command

This commit is contained in:
lickthecheese 2020-01-31 17:17:11 -05:00
parent 2a2ada4081
commit 3ec244f557
5 changed files with 32 additions and 2 deletions

Binary file not shown.

25
bot.py
View File

@ -1,7 +1,28 @@
#!/usr/bin/env python3
import teambot, sys, os
class Cirles(teambot.Handler):
class Circles(teambot.Handler):
def __init__(self, bot):
self.modules = []
self.cmd = {}
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)
m.init()
self.modules.append(m)
def registerCommand(self, txt, func):
self.cmd[txt] = func
def on_connection_established(self):
self.loadMods()
def on_pubmessage(self,c,n,m):
if m.startswith(self.prefix):
args = m[len(self.prefix):].strip().split()
cmd = args.pop
if cmd in self.cmd:
self.cmd[cmd](self,c,n,m)

View File

Binary file not shown.

9
modules/loadme.py Normal file
View File

@ -0,0 +1,9 @@
# load me
def test():
print('hey')
def init(self):
self.registerCommand('test', test)