Advertisement
_andrea_

Untitled

Aug 14th, 2022
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.75 KB | None | 0 0
  1. @typing
  2. @log
  3. async def stats(client: Client, message: Message, summoner_name: str = None, refresh: bool = False,
  4.                 language: str = None):
  5.     user_id = message.from_user.id
  6.     summoner_name = summoner_name or await parse_summoner_name(client, message, message.command[1:])
  7.     summoner = await async_api.get_summoner_by_name(summoner_name)
  8.     if not summoner:
  9.         return await summoner_not_found(message, language)
  10.     encrypted_account_id, summoner_id, puuid = summoner.accountId, summoner.id, summoner.puuid
  11.     # match_number = await async_api.get_match_number(encrypted_account_id)
  12.     if language is None:
  13.         language, mastery_score, last_match, ranks = await asyncio.gather(
  14.             get_language(user_id),
  15.             async_api.get_mastery_score(summoner_id),
  16.             async_api.get_nth_match(puuid),
  17.             async_api.get_league(summoner_id),
  18.             return_exceptions = True
  19.         )
  20.     else:
  21.         mastery_score, last_match, ranks = await asyncio.gather(
  22.             async_api.get_mastery_score(summoner_id),
  23.             async_api.get_nth_match(puuid),
  24.             async_api.get_league(summoner_id),
  25.             return_exceptions = True
  26.         )
  27.     last_match: types.MatchDto
  28.     text = [
  29.         league.stats_name.get(language, f'<code>{escape(summoner.name)}</code>'),
  30.         league.stats_summoner_level.get(language, summoner.summonerLevel),
  31.         league.stats_total_mastery.get(language, mastery_score),
  32.         # league.stats_match_number.get(language, match_number),
  33.     ]
  34.     if last_match:
  35.         text.append(
  36.             league.stats_last_match.get(
  37.                 language,
  38.                 datetime.fromtimestamp(
  39.                     last_match.info.gameCreation // 1000
  40.                 ).strftime('%d/%m/%Y %H:%M:%S UTC')
  41.             )
  42.         )
  43.     if isinstance(ranks, set) and ranks:
  44.         ranks = sorted(ranks, key = lambda x: x.queueType, reverse = True)
  45.         for rank in ranks:
  46.             text.append('')
  47.             text.append(f'<u>{" ".join(rank.queueType.split("_"))}</u>')
  48.             text.append(f'{rank.tier} {rank.rank} {rank.leaguePoints}')
  49.             text.append(f'<code>{league.stats_wins.get(language, rank.wins)}</code>')
  50.             text.append(f'<code>{league.stats_losses.get(language, rank.losses)}</code>')
  51.             total_matches = rank.wins + rank.losses
  52.             text.append(f'<code>{league.stats_total_matches.get(language, total_matches)}</code>')
  53.             text.append(f'<code>{league.stats_ratio.get(language, math.floor(rank.wins / total_matches * 100))}</code>')
  54.             if rank.miniSeries:
  55.                 text.append(
  56.                     f'<code>{league.stats_promo.get(language, rank.miniSeries.progress.replace("N", "-"))}</code>'
  57.                 )
  58.             if rank.freshBlood:
  59.                 text.append(f'<b>{league.stats_fresh_blood.get(language)}</b>')
  60.             if rank.veteran:
  61.                 text.append(f'<b>{league.stats_veteran.get(language)}</b>')
  62.     text = '\n'.join(text).strip()
  63.     reply_markup = keyboards.get_stats_kb(summoner_name, language)
  64.     if refresh:
  65.         if text != message.caption.html:
  66.             # print(text, message.caption.html, sep = '\n\n\n\n')
  67.             await message.edit_caption(
  68.                 text,
  69.                 reply_markup = reply_markup
  70.             )
  71.     else:
  72.         try:
  73.             await message.reply_photo(
  74.                 async_api.get_profile_icon_url(summoner.profileIconId),
  75.                 caption = text,
  76.                 reply_markup = reply_markup
  77.             )
  78.         except:
  79.             await message.reply_photo(
  80.                 async_api.get_profile_icon_url(0),
  81.                 caption = text,
  82.                 reply_markup = reply_markup
  83.             )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement