From 3d07cf6ecf2882f7ae60b0a174a91f4332bbaa08 Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Mon, 17 Nov 2014 21:17:37 -0800 Subject: [PATCH] make plugins dir based --- plugins/example/counter.py | 9 --------- plugins/example/repeat.py | 8 -------- plugins/example/repeat2.py | 8 -------- rtmbot.py | 20 ++++++++++++++------ 4 files changed, 14 insertions(+), 31 deletions(-) delete mode 100644 plugins/example/counter.py delete mode 100644 plugins/example/repeat.py delete mode 100644 plugins/example/repeat2.py diff --git a/plugins/example/counter.py b/plugins/example/counter.py deleted file mode 100644 index 5846c94..0000000 --- a/plugins/example/counter.py +++ /dev/null @@ -1,9 +0,0 @@ -import time -crontable = [] -outputs = [] - -#crontable.append([.5,"add_number"]) -crontable.append([5,"say_time"]) - -def say_time(): - outputs.append(["D030GJLM2", time.time()]) diff --git a/plugins/example/repeat.py b/plugins/example/repeat.py deleted file mode 100644 index e13a51b..0000000 --- a/plugins/example/repeat.py +++ /dev/null @@ -1,8 +0,0 @@ -import time -crontable = [] -outputs = [] - -def process_message(data): - if data['channel'].startswith("D"): - outputs.append([data['channel'], "from repeat1: " + data['text']]) - diff --git a/plugins/example/repeat2.py b/plugins/example/repeat2.py deleted file mode 100644 index 95738fc..0000000 --- a/plugins/example/repeat2.py +++ /dev/null @@ -1,8 +0,0 @@ -import time -crontable = [] -outputs = [] - -def process_message(data): - if data['channel'].startswith("D"): - outputs.append([data['channel'], "from repeat2: " + data['text']]) - diff --git a/rtmbot.py b/rtmbot.py index d89a629..958e1d9 100755 --- a/rtmbot.py +++ b/rtmbot.py @@ -1,5 +1,8 @@ #!/usr/bin/python +import sys +sys.dont_write_bytecode = True + import glob import yaml import json @@ -47,13 +50,15 @@ class RtmBot(object): plugin.do_jobs() def load_plugins(self): path = os.path.dirname(sys.argv[0]) - sys.path.insert(0, path + "/plugins") - for plugin in glob.glob(path+'/plugins/*.py'): + for plugin in glob.glob(path+'/plugins/*'): + sys.path.insert(0, plugin) + for plugin in glob.glob(path+'/plugins/*/*.py'): + print plugin name = plugin.split('/')[-1][:-2] - try: - self.bot_plugins.append(Plugin(name)) - except: - print "error loading plugin %s" % name +# try: + self.bot_plugins.append(Plugin(name)) +# except: +# print "error loading plugin %s" % name class Plugin(object): def __init__(self, name): @@ -69,7 +74,10 @@ class Plugin(object): print self.module.crontable def do(self, function_name, data): if function_name in dir(self.module): +# try: eval("self.module."+function_name)(data) +# except: +# dbg("problem in module") def do_jobs(self): for job in self.jobs: job.check()