exceptional handling of exception
This commit is contained in:
parent
afaa57878b
commit
f29bc7764d
2 changed files with 17 additions and 2 deletions
8
doc/example-plugins/canary.py
Normal file
8
doc/example-plugins/canary.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import time
|
||||||
|
outputs = []
|
||||||
|
|
||||||
|
def canary():
|
||||||
|
#NOTE: you must add a real channel ID for this to work
|
||||||
|
outputs.append(["D12345678", "bot started: " + str(time.time())])
|
||||||
|
|
||||||
|
canary()
|
|
@ -44,7 +44,10 @@ class RtmBot(object):
|
||||||
for plugin in self.bot_plugins:
|
for plugin in self.bot_plugins:
|
||||||
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])
|
||||||
|
if channel != None:
|
||||||
channel.send_message("%s" % output[1])
|
channel.send_message("%s" % output[1])
|
||||||
|
else:
|
||||||
|
raise UnknownChannel
|
||||||
def crons(self):
|
def crons(self):
|
||||||
for plugin in self.bot_plugins:
|
for plugin in self.bot_plugins:
|
||||||
plugin.do_jobs()
|
plugin.do_jobs()
|
||||||
|
@ -52,7 +55,8 @@ class RtmBot(object):
|
||||||
path = os.path.dirname(sys.argv[0])
|
path = os.path.dirname(sys.argv[0])
|
||||||
for plugin in glob.glob(path+'/plugins/*'):
|
for plugin in glob.glob(path+'/plugins/*'):
|
||||||
sys.path.insert(0, plugin)
|
sys.path.insert(0, plugin)
|
||||||
for plugin in glob.glob(path+'/plugins/*/*.py'):
|
sys.path.insert(0, path+'/plugins/')
|
||||||
|
for plugin in glob.glob(path+'/plugins/*.py') + glob.glob(path+'/plugins/*/*.py'):
|
||||||
print plugin
|
print plugin
|
||||||
name = plugin.split('/')[-1][:-2]
|
name = plugin.split('/')[-1][:-2]
|
||||||
# try:
|
# try:
|
||||||
|
@ -115,6 +119,9 @@ class Job(object):
|
||||||
self.lastrun = time.time()
|
self.lastrun = time.time()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class UnknownChannel(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
config = yaml.load(file('rtmbot.conf', 'r'))
|
config = yaml.load(file('rtmbot.conf', 'r'))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue