fix(pterodactyl): don't allow pings through the websocket chat
All checks were successful
Actions / Lint Code (Ruff & Pylint) (push) Successful in 21s
Actions / Build Documentation (MkDocs) (push) Successful in 25s

This commit is contained in:
Seaswimmer 2024-03-02 15:11:40 -05:00
parent 1f51cb2a27
commit a7a42be4ed
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -69,7 +69,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
if server_message: if server_message:
channel = coginstance.bot.get_channel(await config.chat_channel()) channel = coginstance.bot.get_channel(await config.chat_channel())
if channel is not None: if channel is not None:
await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...') await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
join_message = await check_if_join_message(content) join_message = await check_if_join_message(content)
if join_message: if join_message:
@ -78,7 +78,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
if coginstance.bot.embed_requested(channel): if coginstance.bot.embed_requested(channel):
await channel.send(embed=await generate_join_leave_embed(join_message, True)) await channel.send(embed=await generate_join_leave_embed(join_message, True))
else: else:
await channel.send(f"{join_message} joined the game") await channel.send(f"{join_message} joined the game", allowed_mentions=discord.AllowedMentions.none())
leave_message = await check_if_leave_message(content) leave_message = await check_if_leave_message(content)
if leave_message: if leave_message:
@ -87,7 +87,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
if coginstance.bot.embed_requested(channel): if coginstance.bot.embed_requested(channel):
await channel.send(embed=await generate_join_leave_embed(leave_message, False)) await channel.send(embed=await generate_join_leave_embed(leave_message, False))
else: else:
await channel.send(f"{leave_message} left the game") await channel.send(f"{leave_message} left the game", allowed_mentions=discord.AllowedMentions.none())
achievement_message = await check_if_achievement_message(content) achievement_message = await check_if_achievement_message(content)
if achievement_message: if achievement_message:
@ -164,7 +164,7 @@ async def check_if_chat_message(text: str) -> Union[bool, dict]:
regex = await config.chat_regex() regex = await config.chat_regex()
match: Optional[re.Match[str]] = re.match(regex, text) match: Optional[re.Match[str]] = re.match(regex, text)
if match: if match:
groups = {"time": match.group(1), "username": match.group(2), "message": match.group(3)} groups = {"username": match.group(1), "message": match.group(2)}
logger.debug("Message is a chat message\n%s", json.dumps(groups)) logger.debug("Message is a chat message\n%s", json.dumps(groups))
return groups return groups
logger.debug("Message is not a chat message") logger.debug("Message is not a chat message")
@ -224,7 +224,7 @@ async def send_chat_discord(coginstance: Pterodactyl, username: str, message: st
webhook = discord.utils.get(webhooks, name="Pterodactyl Chat") webhook = discord.utils.get(webhooks, name="Pterodactyl Chat")
if webhook is None: if webhook is None:
webhook = await channel.create_webhook(name="Pterodactyl Chat") webhook = await channel.create_webhook(name="Pterodactyl Chat")
await webhook.send(content=message, username=username, avatar_url=avatar_url) await webhook.send(content=message, username=username, avatar_url=avatar_url, allowed_mentions=discord.AllowedMentions.none())
logger.debug("Chat message sent to Discord") logger.debug("Chat message sent to Discord")
else: else:
logger.debug("Chat channel not set. Skipping sending chat message to Discord") logger.debug("Chat channel not set. Skipping sending chat message to Discord")