cleanup
This commit is contained in:
parent
f7d7db682b
commit
7f56355ef7
1 changed files with 11 additions and 13 deletions
24
rtmbot.py
24
rtmbot.py
|
@ -9,6 +9,10 @@ import time
|
||||||
|
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
|
def dbg(debug_string):
|
||||||
|
if debug:
|
||||||
|
print debug_string
|
||||||
|
|
||||||
class RtmBot(object):
|
class RtmBot(object):
|
||||||
def __init__(self, token):
|
def __init__(self, token):
|
||||||
self.token = token
|
self.token = token
|
||||||
|
@ -24,13 +28,13 @@ class RtmBot(object):
|
||||||
while True:
|
while True:
|
||||||
for reply in self.slack_client.read():
|
for reply in self.slack_client.read():
|
||||||
self.input(reply)
|
self.input(reply)
|
||||||
#print self.bot_plugins
|
|
||||||
self.crons()
|
self.crons()
|
||||||
self.output()
|
self.output()
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
def input(self, data):
|
def input(self, data):
|
||||||
if "type" in data:
|
if "type" in data:
|
||||||
function_name = "process_" + data["type"]
|
function_name = "process_" + data["type"]
|
||||||
|
dbg(function_name)
|
||||||
for plugin in self.bot_plugins:
|
for plugin in self.bot_plugins:
|
||||||
plugin.do(function_name, data)
|
plugin.do(function_name, data)
|
||||||
def output(self):
|
def output(self):
|
||||||
|
@ -38,23 +42,18 @@ class RtmBot(object):
|
||||||
for output in plugin.do_output():
|
for output in plugin.do_output():
|
||||||
channel = self.slack_client.server.channels.find(output[0])
|
channel = self.slack_client.server.channels.find(output[0])
|
||||||
channel.send_message("%s" % output[1])
|
channel.send_message("%s" % output[1])
|
||||||
#plugin.do_output()
|
|
||||||
pass
|
|
||||||
#print self.bot_plugins[plugin].replies()
|
|
||||||
def crons(self):
|
def crons(self):
|
||||||
for plugin in self.bot_plugins:
|
for plugin in self.bot_plugins:
|
||||||
plugin.do_jobs()
|
plugin.do_jobs()
|
||||||
pass
|
|
||||||
#print job
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
path = os.path.dirname(sys.argv[0])
|
path = os.path.dirname(sys.argv[0])
|
||||||
sys.path.insert(0, path + "/plugins")
|
sys.path.insert(0, path + "/plugins")
|
||||||
for plugin in glob.glob(path+'/plugins/*.py'):
|
for plugin in glob.glob(path+'/plugins/*.py'):
|
||||||
name = plugin.split('/')[-1].rstrip('.py')
|
name = plugin.split('/')[-1][:-2]
|
||||||
# try:
|
try:
|
||||||
self.bot_plugins.append(Plugin(name))
|
self.bot_plugins.append(Plugin(name))
|
||||||
# except:
|
except:
|
||||||
# print "error loading plugins"
|
print "error loading plugin %s" % name
|
||||||
|
|
||||||
class Plugin(object):
|
class Plugin(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
@ -101,9 +100,8 @@ class Job(object):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
proc = {k[8:]: v for k, v in globals().items() if k.startswith("process_")}
|
|
||||||
config = yaml.load(file('rtmbot.conf', 'r'))
|
config = yaml.load(file('rtmbot.conf', 'r'))
|
||||||
|
debug = config["DEBUG"]
|
||||||
bot = RtmBot(config["SLACK_TOKEN"])
|
bot = RtmBot(config["SLACK_TOKEN"])
|
||||||
bot.start()
|
bot.start()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue