fix(pterodactyl): don't call config 28 qunintillion times for no reason in the websocket message handler

This commit is contained in:
SeaswimmerTheFsh 2024-03-09 23:26:27 -05:00
parent 4c603eea46
commit 40b846123f
Signed by untrusted user who does not match committer: cswimr
GPG key ID: 0BB727FE47D716AE

View file

@ -52,18 +52,18 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
if await config.mask_ip() is True: if await config.mask_ip() is True:
content = mask_ip(content) content = mask_ip(content)
channel = coginstance.bot.get_channel(await config.console_channel()) console_channel = coginstance.bot.get_channel(await config.console_channel())
if channel is not None: chat_channel = coginstance.bot.get_channel(await config.chat_channel())
if console_channel is not None:
if content.startswith('['): if content.startswith('['):
pagified_content = pagify(content, delims=[" ", "\n"]) pagified_content = pagify(content, delims=[" ", "\n"])
for page in pagified_content: for page in pagified_content:
await channel.send(content=page, allowed_mentions=discord.AllowedMentions.none()) await console_channel.send(content=page, allowed_mentions=discord.AllowedMentions.none())
server_message = await check_if_server_message(content) server_message = await check_if_server_message(content)
if server_message: if server_message:
channel = coginstance.bot.get_channel(await config.chat_channel()) if chat_channel is not None:
if channel is not None: await chat_channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
chat_message = await check_if_chat_message(content) chat_message = await check_if_chat_message(content)
if chat_message: if chat_message:
@ -75,30 +75,27 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
join_message = await check_if_join_message(content) join_message = await check_if_join_message(content)
if join_message: if join_message:
channel = coginstance.bot.get_channel(await config.chat_channel()) if chat_channel is not None:
if channel is not None: if coginstance.bot.embed_requested(chat_channel):
if coginstance.bot.embed_requested(channel): await chat_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", allowed_mentions=discord.AllowedMentions.none()) await chat_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:
channel = coginstance.bot.get_channel(await config.chat_channel()) if chat_channel is not None:
if channel is not None: if coginstance.bot.embed_requested(chat_channel):
if coginstance.bot.embed_requested(channel): await chat_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", allowed_mentions=discord.AllowedMentions.none()) await chat_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:
channel = coginstance.bot.get_channel(await config.chat_channel()) if chat_channel is not None:
if channel is not None: if coginstance.bot.embed_requested(chat_channel):
if coginstance.bot.embed_requested(channel): await chat_channel.send(embed=await generate_achievement_embed(achievement_message['username'], achievement_message['achievement'], achievement_message['challenge']))
await channel.send(embed=await generate_achievement_embed(achievement_message['username'], achievement_message['achievement'], achievement_message['challenge']))
else: else:
await channel.send(f"{achievement_message['username']} has {'completed the challenge' if achievement_message['challenge'] else 'made the advancement'} {achievement_message['achievement']}") await chat_channel.send(f"{achievement_message['username']} has {'completed the challenge' if achievement_message['challenge'] else 'made the advancement'} {achievement_message['achievement']}")
if message['event'] == 'status': if message['event'] == 'status':
old_status = await config.current_status() old_status = await config.current_status()