fix(pterodactyl): removed ansi escape codes
This commit is contained in:
parent
c740cdc6dc
commit
ec2cd09f8e
1 changed files with 8 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import websockets
|
import websockets
|
||||||
|
@ -77,13 +78,19 @@ class Pterodactyl(commands.Cog):
|
||||||
if json.loads(message)['event'] == 'console output' and await self.config.console_channel() is not None:
|
if json.loads(message)['event'] == 'console output' and await self.config.console_channel() is not None:
|
||||||
channel = self.bot.get_channel(await self.config.console_channel())
|
channel = self.bot.get_channel(await self.config.console_channel())
|
||||||
if channel is not None:
|
if channel is not None:
|
||||||
await channel.send(json.loads(message)['args'][0][:1900])
|
content = self.remove_ansi_escape_codes(json.loads(message)['args'][0][:1900])
|
||||||
|
await channel.send(content=content)
|
||||||
#TODO - Add pagification for long messages to prevent Discord API errors
|
#TODO - Add pagification for long messages to prevent Discord API errors
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as e:
|
||||||
self.logger.debug("WebSocket connection closed: %s", e)
|
self.logger.debug("WebSocket connection closed: %s", e)
|
||||||
websocket_credentials = client.servers.get_websocket(server_id)
|
websocket_credentials = client.servers.get_websocket(server_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
def remove_ansi_escape_codes(self, text: str):
|
||||||
|
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||||
|
#NOTE - https://chat.openai.com/share/d92f9acf-d776-4fd6-a53f-b14ac15dd540
|
||||||
|
return ansi_escape.sub('', text)
|
||||||
|
|
||||||
def get_task(self):
|
def get_task(self):
|
||||||
return self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection")
|
return self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue