Advertisement
RogellParadox

Bot

Mar 28th, 2023
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. =========================================
  2. main.py
  3. =========================================
  4.  
  5. from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup
  6. from telegram.ext import (Application, CommandHandler, CallbackQueryHandler, MessageHandler, filters, ConversationHandler, CallbackContext, PrefixHandler)
  7. import random, logging, datetime, requests, pytz, os, scrapy, platform
  8. import re, json, pytz
  9. import socket as socket
  10. from survey import main_survey
  11.  
  12. #LOG
  13. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
  14. #
  15.  
  16. def main():
  17.     app = Application.builder().token(os.environ['TGTOKEN']).build()
  18.     logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
  19.  
  20.     app.add_handler(PrefixHandler('?', 'ask', main_survey))
  21.  
  22.     app.run_polling()
  23.  
  24. if __name__ == "__main__":
  25.     main()
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. =========================================
  35. survey.py
  36. =========================================
  37.  
  38. from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup
  39. from telegram.ext import (CommandHandler, CallbackQueryHandler, MessageHandler, filters, ConversationHandler, CallbackContext, PrefixHandler)
  40.  
  41. STATE1, STATE2, STATE3 = range(3)
  42.  
  43.  
  44. async def state1(update, context):
  45.  
  46.     buttons = [[
  47.         InlineKeyboardButton("Google", callback_data="google"),
  48.         InlineKeyboardButton("Bing", callback_data="bing"),
  49.         InlineKeyboardButton("Yahoo!", callback_data="yahoo")
  50.         ]
  51.  
  52.     ]
  53.     ReplyKeyboardMarkup = InlineKeyboardMarkup(buttons)
  54.  
  55.     await update.message.reply_text("Stage 1. What's your favourite search engine?", reply_markup= ReplyKeyboardMarkup)
  56.     return STATE2
  57.  
  58. async def state2(update, context):
  59.     buttons = [[
  60.         InlineKeyboardButton("Gmail", callback_data="gmail"),
  61.         InlineKeyboardButton("Outlook", callback_data="outlook"),
  62.         InlineKeyboardButton("Yahoo!", callback_data="yahoomail")]
  63.  
  64.     ]
  65.     ReplyKeyboardMarkup = InlineKeyboardMarkup(buttons)
  66.  
  67.     await update.message.reply_text("Stage 2. What's your favourite e-mail provider?", reply_markup= ReplyKeyboardMarkup)
  68.     return STATE3
  69.  
  70. async def state3(update, context):
  71.     await update.message.reply_text("Thank you for your answers!")
  72.     return ConversationHandler.END
  73.  
  74.  
  75. async def main_survey(update, context):
  76.     print("OK")
  77.     survey_handler = ConversationHandler(
  78.             entry_points=[CallbackQueryHandler(state1)],
  79.             states={
  80.                 STATE1: [CallbackQueryHandler(state1)],
  81.                 STATE2: [CallbackQueryHandler(state2)],
  82.                 STATE3: [CallbackQueryHandler(state3)]
  83.  
  84.             },
  85.             fallbacks=[],
  86.             per_message=True
  87.  
  88.         )
  89.     print(survey_handler)
  90.     return survey_handler
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement