register command
This commit is contained in:
parent
2a2ada4081
commit
3ec244f557
Binary file not shown.
25
bot.py
25
bot.py
|
@ -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)
|
||||
|
||||
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
# load me
|
||||
|
||||
def test():
|
||||
print('hey')
|
||||
|
||||
def init(self):
|
||||
self.registerCommand('test', test)
|
||||
|
||||
|
Loading…
Reference in New Issue