1- from typing import Tuple , Callable
2-
3- import discord as lib_discord
4- import discord .ui
1+ import discord
2+ from discord import Embed
53from discord import app_commands
64from discord .ext import commands
75
@@ -17,17 +15,17 @@ def __init__(self, client: commands.Bot) -> None:
1715 self .client = client
1816 self .riotService = RiotRankService ()
1917
20- def create_player_embed (self , memberRankLol : MemberRankLol ) -> lib_discord . Embed :
18+ def create_player_embed (self , memberRankLol : MemberRankLol ) -> Embed :
2119 if memberRankLol .empty_lol_data ():
22- embed = lib_discord . Embed (
20+ embed = Embed (
2321 title = f"{ memberRankLol .riotName } #{ memberRankLol .tag } " ,
2422 description = "Unranked" ,
2523 color = 0x000000
2624 )
2725 embed .set_thumbnail (url = self .riotService .get_icone_url (memberRankLol .profileIconId ))
2826 return embed
2927
30- embed = lib_discord . Embed (
28+ embed = Embed (
3129 title = f"{ memberRankLol .riotName } #{ memberRankLol .tag } " ,
3230 description = f"{ memberRankLol .rank .emote } { memberRankLol .rank .name } { memberRankLol .get_division ()} { memberRankLol .lp } LP" ,
3331 color = int (memberRankLol .rank .color , 16 )
@@ -43,8 +41,8 @@ def create_player_embed(self, memberRankLol: MemberRankLol) -> lib_discord.Embed
4341 @app_commands .describe (riot_name = "votre nom d'invocateur" )
4442 @app_commands .describe (tag = "votre tag" )
4543 @app_commands .describe (discord = "compte discord du joueur, par défaut votre compte" )
46- async def register (self , interaction : lib_discord .Interaction , riot_name : str , tag : str ,
47- discord : lib_discord .Member = None ):
44+ async def register (self , interaction : discord .Interaction , riot_name : str , tag : str ,
45+ discord : discord .Member = None ):
4846 try :
4947 discord_id = interaction .user .id if discord is None else discord .id
5048
@@ -66,7 +64,7 @@ async def register(self, interaction: lib_discord.Interaction, riot_name: str, t
6664 await interaction .response .send_message (embed = embed , content = None )
6765
6866 @app_commands .command (name = "lol_leaderboard" , description = "affiche le leaderboard des joueurs du serveur" )
69- async def leaderboard (self , interaction : lib_discord .Interaction ):
67+ async def leaderboard (self , interaction : discord .Interaction ):
7068 await interaction .response .defer (ephemeral = False , thinking = True )
7169
7270 try :
@@ -94,7 +92,7 @@ async def leaderboard(self, interaction: lib_discord.Interaction):
9492
9593 @app_commands .command (name = "show_lol_rank" , description = "affiche le rank LoL d'un joueur" )
9694 @app_commands .describe (discord = "compte discord du joueur, par défaut votre compte" )
97- async def show_rank (self , interaction : lib_discord .Interaction , discord : lib_discord .Member ):
95+ async def show_rank (self , interaction : discord .Interaction , discord : discord .Member ):
9896 discord_id = interaction .user .id if discord is None else discord .id
9997
10098 memberLolAccounts = self .riotService .get_member_accounts (interaction .guild_id , discord_id )
@@ -103,7 +101,7 @@ async def show_rank(self, interaction: lib_discord.Interaction, discord: lib_dis
103101 await interaction .response .send_message ("Ce joueur n'est pas enregistré" , ephemeral = True )
104102 return
105103
106- async def send_message (embeds_to_send : list [lib_discord . Embed ]):
104+ async def send_message (embeds_to_send : list [Embed ]):
107105 if len (embeds_to_send ) != len (memberLolAccounts ):
108106 return await interaction .followup .send (embeds = embeds_to_send , content = None )
109107
@@ -121,7 +119,7 @@ async def send_message(embeds_to_send: list[lib_discord.Embed]):
121119
122120 @app_commands .command (name = "remove_lol_account" , description = "supprime un compte LoL" )
123121 @app_commands .describe (riot_name = "le nom du compte à supprimer" )
124- async def remove_account (self , interaction : lib_discord .Interaction , riot_name : str ):
122+ async def remove_account (self , interaction : discord .Interaction , riot_name : str ):
125123 memberRankLol = self .riotService .remove_member_by_name (interaction .guild_id , interaction .user .id , riot_name )
126124
127125 if not memberRankLol :
@@ -133,7 +131,7 @@ async def remove_account(self, interaction: lib_discord.Interaction, riot_name:
133131
134132 @app_commands .command (name = "lol_ranked_history" , description = "affiche les 10 dernières parties classées" )
135133 @app_commands .describe (discord = "compte discord du joueur, par défaut votre compte" )
136- async def ranked_history (self , interaction : lib_discord .Interaction , discord : lib_discord .Member = None ):
134+ async def ranked_history (self , interaction : discord .Interaction , discord : discord .Member = None ):
137135 await interaction .response .defer (ephemeral = False , thinking = True )
138136 discord_id = interaction .user .id if discord is None else discord .id
139137
@@ -142,29 +140,28 @@ async def ranked_history(self, interaction: lib_discord.Interaction, discord: li
142140 await interaction .followup .send ("Ce joueur n'est pas enregistré" , ephemeral = True )
143141 return
144142
145- account = accounts [0 ]
146-
147- ranked_history = self .riotService .riot_api .get_ranked_history (account .puuid )
148- games_information = self .riotService .riot_api .get_matchs_data (ranked_history )
149- player_game_info = [PlayerGameInfoLoL (game , account .puuid ) for game in games_information ]
150-
151- number_of_wins = len ([game for game in player_game_info if game .status == GameStatus .WIN .value ])
152- number_of_games = len ([game for game in player_game_info if game .status != GameStatus .REMAKE .value ])
153- winrate = round ((number_of_wins / number_of_games ) * 100 , 2 ) if number_of_games != 0 else 0
154- description = f"Winrate sur { number_of_games } games: { winrate } %\n \n "
155-
156- view = ViewPages (
157- interaction ,
158- f"Historique de { account .riotName } #{ account .tag } " ,
159- player_game_info ,
160- 10 ,
161- lambda game : f"{ game .status } : { game .championName } - { game .kills } /{ game .deaths } /{ game .assists } - { game .gameDuration // 60 } m{ game .gameDuration % 60 } s - <t:{ game .endTime // 1000 } :R>" ,
162- description = description ,
163- defer_was_called_on_interaction = True
164- )
165-
166- await view .start ()
167-
143+ embeds = []
144+ for account in accounts :
145+ # fetch data
146+ ranked_history = self .riotService .riot_api .get_ranked_history (account .puuid )
147+ games_information = self .riotService .riot_api .get_matchs_data (ranked_history )
148+ player_game_info = [PlayerGameInfoLoL (game , account .puuid ) for game in games_information ]
149+
150+ # sorting data
151+ number_of_wins = len ([game for game in player_game_info if game .status == GameStatus .WIN .value ])
152+ number_of_games = len ([game for game in player_game_info if game .status != GameStatus .REMAKE .value ])
153+ winrate = round ((number_of_wins / number_of_games ) * 100 , 2 ) if number_of_games != 0 else 0
154+ description = f"Winrate sur { number_of_games } games: { winrate } %\n \n "
155+
156+ # create embeds
157+ for game in player_game_info :
158+ description += f"{ game .status } { game .championName } - { game .kills } /{ game .deaths } /{ game .assists } - <t:{ game .endTime // 1000 } :R>\n "
159+
160+ embed = Embed (title = f"Ranked History - { account .getName ()} " , description = description )
161+ embed .set_thumbnail (url = self .riotService .get_icone_url (account .profileIconId ))
162+ embeds .append (embed )
163+
164+ await interaction .followup .send (embeds = embeds )
168165
169166async def setup (bot ):
170167 await bot .add_cog (LolRank (bot ))
0 commit comments