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

Commit b977a7d

Browse files
author
Jeff Ammons
committed
Basic plugin functionality working in repeat.py Plugin
1 parent 5d443a1 commit b977a7d

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

rtmbot/core.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def connect(self):
6767

6868
def _start(self):
6969
self.connect()
70-
self.load_plugins() # <<<<------------------------
70+
self.load_plugins()
7171
while True:
7272
for reply in self.slack_client.rtm_read():
73-
self.input(reply)
73+
self.input(reply) # <<<<------------------------
7474
self.crons()
7575
self.output()
7676
self.autoping()
@@ -176,25 +176,38 @@ def register_jobs(self):
176176
pass
177177

178178
def do(self, function_name, data):
179-
if function_name in dir(self.module):
179+
try:
180+
func = getattr(self, function_name)
181+
except AttributeError:
182+
pass
183+
else:
180184
if self.debug is True:
181185
# this makes the plugin fail with stack trace in debug mode
182-
eval("self.module." + function_name)(data)
186+
func(data)
183187
else:
184188
# otherwise we log the exception and carry on
185189
try:
186-
eval("self.module." + function_name)(data)
190+
func(data)
187191
except Exception:
188-
logging.exception("problem in module {} {}".format(function_name, data))
189-
if "catch_all" in dir(self.module):
192+
logging.exception("Problem in Plugin Class: {}: {} \n{}".format(
193+
self.name, function_name, data)
194+
)
195+
196+
try:
197+
func = getattr(self, 'catch_all')
198+
except AttributeError:
199+
return
200+
else:
190201
if self.debug is True:
191202
# this makes the plugin fail with stack trace in debug mode
192-
self.module.catch_all(data)
203+
self.catch_all(data)
193204
else:
194205
try:
195-
self.module.catch_all(data)
206+
self.catch_all(data)
196207
except Exception:
197-
logging.exception("problem in catch all: {} {}".format(self.module, data))
208+
logging.exception("Problem in catch all: {}: {} {}".format(
209+
self.name, self.module, data)
210+
)
198211

199212
def do_jobs(self):
200213
for job in self.jobs:
@@ -203,14 +216,11 @@ def do_jobs(self):
203216
def do_output(self):
204217
output = []
205218
while True:
206-
if 'outputs' in dir(self.module):
207-
if len(self.module.outputs) > 0:
208-
logging.info("output from {}".format(self.module))
209-
output.append(self.module.outputs.pop(0))
210-
else:
211-
break
219+
if len(self.outputs) > 0:
220+
logging.info("output from {}".format(self.name))
221+
output.append(self.outputs.pop(0))
212222
else:
213-
self.module.outputs = []
223+
break
214224
return output
215225

216226

0 commit comments

Comments
 (0)