Commit graph

607 commits

Author SHA1 Message Date
Anders Kaseorg 1e6513136a tests: Set encoding for mock HTTP responses.
Fixes warnings like ‘UserWarning: Trying to detect encoding from a
tiny portion of (2) byte(s).’

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-08-24 18:03:52 -07:00
Anders Kaseorg e8bb65b188 tests: Replace deprecated assertRaisesRegexp with assertRaisesRegex.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-08-24 17:20:53 -07:00
Anders Kaseorg b02b84204a merels: Add missing __init__.py, and really fix the tests.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-08-24 16:05:34 -07:00
PIG208 66434d07cf bots: Indicate source of bot (from source/module/registry) upon startup.
Amend tests to include new parameter.
2021-07-29 11:08:33 -07:00
PIG208 4bc0c607c1 bots: Find external packaged bots via 'zulip_bots.registry' entry_point.
Now we will be able to execute `zulip-run-bot` with the `-r` argument
to search for and run bots from the `zulip_bots.registry` entry_point.

Each entry point should have the name correspond to the bot name,
and have the value be the bot module. E.g, an Python package for a
bot called "packaged_bot" should have an `entry_points` setup like
the following:

setup(
    ...
    entry_points={
        "zulip_bot.registry":[
            "packaged_bot=packaged_bot.packaged_bot"
        ]
    }
    ...
)

whose file structure may look like this:

packaged_bot/
├───packaged_bot/
|   ├───packaged_bot.py  # The bot module
|   ├───test_packaged_bot.py
|   ├───packaged_bot.conf
|   └───doc.md
└───setup.py  # Register the entry points here

Add test case.
2021-07-29 11:08:31 -07:00
anehls93 71d488e560 zulip_bots: Add doc.md for game_of_fifteen bot.
Finishes #513.
2021-06-28 12:40:20 -02:30
PIG208 9ce7c52a10 pyupgrade: Reformat with --py36-plus.
This includes mainly fixes of string literals using f-strings or
.format(...), as well as unpacking of list comprehensions.
2021-06-02 18:45:57 -07:00
PIG208 e27ac0ddbe pyupgrade: Replace Text with str.
We uses `pyupgrade --py3-plus` to automatically replace all occurence
of `Text`. But manual fix is required to remove the unused imports. Note
that with this configuration pyupgrade also convert string literals to
.format(...) style, which is manually not included in the commit as well.
2021-06-02 18:45:57 -07:00
PIG208 6f3f9bf7e4 black: Reformat without skipping string normalization. 2021-06-02 18:45:57 -07:00
PIG208 fba21bb00d black: Reformat skipping string normalization. 2021-06-02 18:45:57 -07:00
PIG208 5580c68ae5 isort: Reformat using isort. 2021-06-02 18:45:57 -07:00
PIG208 37e2596124 zulip_bots: Add docstrings and comments for TerminalBotHandler. 2021-05-27 23:52:07 -07:00
PIG208 d949f2024f zulip_bots: Rename SimpleMessageServer to MockMessageServer.
Given that the purpose of this message server is solely for testing,
we rename it for clarity.
2021-05-27 23:52:07 -07:00
PIG208 bd27631dd1 zulip-bots: Yield cache storage instead bot storage.
Fixes the bug that the context manager doesn't actually manage the
storage.
2021-05-27 23:49:41 -07:00
PIG208 b8389b78c1 zulip-bots: Use context manager for incrementor. 2021-05-24 14:30:19 -07:00
PIG208 86fa9f5e35 zulip-bots: Implement context manager.
The context manager is implemented based on a newly added storage called
CachedStorage. It is a bufferred storage that doesn't sync with the
database until it's flushed. With CachedStorage, we can implement the
context manager easily by loading all the data on __enter__ and just
flush all the modified (dirty) data on __exit__. This approach can help
the user minimize the number of round-trips to the server almost
invisibly (despite the fact that they need to use it with "with").

Fixes: #679
2021-05-24 14:30:19 -07:00
PIG208 e0723c1db4 zulip-bots: Move protocols for context manager. 2021-05-24 14:30:19 -07:00
PIG208 b04f5f9753 terminal: Implement react for TerminalBotHandler.
Fixes: #686
2021-05-24 14:22:29 -07:00
PIG208 0b35ed0a93 terminal: Extract message server from the handler.
This makes the user and the bot to share the message server when
sending messages. As a result, the message id can be shared. And history
messages sent by the user will be stored as well.
2021-05-24 14:22:29 -07:00
PIG208 fb77f4bad4 terminal: Apply BotHandler for TerminalBotHandler. 2021-05-24 14:22:29 -07:00
PIG208 5a17c60987 lint: Pre-fix places where Black will reformat incorrectly. 2021-05-24 14:02:51 -07:00
Eeshan Garg 63fefd2a0f pypi: Release version 0.8.0. 2021-05-19 22:44:45 -02:30
PIG208 42aecf683e zulip-bots: Fix incrementor to handle edit time limit error.
When the incrementor attempts to edit a message that was sent long
ago, it will fail and the message will not be updated, nor will a
new message be sent.

Fixes: #673
2021-04-06 17:36:22 -07:00
Anders Kaseorg 19f5b4f6a6 mypy: Fix exec_module type: ignore comments.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-10 09:58:18 -08:00
Anders Kaseorg f2e2f1c7ff zulip_bots: Remove fallback code for Python < 3.5.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-04 15:41:08 -08:00
Anders Kaseorg 56f4d3b2a8 simple_lib: Replace deprecated ConfigParser.readfp call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-04 15:30:57 -08:00
Anders Kaseorg 717a549f4b mypy: Prohibit unreachable code.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-04 15:17:09 -08:00
Anders Kaseorg 30f241a126 mypy: Remove unused type: ignore comments.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-04 15:09:58 -08:00
Anders Kaseorg 5b5fda2354 Fix % formatting without a tuple.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-04 15:04:38 -08:00
Ganesh Pawar 44b6fd395a tests: Fix tests failing on Windows.
Tests were failing on Windows since paths are case-insensitive on it.
This uses pathlib library to compare paths on all platforms.

Fixes #651
2021-03-04 11:28:35 -08:00
LoopThrough-i-j f56f824676 zulip-bots: Replace ExternalBotHandler type by BotHandler.
The functions `extract_query_without_mention` and
`is_private_message_but_not_group_pm` now accept `BotHandler`
instead of `ExternalBotHandler` which allows passing objects of both
`EmbeddedBotHandler` and `ExternalBotHandler`.

Fixes #639
2021-03-03 13:31:59 -08:00
LoopThrough-i-j 1fb3d529a9 zulip-bots: Set bot_handler type to BotHandler.
- Set `bot_handler` type to `BotHandler`.
- Fix mypy issues in improperly typed variables, params and returns.

Fixes part of #639
2021-03-03 13:31:50 -08:00
LoopThrough-i-j a994c58439 zulip-bots: Add BotHandler Protocol.
- The `BotHandler` Protocol is a mypy Protocol
  s.t. all BotHandlers can use it as a default type.
- Fix ExternalBotHandler and StubBotHandler to
  follow `BotHandler` Protocol

Fixes part of #639
2021-03-03 13:31:37 -08:00
LoopThrough-i-j 889e5e333d zulip-bots: Add BotStorage Protocol.
The `BotStorage` Protocol is created to add a common type to all
storage classes.

Note: Protocol is imported from `typing_extensions` as `typing`
doesn't provide Protocol for python <= 3.7.
2021-03-03 13:30:55 -08:00
LoopThrough-i-j 3887ad102e python-zulip-api: Drop python3.5 support.
Fixes Part of #655
2021-02-26 07:32:47 -08:00
LoopThrough-i-j 4c75057de1 dropbox-bot: Update to support dropbox>=11.0.0.
Changes in dropox version >= 11.0 broke the dropbox bot.
The required fixes are mentioned at:
https://github.com/dropbox/dropbox-sdk-python/blob/main/UPGRADING.md#upgrading-from-v10xx-to-v1100
2021-02-23 19:19:16 -08:00
Ahmed Abuamra 9ce2ea53a5 integrations: Remove !avatar from game handler.
The issue linked to this commit suggest suggests to replace the avatar
with the username only, I just needed to remove !avatar as the code
already shows the username.

Fixes part of #632.
2021-02-18 18:35:01 -08:00
LoopThrough-i-j e995e52896 dropbox_share bot: Pin dropbox version to 10.10.0.
Tests for dropbox_share bot fails for version >= 11.0.0.
2021-01-26 12:57:44 -08:00
Eeshan Garg befbb953dd pypi: Release version 0.7.1. 2020-10-09 15:50:43 -02:30
Anders Kaseorg 5f81eb3a70 Update zulipchat.com links to zulip.com.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 21:06:58 -07:00
Lunatic Luna 3b1ef57694 bots: Support adding reactions to message for a bot.
It adds a react() function that allows a bot to react to a message in lib.py.
It adds an example of the use of react() function and its test.

The changes are in the following files:
  - lib.py
  - helloworld.py
  - tests/test_lib.py
  - test_lib.py
2020-05-08 10:46:56 -04:00
neiljp (Neil Pilgrim) 540d453237 setup.py: Add Source & Documentation project_urls.
The only existing url points to zulip.org -> zulipchat.com
2020-05-05 09:20:50 -04:00
pemontto a9268a1947 jira: Add JQL search command. 2020-04-28 12:46:40 -07:00
pemontto a46dae37f5 jira: Add search command. 2020-04-28 12:46:40 -07:00
pemontto b0c2b1b9c8 jira: Use display_url in output. 2020-04-28 12:45:36 -07:00
pemontto 3ca336246d jira: Allow overriding https. 2020-04-28 12:45:36 -07:00
pemontto ae8a3516fb jira: Fix deprecation warning. 2020-04-28 12:45:36 -07:00
Rohitt Vashishtha bdf0c7ff5c bots: Use ids for sending message. 2020-04-28 11:56:16 -04:00
Rohitt Vashishtha 5c32054415 bots: Do not reply in group PMs unless explicitly mentioned.
Previously, if a bot was accidentally added to a group PM, we would
have no option but to leave that conversation because the bot would
reply to all the messages sent in that conversation. This also has
potential to cause infinite loops in case two bots are added to a
group PM since they could keep on replying to each other's messages.

Fixes #551.
2020-04-28 11:56:16 -04:00
Rohitt Vashishtha fe78a363b0 bots: Do not remove self from list of recipients in group PMs.
The origin of this line seems like an arbitary decision when writing the
wikipedia bot in ad25f27853. Removing self
doesn't have any other significance, and not making any changes to the
recipient list helps with https://github.com/zulip/zulip/issues/14228.

Fixes #552.
2020-04-28 11:56:16 -04:00