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 <leonardo.rezende@trt19.jus.br>
Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
This commit is contained in:
Leonardo Rezende 2020-08-13 08:38:23 -03:00 committed by GitHub
parent 2789fd2bff
commit dea24bcb7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -56,6 +56,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Kjwon15 <https://github.com/kjwon15>`_
- `Li-aung Yip <https://github.com/LiaungYip>`_
- `Loo Zheng Yuan <https://github.com/loozhengyuan>`_
- `LRezende <https://github.com/lrezende>`_
- `macrojames <https://github.com/macrojames>`_
- `Michael Elovskikh <https://github.com/wronglink>`_
- `Mischa Krüger <https://github.com/Makman2>`_

View file

@ -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