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

Commit 0455787

Browse files
author
Jeff Ammons
committed
Clean up docs re: Jobs
Also made a few bug fixes from PR notes.
1 parent 48491a8 commit 0455787

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ A Slack bot written in Python that connects via the RTM API.
88

99
Python-rtmbot is a bot engine. The plugins architecture should be familiar to anyone with knowledge of the [Slack API](https://api.slack.com) and Python. The configuration file format is YAML.
1010

11+
This project is currently pre-1.0. As such, you should plan for it to have breaking changes from time to time. For any breaking changes, we will bump the minor version while we are pre-1.0. (e.g. 0.2.4 -> 0.3.0 implies breaking changes). If stabiilty is important, you'll likely want to lock in a specific minor version)
12+
1113
Some differences to webhooks:
1214

1315
1. Doesn't require a webserver to receive messages
@@ -143,29 +145,29 @@ Plugins also have access to the connected SlackClient instance for more complex
143145
def process_message(self, data):
144146
self.slack_client.api_call(
145147
"chat.postMessage", channel="#general", text="Hello from Python! :tada:",
146-
username='pybot', icon_emoji=':robot_face:'
148+
username="pybot", icon_emoji=":robot_face:"
147149

148150

149151
####Timed jobs
150-
Plugins can also run methods on a schedule. This allows a plugin to poll for updates or perform housekeeping during its lifetime. This is done by appending a two item array to the crontable array. The first item is the interval in seconds and the second item is the method to run. For example, this will print "hello world" every 10 seconds.
152+
Plugins can also run methods on a schedule. This allows a plugin to poll for updates or perform housekeeping during its lifetime. Jobs define a run() method and return any outputs to be sent to channels. They also have access to a SlackClient instance that allows them to make calls to the Slack Web API.
151153

152-
Note that the Job uses the associated Plugin's output array to output back to the RTM stream.
154+
For example, this will print "hello world" every 10 seconds. You can output multiple messages two the same or different channels by passing multiple pairs of [Channel, Message] combos.
153155

154156
from core import Plugin, Job
155157

156158

157159
class myJob(Job):
158160

159-
def say_hello(self):
160-
self.plugin.outputs.append(["C12345667", "hello world"])
161+
def run(self, slack_client):
162+
return [["C12345667", "hello world"]]
161163

162164

163165
class myPlugin(Plugin):
164166

165167
def register_jobs(self):
166-
job = myJob(10, 'say_hello', self.debug, self)
168+
job = myJob(10, debug=True)
167169
self.jobs.append(job)
168170

169171

170172
####Plugin misc
171-
The data within a plugin persists for the life of the rtmbot process. If you need persistent data, you should use something like sqlite or the python pickle libraries.
173+
The data within a plugin persists for the life of the rtmbot process. If you need persistent data, you should use something like sqlite or the python pickle libraries.

rtmbot/bin/run_rtmbot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ def parse_args():
2121

2222

2323
def main(args=None):
24-
# load args with config path
25-
args = parse_args()
24+
# load args with config path if not specified
25+
if not args:
26+
args = parse_args()
27+
2628
config = yaml.load(open(args.config or 'rtmbot.conf', 'r'))
2729
bot = RtmBot(config)
2830
try:

rtmbot/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ def do_jobs(self):
239239

240240
# job attempted execution so reset the timer and log output
241241
job.lastrun = time.time()
242-
self.outputs.append(job_output)
242+
for out in job_output:
243+
self.outputs.append(out)
243244

244245
def do_output(self):
245246
output = []
@@ -292,9 +293,9 @@ def run(self, slack_client):
292293
293294
This method should return an array of outputs in the form of::
294295
295-
[Channel Identifier, Output String]
296+
[[Channel Identifier, Output String]]
296297
or
297-
['C12345678', 'Here's my output for this channel']
298+
[['C12345678', 'Here's my output for this channel'], ['C87654321', 'Different output']
298299
'''
299300
raise NotImplementedError
300301

0 commit comments

Comments
 (0)