add_account.py 3.2 KB

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