Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery)
  2. from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
  3.                           ConversationHandler, CallbackQueryHandler)
  4.  
  5. import logging
  6.  
  7. # Enable logging
  8. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  9.                     level=logging.INFO)
  10.  
  11. logger = logging.getLogger(__name__)
  12.  
  13. USERNAME, PASSWORD = range(2)
  14.  
  15.  
  16. def start(bot, update):
  17.     reply_keyboard = [['Boy', 'Girl', 'Other']]
  18.  
  19.     update.message.reply_text(
  20.         'Hi! I am a bot. I will hold a conversation with you. '
  21.         'Send /cancel to stop talking to me.\n\n'
  22.         'I will log you into classeviva!\n\n'
  23.         'Send me your username or email!')
  24.  
  25.     return USERNAME
  26.  
  27.  
  28. def username(bot, update):
  29.     button_list = [[InlineKeyboardButton("Riprova", callback_data='riprova')]]
  30.     reply_retry = InlineKeyboardMarkup(button_list)
  31.  
  32.     user = update.message.from_user
  33.     logger.info("Username of %s: %s", user.first_name, update.message.text)
  34.     update.message.reply_text('If it is correct send me you password',
  35.                               reply_markup=reply_retry)
  36.     if update.callback_query.data == 'riprova':
  37.         return USERNAME
  38.     else:
  39.         return PASSWORD
  40.  
  41.  
  42. def password(bot, update):
  43.     user = update.message.from_user
  44.     logger.info("Password of %s: %s", user.first_name, update.message.text)
  45.  
  46.  
  47. def cancel(bot, update):
  48.     user = update.message.from_user
  49.     logger.info("User %s canceled the conversation.", user.first_name)
  50.     update.message.reply_text('Bye! I hope we can talk again some day.',
  51.                               reply_markup=ReplyKeyboardRemove())
  52.  
  53.     return ConversationHandler.END
  54.  
  55.  
  56. def error(bot, update, error):
  57.     """Log Errors caused by Updates."""
  58.     logger.warning('Update "%s" caused error "%s"', update, error)
  59.  
  60.  
  61. def main():
  62.     updater = Updater("")
  63.         dp = updater.dispatcher
  64.  
  65.  
  66.     conv_handler = ConversationHandler(
  67.         entry_points=[CommandHandler('start', start)],
  68.  
  69.         states={
  70.             USERNAME: [MessageHandler(Filters.text, us LOCATION, BIOername),
  71.                         CallbackQueryHandler(username, pass_user_data=True)],
  72.  
  73.             PASSWORD: [MessageHandler(Filters.text, password)],
  74.  
  75.         },
  76.  
  77.         fallbacks=[CommandHandler('cancel', cancel)]
  78.     )
  79.  
  80.     dp.add_handler(conv_handler)
  81.     dp.add_error_handler(error)
  82.     updater.start_polling()
  83.     updater.idle()
  84.  
  85.  
  86. if __name__ == '__main__':
  87.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement