|  | @@ -1,4 +1,4 @@
 | 
	
		
			
				|  |  | -"""Add account conversation"""
 | 
	
		
			
				|  |  | +"""Add player conversation"""
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import random
 | 
	
		
			
				|  |  |  import string
 | 
	
	
		
			
				|  | @@ -9,34 +9,34 @@ from telegram.ext import MessageHandler, CommandHandler, Filters, ConversationHa
 | 
	
		
			
				|  |  |  from app import api, functions, database, HEADERS, BASE_URL, LOGGER
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -ACCOUNT_ID, CHOOSE, CONFIRM, VERIFICATION = range(4)
 | 
	
		
			
				|  |  | +PLAYER_ID, CHOOSE, CONFIRM, VERIFICATION = range(4)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def conv_ask_account_id(update, context):
 | 
	
		
			
				|  |  | -    """Ask account id"""
 | 
	
		
			
				|  |  | -    LOGGER.info('"@%s" start add account conversation', update.message.from_user.username)
 | 
	
		
			
				|  |  | -    update.message.reply_text('Send me your Rival Regions account name or ID.')
 | 
	
		
			
				|  |  | -    return ACCOUNT_ID
 | 
	
		
			
				|  |  | +def conv_ask_player_id(update, context):
 | 
	
		
			
				|  |  | +    """Ask player id"""
 | 
	
		
			
				|  |  | +    LOGGER.info('"@%s" start add player conversation', update.message.from_user.username)
 | 
	
		
			
				|  |  | +    update.message.reply_text('Send me your Rival Regions player name or ID.')
 | 
	
		
			
				|  |  | +    return PLAYER_ID
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def conv_account_choose(update, context):
 | 
	
		
			
				|  |  | +def conv_player_choose(update, context):
 | 
	
		
			
				|  |  |      """Ask max resource"""
 | 
	
		
			
				|  |  | -    account_name = update.message.text
 | 
	
		
			
				|  |  | +    player_name = update.message.text
 | 
	
		
			
				|  |  |      LOGGER.info(
 | 
	
		
			
				|  |  | -        '"@%s" searching for account name "%s"', 
 | 
	
		
			
				|  |  | +        '"@%s" searching for player name "%s"', 
 | 
	
		
			
				|  |  |          update.message.from_user.username,
 | 
	
		
			
				|  |  | -        account_name
 | 
	
		
			
				|  |  | +        player_name
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  | -    accounts = api.get_accounts_by_name(account_name)
 | 
	
		
			
				|  |  | -    if len(accounts) == 0:
 | 
	
		
			
				|  |  | -        update.message.reply_text('No accounts found witht that name, try again')
 | 
	
		
			
				|  |  | -        return ACCOUNT_ID
 | 
	
		
			
				|  |  | -    context.user_data['account_list'] = accounts
 | 
	
		
			
				|  |  | +    players = api.get_players_by_name(player_name)
 | 
	
		
			
				|  |  | +    if len(players) == 0:
 | 
	
		
			
				|  |  | +        update.message.reply_text('No players found witht that name, try again')
 | 
	
		
			
				|  |  | +        return PLAYER_ID
 | 
	
		
			
				|  |  | +    context.user_data['player_list'] = players
 | 
	
		
			
				|  |  |      message = 'Chose from list:\n'
 | 
	
		
			
				|  |  | -    for num, account in enumerate(accounts, start=1):
 | 
	
		
			
				|  |  | -        message += '{}) {} ({})\n'.format(num, account['name'], account['level'])
 | 
	
		
			
				|  |  | +    for num, player in enumerate(players, start=1):
 | 
	
		
			
				|  |  | +        message += '{}) {} ({})\n'.format(num, player['name'], player['level'])
 | 
	
		
			
				|  |  |      update.message.reply_text(message)
 | 
	
		
			
				|  |  |      return CHOOSE
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def conv_account_number_error(update, context):
 | 
	
		
			
				|  |  | +def conv_player_number_error(update, context):
 | 
	
		
			
				|  |  |      """Wrong input error"""
 | 
	
		
			
				|  |  |      incorrect_input = update.message.text
 | 
	
		
			
				|  |  |      LOGGER.info(
 | 
	
	
		
			
				|  | @@ -51,35 +51,35 @@ def conv_account_number_error(update, context):
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  |      return CHOOSE
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def conv_account_id_confirm(update, context):
 | 
	
		
			
				|  |  | -    """Confirm account """
 | 
	
		
			
				|  |  | -    account_id = int(update.message.text)
 | 
	
		
			
				|  |  | -    if account_id <= 25:
 | 
	
		
			
				|  |  | -        account_index = account_id-1
 | 
	
		
			
				|  |  | -        if account_index >= len(context.user_data['account_list']):
 | 
	
		
			
				|  |  | -            update.message.reply_text('{} is not an option, try again.'.format(account_id),)
 | 
	
		
			
				|  |  | +def conv_player_id_confirm(update, context):
 | 
	
		
			
				|  |  | +    """Confirm player """
 | 
	
		
			
				|  |  | +    player_id = int(update.message.text)
 | 
	
		
			
				|  |  | +    if player_id <= 25:
 | 
	
		
			
				|  |  | +        player_index = player_id-1
 | 
	
		
			
				|  |  | +        if player_index >= len(context.user_data['player_list']):
 | 
	
		
			
				|  |  | +            update.message.reply_text('{} is not an option, try again.'.format(player_id),)
 | 
	
		
			
				|  |  |              return CHOOSE
 | 
	
		
			
				|  |  | -        account = context.user_data['account_list'][account_index]
 | 
	
		
			
				|  |  | -        account_id = account['id']
 | 
	
		
			
				|  |  | -    context.user_data['account_id'] = account_id
 | 
	
		
			
				|  |  | +        player = context.user_data['player_list'][player_index]
 | 
	
		
			
				|  |  | +        player_id = player['id']
 | 
	
		
			
				|  |  | +    context.user_data['player_id'] = player_id
 | 
	
		
			
				|  |  |      update.message.reply_text(
 | 
	
		
			
				|  |  | -        'Retreiving account from Rival Regions, this might take a couple seconds.'
 | 
	
		
			
				|  |  | +        'Retreiving player from Rival Regions, this might take a couple seconds.'
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  |      LOGGER.info(
 | 
	
		
			
				|  |  | -        '"@%s" RR account id "%s"',
 | 
	
		
			
				|  |  | +        '"@%s" RR player id "%s"',
 | 
	
		
			
				|  |  |          update.message.from_user.username,
 | 
	
		
			
				|  |  | -        account_id
 | 
	
		
			
				|  |  | +        player_id
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  | -    account = api.get_rr_account(account_id)
 | 
	
		
			
				|  |  | +    player = api.get_rr_player(player_id)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      message_list = [
 | 
	
		
			
				|  |  | -        '*Account details*',
 | 
	
		
			
				|  |  | -        '*ID*: {}'.format(account_id),
 | 
	
		
			
				|  |  | -        '*Name*: {}'.format(functions.escape_text(account['name'])),
 | 
	
		
			
				|  |  | -        '*Region*: {}'.format(account['region']),
 | 
	
		
			
				|  |  | -        '*Residency*: {}'.format(account['residency']),
 | 
	
		
			
				|  |  | -        '*Registration date*: {}'.format(account['registation_date']),
 | 
	
		
			
				|  |  | -        '\nPlease confirm this is your account by typing \'confirm\'.',
 | 
	
		
			
				|  |  | +        '*Player details*',
 | 
	
		
			
				|  |  | +        '*ID*: {}'.format(player_id),
 | 
	
		
			
				|  |  | +        '*Name*: {}'.format(functions.escape_text(player['name'])),
 | 
	
		
			
				|  |  | +        '*Region*: {}'.format(player['region']),
 | 
	
		
			
				|  |  | +        '*Residency*: {}'.format(player['residency']),
 | 
	
		
			
				|  |  | +        '*Registration date*: {}'.format(player['registation_date']),
 | 
	
		
			
				|  |  | +        '\nPlease confirm this is your player by typing \'confirm\'.',
 | 
	
		
			
				|  |  |      ]
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      update.message.reply_text(
 | 
	
	
		
			
				|  | @@ -91,7 +91,7 @@ def conv_account_id_confirm(update, context):
 | 
	
		
			
				|  |  |  def conv_verification(update, context):
 | 
	
		
			
				|  |  |      """Sending announcement"""
 | 
	
		
			
				|  |  |      update.message.reply_text(
 | 
	
		
			
				|  |  | -        'Verification code will be send to your Rival Region account in a couple of secconds. ' + \
 | 
	
		
			
				|  |  | +        'Verification code will be send to your Rival Region player in a couple of secconds. ' + \
 | 
	
		
			
				|  |  |          'Check your personal messages for a verification code and send it here.',
 | 
	
		
			
				|  |  |          parse_mode=ParseMode.MARKDOWN
 | 
	
		
			
				|  |  |      )
 | 
	
	
		
			
				|  | @@ -104,7 +104,7 @@ def conv_verification(update, context):
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  |      message = 'Your verification code:\n{}\n\n'.format(verification_code) + \
 | 
	
		
			
				|  |  |      'Please don\'t share this code except with @rr_verification_bot on Telegram.'
 | 
	
		
			
				|  |  | -    api.send_personal_message(context.user_data['account_id'], message)
 | 
	
		
			
				|  |  | +    api.send_personal_message(context.user_data['player_id'], message)
 | 
	
		
			
				|  |  |      context.user_data['verification_code'] = verification_code
 | 
	
		
			
				|  |  |      return VERIFICATION
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -136,15 +136,15 @@ def conv_finish(update, context):
 | 
	
		
			
				|  |  |              parse_mode=ParseMode.MARKDOWN
 | 
	
		
			
				|  |  |          )
 | 
	
		
			
				|  |  |          return VERIFICATION
 | 
	
		
			
				|  |  | -    account_id = context.user_data['account_id']
 | 
	
		
			
				|  |  | +    player_id = context.user_data['player_id']
 | 
	
		
			
				|  |  |      LOGGER.info(
 | 
	
		
			
				|  |  | -        '"@%s" succesfully verified RR account "%s"',
 | 
	
		
			
				|  |  | +        '"@%s" succesfully verified RR player "%s"',
 | 
	
		
			
				|  |  |          update.message.from_user.username,
 | 
	
		
			
				|  |  | -        account_id,
 | 
	
		
			
				|  |  | +        player_id,
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  | -    database.verify_rr_account(update.message.from_user.id, account_id)
 | 
	
		
			
				|  |  | +    database.verify_rr_player(update.message.from_user.id, player_id)
 | 
	
		
			
				|  |  |      update.message.reply_text(
 | 
	
		
			
				|  |  | -        'Verificated your Rival Region account to Telegram. Type /accounts to see your accounts',
 | 
	
		
			
				|  |  | +        'Verificated your Rival Region player to Telegram. Type /players to see your players',
 | 
	
		
			
				|  |  |          parse_mode=ParseMode.MARKDOWN
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  |      context.user_data.clear()
 | 
	
	
		
			
				|  | @@ -168,15 +168,15 @@ def conv_cancel(update, context):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # announcement conversation
 | 
	
		
			
				|  |  |  ADD_ACCOUNT_CONV = ConversationHandler(
 | 
	
		
			
				|  |  | -    entry_points=[CommandHandler('add_account', conv_ask_account_id)],
 | 
	
		
			
				|  |  | +    entry_points=[CommandHandler('add_account', conv_ask_player_id)],
 | 
	
		
			
				|  |  |      states={
 | 
	
		
			
				|  |  | -        ACCOUNT_ID: [
 | 
	
		
			
				|  |  | -            MessageHandler(Filters.regex(r'^\d*$'), conv_account_id_confirm),
 | 
	
		
			
				|  |  | -            MessageHandler(Filters.text, conv_account_choose),
 | 
	
		
			
				|  |  | +        PLAYER_ID: [
 | 
	
		
			
				|  |  | +            MessageHandler(Filters.regex(r'^\d*$'), conv_player_id_confirm),
 | 
	
		
			
				|  |  | +            MessageHandler(Filters.text, conv_player_choose),
 | 
	
		
			
				|  |  |          ],
 | 
	
		
			
				|  |  |          CHOOSE: [
 | 
	
		
			
				|  |  | -            MessageHandler(Filters.regex(r'^\d*$'), conv_account_id_confirm),
 | 
	
		
			
				|  |  | -            MessageHandler(Filters.text, conv_account_choose),
 | 
	
		
			
				|  |  | +            MessageHandler(Filters.regex(r'^\d*$'), conv_player_id_confirm),
 | 
	
		
			
				|  |  | +            MessageHandler(Filters.text, conv_player_choose),
 | 
	
		
			
				|  |  |          ],
 | 
	
		
			
				|  |  |          CONFIRM: [
 | 
	
		
			
				|  |  |              MessageHandler(Filters.regex('confirm'), conv_verification),
 |