From 1875ba2f7b7a2f2ebdb6e6d15fe891b3e66be0d2 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 12 Jun 2021 15:47:41 +0200 Subject: [PATCH] update python-telegram-bot API --- README.md | 2 +- telegram-bot/Dockerfile | 2 ++ telegram-bot/fortunes-spam-bot.py | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d8795b6..f71b2f1 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You can use the content of the *mastodon-bot* directory to create your own Masto # License -Copyright 2003-2018 Davide Alberani +Copyright 2003-2021 Davide Alberani Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/telegram-bot/Dockerfile b/telegram-bot/Dockerfile index 03a8cc9..264389f 100644 --- a/telegram-bot/Dockerfile +++ b/telegram-bot/Dockerfile @@ -9,6 +9,8 @@ RUN \ git clone https://github.com/alberanid/fortunes-spam.git COPY fortunes-spam-bot.py /fortunes-spam +VOLUME /fortunes + WORKDIR /fortunes-spam ENTRYPOINT ["python3", "fortunes-spam-bot.py"] diff --git a/telegram-bot/fortunes-spam-bot.py b/telegram-bot/fortunes-spam-bot.py index fbec7be..67389e9 100755 --- a/telegram-bot/fortunes-spam-bot.py +++ b/telegram-bot/fortunes-spam-bot.py @@ -4,7 +4,7 @@ Build it with: docker build -t fortunes-spam-bot . Run it with something like: docker run -ti --rm -e SPAMBOT_TOKEN=your-telegram-token fortunes-spam-bot -Copyright 2018 Davide Alberani Apache 2.0 license +Copyright 2018-2021 Davide Alberani Apache 2.0 license """ import os @@ -17,8 +17,12 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s logger = logging.getLogger(__name__) +EXTERNAL_VOL = '/fortunes' def getSpam(section): + extPath = os.path.join(EXTERNAL_VOL, section) + if os.path.isfile(extPath): + section = extPath cmd = ['fortune', '-o', section] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() @@ -35,22 +39,22 @@ def getSpam(section): return stdout -def serve(section, bot, update): +def serve(section, update, context): spam = getSpam(section) - logging.info('%s wants some spam; serving:\n%s' % (update.message.from_user.name, spam)) + logging.info('%s wants some spam; serving:\n%s' % (update.effective_user.username, spam)) update.message.reply_text(spam) -def en(bot, update): - return serve('spam-o', bot, update) +def en(update, context): + return serve('spam-o', update, context) -def it(bot, update): - return serve('spam-ita-o', bot, update) +def it(update, context): + return serve('spam-ita-o', update, context) -def about(bot, update): - logging.info('%s required more info' % update.message.from_user.name) +def about(update, context): + logging.info('%s required more info' % update.effective_user.username) update.message.reply_text('See https://github.com/alberanid/fortunes-spam')