misc(pterodactyl): renamed tellraw to chat_command

This commit is contained in:
Seaswimmer 2024-02-29 22:41:06 -05:00
parent 37cdca09ec
commit 417f297193
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -28,7 +28,7 @@ class Pterodactyl(commands.Cog):
startup_arguments=None, startup_arguments=None,
power_action_in_progress=False, power_action_in_progress=False,
chat_regex=r"\[(\d{2}:\d{2}:\d{2})\sINFO\]:\s<(\w+)>\s(.*)", chat_regex=r"\[(\d{2}:\d{2}:\d{2})\sINFO\]:\s<(\w+)>\s(.*)",
tellraw_json='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]', chat_command='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',
api_endpoint="minecraft", api_endpoint="minecraft",
chat_channel=None chat_channel=None
) )
@ -147,12 +147,10 @@ class Pterodactyl(commands.Cog):
else: else:
self.logger.debug("Chat channel not set. Skipping sending chat message to Discord") self.logger.debug("Chat channel not set. Skipping sending chat message to Discord")
async def get_tellraw_string(self, username: str, message: str, color: discord.Color): async def get_chat_command(self, username: str, message: str, color: discord.Color):
tellraw = await self.config.tellraw_json() command = await self.config.chat_command()
self.logger.debug("Generating tellraw string:\n%s", tellraw) command = command.replace(".$U", username).replace(".$M", message).replace(".$C", str(color))
tellraw = tellraw.replace(".$U", username).replace(".$M", message).replace(".$C", str(color)) return command
self.logger.debug("Tellraw string generated:\n%s", tellraw)
return tellraw
def get_task(self): def get_task(self):
task = self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection") task = self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection")
@ -192,7 +190,7 @@ class Pterodactyl(commands.Cog):
channel = self.bot.get_channel(await self.config.console_channel()) channel = self.bot.get_channel(await self.config.console_channel())
if channel: if channel:
await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}") await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}")
msg = json.dumps({"event": "send command", "args": [await self.get_tellraw_string(message.author.display_name, message.content, message.author.color)]}) msg = json.dumps({"event": "send command", "args": [await self.get_chat_command(message.author.display_name, message.content, message.author.color)]})
self.logger.debug("Sending chat message to server:\n%s", msg) self.logger.debug("Sending chat message to server:\n%s", msg)
try: try:
await self.websocket.send(msg) await self.websocket.send(msg)
@ -257,7 +255,7 @@ class Pterodactyl(commands.Cog):
@pterodactyl_config_chat.command(name = "regex") @pterodactyl_config_chat.command(name = "regex")
async def pterodactyl_config_chat_regex(self, ctx: commands.Context, *, regex: str = None) -> None: async def pterodactyl_config_chat_regex(self, ctx: commands.Context, *, regex: str = None) -> None:
"""Set the regex pattern to match chat messages. """Set the regex pattern to match chat messages on the server.
See [documentation]() for more information.""" See [documentation]() for more information."""
#TODO - fix this link #TODO - fix this link
@ -267,15 +265,15 @@ class Pterodactyl(commands.Cog):
await self.config.chat_regex.set(regex) await self.config.chat_regex.set(regex)
await ctx.send(f"Chat regex set to:\n{box(regex, 'regex')}") await ctx.send(f"Chat regex set to:\n{box(regex, 'regex')}")
@pterodactyl_config_chat.command(name = "tellraw") @pterodactyl_config_chat.command(name = "command")
async def pterodactyl_config_chat_tellraw(self, ctx: commands.Context, *, tellraw: str = None) -> None: async def pterodactyl_config_chat_command(self, ctx: commands.Context, *, command: str = None) -> None:
"""Set the tellraw JSON to send chat messages to Discord. """Set the command that will be used to send messages from Discord.
Required placeholders: `.$U` (username), `.$M` (message), `.$C` (color) Required placeholders: `.$U` (username), `.$M` (message), `.$C` (color)
See [documentation]() for more information.""" See [documentation]() for more information."""
#TODO - fix this link #TODO - fix this link
if tellraw is None: if command is None:
tellraw = await self.config.tellraw_json() command = await self.config.chat_command()
return await ctx.send(f"Tellraw JSON is currently set to:\n{box(tellraw, 'json')}") return await ctx.send(f"Chat command is currently set to:\n{box(command, 'json')}")
await self.config.tellraw_json.set(tellraw) await self.config.chat_command.set(command)
await ctx.send(f"Tellraw JSON set to:\n{box(tellraw, 'json')}") await ctx.send(f"Chat command set to:\n{box(command, 'json')}")