forked from cswimr/SeaCogs
fix(pterodactyl): adding debug logging so i can figure out what's failing in the chat system
This commit is contained in:
parent
9a698fbac6
commit
7e728087c4
1 changed files with 9 additions and 0 deletions
|
@ -111,22 +111,29 @@ class Pterodactyl(commands.Cog):
|
|||
return ansi_escape.sub('', text)
|
||||
|
||||
def check_if_chat_message(self, text: str) -> Union[bool, dict]:
|
||||
self.logger.debug("Checking if message is a chat message")
|
||||
regex = self.config.chat_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
self.logger.debug("Message is a chat message")
|
||||
return {"time": match.group(1), "username": match.group(2), "message": match.group(3)}
|
||||
self.logger.debug("Message is not a chat message")
|
||||
return False
|
||||
|
||||
async def get_info(self, username: str) -> Optional[dict]:
|
||||
self.logger.debug("Retrieving player info for %s", username)
|
||||
endpoint = await self.config.endpoint()
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(f"https://playerdb.co/api/player/{endpoint}/{username}") as response:
|
||||
if response.status == 200:
|
||||
self.logger.debug("Player info retrieved for %s", username)
|
||||
return await response.json()
|
||||
else:
|
||||
self.logger.error("Failed to retrieve player info for %s: %s", username, response.status)
|
||||
return None
|
||||
|
||||
async def send_chat_discord(self, username: str, message: str, avatar_url: str) -> None:
|
||||
self.logger.debug("Sending chat message to Discord")
|
||||
channel = self.bot.get_channel(await self.config.chat_channel())
|
||||
if channel is not None:
|
||||
webhooks = await channel.webhooks()
|
||||
|
@ -134,6 +141,8 @@ class Pterodactyl(commands.Cog):
|
|||
if webhook is None:
|
||||
webhook = await channel.create_webhook(name="Pterodactyl Chat")
|
||||
await webhook.send(content=message, username=username, avatar_url=avatar_url)
|
||||
self.logger.debug("Chat message sent to Discord")
|
||||
self.logger.debug("Chat channel not set. Skipping sending chat message to Discord")
|
||||
|
||||
def get_task(self):
|
||||
return self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection")
|
||||
|
|
Loading…
Reference in a new issue