from email import message from discord.ext import tasks, commands import discord import asyncio import traceback import os class Extension: core = None track_guild_id = 0 track_channel_id = 712673654487515238 track_webhook_id = 740681080557797499 track_role_id = 744928190895489074 no_reason = {} def __init__(self, core): if not os.getenv("WEBHOOK_HELPER_ENABLED", None): return None self.core = core self.track_guild_id = core.main_server_id self.webhook_reaction_translate = { "😘":('ban', {"profile":"", "reason":"", "minutes":0, "discord_user":None}), "🔨":('ban', {"profile":"", "reason":"", "minutes":30, "discord_user":None}), "⚒️":('ban', {"profile":"", "reason":"", "minutes":120, "discord_user":None}), "📨":(self.no_reason, {"requester":""}), "🦵":("kick", {"profile":"", "discord_user":None}), "🔇":("mute", {"profile":""}), "😇":("unban", {"profile":"", "discord_user":None}), "<:hueglot:713139400028061767>":("kick", {"profile":"", "requester_profile":"", "discord_user":None}), "🔍":("profile", {"profile":"", "discord_user":None}), "🔎":("unban", {"profile":"", "requester_profile":"", "discord_user":None}) } @core.listen() async def on_message(message: discord.Message): if message.webhook_id != self.track_webhook_id: return for emoji in list(self.webhook_reaction_translate.keys()): try: await message.add_reaction(emoji) except Exception as err: print(f"Cannot add reaction on webhook, error: {err}") return @core.listen() async def on_raw_reaction_add(payload): channel = await self.core.fetch_channel(payload.channel_id) message: discord.Message = await channel.fetch_message(payload.message_id) user: discord.User = await self.core.fetch_user(payload.user_id) if message.webhook_id != self.track_webhook_id: return if self.core.user.id == payload.user_id: return if not message.guild.get_member(user.id).get_role(self.track_role_id): return print(payload.emoji, message.webhook_id, self.core.user.id == payload.user_id, message.guild.get_member(user.id).get_role(self.track_role_id)) if str(payload.emoji) in self.webhook_reaction_translate.keys(): executor, kwargs = self.webhook_reaction_translate[str(payload.emoji)] if "requester" in kwargs: kwargs["requester"] = user.id if "discord_user" in kwargs: kwargs["discord_user"] = user if "reason" in kwargs and not user.id in self.no_reason: def check(msg: discord.Message): return msg.author == user and msg.channel == message.channel try: req_msg = await message.channel.send(content=f"{user.mention}!\nВведи причину отправив сообщение") msg = await self.core.wait_for("message", timeout=60.0, check=check) except asyncio.TimeoutError: await message.channel.send(content=f"{user.mention}!\nДействие {payload.emoji} отменено спустя время", delete_after=60) return try: await req_msg.delete() except Exception as err: print("Cannot delete request reason message, error: " +err) #не ну это пиздец if len(msg.content.split(" ")) > 0 and msg.content.lower().split(" ")[0] == "отмена": return await message.channel.send(content=f"{user.mention}!\nДействие {payload.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"] = message.embeds[0].url if "requester_profile" in kwargs: kwargs["profile"] = message.embeds[0].author.url del kwargs["requester_profile"] 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 message.channel.send(content=f"{user.mention}!\nДействие {payload.emoji} невозможно из-за ошибки: {err}. Стоит написать добродею!", delete_after=60) return await message.channel.send(content=f"{user.mention}!\nДействие {payload.emoji} дало ответ: {result}") async def null_reason(self, requester): self.no_reason[requester] = "no reason" return "Следующий бан будет без причины"