Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Merge 52c8cef into 006e28f
Browse files Browse the repository at this point in the history
  • Loading branch information
tiphaine committed May 18, 2016
2 parents 006e28f + 52c8cef commit 67fd67b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/example-plugins/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

def say_time():
# NOTE: you must add a real channel ID for this to work
outputs.append(["D12345678", time.time()])
outputs.append(["D12345678", str(time.time())])
30 changes: 18 additions & 12 deletions rtmbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def __init__(self, config):
Params:
- config (dict):
- SLACK_TOKEN: your authentication token from Slack
- BASE_PATH (optional: defaults to execution directory) RtmBot will
look in this directory for plugins.
- LOGFILE (optional: defaults to rtmbot.log) The filename for logs, will
be stored inside the BASE_PATH directory
- DEBUG (optional: defaults to False) with debug enabled, RtmBot will
break on errors
- BASE_PATH (optional: defaults to execution directory)
RtmBot will look in this directory for plugins.
- LOGFILE (optional: defaults to rtmbot.log) The filename
for logs, will be stored inside the BASE_PATH directory
- DEBUG (optional: defaults to False) with debug enabled,
RtmBot will break on errors
'''
# set the config object
self.config = config
Expand Down Expand Up @@ -101,7 +101,7 @@ def output(self):
if limiter:
time.sleep(.1)
limiter = False
message = output[1].encode('ascii', 'ignore')
message = output[1].encode('ascii', 'ignore').decode()
channel.send_message("{}".format(message))
limiter = True

Expand Down Expand Up @@ -132,7 +132,8 @@ def __init__(self, name, plugin_config=None):
- name (str)
- plugin config (dict) - (from the yaml config)
Values in config:
- DEBUG (bool) - this will be overridden if debug is set in config for this plugin
- DEBUG (bool) - this will be overridden if debug is set in
config for this plugin
'''
if plugin_config is None:
plugin_config = {}
Expand All @@ -149,7 +150,8 @@ def __init__(self, name, plugin_config=None):
def register_jobs(self):
if 'crontable' in dir(self.module):
for interval, function in self.module.crontable:
self.jobs.append(Job(interval, eval("self.module." + function), self.debug))
self.jobs.append(
Job(interval, eval("self.module." + function), self.debug))
logging.info(self.module.crontable)
self.module.crontable = []
else:
Expand All @@ -165,7 +167,8 @@ def do(self, function_name, data):
try:
eval("self.module." + function_name)(data)
except Exception:
logging.exception("problem in module {} {}".format(function_name, data))
logging.exception(
"problem in module {} {}".format(function_name, data))
if "catch_all" in dir(self.module):
if self.debug is True:
# this makes the plugin fail with stack trace in debug mode
Expand All @@ -174,7 +177,9 @@ def do(self, function_name, data):
try:
self.module.catch_all(data)
except Exception:
logging.exception("problem in catch all: {} {}".format(self.module, data))
logging.exception(
"problem in catch all: {} {}".format(
self.module, data))

def do_jobs(self):
for job in self.jobs:
Expand Down Expand Up @@ -217,7 +222,8 @@ def check(self):
try:
self.function()
except Exception:
logging.exception("Problem in job check: {}".format(self.function))
logging.exception(
"Problem in job check: {}".format(self.function))
self.lastrun = time.time()


Expand Down

0 comments on commit 67fd67b

Please sign in to comment.