In order to make the layout of all bots consistent, this commit
moves each bot into a folder with its name and modifies 'run.py'
so that only bots with such a structure can be executed. 'lib'
gets renamed to 'bots'.
Splitting out some of the bot functions into a library
will make it easier for heavily customized bots to have
their own version of run.py, instead of the shared one
that we use for everyone now. If they use bot_lib.py
directly, they will still most likely conform to
the "Handler" interface as long as they call
run_message_handler_for_bot.
Most bots should continue to use contrib_bots/run.py
for now.
Pressing control-c while run.py is being executed has terminated the
script, but threw an ugly traceback. To signal the user that his
method of exit was appropriate, we handle control-c calling exit(0).
'contribot_bots' should only provide a restricted access to the
client API, yet 'client' and 'rate_limit were fully exposed. While
not fully restricting access to those objects, this commits hides
them with prepending underscores.
To prevent bots from accidently entering an infinite message loop,
where they send messages as a reacting to their own messages,
this commit adds the RateLimit class to run.py. It specifies how
many messages can be sent in a given time interval. If this rate
is exceeded, run.py exits with an error.
Fixes#3210.
Now the development API (which is inside the repo, api/) is used when the envionment is a development one.
Credits to Steve Howell (@showell) for the instructions on how to fix this.
- Expose some information about user profile in `RestrictedClient`
class, like `full_name` and `email` of the user.
- Add `client` argument to `triage_message()`, now it's possible to
call bot with another method instead of calling the specified
keyword.
Allow to import code from subdirectory of `contrib_bots/lib`.
Because sometimes bot requires grouping in their directory,
especially for the bot that has configuartion file and documentation.
This allows bots to be stateful. It doesn't handle persistence
after the bot shuts down, but it does store state between
invocations of handle_message.
This commit also starts to build out the infrastructure for
helping Zulip contributors to more easily author bots in
a way that sets up for running some bots on the server itself.