import discord import traceback import time import io from discord.utils import MISSING class Extension: core = None def __init__(self, core): self.core = core @core.tree.command(name = "profile", description = "Проверить профиль") @discord.app_commands.describe(profile=core.ANY_INPUT) async def check_profile_next( interaction: discord.Interaction, profile: str = "" ): return await self.processMessage(interaction, profile) async def getPlayer(self, profile:str, discord_user: discord.Member): steam64 = await self.core.GetSteam64OfDiscord(discord_user) player = await self.core.GetPlayer(profile, steam64) if profile else await self.core.GetPlayer(steam64, steam64) return player async def processMessage(self, interaction: discord.Interaction = None, profile: str = "", message: discord.Message = None, discord_user: discord.Member = None, content_to_response: str = "" ): if interaction: await interaction.response.defer(thinking=True) player = await self.getPlayer(profile, interaction.user if interaction else discord_user) file = None filename = None if player.hasAnyConnect: #create image if posible try: chartImage = await player.getGametimeViaImage() filename = f"{player.steam64}.{int(time.time())}.png" print(f"Size of image: {len(chartImage)} bytes") file = discord.File(io.BytesIO(chartImage), filename=filename) except: traceback.print_exc() pass embed: discord.Embed = player.embedNext if file and filename: embed.set_image(url=f"attachment://{filename}") if interaction: return await interaction.followup.send( content = content_to_response if content_to_response else MISSING, embed=embed, file=file, ephemeral=False) if message: return await message.channel.send( content = content_to_response if content_to_response else MISSING, embed=embed, file=file) raise Exception('Unknown processor') else: if interaction: return await interaction.followup.send( content = content_to_response if content_to_response else MISSING, embed=embed, ephemeral=False) if message: return await message.channel.send( content = content_to_response if content_to_response else MISSING, embed=embed, ephemeral=False) raise Exception('Unknown processor') async def __call__(self, *args, **kwds): return [self.processMessage]