From dea24bcb7cc5d08fabea17cc3422176af65fd006 Mon Sep 17 00:00:00 2001 From: Leonardo Rezende Date: Thu, 13 Aug 2020 08:38:23 -0300 Subject: [PATCH] Refine pollbot.py example (#2047) * pollbot.py example was sending the poll to the effective_user and not effective_chat... well, it's a poll to be answered by multiple uses. * Use User.mention_html() shortcut Co-authored-by: Leonardo Co-authored-by: Hinrich Mahler --- AUTHORS.rst | 1 + examples/pollbot.py | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index bb133c30d..f49a3b992 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -56,6 +56,7 @@ The following wonderful people contributed directly or indirectly to this projec - `Kjwon15 `_ - `Li-aung Yip `_ - `Loo Zheng Yuan `_ +- `LRezende `_ - `macrojames `_ - `Michael Elovskikh `_ - `Mischa Krüger `_ diff --git a/examples/pollbot.py b/examples/pollbot.py index 6fd4b10c1..1560bf3b9 100644 --- a/examples/pollbot.py +++ b/examples/pollbot.py @@ -13,7 +13,6 @@ from telegram import (Poll, ParseMode, KeyboardButton, KeyboardButtonPollType, ReplyKeyboardMarkup, ReplyKeyboardRemove) from telegram.ext import (Updater, CommandHandler, PollAnswerHandler, PollHandler, MessageHandler, Filters) -from telegram.utils.helpers import mention_html logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) @@ -29,7 +28,7 @@ def start(update, context): def poll(update, context): """Sends a predefined poll""" questions = ["Good", "Really good", "Fantastic", "Great"] - message = context.bot.send_poll(update.effective_user.id, "How are you?", questions, + message = context.bot.send_poll(update.effective_chat.id, "How are you?", questions, is_anonymous=False, allows_multiple_answers=True) # Save some info about the poll the bot_data for later use in receive_poll_answer payload = {message.poll.id: {"questions": questions, "message_id": message.message_id, @@ -53,9 +52,9 @@ def receive_poll_answer(update, context): answer_string += questions[question_id] + " and " else: answer_string += questions[question_id] - user_mention = mention_html(update.effective_user.id, update.effective_user.full_name) context.bot.send_message(context.bot_data[poll_id]["chat_id"], - "{} feels {}!".format(user_mention, answer_string), + "{} feels {}!".format(update.effective_user.mention_html(), + answer_string), parse_mode=ParseMode.HTML) context.bot_data[poll_id]["answers"] += 1 # Close poll after three participants voted