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 acb3c6b75a
commit 6af0bdfe6e
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:
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
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
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
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)
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
client = Client()
client = Client(config_file=config_file)
restricted_client = RestrictedClient(client)
message_handler = lib_module.handler_class()
@ -76,6 +76,9 @@ def run():
parser.add_option('--quiet', '-q',
action='store_true',
help='Turn off logging output.')
parser.add_option('--config-file',
action='store',
help='(alternate config file to ~/.zuliprc)')
(options, args) = parser.parse_args()
if len(args) == 0:
@ -87,7 +90,11 @@ def run():
if not options.quiet:
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__':
run()