From 879f44ab3a25f64575592b76d0f3a918093dddb5 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Tue, 18 Jul 2017 01:47:16 -0230 Subject: [PATCH] bots: Move all bots and the bots API to separate package. --- .gitignore | 1 - bots_api/run.py | 86 ------------------ {bots_api => tools}/test-bots | 10 +- zulip_bots/MANIFEST.in | 5 + bots/readme.md => zulip_bots/README.md | 12 ++- zulip_bots/setup.py | 78 ++++++++++++++++ {bots => zulip_bots/zulip_bots}/.gitignore | 0 {bots => zulip_bots/zulip_bots}/__init__.py | 0 .../zulip_bots/bots}/__init__.py | 0 .../zulip_bots/bots/commute}/__init__.py | 0 .../zulip_bots/bots}/commute/commute.conf | 0 .../zulip_bots/bots}/commute/commute.py | 0 .../zulip_bots/bots}/commute/readme.md | 0 .../zulip_bots/bots/converter}/__init__.py | 0 .../converter/assets/multiple-converts.png | Bin .../bots}/converter/converter.config | 0 .../zulip_bots/bots}/converter/converter.py | 3 +- .../zulip_bots/bots}/converter/readme.md | 0 .../bots}/converter/test_converter.py | 2 +- .../zulip_bots/bots}/converter/utils.py | 0 .../zulip_bots/bots/define}/__init__.py | 0 .../bots}/define/assets/correct_word.png | Bin .../bots}/define/assets/wrong_word.png | Bin .../zulip_bots/bots}/define/define.py | 0 .../zulip_bots/bots}/define/readme.md | 0 .../zulip_bots/bots}/define/requirements.txt | 0 .../zulip_bots/bots}/define/test_define.py | 2 +- .../zulip_bots/bots/encrypt}/__init__.py | 0 .../encrypt/assets/EncryptBot-terminal.png | Bin .../bots}/encrypt/assets/EncryptBot-test.png | Bin .../bots}/encrypt/assets/EncryptBot-test2.png | Bin .../bots}/encrypt/assets/EncryptBot-test3.png | Bin .../zulip_bots/bots}/encrypt/encrypt.py | 0 .../zulip_bots/bots}/encrypt/readme.md | 0 .../zulip_bots/bots}/encrypt/test_encrypt.py | 2 +- .../zulip_bots/bots/followup}/__init__.py | 0 .../zulip_bots/bots}/followup/followup.py | 0 .../bots}/followup/test_followup.py | 2 +- .../zulip_bots/bots/foursquare}/__init__.py | 0 .../bots}/foursquare/foursquare.conf | 0 .../zulip_bots/bots}/foursquare/foursquare.py | 0 .../zulip_bots/bots}/foursquare/readme.md | 0 .../zulip_bots/bots/giphy}/__init__.py | 0 .../bots}/giphy/fixtures/test_1.json | 0 .../zulip_bots/bots}/giphy/giphy.py | 0 .../zulip_bots/bots}/giphy/test_giphy.py | 2 +- .../bots/git_hub_comment}/__init__.py | 0 .../bots}/git_hub_comment/git_hub_comment.py | 0 .../bots}/git_hub_comment/readme.md | 4 +- .../zulip_bots/bots/github}/__init__.py | 0 .../zulip_bots/bots}/github/github.py | 0 .../bots/github_detail}/__init__.py | 0 .../github_detail/fixtures/test_404.json | 0 .../github_detail/fixtures/test_issue.json | 0 .../github_detail/fixtures/test_pull.json | 0 .../bots}/github_detail/github_detail.py | 0 .../zulip_bots/bots}/github_detail/readme.md | 0 .../bots}/github_detail/test_github_detail.py | 9 +- .../bots/github_issues}/__init__.py | 0 .../bots}/github_issues/github_issues.py | 0 .../zulip_bots/bots/googlesearch}/__init__.py | 0 .../bots}/googlesearch/googlesearch.py | 0 .../zulip_bots/bots}/googlesearch/readme.md | 0 .../zulip_bots/bots/helloworld}/__init__.py | 0 .../zulip_bots/bots}/helloworld/helloworld.py | 0 .../zulip_bots/bots}/helloworld/readme.md | 0 .../bots}/helloworld/test_helloworld.py | 2 +- .../zulip_bots/bots/help}/__init__.py | 0 .../zulip_bots/bots}/help/help.py | 0 .../zulip_bots/bots}/help/test_help.py | 2 +- .../zulip_bots/bots/howdoi}/__init__.py | 0 .../bots}/howdoi/assets/answer_howdoi_all.png | Bin .../bots}/howdoi/assets/answer_howdowe.png | Bin .../howdoi/assets/question_howdoi_all.png | Bin .../bots}/howdoi/assets/question_howdowe.png | Bin .../zulip_bots/bots}/howdoi/howdoi.py | 0 .../zulip_bots/bots}/howdoi/readme.md | 0 .../zulip_bots/bots/incrementor}/__init__.py | 0 .../bots}/incrementor/incrementor.py | 0 .../zulip_bots/bots}/incrementor/readme.md | 0 .../zulip_bots/bots/john}/__init__.py | 0 .../zulip_bots/bots}/john/assets/assist.png | Bin .../bots}/john/assets/greetings.png | Bin .../zulip_bots/bots}/john/assets/joke.png | Bin .../bots}/john/assets/var/jokes.json | 0 .../zulip_bots/bots}/john/john.py | 4 - .../zulip_bots/bots}/john/readme.md | 0 .../zulip_bots/bots/thesaurus}/__init__.py | 0 .../bots}/thesaurus/requirements.txt | 0 .../bots}/thesaurus/test_thesaurus.py | 2 +- .../zulip_bots/bots}/thesaurus/thesaurus.py | 0 .../zulip_bots/bots/tictactoe}/__init__.py | 0 .../zulip_bots/bots}/tictactoe/readme.md | 0 .../zulip_bots/bots}/tictactoe/tictactoe.py | 0 .../zulip_bots/bots/virtual_fs}/__init__.py | 0 .../zulip_bots/bots}/virtual_fs/readme.md | 0 .../bots}/virtual_fs/test_virtual_fs.py | 2 +- .../zulip_bots/bots}/virtual_fs/virtual_fs.py | 0 .../zulip_bots/bots/weather}/__init__.py | 0 .../bots}/weather/assets/screen1.png | Bin .../bots}/weather/assets/screen2.png | Bin .../zulip_bots/bots}/weather/readme.md | 0 .../zulip_bots/bots}/weather/weather.conf | 0 .../zulip_bots/bots}/weather/weather.py | 0 .../zulip_bots/bots/wikipedia}/__init__.py | 0 .../bots}/wikipedia/test_wikipedia.py | 2 +- .../zulip_bots/bots}/wikipedia/wikipedia.py | 0 .../zulip_bots/bots/xkcd}/__init__.py | 0 .../bots}/xkcd/assets/xkcd-help.png | Bin .../bots}/xkcd/assets/xkcd-latest.png | Bin .../bots}/xkcd/assets/xkcd-random.png | Bin .../bots}/xkcd/assets/xkcd-specific-id.png | Bin .../bots}/xkcd/assets/xkcd-wrong-command.png | Bin .../bots}/xkcd/assets/xkcd-wrong-id.png | Bin .../zulip_bots/bots}/xkcd/readme.md | 0 .../zulip_bots/bots}/xkcd/test_xkcd.py | 2 +- .../zulip_bots/bots}/xkcd/xkcd.py | 0 .../zulip_bots/bots/yoda}/__init__.py | 0 .../bots}/yoda/assets/yoda-speak-api.png | Bin .../zulip_bots/bots}/yoda/readme.md | 2 +- .../zulip_bots/bots}/yoda/yoda.conf | 0 .../zulip_bots/bots}/yoda/yoda.py | 0 .../zulip_bots/bots/youtube}/__init__.py | 0 .../bots}/youtube/assets/screen.png | Bin .../zulip_bots/bots}/youtube/readme.md | 0 .../zulip_bots/bots}/youtube/youtube.py | 0 .../zulip_bots/lib.py | 11 +-- .../zulip_bots}/provision.py | 2 +- zulip_bots/zulip_bots/run.py | 62 +++++++++++++ .../zulip_bots/test_lib.py | 16 ++-- 130 files changed, 183 insertions(+), 144 deletions(-) delete mode 100755 bots_api/run.py rename {bots_api => tools}/test-bots (89%) create mode 100644 zulip_bots/MANIFEST.in rename bots/readme.md => zulip_bots/README.md (95%) create mode 100755 zulip_bots/setup.py rename {bots => zulip_bots/zulip_bots}/.gitignore (100%) rename {bots => zulip_bots/zulip_bots}/__init__.py (100%) rename {bots/commute => zulip_bots/zulip_bots/bots}/__init__.py (100%) rename {bots/converter => zulip_bots/zulip_bots/bots/commute}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/commute/commute.conf (100%) rename {bots => zulip_bots/zulip_bots/bots}/commute/commute.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/commute/readme.md (100%) rename {bots/define => zulip_bots/zulip_bots/bots/converter}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/converter/assets/multiple-converts.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/converter/converter.config (100%) rename {bots => zulip_bots/zulip_bots/bots}/converter/converter.py (99%) rename {bots => zulip_bots/zulip_bots/bots}/converter/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/converter/test_converter.py (94%) mode change 100644 => 100755 rename {bots => zulip_bots/zulip_bots/bots}/converter/utils.py (100%) rename {bots/encrypt => zulip_bots/zulip_bots/bots/define}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/define/assets/correct_word.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/define/assets/wrong_word.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/define/define.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/define/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/define/requirements.txt (100%) rename {bots => zulip_bots/zulip_bots/bots}/define/test_define.py (94%) mode change 100644 => 100755 rename {bots/followup => zulip_bots/zulip_bots/bots/encrypt}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/assets/EncryptBot-terminal.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/assets/EncryptBot-test.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/assets/EncryptBot-test2.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/assets/EncryptBot-test3.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/encrypt.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/encrypt/test_encrypt.py (93%) mode change 100644 => 100755 rename {bots/foursquare => zulip_bots/zulip_bots/bots/followup}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/followup/followup.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/followup/test_followup.py (95%) mode change 100644 => 100755 rename {bots/giphy => zulip_bots/zulip_bots/bots/foursquare}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/foursquare/foursquare.conf (100%) rename {bots => zulip_bots/zulip_bots/bots}/foursquare/foursquare.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/foursquare/readme.md (100%) rename {bots/git_hub_comment => zulip_bots/zulip_bots/bots/giphy}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/giphy/fixtures/test_1.json (100%) rename {bots => zulip_bots/zulip_bots/bots}/giphy/giphy.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/giphy/test_giphy.py (94%) mode change 100644 => 100755 rename {bots/github => zulip_bots/zulip_bots/bots/git_hub_comment}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/git_hub_comment/git_hub_comment.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/git_hub_comment/readme.md (95%) rename {bots/github_detail => zulip_bots/zulip_bots/bots/github}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/github/github.py (100%) rename {bots/github_issues => zulip_bots/zulip_bots/bots/github_detail}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_detail/fixtures/test_404.json (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_detail/fixtures/test_issue.json (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_detail/fixtures/test_pull.json (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_detail/github_detail.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_detail/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_detail/test_github_detail.py (93%) mode change 100644 => 100755 rename {bots/googlesearch => zulip_bots/zulip_bots/bots/github_issues}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/github_issues/github_issues.py (100%) rename {bots/helloworld => zulip_bots/zulip_bots/bots/googlesearch}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/googlesearch/googlesearch.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/googlesearch/readme.md (100%) rename {bots/help => zulip_bots/zulip_bots/bots/helloworld}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/helloworld/helloworld.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/helloworld/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/helloworld/test_helloworld.py (89%) mode change 100644 => 100755 rename {bots/howdoi => zulip_bots/zulip_bots/bots/help}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/help/help.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/help/test_help.py (90%) mode change 100644 => 100755 rename {bots/incrementor => zulip_bots/zulip_bots/bots/howdoi}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/howdoi/assets/answer_howdoi_all.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/howdoi/assets/answer_howdowe.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/howdoi/assets/question_howdoi_all.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/howdoi/assets/question_howdowe.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/howdoi/howdoi.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/howdoi/readme.md (100%) rename {bots/john => zulip_bots/zulip_bots/bots/incrementor}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/incrementor/incrementor.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/incrementor/readme.md (100%) rename {bots/thesaurus => zulip_bots/zulip_bots/bots/john}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/john/assets/assist.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/john/assets/greetings.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/john/assets/joke.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/john/assets/var/jokes.json (100%) rename {bots => zulip_bots/zulip_bots/bots}/john/john.py (97%) rename {bots => zulip_bots/zulip_bots/bots}/john/readme.md (100%) rename {bots/tictactoe => zulip_bots/zulip_bots/bots/thesaurus}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/thesaurus/requirements.txt (100%) rename {bots => zulip_bots/zulip_bots/bots}/thesaurus/test_thesaurus.py (95%) mode change 100644 => 100755 rename {bots => zulip_bots/zulip_bots/bots}/thesaurus/thesaurus.py (100%) rename {bots/virtual_fs => zulip_bots/zulip_bots/bots/tictactoe}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/tictactoe/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/tictactoe/tictactoe.py (100%) rename {bots/weather => zulip_bots/zulip_bots/bots/virtual_fs}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/virtual_fs/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/virtual_fs/test_virtual_fs.py (98%) mode change 100644 => 100755 rename {bots => zulip_bots/zulip_bots/bots}/virtual_fs/virtual_fs.py (100%) rename {bots/wikipedia => zulip_bots/zulip_bots/bots/weather}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/weather/assets/screen1.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/weather/assets/screen2.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/weather/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/weather/weather.conf (100%) rename {bots => zulip_bots/zulip_bots/bots}/weather/weather.py (100%) rename {bots/xkcd => zulip_bots/zulip_bots/bots/wikipedia}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/wikipedia/test_wikipedia.py (94%) mode change 100644 => 100755 rename {bots => zulip_bots/zulip_bots/bots}/wikipedia/wikipedia.py (100%) rename {bots/yoda => zulip_bots/zulip_bots/bots/xkcd}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/assets/xkcd-help.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/assets/xkcd-latest.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/assets/xkcd-random.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/assets/xkcd-specific-id.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/assets/xkcd-wrong-command.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/assets/xkcd-wrong-id.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/xkcd/test_xkcd.py (96%) mode change 100644 => 100755 rename {bots => zulip_bots/zulip_bots/bots}/xkcd/xkcd.py (100%) rename {bots/youtube => zulip_bots/zulip_bots/bots/yoda}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/yoda/assets/yoda-speak-api.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/yoda/readme.md (97%) rename {bots => zulip_bots/zulip_bots/bots}/yoda/yoda.conf (100%) rename {bots => zulip_bots/zulip_bots/bots}/yoda/yoda.py (100%) rename {bots_api => zulip_bots/zulip_bots/bots/youtube}/__init__.py (100%) rename {bots => zulip_bots/zulip_bots/bots}/youtube/assets/screen.png (100%) rename {bots => zulip_bots/zulip_bots/bots}/youtube/readme.md (100%) rename {bots => zulip_bots/zulip_bots/bots}/youtube/youtube.py (100%) rename bots_api/bot_lib.py => zulip_bots/zulip_bots/lib.py (95%) rename {bots_api => zulip_bots/zulip_bots}/provision.py (99%) create mode 100755 zulip_bots/zulip_bots/run.py rename bots_api/bots_test_lib.py => zulip_bots/zulip_bots/test_lib.py (91%) mode change 100644 => 100755 diff --git a/.gitignore b/.gitignore index 45b83ef..48f0ea8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ dist build eggs parts -var sdist develop-eggs .installed.cfg diff --git a/bots_api/run.py b/bots_api/run.py deleted file mode 100755 index afa95de..0000000 --- a/bots_api/run.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python -from __future__ import print_function -from __future__ import absolute_import - -import importlib -import logging -import optparse -import os -import sys -import provision -from types import ModuleType - -our_dir = os.path.dirname(os.path.abspath(__file__)) -sys.path.insert(0, our_dir) - -from bot_lib import run_message_handler_for_bot - -def validate_path(bots_fn): - # type: (str) -> None - bots_fn = os.path.realpath(bots_fn) - if not os.path.dirname(bots_fn).startswith(os.path.normpath(os.path.join(our_dir, "../bots"))): - print('Sorry, we will only import code from api/bots.') - sys.exit(1) - - if not bots_fn.endswith('.py'): - print('Please use a .py extension for library files.') - sys.exit(1) - -def get_lib_module(bots_fn): - # type: (str) -> ModuleType - base_bots_fn = os.path.basename(os.path.splitext(bots_fn)[0]) - sys.path.insert(1, os.path.dirname(bots_fn)) - module_name = base_bots_fn - module = importlib.import_module(module_name) - return module - -def run(): - # type: () -> None - usage = ''' - ./run.py - Example: ./run.py lib/followup.py - (This program loads bot-related code from the - library code and then runs a message loop, - feeding messages to the library code to handle.) - Please make sure you have a current ~/.zuliprc - file with the credentials you want to use for - this bot. - See lib/readme.md for more context. - ''' - - parser = optparse.OptionParser(usage=usage) - 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)') - parser.add_option('--provision', - action='store_true', - help='Install dependencies for the bot') - parser.add_option('--force', - action='store_true', - help='Try running the bot even if dependencies install fails.') - (options, args) = parser.parse_args() - - if len(args) == 0: - print('You must specify a library!') - sys.exit(1) - bots_fn = args[0] - - validate_path(bots_fn) - if options.provision: - print("Provisioning") - provision.provision_bot(os.path.dirname(bots_fn), options.force) - lib_module = get_lib_module(bots_fn) - if not options.quiet: - logging.basicConfig(stream=sys.stdout, level=logging.INFO) - - run_message_handler_for_bot( - lib_module=lib_module, - config_file=options.config_file, - quiet=options.quiet - ) - -if __name__ == '__main__': - run() diff --git a/bots_api/test-bots b/tools/test-bots similarity index 89% rename from bots_api/test-bots rename to tools/test-bots index 8761625..9cdb0d5 100755 --- a/bots_api/test-bots +++ b/tools/test-bots @@ -17,11 +17,11 @@ def dir_join(dir1, dir2): if __name__ == '__main__': - bots_dir = os.path.dirname(os.path.abspath(__file__)) - root_dir = dir_join(bots_dir, '..') - bots_test_dir = dir_join(bots_dir, '../bots') + tools_dir = os.path.dirname(os.path.abspath(__file__)) + bots_dir = os.path.join(tools_dir, '..', 'zulip_bots', 'zulip_bots') + bots_test_dir = dir_join(bots_dir, 'bots') - sys.path.insert(0, root_dir) + sys.path.insert(0, bots_dir) sys.path.insert(0, bots_test_dir) btd = bots_test_dir @@ -57,7 +57,7 @@ if __name__ == '__main__': sys.path.insert(0, dep_path) try: suites.append(loader.discover(start_dir = dir_join(bots_test_dir, bot_to_test), - top_level_dir = root_dir)) + top_level_dir = bots_dir)) except ImportError: logging.error("Bot %s requires __init__.py to be added" % (bot_to_test)) failed = True diff --git a/zulip_bots/MANIFEST.in b/zulip_bots/MANIFEST.in new file mode 100644 index 0000000..4d7887c --- /dev/null +++ b/zulip_bots/MANIFEST.in @@ -0,0 +1,5 @@ +include zulip_bots/bots/giphy/fixtures/test_1.json +include zulip_bots/bots/github_detail/fixtures/test_404.json +include zulip_bots/bots/github_detail/fixtures/test_issue.json +include zulip_bots/bots/github_detail/fixtures/test_pull.json + diff --git a/bots/readme.md b/zulip_bots/README.md similarity index 95% rename from bots/readme.md rename to zulip_bots/README.md index 85a37e8..0a30285 100644 --- a/bots/readme.md +++ b/zulip_bots/README.md @@ -24,13 +24,17 @@ to messages in any of the following settings: account specific authentication, for example: a gmail bot that lets one send emails directly through Zulip. +## Installing + +To install the bots and bots API, run: + + python setup.py install + ## Running bots -Here is an example of running the "follow-up" bot from -inside a Zulip repo (and in your remote instance): +Here is an example of running the "follow-up" bot: - cd ~/zulip/api - bots_api/run.py bots/followup/followup.py --config-file ~/.zuliprc-prod + zulip-run-bot followup --config-file ~/.zuliprc-prod Once the bot code starts running, you will see a message explaining how to use the bot, as well as diff --git a/zulip_bots/setup.py b/zulip_bots/setup.py new file mode 100755 index 0000000..fe62338 --- /dev/null +++ b/zulip_bots/setup.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function + +import sys + +# We should be installable with either setuptools or distutils. +package_info = dict( + name='zulip_bots', + version='0.3.1', + description='Zulip\'s Bot framework', + author='Zulip Open Source Project', + author_email='zulip-devel@googlegroups.com', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Topic :: Communications :: Chat', + ], + url='https://www.zulip.org/', + entry_points={ + 'console_scripts': [ + 'zulip-run-bot=zulip_bots.run:main', + ], + }, + include_package_data=True, +) # type: Dict[str, Any] + +setuptools_info = dict( + install_requires=[ + 'zulip>=0.3.1', + 'mock>=2.0.0', + 'html2text', # for bots/define + 'PyDictionary', # for bots/thesaurus + ], +) + +try: + from setuptools import setup, find_packages + package_info.update(setuptools_info) + package_info['packages'] = find_packages() + +except ImportError: + from distutils.core import setup + from distutils.version import LooseVersion + from importlib import import_module + + # Manual dependency check + def check_dependency_manually(module_name, version=None): + try: + module = import_module(module_name) + if version is not None: + assert(LooseVersion(module.__version__) >= LooseVersion(version)) + except (ImportError, AssertionError): + if version is not None: + print("{name}>={version} is not installed.".format( + req=req, version=version), file=sys.stderr) + else: + print("{name} is not installed.".format(name=module_name), file=sys.stderr) + sys.exit(1) + + check_dependency_manually('zulip', '0.3.1') + check_dependency_manually('mock', '2.0.0') + check_dependency_manually('html2text') + check_dependency_manually('PyDictionary') + + # Include all submodules under bots/ + package_list = ['zulip_bots'] + dirs = os.listdir('zulip_bots/bots/') + for dir_name in dirs: + if os.path.isdir(os.path.join('zulip_bots/bots/', dir_name)): + package_list.append('zulip_bots.bots.' + dir_name) + package_info['packages'] = package_list + + +setup(**package_info) diff --git a/bots/.gitignore b/zulip_bots/zulip_bots/.gitignore similarity index 100% rename from bots/.gitignore rename to zulip_bots/zulip_bots/.gitignore diff --git a/bots/__init__.py b/zulip_bots/zulip_bots/__init__.py similarity index 100% rename from bots/__init__.py rename to zulip_bots/zulip_bots/__init__.py diff --git a/bots/commute/__init__.py b/zulip_bots/zulip_bots/bots/__init__.py similarity index 100% rename from bots/commute/__init__.py rename to zulip_bots/zulip_bots/bots/__init__.py diff --git a/bots/converter/__init__.py b/zulip_bots/zulip_bots/bots/commute/__init__.py similarity index 100% rename from bots/converter/__init__.py rename to zulip_bots/zulip_bots/bots/commute/__init__.py diff --git a/bots/commute/commute.conf b/zulip_bots/zulip_bots/bots/commute/commute.conf similarity index 100% rename from bots/commute/commute.conf rename to zulip_bots/zulip_bots/bots/commute/commute.conf diff --git a/bots/commute/commute.py b/zulip_bots/zulip_bots/bots/commute/commute.py similarity index 100% rename from bots/commute/commute.py rename to zulip_bots/zulip_bots/bots/commute/commute.py diff --git a/bots/commute/readme.md b/zulip_bots/zulip_bots/bots/commute/readme.md similarity index 100% rename from bots/commute/readme.md rename to zulip_bots/zulip_bots/bots/commute/readme.md diff --git a/bots/define/__init__.py b/zulip_bots/zulip_bots/bots/converter/__init__.py similarity index 100% rename from bots/define/__init__.py rename to zulip_bots/zulip_bots/bots/converter/__init__.py diff --git a/bots/converter/assets/multiple-converts.png b/zulip_bots/zulip_bots/bots/converter/assets/multiple-converts.png similarity index 100% rename from bots/converter/assets/multiple-converts.png rename to zulip_bots/zulip_bots/bots/converter/assets/multiple-converts.png diff --git a/bots/converter/converter.config b/zulip_bots/zulip_bots/bots/converter/converter.config similarity index 100% rename from bots/converter/converter.config rename to zulip_bots/zulip_bots/bots/converter/converter.config diff --git a/bots/converter/converter.py b/zulip_bots/zulip_bots/bots/converter/converter.py similarity index 99% rename from bots/converter/converter.py rename to zulip_bots/zulip_bots/bots/converter/converter.py index a84de5a..1e50916 100644 --- a/bots/converter/converter.py +++ b/zulip_bots/zulip_bots/bots/converter/converter.py @@ -5,11 +5,10 @@ from __future__ import division import copy import importlib -import sys from math import log10, floor -import utils import re +from zulip_bots.bots.converter import utils def is_float(value): try: diff --git a/bots/converter/readme.md b/zulip_bots/zulip_bots/bots/converter/readme.md similarity index 100% rename from bots/converter/readme.md rename to zulip_bots/zulip_bots/bots/converter/readme.md diff --git a/bots/converter/test_converter.py b/zulip_bots/zulip_bots/bots/converter/test_converter.py old mode 100644 new mode 100755 similarity index 94% rename from bots/converter/test_converter.py rename to zulip_bots/zulip_bots/bots/converter/test_converter.py index 856fbf0..75b2f93 --- a/bots/converter/test_converter.py +++ b/zulip_bots/zulip_bots/bots/converter/test_converter.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestConverterBot(BotTestCase): bot_name = "converter" diff --git a/bots/converter/utils.py b/zulip_bots/zulip_bots/bots/converter/utils.py similarity index 100% rename from bots/converter/utils.py rename to zulip_bots/zulip_bots/bots/converter/utils.py diff --git a/bots/encrypt/__init__.py b/zulip_bots/zulip_bots/bots/define/__init__.py similarity index 100% rename from bots/encrypt/__init__.py rename to zulip_bots/zulip_bots/bots/define/__init__.py diff --git a/bots/define/assets/correct_word.png b/zulip_bots/zulip_bots/bots/define/assets/correct_word.png similarity index 100% rename from bots/define/assets/correct_word.png rename to zulip_bots/zulip_bots/bots/define/assets/correct_word.png diff --git a/bots/define/assets/wrong_word.png b/zulip_bots/zulip_bots/bots/define/assets/wrong_word.png similarity index 100% rename from bots/define/assets/wrong_word.png rename to zulip_bots/zulip_bots/bots/define/assets/wrong_word.png diff --git a/bots/define/define.py b/zulip_bots/zulip_bots/bots/define/define.py similarity index 100% rename from bots/define/define.py rename to zulip_bots/zulip_bots/bots/define/define.py diff --git a/bots/define/readme.md b/zulip_bots/zulip_bots/bots/define/readme.md similarity index 100% rename from bots/define/readme.md rename to zulip_bots/zulip_bots/bots/define/readme.md diff --git a/bots/define/requirements.txt b/zulip_bots/zulip_bots/bots/define/requirements.txt similarity index 100% rename from bots/define/requirements.txt rename to zulip_bots/zulip_bots/bots/define/requirements.txt diff --git a/bots/define/test_define.py b/zulip_bots/zulip_bots/bots/define/test_define.py old mode 100644 new mode 100755 similarity index 94% rename from bots/define/test_define.py rename to zulip_bots/zulip_bots/bots/define/test_define.py index 636d943..d0ced38 --- a/bots/define/test_define.py +++ b/zulip_bots/zulip_bots/bots/define/test_define.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestDefineBot(BotTestCase): bot_name = "define" diff --git a/bots/followup/__init__.py b/zulip_bots/zulip_bots/bots/encrypt/__init__.py similarity index 100% rename from bots/followup/__init__.py rename to zulip_bots/zulip_bots/bots/encrypt/__init__.py diff --git a/bots/encrypt/assets/EncryptBot-terminal.png b/zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-terminal.png similarity index 100% rename from bots/encrypt/assets/EncryptBot-terminal.png rename to zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-terminal.png diff --git a/bots/encrypt/assets/EncryptBot-test.png b/zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-test.png similarity index 100% rename from bots/encrypt/assets/EncryptBot-test.png rename to zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-test.png diff --git a/bots/encrypt/assets/EncryptBot-test2.png b/zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-test2.png similarity index 100% rename from bots/encrypt/assets/EncryptBot-test2.png rename to zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-test2.png diff --git a/bots/encrypt/assets/EncryptBot-test3.png b/zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-test3.png similarity index 100% rename from bots/encrypt/assets/EncryptBot-test3.png rename to zulip_bots/zulip_bots/bots/encrypt/assets/EncryptBot-test3.png diff --git a/bots/encrypt/encrypt.py b/zulip_bots/zulip_bots/bots/encrypt/encrypt.py similarity index 100% rename from bots/encrypt/encrypt.py rename to zulip_bots/zulip_bots/bots/encrypt/encrypt.py diff --git a/bots/encrypt/readme.md b/zulip_bots/zulip_bots/bots/encrypt/readme.md similarity index 100% rename from bots/encrypt/readme.md rename to zulip_bots/zulip_bots/bots/encrypt/readme.md diff --git a/bots/encrypt/test_encrypt.py b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py old mode 100644 new mode 100755 similarity index 93% rename from bots/encrypt/test_encrypt.py rename to zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py index 363ca3e..1cd2386 --- a/bots/encrypt/test_encrypt.py +++ b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestEncryptBot(BotTestCase): bot_name = "encrypt" diff --git a/bots/foursquare/__init__.py b/zulip_bots/zulip_bots/bots/followup/__init__.py similarity index 100% rename from bots/foursquare/__init__.py rename to zulip_bots/zulip_bots/bots/followup/__init__.py diff --git a/bots/followup/followup.py b/zulip_bots/zulip_bots/bots/followup/followup.py similarity index 100% rename from bots/followup/followup.py rename to zulip_bots/zulip_bots/bots/followup/followup.py diff --git a/bots/followup/test_followup.py b/zulip_bots/zulip_bots/bots/followup/test_followup.py old mode 100644 new mode 100755 similarity index 95% rename from bots/followup/test_followup.py rename to zulip_bots/zulip_bots/bots/followup/test_followup.py index c929b3c..b28e159 --- a/bots/followup/test_followup.py +++ b/zulip_bots/zulip_bots/bots/followup/test_followup.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestFollowUpBot(BotTestCase): bot_name = "followup" diff --git a/bots/giphy/__init__.py b/zulip_bots/zulip_bots/bots/foursquare/__init__.py similarity index 100% rename from bots/giphy/__init__.py rename to zulip_bots/zulip_bots/bots/foursquare/__init__.py diff --git a/bots/foursquare/foursquare.conf b/zulip_bots/zulip_bots/bots/foursquare/foursquare.conf similarity index 100% rename from bots/foursquare/foursquare.conf rename to zulip_bots/zulip_bots/bots/foursquare/foursquare.conf diff --git a/bots/foursquare/foursquare.py b/zulip_bots/zulip_bots/bots/foursquare/foursquare.py similarity index 100% rename from bots/foursquare/foursquare.py rename to zulip_bots/zulip_bots/bots/foursquare/foursquare.py diff --git a/bots/foursquare/readme.md b/zulip_bots/zulip_bots/bots/foursquare/readme.md similarity index 100% rename from bots/foursquare/readme.md rename to zulip_bots/zulip_bots/bots/foursquare/readme.md diff --git a/bots/git_hub_comment/__init__.py b/zulip_bots/zulip_bots/bots/giphy/__init__.py similarity index 100% rename from bots/git_hub_comment/__init__.py rename to zulip_bots/zulip_bots/bots/giphy/__init__.py diff --git a/bots/giphy/fixtures/test_1.json b/zulip_bots/zulip_bots/bots/giphy/fixtures/test_1.json similarity index 100% rename from bots/giphy/fixtures/test_1.json rename to zulip_bots/zulip_bots/bots/giphy/fixtures/test_1.json diff --git a/bots/giphy/giphy.py b/zulip_bots/zulip_bots/bots/giphy/giphy.py similarity index 100% rename from bots/giphy/giphy.py rename to zulip_bots/zulip_bots/bots/giphy/giphy.py diff --git a/bots/giphy/test_giphy.py b/zulip_bots/zulip_bots/bots/giphy/test_giphy.py old mode 100644 new mode 100755 similarity index 94% rename from bots/giphy/test_giphy.py rename to zulip_bots/zulip_bots/bots/giphy/test_giphy.py index b1f8145..1f6d545 --- a/bots/giphy/test_giphy.py +++ b/zulip_bots/zulip_bots/bots/giphy/test_giphy.py @@ -5,7 +5,7 @@ from __future__ import print_function import json -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestGiphyBot(BotTestCase): bot_name = "giphy" diff --git a/bots/github/__init__.py b/zulip_bots/zulip_bots/bots/git_hub_comment/__init__.py similarity index 100% rename from bots/github/__init__.py rename to zulip_bots/zulip_bots/bots/git_hub_comment/__init__.py diff --git a/bots/git_hub_comment/git_hub_comment.py b/zulip_bots/zulip_bots/bots/git_hub_comment/git_hub_comment.py similarity index 100% rename from bots/git_hub_comment/git_hub_comment.py rename to zulip_bots/zulip_bots/bots/git_hub_comment/git_hub_comment.py diff --git a/bots/git_hub_comment/readme.md b/zulip_bots/zulip_bots/bots/git_hub_comment/readme.md similarity index 95% rename from bots/git_hub_comment/readme.md rename to zulip_bots/zulip_bots/bots/git_hub_comment/readme.md index 06ffc56..8c21fe1 100644 --- a/bots/git_hub_comment/readme.md +++ b/zulip_bots/zulip_bots/bots/git_hub_comment/readme.md @@ -27,7 +27,7 @@ Here is an example of running the `git_hub_comment` bot from inside a Zulip repo: `cd ~/zulip/api` - `bots_api/run.py bots/git_hub_comment/git_hub_comment.py --config-file ~/.zuliprc-prod` + `zulip-run-bot git_hub_comment --config-file ~/.zuliprc-prod` Once the bot code starts running, you will see a message explaining how to use the bot, as well as @@ -49,5 +49,3 @@ page to create a user-owned bot. email=someuser@example.com key= site=https://zulip.somewhere.com - - diff --git a/bots/github_detail/__init__.py b/zulip_bots/zulip_bots/bots/github/__init__.py similarity index 100% rename from bots/github_detail/__init__.py rename to zulip_bots/zulip_bots/bots/github/__init__.py diff --git a/bots/github/github.py b/zulip_bots/zulip_bots/bots/github/github.py similarity index 100% rename from bots/github/github.py rename to zulip_bots/zulip_bots/bots/github/github.py diff --git a/bots/github_issues/__init__.py b/zulip_bots/zulip_bots/bots/github_detail/__init__.py similarity index 100% rename from bots/github_issues/__init__.py rename to zulip_bots/zulip_bots/bots/github_detail/__init__.py diff --git a/bots/github_detail/fixtures/test_404.json b/zulip_bots/zulip_bots/bots/github_detail/fixtures/test_404.json similarity index 100% rename from bots/github_detail/fixtures/test_404.json rename to zulip_bots/zulip_bots/bots/github_detail/fixtures/test_404.json diff --git a/bots/github_detail/fixtures/test_issue.json b/zulip_bots/zulip_bots/bots/github_detail/fixtures/test_issue.json similarity index 100% rename from bots/github_detail/fixtures/test_issue.json rename to zulip_bots/zulip_bots/bots/github_detail/fixtures/test_issue.json diff --git a/bots/github_detail/fixtures/test_pull.json b/zulip_bots/zulip_bots/bots/github_detail/fixtures/test_pull.json similarity index 100% rename from bots/github_detail/fixtures/test_pull.json rename to zulip_bots/zulip_bots/bots/github_detail/fixtures/test_pull.json diff --git a/bots/github_detail/github_detail.py b/zulip_bots/zulip_bots/bots/github_detail/github_detail.py similarity index 100% rename from bots/github_detail/github_detail.py rename to zulip_bots/zulip_bots/bots/github_detail/github_detail.py diff --git a/bots/github_detail/readme.md b/zulip_bots/zulip_bots/bots/github_detail/readme.md similarity index 100% rename from bots/github_detail/readme.md rename to zulip_bots/zulip_bots/bots/github_detail/readme.md diff --git a/bots/github_detail/test_github_detail.py b/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py old mode 100644 new mode 100755 similarity index 93% rename from bots/github_detail/test_github_detail.py rename to zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py index 124d071..b562138 --- a/bots/github_detail/test_github_detail.py +++ b/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py @@ -3,16 +3,9 @@ from __future__ import absolute_import from __future__ import print_function -import os -import sys import json -our_dir = os.path.dirname(os.path.abspath(__file__)) -sys.path.insert(0, os.path.normpath(os.path.join(our_dir))) -# For dev setups, we can find the API in the repo itself. -if os.path.exists(os.path.join(our_dir, '..')): - sys.path.insert(0, '..') -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestGithubDetailBot(BotTestCase): bot_name = "github_detail" diff --git a/bots/googlesearch/__init__.py b/zulip_bots/zulip_bots/bots/github_issues/__init__.py similarity index 100% rename from bots/googlesearch/__init__.py rename to zulip_bots/zulip_bots/bots/github_issues/__init__.py diff --git a/bots/github_issues/github_issues.py b/zulip_bots/zulip_bots/bots/github_issues/github_issues.py similarity index 100% rename from bots/github_issues/github_issues.py rename to zulip_bots/zulip_bots/bots/github_issues/github_issues.py diff --git a/bots/helloworld/__init__.py b/zulip_bots/zulip_bots/bots/googlesearch/__init__.py similarity index 100% rename from bots/helloworld/__init__.py rename to zulip_bots/zulip_bots/bots/googlesearch/__init__.py diff --git a/bots/googlesearch/googlesearch.py b/zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py similarity index 100% rename from bots/googlesearch/googlesearch.py rename to zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py diff --git a/bots/googlesearch/readme.md b/zulip_bots/zulip_bots/bots/googlesearch/readme.md similarity index 100% rename from bots/googlesearch/readme.md rename to zulip_bots/zulip_bots/bots/googlesearch/readme.md diff --git a/bots/help/__init__.py b/zulip_bots/zulip_bots/bots/helloworld/__init__.py similarity index 100% rename from bots/help/__init__.py rename to zulip_bots/zulip_bots/bots/helloworld/__init__.py diff --git a/bots/helloworld/helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/helloworld.py similarity index 100% rename from bots/helloworld/helloworld.py rename to zulip_bots/zulip_bots/bots/helloworld/helloworld.py diff --git a/bots/helloworld/readme.md b/zulip_bots/zulip_bots/bots/helloworld/readme.md similarity index 100% rename from bots/helloworld/readme.md rename to zulip_bots/zulip_bots/bots/helloworld/readme.md diff --git a/bots/helloworld/test_helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py old mode 100644 new mode 100755 similarity index 89% rename from bots/helloworld/test_helloworld.py rename to zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py index 4b36822..d53f735 --- a/bots/helloworld/test_helloworld.py +++ b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py @@ -5,7 +5,7 @@ from __future__ import print_function from six.moves import zip -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestHelloWorldBot(BotTestCase): bot_name = "helloworld" diff --git a/bots/howdoi/__init__.py b/zulip_bots/zulip_bots/bots/help/__init__.py similarity index 100% rename from bots/howdoi/__init__.py rename to zulip_bots/zulip_bots/bots/help/__init__.py diff --git a/bots/help/help.py b/zulip_bots/zulip_bots/bots/help/help.py similarity index 100% rename from bots/help/help.py rename to zulip_bots/zulip_bots/bots/help/help.py diff --git a/bots/help/test_help.py b/zulip_bots/zulip_bots/bots/help/test_help.py old mode 100644 new mode 100755 similarity index 90% rename from bots/help/test_help.py rename to zulip_bots/zulip_bots/bots/help/test_help.py index 9048531..60c8ea3 --- a/bots/help/test_help.py +++ b/zulip_bots/zulip_bots/bots/help/test_help.py @@ -5,7 +5,7 @@ from __future__ import print_function from six.moves import zip -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestHelpBot(BotTestCase): bot_name = "help" diff --git a/bots/incrementor/__init__.py b/zulip_bots/zulip_bots/bots/howdoi/__init__.py similarity index 100% rename from bots/incrementor/__init__.py rename to zulip_bots/zulip_bots/bots/howdoi/__init__.py diff --git a/bots/howdoi/assets/answer_howdoi_all.png b/zulip_bots/zulip_bots/bots/howdoi/assets/answer_howdoi_all.png similarity index 100% rename from bots/howdoi/assets/answer_howdoi_all.png rename to zulip_bots/zulip_bots/bots/howdoi/assets/answer_howdoi_all.png diff --git a/bots/howdoi/assets/answer_howdowe.png b/zulip_bots/zulip_bots/bots/howdoi/assets/answer_howdowe.png similarity index 100% rename from bots/howdoi/assets/answer_howdowe.png rename to zulip_bots/zulip_bots/bots/howdoi/assets/answer_howdowe.png diff --git a/bots/howdoi/assets/question_howdoi_all.png b/zulip_bots/zulip_bots/bots/howdoi/assets/question_howdoi_all.png similarity index 100% rename from bots/howdoi/assets/question_howdoi_all.png rename to zulip_bots/zulip_bots/bots/howdoi/assets/question_howdoi_all.png diff --git a/bots/howdoi/assets/question_howdowe.png b/zulip_bots/zulip_bots/bots/howdoi/assets/question_howdowe.png similarity index 100% rename from bots/howdoi/assets/question_howdowe.png rename to zulip_bots/zulip_bots/bots/howdoi/assets/question_howdowe.png diff --git a/bots/howdoi/howdoi.py b/zulip_bots/zulip_bots/bots/howdoi/howdoi.py similarity index 100% rename from bots/howdoi/howdoi.py rename to zulip_bots/zulip_bots/bots/howdoi/howdoi.py diff --git a/bots/howdoi/readme.md b/zulip_bots/zulip_bots/bots/howdoi/readme.md similarity index 100% rename from bots/howdoi/readme.md rename to zulip_bots/zulip_bots/bots/howdoi/readme.md diff --git a/bots/john/__init__.py b/zulip_bots/zulip_bots/bots/incrementor/__init__.py similarity index 100% rename from bots/john/__init__.py rename to zulip_bots/zulip_bots/bots/incrementor/__init__.py diff --git a/bots/incrementor/incrementor.py b/zulip_bots/zulip_bots/bots/incrementor/incrementor.py similarity index 100% rename from bots/incrementor/incrementor.py rename to zulip_bots/zulip_bots/bots/incrementor/incrementor.py diff --git a/bots/incrementor/readme.md b/zulip_bots/zulip_bots/bots/incrementor/readme.md similarity index 100% rename from bots/incrementor/readme.md rename to zulip_bots/zulip_bots/bots/incrementor/readme.md diff --git a/bots/thesaurus/__init__.py b/zulip_bots/zulip_bots/bots/john/__init__.py similarity index 100% rename from bots/thesaurus/__init__.py rename to zulip_bots/zulip_bots/bots/john/__init__.py diff --git a/bots/john/assets/assist.png b/zulip_bots/zulip_bots/bots/john/assets/assist.png similarity index 100% rename from bots/john/assets/assist.png rename to zulip_bots/zulip_bots/bots/john/assets/assist.png diff --git a/bots/john/assets/greetings.png b/zulip_bots/zulip_bots/bots/john/assets/greetings.png similarity index 100% rename from bots/john/assets/greetings.png rename to zulip_bots/zulip_bots/bots/john/assets/greetings.png diff --git a/bots/john/assets/joke.png b/zulip_bots/zulip_bots/bots/john/assets/joke.png similarity index 100% rename from bots/john/assets/joke.png rename to zulip_bots/zulip_bots/bots/john/assets/joke.png diff --git a/bots/john/assets/var/jokes.json b/zulip_bots/zulip_bots/bots/john/assets/var/jokes.json similarity index 100% rename from bots/john/assets/var/jokes.json rename to zulip_bots/zulip_bots/bots/john/assets/var/jokes.json diff --git a/bots/john/john.py b/zulip_bots/zulip_bots/bots/john/john.py similarity index 97% rename from bots/john/john.py rename to zulip_bots/zulip_bots/bots/john/john.py index 29cf2e3..c0ad54c 100644 --- a/bots/john/john.py +++ b/zulip_bots/zulip_bots/bots/john/john.py @@ -1,6 +1,5 @@ import json import os -import sys from random import choice @@ -12,9 +11,6 @@ except ImportError: Please: pip install chatterbot""") BOTS_DIR = os.path.dirname(os.path.abspath(__file__)) -os.chdir(os.path.dirname(BOTS_DIR)) -sys.path.insert(0, os.path.dirname(BOTS_DIR)) - JOKES_PATH = os.path.join(BOTS_DIR, 'assets/var/jokes.json') DATABASE_PATH = os.path.join(BOTS_DIR, 'assets/var/database.db') DIRECTORY_PATH = os.path.join(BOTS_DIR, 'assets') diff --git a/bots/john/readme.md b/zulip_bots/zulip_bots/bots/john/readme.md similarity index 100% rename from bots/john/readme.md rename to zulip_bots/zulip_bots/bots/john/readme.md diff --git a/bots/tictactoe/__init__.py b/zulip_bots/zulip_bots/bots/thesaurus/__init__.py similarity index 100% rename from bots/tictactoe/__init__.py rename to zulip_bots/zulip_bots/bots/thesaurus/__init__.py diff --git a/bots/thesaurus/requirements.txt b/zulip_bots/zulip_bots/bots/thesaurus/requirements.txt similarity index 100% rename from bots/thesaurus/requirements.txt rename to zulip_bots/zulip_bots/bots/thesaurus/requirements.txt diff --git a/bots/thesaurus/test_thesaurus.py b/zulip_bots/zulip_bots/bots/thesaurus/test_thesaurus.py old mode 100644 new mode 100755 similarity index 95% rename from bots/thesaurus/test_thesaurus.py rename to zulip_bots/zulip_bots/bots/thesaurus/test_thesaurus.py index 8d04b71..9a4a8db --- a/bots/thesaurus/test_thesaurus.py +++ b/zulip_bots/zulip_bots/bots/thesaurus/test_thesaurus.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestThesaurusBot(BotTestCase): bot_name = "thesaurus" diff --git a/bots/thesaurus/thesaurus.py b/zulip_bots/zulip_bots/bots/thesaurus/thesaurus.py similarity index 100% rename from bots/thesaurus/thesaurus.py rename to zulip_bots/zulip_bots/bots/thesaurus/thesaurus.py diff --git a/bots/virtual_fs/__init__.py b/zulip_bots/zulip_bots/bots/tictactoe/__init__.py similarity index 100% rename from bots/virtual_fs/__init__.py rename to zulip_bots/zulip_bots/bots/tictactoe/__init__.py diff --git a/bots/tictactoe/readme.md b/zulip_bots/zulip_bots/bots/tictactoe/readme.md similarity index 100% rename from bots/tictactoe/readme.md rename to zulip_bots/zulip_bots/bots/tictactoe/readme.md diff --git a/bots/tictactoe/tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py similarity index 100% rename from bots/tictactoe/tictactoe.py rename to zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py diff --git a/bots/weather/__init__.py b/zulip_bots/zulip_bots/bots/virtual_fs/__init__.py similarity index 100% rename from bots/weather/__init__.py rename to zulip_bots/zulip_bots/bots/virtual_fs/__init__.py diff --git a/bots/virtual_fs/readme.md b/zulip_bots/zulip_bots/bots/virtual_fs/readme.md similarity index 100% rename from bots/virtual_fs/readme.md rename to zulip_bots/zulip_bots/bots/virtual_fs/readme.md diff --git a/bots/virtual_fs/test_virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py old mode 100644 new mode 100755 similarity index 98% rename from bots/virtual_fs/test_virtual_fs.py rename to zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py index 6cffe79..01c6305 --- a/bots/virtual_fs/test_virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestVirtualFsBot(BotTestCase): bot_name = "virtual_fs" diff --git a/bots/virtual_fs/virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py similarity index 100% rename from bots/virtual_fs/virtual_fs.py rename to zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py diff --git a/bots/wikipedia/__init__.py b/zulip_bots/zulip_bots/bots/weather/__init__.py similarity index 100% rename from bots/wikipedia/__init__.py rename to zulip_bots/zulip_bots/bots/weather/__init__.py diff --git a/bots/weather/assets/screen1.png b/zulip_bots/zulip_bots/bots/weather/assets/screen1.png similarity index 100% rename from bots/weather/assets/screen1.png rename to zulip_bots/zulip_bots/bots/weather/assets/screen1.png diff --git a/bots/weather/assets/screen2.png b/zulip_bots/zulip_bots/bots/weather/assets/screen2.png similarity index 100% rename from bots/weather/assets/screen2.png rename to zulip_bots/zulip_bots/bots/weather/assets/screen2.png diff --git a/bots/weather/readme.md b/zulip_bots/zulip_bots/bots/weather/readme.md similarity index 100% rename from bots/weather/readme.md rename to zulip_bots/zulip_bots/bots/weather/readme.md diff --git a/bots/weather/weather.conf b/zulip_bots/zulip_bots/bots/weather/weather.conf similarity index 100% rename from bots/weather/weather.conf rename to zulip_bots/zulip_bots/bots/weather/weather.conf diff --git a/bots/weather/weather.py b/zulip_bots/zulip_bots/bots/weather/weather.py similarity index 100% rename from bots/weather/weather.py rename to zulip_bots/zulip_bots/bots/weather/weather.py diff --git a/bots/xkcd/__init__.py b/zulip_bots/zulip_bots/bots/wikipedia/__init__.py similarity index 100% rename from bots/xkcd/__init__.py rename to zulip_bots/zulip_bots/bots/wikipedia/__init__.py diff --git a/bots/wikipedia/test_wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py old mode 100644 new mode 100755 similarity index 94% rename from bots/wikipedia/test_wikipedia.py rename to zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py index 2769f0f..1c433b4 --- a/bots/wikipedia/test_wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from __future__ import print_function -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestWikipediaBot(BotTestCase): bot_name = "wikipedia" diff --git a/bots/wikipedia/wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py similarity index 100% rename from bots/wikipedia/wikipedia.py rename to zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py diff --git a/bots/yoda/__init__.py b/zulip_bots/zulip_bots/bots/xkcd/__init__.py similarity index 100% rename from bots/yoda/__init__.py rename to zulip_bots/zulip_bots/bots/xkcd/__init__.py diff --git a/bots/xkcd/assets/xkcd-help.png b/zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-help.png similarity index 100% rename from bots/xkcd/assets/xkcd-help.png rename to zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-help.png diff --git a/bots/xkcd/assets/xkcd-latest.png b/zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-latest.png similarity index 100% rename from bots/xkcd/assets/xkcd-latest.png rename to zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-latest.png diff --git a/bots/xkcd/assets/xkcd-random.png b/zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-random.png similarity index 100% rename from bots/xkcd/assets/xkcd-random.png rename to zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-random.png diff --git a/bots/xkcd/assets/xkcd-specific-id.png b/zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-specific-id.png similarity index 100% rename from bots/xkcd/assets/xkcd-specific-id.png rename to zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-specific-id.png diff --git a/bots/xkcd/assets/xkcd-wrong-command.png b/zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-wrong-command.png similarity index 100% rename from bots/xkcd/assets/xkcd-wrong-command.png rename to zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-wrong-command.png diff --git a/bots/xkcd/assets/xkcd-wrong-id.png b/zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-wrong-id.png similarity index 100% rename from bots/xkcd/assets/xkcd-wrong-id.png rename to zulip_bots/zulip_bots/bots/xkcd/assets/xkcd-wrong-id.png diff --git a/bots/xkcd/readme.md b/zulip_bots/zulip_bots/bots/xkcd/readme.md similarity index 100% rename from bots/xkcd/readme.md rename to zulip_bots/zulip_bots/bots/xkcd/readme.md diff --git a/bots/xkcd/test_xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py old mode 100644 new mode 100755 similarity index 96% rename from bots/xkcd/test_xkcd.py rename to zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py index 703df78..78d0fea --- a/bots/xkcd/test_xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py @@ -4,7 +4,7 @@ from __future__ import absolute_import from __future__ import print_function import mock -from bots_test_lib import BotTestCase +from zulip_bots.test_lib import BotTestCase class TestXkcdBot(BotTestCase): bot_name = "xkcd" diff --git a/bots/xkcd/xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py similarity index 100% rename from bots/xkcd/xkcd.py rename to zulip_bots/zulip_bots/bots/xkcd/xkcd.py diff --git a/bots/youtube/__init__.py b/zulip_bots/zulip_bots/bots/yoda/__init__.py similarity index 100% rename from bots/youtube/__init__.py rename to zulip_bots/zulip_bots/bots/yoda/__init__.py diff --git a/bots/yoda/assets/yoda-speak-api.png b/zulip_bots/zulip_bots/bots/yoda/assets/yoda-speak-api.png similarity index 100% rename from bots/yoda/assets/yoda-speak-api.png rename to zulip_bots/zulip_bots/bots/yoda/assets/yoda-speak-api.png diff --git a/bots/yoda/readme.md b/zulip_bots/zulip_bots/bots/yoda/readme.md similarity index 97% rename from bots/yoda/readme.md rename to zulip_bots/zulip_bots/bots/yoda/readme.md index 5ac6f17..e12f2af 100644 --- a/bots/yoda/readme.md +++ b/zulip_bots/zulip_bots/bots/yoda/readme.md @@ -44,7 +44,7 @@ Here is an example of running the "yoda" bot from inside a Zulip repo: cd ~/zulip/api - bots_api/run.py bots/yoda/yoda.py --config-file ~/.zuliprc-prod + zulip-run-bot yoda --config-file ~/.zuliprc-prod Once the bot code starts running, you will see a message explaining how to use the bot, as well as diff --git a/bots/yoda/yoda.conf b/zulip_bots/zulip_bots/bots/yoda/yoda.conf similarity index 100% rename from bots/yoda/yoda.conf rename to zulip_bots/zulip_bots/bots/yoda/yoda.conf diff --git a/bots/yoda/yoda.py b/zulip_bots/zulip_bots/bots/yoda/yoda.py similarity index 100% rename from bots/yoda/yoda.py rename to zulip_bots/zulip_bots/bots/yoda/yoda.py diff --git a/bots_api/__init__.py b/zulip_bots/zulip_bots/bots/youtube/__init__.py similarity index 100% rename from bots_api/__init__.py rename to zulip_bots/zulip_bots/bots/youtube/__init__.py diff --git a/bots/youtube/assets/screen.png b/zulip_bots/zulip_bots/bots/youtube/assets/screen.png similarity index 100% rename from bots/youtube/assets/screen.png rename to zulip_bots/zulip_bots/bots/youtube/assets/screen.png diff --git a/bots/youtube/readme.md b/zulip_bots/zulip_bots/bots/youtube/readme.md similarity index 100% rename from bots/youtube/readme.md rename to zulip_bots/zulip_bots/bots/youtube/readme.md diff --git a/bots/youtube/youtube.py b/zulip_bots/zulip_bots/bots/youtube/youtube.py similarity index 100% rename from bots/youtube/youtube.py rename to zulip_bots/zulip_bots/bots/youtube/youtube.py diff --git a/bots_api/bot_lib.py b/zulip_bots/zulip_bots/lib.py similarity index 95% rename from bots_api/bot_lib.py rename to zulip_bots/zulip_bots/lib.py index 65695bb..1919f4c 100644 --- a/bots_api/bot_lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -14,12 +14,6 @@ if False: from typing import Any, Optional, List, Dict from types import ModuleType -our_dir = os.path.dirname(os.path.abspath(__file__)) - -# For dev setups, we can find the API in the repo itself. -if os.path.exists(os.path.join(our_dir, '../zulip')): - sys.path.insert(0, os.path.join(our_dir, '../')) - from zulip import Client def exit_gracefully(signum, frame): @@ -103,11 +97,12 @@ class ExternalBotHandler(object): def get_config_info(self, bot_name, section=None, optional=False): # type: (str, Optional[str], Optional[bool]) -> Dict[str, Any] conf_file_path = os.path.realpath(os.path.join( - our_dir, '..', 'bots', bot_name, bot_name + '.conf')) + our_dir, 'bots', bot_name, bot_name + '.conf')) section = section or bot_name config = configparser.ConfigParser() try: - config.readfp(open(conf_file_path)) # type: ignore + with open(config_file_path) as conf: + config.readfp(conf) # type: ignore except IOError: if optional: return dict() diff --git a/bots_api/provision.py b/zulip_bots/zulip_bots/provision.py similarity index 99% rename from bots_api/provision.py rename to zulip_bots/zulip_bots/provision.py index e265a29..6c49e63 100755 --- a/bots_api/provision.py +++ b/zulip_bots/zulip_bots/provision.py @@ -46,7 +46,7 @@ def run(): ''' - bots_dir = dir_join(os.path.dirname(os.path.abspath(__file__)), '../bots') + bots_dir = dir_join(os.path.dirname(os.path.abspath(__file__)), 'bots') available_bots = [b for b in os.listdir(bots_dir) if os.path.isdir(dir_join(bots_dir, b))] parser = argparse.ArgumentParser(usage=usage) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py new file mode 100755 index 0000000..1535341 --- /dev/null +++ b/zulip_bots/zulip_bots/run.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +from __future__ import print_function +from __future__ import absolute_import + +import logging +import optparse +import sys +from types import ModuleType +from importlib import import_module + +from zulip_bots.lib import run_message_handler_for_bot + + +def parse_args(): + usage = ''' + zulip-run-bot + Example: zulip-run-bot followup + (This program loads bot-related code from the + library code and then runs a message loop, + feeding messages to the library code to handle.) + Please make sure you have a current ~/.zuliprc + file with the credentials you want to use for + this bot. + See lib/readme.md for more context. + ''' + + parser = optparse.OptionParser(usage=usage) + 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)') + + parser.add_option('--force', + action='store_true', + help='Try running the bot even if dependencies install fails.') + (options, args) = parser.parse_args() + if not args: + parser.error('You must specify the name of the bot!') + + return (options, args) + + +def main(): + # type: () -> None + (options, args) = parse_args() + bot_name = args[0] + + lib_module = import_module('zulip_bots.bots.{bot}.{bot}'.format(bot=bot_name)) + if not options.quiet: + logging.basicConfig(stream=sys.stdout, level=logging.INFO) + + run_message_handler_for_bot( + lib_module=lib_module, + config_file=options.config_file, + quiet=options.quiet + ) + +if __name__ == '__main__': + main() diff --git a/bots_api/bots_test_lib.py b/zulip_bots/zulip_bots/test_lib.py old mode 100644 new mode 100755 similarity index 91% rename from bots_api/bots_test_lib.py rename to zulip_bots/zulip_bots/test_lib.py index c6c279e..a591455 --- a/bots_api/bots_test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -4,7 +4,6 @@ from __future__ import absolute_import from __future__ import print_function import os -import sys import json import logging @@ -14,18 +13,17 @@ import unittest from mock import MagicMock, patch -from run import get_lib_module -from bot_lib import StateHandler -from bots_api import bot_lib +from zulip_bots.lib import StateHandler +import zulip_bots.lib from six.moves import zip from contextlib import contextmanager +from importlib import import_module from unittest import TestCase from typing import List, Dict, Any, Optional, Callable from types import ModuleType -current_dir = os.path.dirname(os.path.abspath(__file__)) class BotTestCase(TestCase): bot_name = '' # type: str @@ -36,15 +34,13 @@ class BotTestCase(TestCase): # handler class. Eventually, we want bot's handler classes to # inherit from a common prototype specifying the handle_message # function. - bot_module_path = os.path.normpath(os.path.join( - current_dir, '..', 'bots', self.bot_name, self.bot_name + '.py')) - lib_module = get_lib_module(bot_module_path) + lib_module = import_module('zulip_bots.bots.{bot}.{bot}'.format(bot=self.bot_name)) return lib_module.handler_class() def setUp(self): # type: () -> None # Mocking ExternalBotHandler - self.patcher = patch('bots_api.bot_lib.ExternalBotHandler') + self.patcher = patch('zulip_bots.lib.ExternalBotHandler') self.MockClass = self.patcher.start() self.message_handler = self.get_bot_message_handler() @@ -111,7 +107,7 @@ class BotTestCase(TestCase): """ assert test_name is not None base_path = os.path.realpath(os.path.join(os.path.dirname( - os.path.abspath(__file__)), '..', 'bots', self.bot_name, 'fixtures')) + os.path.abspath(__file__)), 'bots', self.bot_name, 'fixtures')) http_data_path = os.path.join(base_path, '{}.json'.format(test_name)) with open(http_data_path, 'r') as http_data_file: http_data = json.load(http_data_file)