From 1e5df9d93a91556a5849100c34bf2b1623637428 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 18 Aug 2018 19:24:18 +0200 Subject: [PATCH] add "/about" Telegram command --- telegram-bot/fortunes-spam-bot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/telegram-bot/fortunes-spam-bot.py b/telegram-bot/fortunes-spam-bot.py index 6f19d5a..fbec7be 100755 --- a/telegram-bot/fortunes-spam-bot.py +++ b/telegram-bot/fortunes-spam-bot.py @@ -37,8 +37,7 @@ def getSpam(section): def serve(section, bot, update): spam = getSpam(section) - logging.info('%s wants some spam' % update.message.from_user.name) - logging.info('served: %s' % spam) + logging.info('%s wants some spam; serving:\n%s' % (update.message.from_user.name, spam)) update.message.reply_text(spam) @@ -50,12 +49,18 @@ def it(bot, update): return serve('spam-ita-o', bot, update) +def about(bot, update): + logging.info('%s required more info' % update.message.from_user.name) + update.message.reply_text('See https://github.com/alberanid/fortunes-spam') + + if __name__ == '__main__': - if not 'SPAMBOT_TOKEN' in os.environ: + if 'SPAMBOT_TOKEN' not in os.environ: print("Please specify the Telegram token in the SPAMBOT_TOKEN environment variable") logging.info('start serving delicious spam') updater = Updater(os.environ['SPAMBOT_TOKEN']) updater.dispatcher.add_handler(CommandHandler('en', en)) updater.dispatcher.add_handler(CommandHandler('it', it)) + updater.dispatcher.add_handler(CommandHandler('about', about)) updater.start_polling() updater.idle()