From 3cf3ccc83a5a63fea4a7eb11d00710e97153f114 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 30 May 2023 23:00:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D0=B2=D0=BD=D1=8F=D0=BA=20=D1=81?= =?UTF-8?q?=20=D0=BC=D0=B8=D0=BA=D1=80=D0=BE=D1=84=D0=BE=D0=BD=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin_ext/mute.py | 19 +++++++++++++++++++ admin_ext/unmute.py | 19 +++++++++++++++++++ player.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 admin_ext/mute.py create mode 100644 admin_ext/unmute.py diff --git a/admin_ext/mute.py b/admin_ext/mute.py new file mode 100644 index 0000000..1158ee5 --- /dev/null +++ b/admin_ext/mute.py @@ -0,0 +1,19 @@ +import discord + +class Extension: + core = None + def __init__(self, core): + self.core = core + @core.tree.command(name = "mute", description = "Выключить микрофон") + @discord.app_commands.describe(profile=core.ANY_INPUT) + async def mute_player( + interaction: discord.Interaction, + profile: str + ): + await interaction.response.defer(thinking=True) + return await interaction.followup.send(f'{await self.__call__(profile, interaction.user)}', ephemeral=False) + + async def __call__(self, profile, discord_user): + steam64 = await self.core.GetSteam64OfDiscord(discord_user) + player = await self.core.GetPlayer(profile, steam64, False) + return await player.mute() \ No newline at end of file diff --git a/admin_ext/unmute.py b/admin_ext/unmute.py new file mode 100644 index 0000000..9411b08 --- /dev/null +++ b/admin_ext/unmute.py @@ -0,0 +1,19 @@ +import discord + +class Extension: + core = None + def __init__(self, core): + self.core = core + @core.tree.command(name = "unmute", description = "Включить микрофон") + @discord.app_commands.describe(profile=core.ANY_INPUT) + async def unmute_player( + interaction: discord.Interaction, + profile: str + ): + await interaction.response.defer(thinking=True) + return await interaction.followup.send(f'{await self.__call__(profile, interaction.user)}', ephemeral=False) + + async def __call__(self, profile, discord_user): + steam64 = await self.core.GetSteam64OfDiscord(discord_user) + player = await self.core.GetPlayer(profile, steam64, False) + return await player.unmute() \ No newline at end of file diff --git a/player.py b/player.py index 5bae005..f314416 100644 --- a/player.py +++ b/player.py @@ -228,6 +228,38 @@ class Player: raise AdminLowPermition raise UnknownBackendResponse + async def mute(self): + async with aiohttp.ClientSession(cookies={ + "secretkey":os.getenv("BACKEND_SECRETKEY"), + "steam64": self.requester_steam64}) as session: + async with session.post(f"{os.getenv('BACKEND_URL')}/api/admin/mute?steam64={self.steam64}", ssl=False) as response: + result = await response.text() + if response.status == 200: + return "Выключен микрофон" + elif response.status == 404: + raise NotFoundPlayerOnServer + elif response.status == 403: + raise LowPermition + elif response.status == 406: + raise AdminLowPermition + raise UnknownBackendResponse + + async def unmute(self): + async with aiohttp.ClientSession(cookies={ + "secretkey":os.getenv("BACKEND_SECRETKEY"), + "steam64": self.requester_steam64}) as session: + async with session.delete(f"{os.getenv('BACKEND_URL')}/api/admin/mute?steam64={self.steam64}", ssl=False) as response: + result = await response.text() + if response.status == 200: + return "Включен микрофон" + elif response.status == 404: + raise NotFoundPlayerOnServer + elif response.status == 403: + raise LowPermition + elif response.status == 406: + raise AdminLowPermition + raise UnknownBackendResponse + async def rcon(self, command, args): if not self.current: return "добродей дурачек забыл прогрузить профиль"