From 92186a4770ca31d14cad7b9d455f25e9474c3a17 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 7 Mar 2023 22:46:05 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B6=D0=B5=20=D0=BF=D0=BE=D1=87=D1=82?= =?UTF-8?q?=D0=B8=20=D1=80=D0=B5=D0=BB=D0=B8=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin_ext/kick.py | 11 ++++-- admin_ext/unban.py | 13 +++++-- other_ext/url_checker.py | 75 +++++++++++++++++++++---------------- other_ext/webhook_helper.py | 64 ++++++++++++++++++++++++++----- user_ext/profile.py | 2 +- 5 files changed, 115 insertions(+), 50 deletions(-) diff --git a/admin_ext/kick.py b/admin_ext/kick.py index ee9ab3c..d4e3e4d 100644 --- a/admin_ext/kick.py +++ b/admin_ext/kick.py @@ -1,7 +1,9 @@ import discord class Extension: + core = None def __init__(self, core): + self.core = core @core.tree.command(name = "kick", description = "Кикнуть игрока") @discord.app_commands.describe(profile=core.ANY_INPUT, reason="причина") async def kick_player( @@ -10,6 +12,9 @@ class Extension: reason: str = "" ): await interaction.response.defer(thinking=True) - steam64 = await core.GetSteam64OfDiscord(interaction.user) - player = await core.GetPlayer(profile, steam64, False) - return await interaction.followup.send(f'{await player.kick(reason)}', ephemeral=False) \ No newline at end of file + return await interaction.followup.send(f'{await self.__call__(profile, reason, interaction.user)}', ephemeral=False) + + async def __call__(self, profile, reason, requester): + steam64 = await self.core.GetSteam64OfDiscord(requester) + player = await self.core.GetPlayer(profile, steam64, False) + return await player.kick(reason) \ No newline at end of file diff --git a/admin_ext/unban.py b/admin_ext/unban.py index 75fd45c..18d94a5 100644 --- a/admin_ext/unban.py +++ b/admin_ext/unban.py @@ -1,14 +1,19 @@ import discord class Extension: + core = None def __init__(self, core): + self.core = core @core.tree.command(name = "unban", description = "Разбанить игрока") @discord.app_commands.describe(profile=core.ANY_INPUT) - async def ban_player( + async def unban_player( interaction: discord.Interaction, profile: str ): await interaction.response.defer(thinking=True) - steam64 = await core.GetSteam64OfDiscord(interaction.user) - player = await core.GetPlayer(profile, steam64, False) - return await interaction.followup.send(f'{await player.unban()}', ephemeral=False) \ No newline at end of file + return await interaction.followup.send(f'{await self.__call__(profile, interaction.user)}', ephemeral=False) + + async def __call__(self, profile, requester): + steam64 = await self.core.GetSteam64OfDiscord(requester) + player = await self.core.GetPlayer(profile, steam64, False) + return await player.unban() \ No newline at end of file diff --git a/other_ext/url_checker.py b/other_ext/url_checker.py index 3e52de8..d5defb8 100644 --- a/other_ext/url_checker.py +++ b/other_ext/url_checker.py @@ -7,45 +7,54 @@ class Extension: allow_domains = ["steamcommunity.com","s.team","tenor.com","tf2.pblr-nyk.pro", "pblr-nyk.pro", "youtu.be", "youtube.com"] WEB_URL_REGEX = r"""(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(? 0 and msg.content.lower().split(" ")[0] == "отмена": + return await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} отменено по твоей воле", delete_after=60) + else: + kwargs["reason"] = msg.content + if "reason" in kwargs and user.id in self.no_reason: + kwargs["reason"] = self.no_reason[user.id] + del self.no_reason[user.id] + if "profile" in kwargs: + kwargs["profile"] = reaction.message.embeds[0].url + if "requester_profile" in kwargs: + kwargs["profile"] = reaction.message.embeds[0].author.url + + try: + if type(executor) == str: + result = await self.core.loaded_extensions[executor](**kwargs) + else: + result = await executor(**kwargs) + except Exception as err: + traceback.print_exc() + return await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} невозможно из-за ошибки: {err}. Стоит написать добродею!", delete_after=60) + + return await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} дало ответ: {result}") + async def null_reason(self, requester): self.no_reason[requester] = "no reason" + return "Следующий бан будет без причины" diff --git a/user_ext/profile.py b/user_ext/profile.py index fd29440..dc8aef7 100644 --- a/user_ext/profile.py +++ b/user_ext/profile.py @@ -13,7 +13,7 @@ class Extension: profile: str = "" ): await interaction.response.defer(thinking=True) - player = self.__call__(profile, interaction.user) + player = await self.__call__(profile, interaction.user) return await interaction.followup.send(embed=player.embed, ephemeral=False) async def __call__(self, profile:str, discord_user: discord.Member) -> Player: