commit 4a76d7ac00d4acd8793f743755c77365076ce716 Author: Kai Vogelgesang Date: Fri Oct 2 03:55:30 2020 +0200 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe03fa6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,144 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# End of https://www.toptal.com/developers/gitignore/api/python + +# keep the bot token out of git lol +token.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b05e9a2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3 + +WORKDIR /usr/src/app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY main.py . + +CMD [ "python", "-u", "./main.py" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..610f99c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3" + +services: + bot: + build: . + env_file: + - ./token.env \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..ffb4cee --- /dev/null +++ b/main.py @@ -0,0 +1,42 @@ +import os +import random +import difflib + +import telegram +from telegram import Update +from telegram.ext import Updater, MessageHandler, Filters, CallbackContext + +POSSIBLE_TEXTS = [ + "\U0001F92C", # "serious face with symbols covering mouth" +] + + +def on_message(update: Update, context: CallbackContext): + for word in update.message.text.split(): + if difflib.get_close_matches(word.lower(), ["blockflöte"]): + context.bot.send_message( + chat_id=update.effective_chat.id, text=random.choice(POSSIBLE_TEXTS) + ) + break + + +message_handler = MessageHandler(Filters.text & ~Filters.command, on_message) + +if __name__ == "__main__": + TOKEN = os.environ.get("TOKEN") + + if not TOKEN: + print("Please provide a bot token using the TOKEN environment variable") + exit(1) + + try: + updater = Updater(token=TOKEN, use_context=True) + except telegram.error.InvalidToken: + print("The provided token appears to be invalid") + exit(1) + + dispatcher = updater.dispatcher + + dispatcher.add_handler(message_handler) + + updater.start_polling() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c2f6c0e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +python-telegram-bot==12.8