From 4979e44b7c487e8417ad0640dd38bc4e37801996 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 1 Mar 2024 15:21:44 -0500 Subject: [PATCH] feat(pterodactyl): updated how placeholders are parsed in get_chat_command(), updated documentation to match --- .docs/pterodactyl/setup.md | 8 ++++---- pterodactyl/pterodactyl.py | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.docs/pterodactyl/setup.md b/.docs/pterodactyl/setup.md index 8811bf9..7d5cfaf 100644 --- a/.docs/pterodactyl/setup.md +++ b/.docs/pterodactyl/setup.md @@ -127,11 +127,11 @@ achivement messages: ^\[\d{2}:\d{2}:\d{2} INFO\]: (.*) has (made the advancement The cog uses a tellraw command to send messages to Minecraft from Discord. To change this, use the `[p]pterodactyl config chat command` command. The JSON format Minecraft uses for this is very janky sometimes, if you need help with changing the command, you can join my [Discord server](https://discord.gg/eMUMe77Yb8). -Required placeholders: +Available placeholders: -- `.%U` - replaced with display name -- `.%M` - replaced with message contents -- `.%C` - replaced with top role color (hex) +- `.$U` - replaced with display name +- `.$M` - replaced with message contents +- `.$C` - replaced with top role color (hex) Default: ```json diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index 7f8034c..8bd49a6 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -83,7 +83,13 @@ class Pterodactyl(commands.Cog): async def get_chat_command(self, username: str, message: str, color: discord.Color) -> str: command: str = await config.chat_command() - command = command.replace(".$U", username).replace(".$M", message).replace(".$C", str(color)) + placeholders = { + "U": username, + "M": message, + "C": str(color) + } + for key, value in placeholders.items(): + command = command.replace('$.' + key, value) return command @commands.Cog.listener()