You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
4.0 KiB
105 lines
4.0 KiB
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, "requester":""}),
|
|
"🔨":('ban', {"profile":"", "reason":"", "minutes":30, "requester":""}),
|
|
"⚒️":('ban', {"profile":"", "reason":"", "minutes":120, "requester":""}),
|
|
"📨":(self.no_reason, {"requester":""}),
|
|
"🦵":("kick", {"profile":""}),
|
|
"🔇":("mute", {"profile":""}),
|
|
"😇":("unban", {"profile":""}),
|
|
"hueglot:713139400028061767":("kick", {"profile":"", "requester_profile":""}),
|
|
"🔍":("profile", {"profile":""}),
|
|
"🔎":("unban", {"profile":"", "requester_profile":""})
|
|
}
|
|
|
|
@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:
|
|
message.add_reaction(emoji)
|
|
except Exception as err:
|
|
print(f"Cannot add reaction on webhook, error: {err}")
|
|
return
|
|
|
|
@core.listen()
|
|
async def on_reaction_add(reaction: discord.Reaction, user: discord.User):
|
|
if reaction.message.webhook_id != self.track_webhook_id:
|
|
return
|
|
|
|
if reaction.me:
|
|
return
|
|
|
|
if not reaction.message.guild.get_member(user.id).get_role(self.track_role_id):
|
|
return
|
|
|
|
if str(reaction.emoji) in self.webhook_reaction_translate.keys():
|
|
executor, kwargs = self.webhook_reaction_translate[str(reaction.emoji)]
|
|
if "requester" in kwargs:
|
|
kwargs["requester"] = user.id
|
|
if "reason" in kwargs and not user.id in self.no_reason:
|
|
def check(message: discord.Message):
|
|
return message.author == user and message.channel == reaction.message.channel
|
|
|
|
try:
|
|
req_msg = await reaction.message.channel.send(content=f"{user.mention}!\nВведи причину отправив сообщение")
|
|
msg = await self.core.wait_for("message", timeout=60.0, check=check)
|
|
except asyncio.TimeoutError:
|
|
await reaction.message.channel.send(content=f"{user.mention}!\nДействие {reaction.emoji} отменено спустя время", delete_after=60)
|
|
return
|
|
|
|
try:
|
|
await req_msg.delete()
|
|
except Exception as err:
|
|
print("Cannot delete request reason message, error: " +err)
|
|
|
|
#не ну это пиздец
|
|
if msg.content.split(" ") > 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 "Следующий бан будет без причины"
|
|
|