bots: Add --config-file to contrib_bots/run.py.

This commit is contained in:
Steve Howell 2016-08-24 12:09:11 -07:00
parent e08323c143
commit 05191181d9
2 changed files with 24 additions and 4 deletions

View file

@ -30,7 +30,7 @@ Here is an example of running the "follow-up" bot from
inside a Zulip repo: inside a Zulip repo:
cd ~/zulip/contrib_bots cd ~/zulip/contrib_bots
python run.py lib/followup.py python run.py lib/followup.py --config-file ~/.zuliprc-prod
Once the bot code starts running, you will see a Once the bot code starts running, you will see a
message explaining how to use the bot, as well as message explaining how to use the bot, as well as
@ -40,6 +40,19 @@ to suppress these messages.
The bot code will run continuously until you kill them with The bot code will run continuously until you kill them with
control-C (or otherwise). control-C (or otherwise).
### Configuration
For this document we assume you have some prior experience
with using the Zulip API, but here is a quick review of
what a `.zuliprc` files looks like. You can connect to the
API as your own human user, or you can go into the Zulip settings
page to create a user-owned bot.
[api]
email=someuser@example.com
key=<your api key>
site=https://zulip.somewhere.com
## Architecture ## Architecture
In order to make bot development easy, we separate In order to make bot development easy, we separate

View file

@ -35,9 +35,9 @@ def get_lib_module(lib_fn):
module = importlib.import_module(module_name) module = importlib.import_module(module_name)
return module return module
def run_message_handler_for_bot(lib_module, quiet): def run_message_handler_for_bot(lib_module, quiet, config_file):
# Make sure you set up your ~/.zuliprc # Make sure you set up your ~/.zuliprc
client = Client() client = Client(config_file=config_file)
restricted_client = RestrictedClient(client) restricted_client = RestrictedClient(client)
message_handler = lib_module.handler_class() message_handler = lib_module.handler_class()
@ -76,6 +76,9 @@ def run():
parser.add_option('--quiet', '-q', parser.add_option('--quiet', '-q',
action='store_true', action='store_true',
help='Turn off logging output.') help='Turn off logging output.')
parser.add_option('--config-file',
action='store',
help='(alternate config file to ~/.zuliprc)')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if len(args) == 0:
@ -87,7 +90,11 @@ def run():
if not options.quiet: if not options.quiet:
logging.basicConfig(stream=sys.stdout, level=logging.INFO) logging.basicConfig(stream=sys.stdout, level=logging.INFO)
run_message_handler_for_bot(lib_module, quiet=options.quiet) run_message_handler_for_bot(
lib_module=lib_module,
config_file=options.config_file,
quiet=options.quiet
)
if __name__ == '__main__': if __name__ == '__main__':
run() run()