فهرست منبع

Rename account to player

JoostSijm 5 سال پیش
والد
کامیت
d64e89b72e
2فایلهای تغییر یافته به همراه90 افزوده شده و 90 حذف شده
  1. 53 53
      app/conversations/add_account.py
  2. 37 37
      app/database.py

+ 53 - 53
app/conversations/add_account.py

@@ -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),

+ 37 - 37
app/database.py

@@ -6,47 +6,47 @@ from app import SESSION, LOGGER
 from app.models import Player, TelegramAccount, TelegramHandle, PlayerTelegram
 
 
-def add_telegram_account(update):
-    """Add new Telegram account"""
+def add_telegram_player(update):
+    """Add new Telegram player"""
     session = SESSION()
-    telegram_account = TelegramAccount()
-    telegram_account.id = update.message.from_user.id
-    telegram_account.name = update.message.from_user.name
-    telegram_account.registration_date = datetime.now()
-    session.add(telegram_account)
+    telegram_player = TelegramAccount()
+    telegram_player.id = update.message.from_user.id
+    telegram_player.name = update.message.from_user.name
+    telegram_player.registration_date = datetime.now()
+    session.add(telegram_player)
     session.commit()
     session.close()
-    return telegram_account
+    return telegram_player
 
-def get_telegram_account(telegram_id):
-    """Get Telegram account"""
+def get_telegram_player(telegram_id):
+    """Get Telegram player"""
     session = SESSION()
-    telegram_account = _get_telegram_account(session, telegram_id)
+    telegram_player = _get_telegram_player(session, telegram_id)
     session.close()
-    return telegram_account
+    return telegram_player
 
-def get_rr_accounts(telegram_account):
-    """Get Rival Region accounts associated with Telegram account"""
+def get_rr_players(telegram_player):
+    """Get Rival Region players associated with Telegram player"""
     LOGGER.info(
-        '"%s" get RR accounts',
-        telegram_account.id,
+        '"%s" get RR players',
+        telegram_player.id,
     )
     session = SESSION()
-    accounts = _get_rr_accounts(session, telegram_account.id)
+    players = _get_rr_players(session, telegram_player.id)
     session.close()
-    return accounts
+    return players
 
-def verify_rr_account(telegram_id, account_id):
-    """Verify RR account in database"""
+def verify_rr_player(telegram_id, player_id):
+    """Verify RR player in database"""
     session = SESSION()
-    telegram_account = _get_telegram_account(session, telegram_id)
-    accounts = _get_rr_accounts(session, telegram_id)
-    for account in accounts:
-        if account.id == account_id:
+    telegram_player = _get_telegram_player(session, telegram_id)
+    players = _get_rr_players(session, telegram_id)
+    for player in players:
+        if player.id == player_id:
             LOGGER.info(
-                '"%s" account already connected "%s"',
+                '"%s" player already connected "%s"',
                 telegram_id,
-                account_id
+                player_id
             )
             session.close()
             return
@@ -56,34 +56,34 @@ def verify_rr_account(telegram_id, account_id):
         .all()
     for active_player_telegram in active_player_telegrams:
         LOGGER.info(
-            '"%s" unconnect account "%s"',
+            '"%s" unconnect player "%s"',
             active_player_telegram.telegram_id,
-            account_id
+            player_id
         )
         active_player_telegram.until_date_time = datetime.now()
 
     LOGGER.info(
-        '"%s" connecting account "%s"',
+        '"%s" connecting player "%s"',
         telegram_id,
-        account_id
+        player_id
     )
     player_telegram = PlayerTelegram()
-    player_telegram.telegram_id = telegram_account.id
-    player_telegram.player_id = account_id
+    player_telegram.telegram_id = telegram_player.id
+    player_telegram.player_id = player_id
     player_telegram.from_date_time = datetime.now()
     session.add(player_telegram)
     session.commit()
     session.close()
 
-def _get_telegram_account(session, telegram_id):
-    """Return telegram_account"""
+def _get_telegram_player(session, telegram_id):
+    """Return telegram_player"""
     return session.query(TelegramAccount).get(telegram_id)
 
-def _get_rr_accounts(session, telegram_account_id):
-    """Get Rival Region accounts associated with Telegram account"""
+def _get_rr_players(session, telegram_player_id):
+    """Get Rival Region players associated with Telegram player"""
     return session.query(Player) \
         .join(Player.player_telegram) \
-        .filter(PlayerTelegram.telegram_id == telegram_account_id) \
+        .filter(PlayerTelegram.telegram_id == telegram_player_id) \
         .filter(PlayerTelegram.until_date_time == None) \
         .all()