11from collections import defaultdict
22from dataclasses import dataclass , field
3- from typing import Any , Dict , List
3+ from typing import Any , Dict , List , Optional
44
5+ import discord
56import tenacity
6- from discord import Colour , Embed
7+ from discord import Colour , Embed , app_commands
78from discord .ext import commands
8- from discord . ext . commands import Context
9+ from slaobot import SlaoBot
910from utils .constants import POT_IMAGES
1011from utils .wcl_client import WCLClient
1112
@@ -73,29 +74,18 @@ def calculate_total(self) -> None:
7374
7475
7576class Potions (commands .Cog ):
76- def __init__ (self , bot ):
77- """Cog to check potions used during a raid.
7877
79- :param bot:
80- """
81- self .bot = bot
78+ @app_commands .command (description = 'Использование зелий и иже с ними' )
79+ @app_commands .describe (report_id = 'WCL report ID' )
80+ async def potions (self , interaction : discord .Interaction , report_id : str ) -> None :
81+ """Get data about potions used. """
82+ # noinspection PyUnresolvedReferences
83+ await interaction .response .defer ()
8284
83- @staticmethod
84- def raiders_by_id (rs : Dict [str , Any ]) -> Dict [int , str ]:
85- raiders = rs ['reportData' ]['report' ]['table' ]['data' ]['composition' ]
86- result = defaultdict ()
87-
88- for raider in raiders :
89- result [raider ['id' ]] = raider ['name' ]
90-
91- return result
92-
93- @commands .command (name = 'pot' )
94- async def pot_command (self , ctx : Context , report_id : str ) -> None :
95- """Get data about potions used. Format: <prefix>pot SOME_REPORT_ID."""
96- await self .process_pots (ctx , report_id )
85+ embed = await self .process_pots (report_id )
86+ await interaction .edit_original_response (embed = embed )
9787
98- async def process_pots (self , ctx : Context , report_id : str ) -> None :
88+ async def process_pots (self , report_id : str ) -> Optional [ discord . Embed ] :
9989 async with WCLClient () as client :
10090 try :
10191 rs = await client .get_pots (report_id )
@@ -104,7 +94,7 @@ async def process_pots(self, ctx: Context, report_id: str) -> None:
10494 except tenacity .RetryError :
10595 return
10696
107- raiders_by_id = self .raiders_by_id (table_summary )
97+ raiders_by_id = self ._raiders_by_id (table_summary )
10898
10999 consumables = RaidConsumables ()
110100 consumables .clear_data ()
@@ -132,12 +122,17 @@ async def process_pots(self, ctx: Context, report_id: str) -> None:
132122 value = self ._print_pot_total (consumables .combat_total ),
133123 inline = False )
134124
135- if ctx .message .author != self .bot .user :
136- await ctx .send (embed = embed )
137- else :
138- embeds = ctx .message .embeds
139- embeds .append (embed )
140- await ctx .message .edit (embeds = embeds )
125+ return embed
126+
127+ @staticmethod
128+ def _raiders_by_id (rs : Dict [str , Any ]) -> Dict [int , str ]:
129+ raiders = rs ['reportData' ]['report' ]['table' ]['data' ]['composition' ]
130+ result = defaultdict ()
131+
132+ for raider in raiders :
133+ result [raider ['id' ]] = raider ['name' ]
134+
135+ return result
141136
142137 @staticmethod
143138 def _print_pot_usage (entries : Dict [str , int ]) -> str :
@@ -164,5 +159,5 @@ def _print_pot_total(entries: Dict[str, List]) -> str:
164159 return result if len (result ) > 0 else 'Вагонимся'
165160
166161
167- async def setup (bot ):
168- await bot .add_cog (Potions (bot ))
162+ async def setup (bot : SlaoBot ):
163+ await bot .add_cog (Potions ())
0 commit comments