Commit graph

1475 commits

Author SHA1 Message Date
Robert Hönig 93edededdd zulip_bots: Use real Response object for mock_http_conversation(). 2017-11-28 15:42:22 -08:00
Robert Hönig 41d8ffc20e zulip_bots: Fix yoda bot response parsing. 2017-11-28 15:42:22 -08:00
Robert Hönig 13d181cd09 Remove Python 2.7 testing for zulip_bots and zulip_botserver. 2017-11-28 15:42:22 -08:00
Robert Hönig d6a4c02ba5 Rename bot storage endpoint from state to storage. 2017-11-28 20:41:59 +01:00
Steve Howell 80e4ef9f72 Create terminal.py to run bots in the terminal.
This program replaces zulip_bot_output.py, which had
gotten a little out of date.

It should be able to simulate a terminal conversation for
all of our bots, including those that use "advanced" features:

    third party config files: tested with giphy
    message updates: tested with incrementor
    storage: tested with virtual_fs and others
2017-11-28 10:52:13 -08:00
Steve Howell 536ba1843a Add a command line option to run.py for bot config files.
Before this change, we were looking for config files in
default locations in source control, which is not a good
place to look for them.  Now `run.py` and friends have a
command line argument where users can specify the config
files.

Note that the change to server.py is only a partial fix
to make it so that bots that don't use third party config
files won't crash.  That program needs an overhaul, anyway.
2017-11-28 10:52:13 -08:00
Steve Howell 57c90ddca0 refactor: Extract display_config_file_errors().
This will be useful for handling errors with third party
config files.
2017-11-28 10:52:13 -08:00
Steve Howell 8a15452525 bots: Require bots_details in ExternalBotHandler.
This parameter was defaulting to a dictionary, which is
a classic Python pitfall.
2017-11-28 10:52:13 -08:00
Steve Howell ef30261858 giphy: Make config_info an instance variable.
There was no reason to use a `global` here.
2017-11-28 10:52:13 -08:00
Eeshan Garg 50b5ec0f49 packages: Release 0.3.8 for all PyPI packages. 2017-11-27 23:34:38 -03:30
Robert Hönig a75f1abc60 zulip_bots: Add -c shortcut for --config-file for zulip-run-bots. 2017-11-27 16:45:37 +01:00
Robert Hönig 5894ce131f README.md: Fix typo. 2017-11-27 16:45:19 +01:00
Robert Hönig ea6ddb2312 zulip_bots: Only cache storage.get(). Don't cache put(). 2017-11-24 10:44:34 -08:00
derAnfaenger c264f7ef12 provisioning: Enhance warning for Python 2.7.
Color-highlight the warning. Use print instead
of warnings.warn (this omits unnecessary debug info).
2017-11-23 15:20:34 -08:00
derAnfaenger 819d5f6ebe provisioning: Fix real and venv Python version mixup. 2017-11-23 15:20:34 -08:00
Steve Howell a32446f557 Report client.get_profile() errors nicely (e.g. API key).
This patch is particularly useful in the scenario that your
API key is wrong or out of date, but it's targeted more
generally at any error that `client.get_profile()` reports.
2017-11-22 11:15:00 -08:00
Steve Howell 043d963a99 Fail fast for bad connections with the API and bots.
The API has aggressive retry logic for connecting to a
server, which may make sense for situation where you have
connection blips or server restarts.

When you're first connecting to the API, however, connection
failures are almost certainly a sign of misconfiguration, so
now we fail fast.

The bot lib takes advantage of this API change by catching the
ZulipError exception and exiting gracefully.
2017-11-21 14:21:04 -08:00
Steve Howell a19278da65 Handle configparser errors more gracefully. 2017-11-21 11:54:59 -08:00
Steve Howell e216a29277 minor: Extract client_name local var. 2017-11-21 11:26:12 -08:00
Steve Howell 73ebd719b2 Handle missing config files gracefully.
Before this commit, you would get a traceback if you supplied
a non-existent filename for your config file.  Now we exit
gracefully with a useful error message.
2017-11-21 10:32:45 -08:00
Steve Howell f6440e5b65 Require --config-file and simplify command line usage.
We now require users to specify where their config file is
located, and we no longer default to ~/.zuliprc.

As part of this, we needed to make the "usage" more accurate
in the command line, which I mostly achieved by cutting out
unnecessary stuff.
2017-11-21 09:11:41 -08:00
Steve Howell 57f7088304 Ignore prior coverage data in tools/test-main.
Before this patch, we were reading in old coverage data every
time we ran test-main and had a .coverage file lying around.
This would cause inaccurate data when you changed code, and it
would cause crashes if you moved your working directory on the
file system.
2017-11-20 12:48:36 -08:00
derAnfaenger 940e1260b2 docs: Update outdated links. 2017-11-20 15:09:50 +01:00
derAnfaenger 2a74ad11c5 zulip_bots: Make StateHandler optional.
This has the convenient side-effect of making
the bot_handler.storage attribute read-only.
2017-11-18 08:58:47 -08:00
derAnfaenger f41030b515 API: rename get_state & update_state to get_storage & update_storage. 2017-11-18 08:58:47 -08:00
derAnfaenger 2736223073 bots: Make StateHandler store state on Zulip server.
This makes the StateHandler functional. To reduce the
number of server roundtrips when fetching/updating the
state, the entire state is fetched ocne at bot
initialization and cached. All changes are stored in the
cache and only saved externally after handle_message()
has been executed.

Fixes #141.
2017-11-18 08:58:47 -08:00
derAnfaenger 979bbb1c14 bot tests: Consistently use mock_bot_handler instance of MockClass. 2017-11-18 08:58:47 -08:00
derAnfaenger daad7f24e4 bots: Set JSON as default serializer for StateHandler.
With this change, StateHandler.put() does only accept JSON-able
objects by default. The incrementor test tried to store the return
value of send_reply(), a non-JSON-able MockObject, in the state.
Therefore, this commits also sets functional default test return
values for send_message() and send_reply().
Finally, it fixes the tictactoe bot which relied on directly
modifying the state_ attribute.
2017-11-18 08:58:47 -08:00
derAnfaenger 66da09324e zulip package: Add API functions to access state. 2017-11-18 08:58:47 -08:00
Eeshan Garg bd7db69bac bots/giphy: Document the bot. 2017-11-16 09:09:04 -08:00
derAnfaenger a8b858d78f zulip_bots: Update links to docs. 2017-11-16 13:54:02 +01:00
neiljp (Neil Pilgrim) c24c1d2e61 mypy: Add 'type: ignore' comment due to patching function. 2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) 59b86b5b68 mypy: Add reported issue to 'type: ignore' line in generate_manifest.py. 2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) d929cdb91e botserver testing: Move to six.assertRaisesRegex from Regexp variant.
This ensures 2/3 compatibility. The mypy test also now passes, though
the six stubs appear very minimal - maybe incorrect?
2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) 9ed0fa9e6f mypy: Remove unnecessary 'type: ignore' in google calendar. 2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) 3e55124f4e mypy: Remove 'type: ignore's now that python/mypy#1248 is fixed. 2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) 03f5e9110b mypy: Add comment on ConfigParser.readfp 'type: ignore'.
readfp remains valid but is deprecated, so is not in the python3 stubs.
2017-11-15 13:43:08 -08:00
derAnfaenger 761e3e5855 zulip_bots: Update README.md.
This stubs the zulip_bots README.md
and moves architectural information
to architecture.md.
2017-11-14 09:51:09 -08:00
derAnfaenger 5f3b3436f6 zulip_bots: Remove redundant custom tests in encrypt. 2017-11-14 09:39:00 -08:00
derAnfaenger 9c37f92a01 zulip_bots: Add common tests.
unittest includes by default all module-level classes that inherit
from TestCase and implement at least one method starting with 'test'.
Since it doesn't provide a convenient way for excluding TestSuites,
we need to manually filter out the unwanted testing of our test base
class itself.
2017-11-14 09:39:00 -08:00
Josh Mandel 94b7c2eaef zulip_bots: Make xkcd bot error more verbose. 2017-11-13 17:00:32 +01:00
derAnfaenger 0eb285da29 README.md: Add command for running mypy. 2017-11-13 12:08:14 +01:00
derAnfaenger fa9e5a8e26 zulip_botserver: Test for import error with wrong credentials. 2017-11-10 18:36:20 -08:00
derAnfaenger bf72a8994a zulip_botserver: Raise exception on wrong flaskbotrc file. 2017-11-10 18:36:20 -08:00
derAnfaenger fb116259d0 zulip_botserver: Make tests more realistic.
Specifically, this invokes server.load_lib_modules()
and server.load_bot_handlers() to generate the modules
and handlers, instead of hardcoding them.
2017-11-10 18:36:20 -08:00
derAnfaenger 55332d8cbc zulip_bots: Fix and simplify extract_query_without_mention.
This fixes quirks related to the regex not covering all potential
weird usernames and adds tests for stripping the @-mentions.
2017-11-10 16:09:20 -08:00
Eeshan Garg 0a70a6b46f test-static-analysis: Fix trailing whitespace errors. 2017-11-10 19:24:59 -03:30
Eeshan Garg 0590671fc6 tools/provision: Support specifying path to Python interpreter. 2017-11-10 17:42:38 -03:30
Steve Howell bad8dccef7 provision: Make instructions to source venv more obvious.
(This cleans up the print formatting a bit in tools/provision
and adds an explicit step in README.md.)
2017-11-10 13:04:59 -08:00
derAnfaenger c6aed00aa1 integrations: Make twitter bot handle search terms more intelligently.
When invoked with search terms, twitter bot looks for these terms
in the content of a message to find out if they match. However,
Twitter can return messages that don't directly contain a search term.
This commit adds the tweeter user handle and expanded urls to the
places to look for a search term.
2017-11-07 11:13:29 -08:00