diff --git a/other_ext/webhook_helper.py b/other_ext/webhook_helper.py index 51cbac2..2f0f17a 100644 --- a/other_ext/webhook_helper.py +++ b/other_ext/webhook_helper.py @@ -5,6 +5,7 @@ import asyncio import traceback import os from exceptions import NotFoundPlayerOnServer +import aiohttp class Extension: core = None @@ -33,6 +34,19 @@ class Extension: "🔎":("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: @@ -111,6 +125,12 @@ class Extension: 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) @@ -129,3 +149,13 @@ class Extension: 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}") diff --git a/ws.py b/ws.py index f2f8621..a6c8ee8 100644 --- a/ws.py +++ b/ws.py @@ -2,14 +2,16 @@ import websocket, sys from threading import Thread from json import dumps from time import sleep +import os START_AFTER_CONNECT = None SERVICE_NAME = None def create_pulser(ws: websocket.WebSocketApp): def run(ws): + builddate = int(os.getenv("BUILDDATE", "0")) while 1: - ws.send_text(dumps({"name":SERVICE_NAME})) + ws.send_text(dumps({"name":SERVICE_NAME, "builddate":builddate})) sleep(15) thread = Thread(target=run, args=[ws], daemon=True) thread.start()