From 745f2cd1737bb18ad63dd5edc6dbaeffd871de48 Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Wed, 21 Jul 2021 22:10:05 +0800 Subject: [PATCH] zulip_bots: Add a boilerplate bot for external bots. Add packaged_helloworld as an example of a PyPI package setup for an external zulip bot that can be installed via pip and lanuched without the need to include it in the zulip_bots/bots directory. --- packaged_helloworld/README.md | 2 ++ .../packaged_helloworld/__init__.py | 1 + .../packaged_helloworld/doc.md | 5 ++++ .../packaged_helloworld.py | 30 +++++++++++++++++++ packaged_helloworld/setup.py | 13 ++++++++ 5 files changed, 51 insertions(+) create mode 100644 packaged_helloworld/README.md create mode 100644 packaged_helloworld/packaged_helloworld/__init__.py create mode 100644 packaged_helloworld/packaged_helloworld/doc.md create mode 100644 packaged_helloworld/packaged_helloworld/packaged_helloworld.py create mode 100644 packaged_helloworld/setup.py diff --git a/packaged_helloworld/README.md b/packaged_helloworld/README.md new file mode 100644 index 00000000..2a2fbfac --- /dev/null +++ b/packaged_helloworld/README.md @@ -0,0 +1,2 @@ +This is a boilerplate package for a Zulip bot that can be installed from pip +and launched using the `zulip-run-bots` command. diff --git a/packaged_helloworld/packaged_helloworld/__init__.py b/packaged_helloworld/packaged_helloworld/__init__.py new file mode 100644 index 00000000..5becc17c --- /dev/null +++ b/packaged_helloworld/packaged_helloworld/__init__.py @@ -0,0 +1 @@ +__version__ = "1.0.0" diff --git a/packaged_helloworld/packaged_helloworld/doc.md b/packaged_helloworld/packaged_helloworld/doc.md new file mode 100644 index 00000000..864e8805 --- /dev/null +++ b/packaged_helloworld/packaged_helloworld/doc.md @@ -0,0 +1,5 @@ +Simple Zulip bot that will respond to any query with a "beep boop". + +The packaged_helloworld bot is a boilerplate bot that can be used as a +template for more sophisticated/evolved Zulip bots that can be +installed separately. diff --git a/packaged_helloworld/packaged_helloworld/packaged_helloworld.py b/packaged_helloworld/packaged_helloworld/packaged_helloworld.py new file mode 100644 index 00000000..a8b9aefb --- /dev/null +++ b/packaged_helloworld/packaged_helloworld/packaged_helloworld.py @@ -0,0 +1,30 @@ +# See readme.md for instructions on running this code. +from typing import Any, Dict + +import packaged_helloworld + +from zulip_bots.lib import BotHandler + +__version__ = packaged_helloworld.__version__ + + +class HelloWorldHandler: + def usage(self) -> str: + return """ + This is a boilerplate bot that responds to a user query with + "beep boop", which is robot for "Hello World". + + This bot can be used as a template for other, more + sophisticated, bots that can be installed separately. + """ + + def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> None: + content = "beep boop" # type: str + bot_handler.send_reply(message, content) + + emoji_name = "wave" # type: str + bot_handler.react(message, emoji_name) + return + + +handler_class = HelloWorldHandler diff --git a/packaged_helloworld/setup.py b/packaged_helloworld/setup.py new file mode 100644 index 00000000..d8eebe1e --- /dev/null +++ b/packaged_helloworld/setup.py @@ -0,0 +1,13 @@ +import packaged_helloworld +from setuptools import find_packages, setup + +package_info = { + "name": "packaged_helloworld", + "version": packaged_helloworld.__version__, + "entry_points": { + "zulip_bots.registry": ["packaged_helloworld=packaged_helloworld.packaged_helloworld"], + }, + "packages": find_packages(), +} + +setup(**package_info)