add_account.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """Add account conversation"""
  2. from telegram import ParseMode
  3. from telegram.ext import MessageHandler, CommandHandler, Filters, ConversationHandler, RegexHandler
  4. ACCOUNT_ID, CONFIRM, VERIFICATION = range(3)
  5. def conv_ask_account_id(update, context):
  6. """Ask account id"""
  7. update.message.reply_text('What\'s your Rival Regions acount ID?')
  8. return ACCOUNT_ID
  9. def conv_error_ask_account_id(update, context):
  10. """Ask max resource"""
  11. incorrect_input = update.message.text
  12. update.message.reply_text(
  13. '{}, I don\'t recognize that. What\'s your Rival Regions account ID?'.format(
  14. incorrect_input
  15. ),
  16. )
  17. return ACCOUNT_ID
  18. def conv_account_id_confirm(update, context):
  19. """Sending announcement"""
  20. account_id = update.message.text
  21. message_list = [
  22. '**Account details**',
  23. 'ID: {}'.format(account_id),
  24. 'Name: {}'.format(account_id),
  25. 'Region: {}'.format(account_id),
  26. 'Residency: {}'.format(account_id),
  27. '\nPlease confirm this is your account by typing \'confirm\'',
  28. ]
  29. update.message.reply_text(
  30. '\n'.join(message_list),
  31. parse_mode=ParseMode.MARKDOWN
  32. )
  33. return CONFIRM
  34. def conv_verification(update, context):
  35. """Sending announcement"""
  36. update.message.reply_text(
  37. 'Verification code send to your Rival Region account ' + \
  38. 'Check your personal messages for a verification code and send it here.',
  39. parse_mode=ParseMode.MARKDOWN
  40. )
  41. return VERIFICATION
  42. def conv_finish(update, context):
  43. """Sending announcement"""
  44. update.message.reply_text(
  45. 'Verificated your Rival Region account to Telegram',
  46. parse_mode=ParseMode.MARKDOWN
  47. )
  48. return ConversationHandler.END
  49. def conv_error_finish(update, context):
  50. """Ask max resource"""
  51. incorrect_input = update.message.text
  52. update.message.reply_text(
  53. '"{}" not recognized. Send me the verification code.\n/cancel to cancel'.format(
  54. incorrect_input
  55. ),
  56. )
  57. return VERIFICATION
  58. def conv_cancel(update, context):
  59. """Cancel announcement"""
  60. update.message.reply_text('Canceled action.')
  61. context.user_data.clear()
  62. return ConversationHandler.END
  63. # announcement conversation
  64. ADD_ACCOUNT_CONV = ConversationHandler(
  65. entry_points=[CommandHandler('add_account', conv_ask_account_id)],
  66. states={
  67. ACCOUNT_ID: [
  68. RegexHandler(r'^\d*$', conv_account_id_confirm),
  69. MessageHandler(Filters.text, conv_error_ask_account_id),
  70. ],
  71. CONFIRM: [
  72. MessageHandler(Filters.regex('confirm'), conv_verification),
  73. MessageHandler(Filters.text, conv_cancel),
  74. ],
  75. VERIFICATION: [
  76. MessageHandler(Filters.regex(r'^([a-z]|\d)+$'), conv_finish),
  77. MessageHandler(Filters.text, conv_error_finish),
  78. ],
  79. },
  80. fallbacks=[CommandHandler('cancel', conv_cancel)]
  81. )