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.
161 lines
6.2 KiB
161 lines
6.2 KiB
from email import message
|
|
from discord.ext import tasks, commands
|
|
import discord
|
|
import asyncio
|
|
import traceback
|
|
import os
|
|
from exceptions import NotFoundPlayerOnServer
|
|
import aiohttp
|
|
|
|
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.null_reason, {"requester":""}),
|
|
"🦵":("kick", {"profile":"", "discord_user":None, "reason":""}),
|
|
"🔇":("mute", {"profile":"", "discord_user":None}),
|
|
"😇":("unban", {"profile":"", "discord_user":None}),
|
|
"<:hueglot:713139400028061767>":("kick", {"profile":"", "requester_profile":"", "discord_user":None, "reason":""}),
|
|
"🔍":("profile", {"profile":"", "discord_user":None}),
|
|
"🔎":("profile", {"profile":"", "requester_profile":"", "discord_user":None})
|
|
}
|
|
|
|
self.reaction_translate = {
|
|
'😘':"ban",
|
|
'🔍':"inspect",
|
|
'🦵':"kick",
|
|
'🔨':"ban30",
|
|
'⚒️':"ban120",
|
|
'📨':"noreason",
|
|
'<:hueglot:713139400028061767>':"author_kick",
|
|
'🔇':"mute",
|
|
'😇':"unban",
|
|
'🔎':'author_inspect'
|
|
}
|
|
|
|
@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 = self.webhook_reaction_translate[str(payload.emoji)][0]
|
|
kwargs = self.webhook_reaction_translate[str(payload.emoji)][1].copy()
|
|
|
|
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)
|
|
|
|
try:
|
|
await msg.delete()
|
|
except Exception as err:
|
|
print("Cannot delete user response 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 "requester_profile" in kwargs:
|
|
kwargs["profile"] = message.embeds[0].author.url
|
|
del kwargs["requester_profile"]
|
|
elif "profile" in kwargs:
|
|
kwargs["profile"] = message.embeds[0].url
|
|
#else:
|
|
# return await message.channel.send(content=f"невозможно получить профиль игрока из webhook")
|
|
|
|
print(kwargs)
|
|
|
|
try:
|
|
report_id = message.embeds[0].color.value
|
|
await self.add_action(report_id, str(payload.emoji))
|
|
except Exception:
|
|
traceback.print_exc()
|
|
|
|
try:
|
|
if type(executor) == str:
|
|
result = await self.core.loaded_extensions[executor](**kwargs)
|
|
else:
|
|
result = await executor(**kwargs)
|
|
except NotFoundPlayerOnServer:
|
|
return await message.channel.send(content=f"{user.mention}!\nДействие {payload.emoji} сообщило что игрок сейчас не играет на сервере!\nВозможен пиздеж и провокация!", delete_after=60)
|
|
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 "Следующий бан будет без причины"
|
|
|
|
async def add_action(self, report_id, emoji):
|
|
if emoji in self.reaction_translate:
|
|
async with aiohttp.ClientSession(cookies={
|
|
"secretkey":os.getenv("BACKEND_SECRETKEY")}) as session:
|
|
async with session.post(f"{os.getenv('BACKEND_URL')}/api/server/any/report/{report_id}", data=self.reaction_translate[emoji], ssl = False) as response:
|
|
result = await response.text()
|
|
print(f"Action added with id: {result}")
|
|
else:
|
|
print(f"Not found traslate for reaction: {emoji}")
|
|
|