make plugins dir based

This commit is contained in:
Ryan Huber 2014-11-17 21:17:37 -08:00
parent 29fbb30c75
commit 3d07cf6ecf
4 changed files with 14 additions and 31 deletions

View file

@ -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()])

View file

@ -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']])

View file

@ -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']])

View file

@ -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()