add only quiz type poll example to the poll_example.py

This commit is contained in:
Muhammad Aadil 2023-02-04 10:27:29 +05:00
parent ad7e4bbaf7
commit 10a80e1cfa
1 changed files with 4 additions and 22 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# This is an example file to create polls and handle poll answers
# This is an example file to create quiz polls
import telebot
API_TOKEN = "<api_token>"
@ -8,38 +8,20 @@ API_TOKEN = "<api_token>"
bot = telebot.TeleBot(API_TOKEN)
DATA = {}
@bot.message_handler(commands=["poll"])
def create_poll(message):
bot.send_message(message.chat.id, "English Article Test")
answer_options = ["a", "an", "the", "-"]
# is_anonymous = False -- if you want to check the user answer like here
poll = bot.send_poll(
bot.send_poll(
chat_id=message.chat.id,
question="We are going to '' park.",
options=answer_options,
type='quiz',
correct_option_id=2,
is_anonymous=False,
)
# store the poll_id against user_id in the database
poll_id = poll.poll.id
DATA[message.chat.id] = poll_id
@bot.poll_answer_handler()
def handle_poll_answers(poll):
if DATA.get(poll.user.id) == poll.poll_id:
# to check the correct answer
user_answer = poll.option_ids[0]
correct_answer = 2 # "the" is the correct answer
if user_answer == correct_answer:
bot.send_message(poll.user.id, "Good! You're right.")
else:
bot.send_message(poll.user.id, 'The correct answer is "the" .')
bot.infinity_polling()