From e9fbaa2fc50acbeee73e13e586ea6a7ccfd5d90a Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sun, 28 Mar 2021 00:10:14 -0400 Subject: [PATCH] Working hello world --- .gitignore | 2 ++ README.md | 24 +++++++++++++++++++++++- docker/Dockerfile | 18 ++++++++++++++++++ example/Dockerfile | 5 +++++ example/README.md | 13 +++++++++++++ example/bot.sh | 3 +++ metabot/__init__.py | 0 metabot/bot.py | 43 +++++++++++++++++++++++++++++++++++++++++++ requirements.in | 1 + requirements.txt | 26 ++++++++++++++++++++++++++ 10 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 docker/Dockerfile create mode 100644 example/Dockerfile create mode 100644 example/README.md create mode 100644 example/bot.sh create mode 100644 metabot/__init__.py create mode 100644 metabot/bot.py create mode 100644 requirements.in create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index f8b73e7..886ace5 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,5 @@ dmypy.json # Cython debug symbols cython_debug/ +# Pycharm +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 169ba5c..61c159b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ # runcible-metabot -A Keybase chat bot for use in Drone.io pipelines for notifications. \ No newline at end of file +A Keybase chat bot for use in Drone.io pipelines for notifications. + +## Instructions + +There is an official Docker Image for Keybase clients +https://hub.docker.com/r/keybaseio/client + +[New bot signup workflow](https://gist.github.com/androiddrew/df2e13d63dfd5b4e1d8f19c063ce6654) + +## Docker + +### Building the image + +Run from the root directory +``` +docker build -f ./docker/Dockerfile -t runcible/runcible-metabot . +``` + +### Running the container + +``` +docker run --rm -e KEYBASE_USERNAME="spoonbot" -e KEYBASE_PAPERKEY="$KEYBASE_PAPERKEY" -it runcible/runcible-metabot +``` \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..5986df2 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,18 @@ +FROM keybaseio/client:5.7.0-20210126121847-cfdcb9f95f-python-slim +LABEL maintainer="Drew Bednar " + +# Set the working dir +WORKDIR /app + +# Copy over requirements +COPY requirements.txt /app + +# Install any needed dependencies +RUN pip install --trusted-host pypi.python.org -r requirements.txt + +# Copy over the code now +COPY metabot/ /app +RUN chown -R keybase:keybase /app + +# Run bot.py when the container launches +CMD ["python3", "-m","bot.py"] \ No newline at end of file diff --git a/example/Dockerfile b/example/Dockerfile new file mode 100644 index 0000000..2ba9690 --- /dev/null +++ b/example/Dockerfile @@ -0,0 +1,5 @@ +FROM keybaseio/client +ENV KEYBASE_SERVICE=1 +COPY bot.sh /bot.sh +RUN chmod +x /bot.sh +CMD /bot.sh \ No newline at end of file diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..82dcacd --- /dev/null +++ b/example/README.md @@ -0,0 +1,13 @@ +# Samplebot + +``` +docker build -t runcible/samplebot . +``` + +``` +docker run --rm \ +-e KEYBASE_USERNAME="spoonbot" \ +-e KEYBASE_PAPERKEY="$KEYBASE_PAPERKEY" \ +-e KEYBASE_SERVICE="1"\ +-e CHAT_TARGET="androiddrew" -it runcible/samplebot +``` diff --git a/example/bot.sh b/example/bot.sh new file mode 100644 index 0000000..a762e8e --- /dev/null +++ b/example/bot.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +MSG="sending at $(date)" +keybase chat send $CHAT_TARGET "$MSG" \ No newline at end of file diff --git a/metabot/__init__.py b/metabot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/metabot/bot.py b/metabot/bot.py new file mode 100644 index 0000000..828c8b2 --- /dev/null +++ b/metabot/bot.py @@ -0,0 +1,43 @@ +################################### +# WHAT IS IN THIS EXAMPLE? +# +# This bot listens to two channels for a special text message. When +# it sees this message, it replies in the same channel with a response. +# This also shows sending and receiving unicode characters. +################################### + +import asyncio +import logging +import os + +import pykeybasebot.types.chat1 as chat1 +from pykeybasebot import Bot + +logging.basicConfig(level=logging.DEBUG) + + +class Handler: + async def __call__(self, bot, event): + if event.msg.content.type_name != chat1.MessageTypeStrings.TEXT.value: + return + if event.msg.content.text.body == "🌴ping🌴": + channel = event.msg.channel + await bot.chat.send(channel, "🍹PONG!🍹") + + +listen_options = { + "filter-channels": [ + {"name": "spoonbot,androiddrew"}, + # { + # "name": "runcibleio", + # "topic_name": "general", + # "members_type": "team", + # }, + ] +} + +bot = Bot( + username="spoonbot", paperkey=os.environ["KEYBASE_PAPERKEY"], handler=Handler() +) + +asyncio.run(bot.start(listen_options)) diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..9938956 --- /dev/null +++ b/requirements.in @@ -0,0 +1 @@ +pykeybasebot \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8003fad --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +# +# This file is autogenerated by pip-compile +# To update, run: +# +# pip-compile requirements.in +# +dataclasses-json==0.3.8 + # via pykeybasebot +marshmallow-enum==1.5.1 + # via dataclasses-json +marshmallow==3.10.0 + # via + # dataclasses-json + # marshmallow-enum +mypy-extensions==0.4.3 + # via typing-inspect +pykeybasebot==0.2.1 + # via -r requirements.in +stringcase==1.2.0 + # via dataclasses-json +typing-extensions==3.7.4.3 + # via + # pykeybasebot + # typing-inspect +typing-inspect==0.6.0 + # via dataclasses-json