Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram import Bot, Poll
- from telegram.ext import Updater, CommandHandler, PollAnswerHandler, PollHandler
- from credits import bot_token
- bot = Bot(token=bot_token)
- updater = Updater(token=bot_token)
- dispatcher = updater.dispatcher
- def poll(update, context):
- choices = ["Отлично", "Очень хорошо", "Неплохо", "Так себе"]
- message = context.bot.send_poll(update.effective_chat.id, "Как ты?", choices, is_anonymous=False,
- allows_multiple_answers=True)
- payload = {
- message.poll.id: {
- "choices": choices,
- "message_id": message.message_id,
- "chat_id": update.effective_chat.id,
- "answers": 0
- }
- }
- context.bot_data.update(payload)
- def quiz(update, context):
- questions = ["1", "2", "4", "20"]
- message = update.effective_message.reply_poll("Сколько яиц нужно для пирога?", questions, type=Poll.QUIZ,
- correct_option_id=2)
- payload = {
- message.poll.id:
- {
- "message_id": message.message_id,
- "chat_id": update.effective_chat.id,
- }
- }
- context.bot_data.update(payload)
- def receive_poll_answer(update, context):
- answer = update.poll_answer
- poll_id = answer.poll_id
- context.bot_data[poll_id]['answers']+= 1
- if context.bot_data[poll_id]['answers'] == 6:
- context.bot.stop_poll(context.bot_data[poll_id]['chat_id'],
- context.bot_data[poll_id]['message_id'])
- poll_handler = CommandHandler("poll", poll)
- quiz_handler = CommandHandler("quiz", quiz)
- receive_poll_answer = PollAnswerHandler(receive_poll_answer)
- dispatcher.add_handler(poll_handler)
- dispatcher.add_handler(quiz_handler)
- dispatcher.add_handler(receive_poll_answer)
- updater.start_polling()
- updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement