Skip to content

Commit f29bc77

Browse files
committed
exceptional handling of exception
1 parent afaa578 commit f29bc77

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

doc/example-plugins/canary.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import time
2+
outputs = []
3+
4+
def canary():
5+
#NOTE: you must add a real channel ID for this to work
6+
outputs.append(["D12345678", "bot started: " + str(time.time())])
7+
8+
canary()

rtmbot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@ def output(self):
4444
for plugin in self.bot_plugins:
4545
for output in plugin.do_output():
4646
channel = self.slack_client.server.channels.find(output[0])
47-
channel.send_message("%s" % output[1])
47+
if channel != None:
48+
channel.send_message("%s" % output[1])
49+
else:
50+
raise UnknownChannel
4851
def crons(self):
4952
for plugin in self.bot_plugins:
5053
plugin.do_jobs()
5154
def load_plugins(self):
5255
path = os.path.dirname(sys.argv[0])
5356
for plugin in glob.glob(path+'/plugins/*'):
5457
sys.path.insert(0, plugin)
55-
for plugin in glob.glob(path+'/plugins/*/*.py'):
58+
sys.path.insert(0, path+'/plugins/')
59+
for plugin in glob.glob(path+'/plugins/*.py') + glob.glob(path+'/plugins/*/*.py'):
5660
print plugin
5761
name = plugin.split('/')[-1][:-2]
5862
# try:
@@ -115,6 +119,9 @@ def check(self):
115119
self.lastrun = time.time()
116120
pass
117121

122+
class UnknownChannel(Exception):
123+
pass
124+
118125

119126
if __name__ == "__main__":
120127
config = yaml.load(file('rtmbot.conf', 'r'))

0 commit comments

Comments
 (0)