diff --git a/bot.py b/bot.py index 63919d9..242a2c3 100644 --- a/bot.py +++ b/bot.py @@ -104,7 +104,7 @@ class DiscordClient(commands.Bot): return await interaction.followup.send("Игрок не найден на серверах", ephemeral=True) elif isinstance(error.original, UnknownBackendResponse): traceback.print_exc() - return await interaction.followup.send("Ошибка на стороне сервера в исполнении говнокода, стоит подождать или позвать помощь", ephemeral=False) + return await interaction.followup.send(f"Ошибка на стороне сервера в исполнении говнокода, стоит подождать или позвать помощь. Ответ сервера: {error.original.status_code}", ephemeral=False) elif isinstance(error.original, discord.errors.NotFound): return await interaction.followup.send("Слишком долгий ответ со стороны сервера, причины:\n1) Возможно бекенд сдох\n2)Cлишком долгий незапланированный ответ с сервера\n3)Стоит позвать помощь", ephemeral=True) elif isinstance(error.original, NeedDiscordAuthOfSteam): diff --git a/exceptions.py b/exceptions.py index 0adfd4c..f1e3c53 100644 --- a/exceptions.py +++ b/exceptions.py @@ -1,3 +1,6 @@ +import string + + class CannotCastToSteamID(Exception): pass @@ -14,7 +17,25 @@ class NotFoundPlayerOnServer(Exception): pass class UnknownBackendResponse(Exception): - pass + def __init__(self, request_url: string = None, response = None, *args: object) -> None: + super().__init__(*args) + self.request_url = request_url + self.response = response + print(self.__str__()) + + @property + def status_code(self): + try: + return self.response.status + except: + return 0 + + def __str__(self) -> str: + try: + return f"{self.request_url}, response code: {self.status_code}" + except: + return "Cannot str exception" + class AdminLowPermition(Exception): pass \ No newline at end of file diff --git a/player.py b/player.py index 42ebc7c..2c88066 100644 --- a/player.py +++ b/player.py @@ -189,7 +189,8 @@ class Player: async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.post(f"{os.getenv('BACKEND_URL')}/api/admin/vip?steam64={self.steam64}&amount={amount}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/vip?steam64={self.steam64}&amount={amount}" + async with session.post(url, ssl=False) as response: await response.text() if response.status == 409: return "Нельзя выдать випку по причине что пользователь имеет отличные правила от випа" @@ -203,13 +204,14 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def unvip(self): async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.delete(f"{os.getenv('BACKEND_URL')}/api/admin/vip?steam64={self.steam64}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/vip?steam64={self.steam64}" + async with session.delete(url, ssl=False) as response: await response.text() if response.status == 409: return "У пользователя есть права, но они не вип, так что хуй" @@ -223,14 +225,14 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def kick(self, reason): async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.post(f"{os.getenv('BACKEND_URL')}/api/admin/kick?steam64={self.steam64}&reason={reason}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/kick?steam64={self.steam64}&reason={reason}" + async with session.post(url, ssl=False) as response: result = await response.text() if response.status == 200: return "Кикнут с серверов" @@ -240,13 +242,14 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def mute(self): async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.post(f"{os.getenv('BACKEND_URL')}/api/admin/mute?steam64={self.steam64}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/mute?steam64={self.steam64}" + async with session.post(url, ssl=False) as response: result = await response.text() if response.status == 200: return "Выключен микрофон" @@ -256,13 +259,14 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def unmute(self): async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.delete(f"{os.getenv('BACKEND_URL')}/api/admin/mute?steam64={self.steam64}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/mute?steam64={self.steam64}" + async with session.delete(url, ssl=False) as response: result = await response.text() if response.status == 200: return "Включен микрофон" @@ -272,7 +276,7 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def rcon(self, command, args): if not self.current: @@ -285,7 +289,8 @@ class Player: async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.post(f"{os.getenv('BACKEND_URL')}/api/admin/rcon?srv={server}&command={final_command}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/rcon?srv={server}&command={final_command}" + async with session.post(url, ssl=False) as response: res = await response.text() if response.status == 200: return res @@ -295,6 +300,7 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition + raise UnknownBackendResponse(url, response) else: raise NotFoundPlayerOnServer @@ -302,7 +308,8 @@ class Player: async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.post(f"{os.getenv('BACKEND_URL')}/api/admin/ban?steam64={self.steam64}&ban_reason={reason}&ban_length={minutes}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/ban?steam64={self.steam64}&ban_reason={reason}&ban_length={minutes}" + async with session.post(url, ssl=False) as response: ban_id = await response.text() if response.status in [201, 200]: return f"Игрок теперь забанен! Ид бана: #{ban_id}" @@ -314,13 +321,14 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def unban(self): async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.delete(f"{os.getenv('BACKEND_URL')}/api/admin/ban?steam64={self.steam64}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/ban?steam64={self.steam64}" + async with session.delete(url, ssl=False) as response: ban_id = await response.text() if response.status == 200: return f"Игрок теперь разбанен!" @@ -330,13 +338,14 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) async def foundAlts(self): async with aiohttp.ClientSession(cookies={ "secretkey":os.getenv("BACKEND_SECRETKEY"), "steam64": self.requester_steam64}) as session: - async with session.get(f"{os.getenv('BACKEND_URL')}/api/admin/db/alt?steam64={self.steam64}", ssl=False) as response: + url = f"{os.getenv('BACKEND_URL')}/api/admin/db/alt?steam64={self.steam64}" + async with session.get(url, ssl=False) as response: data = await response.json() if response.status == 200: resp = "Ссылки на аккаунты:\n" @@ -349,7 +358,7 @@ class Player: raise LowPermition elif response.status == 406: raise AdminLowPermition - raise UnknownBackendResponse + raise UnknownBackendResponse(url, response) ############### #user command