From 74f58162de3ad4900d8fbb0bf4467dbf7eecac0e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 21 Mar 2024 15:27:29 -0400 Subject: [PATCH] feat(pterodactyl): allow disabling console commands from being sent through discord --- .docs/pterodactyl/configuration.md | 19 ++++++++++++++++++- pterodactyl/config.py | 1 + pterodactyl/pterodactyl.py | 18 +++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.docs/pterodactyl/configuration.md b/.docs/pterodactyl/configuration.md index 662e81a..9fd4e26 100644 --- a/.docs/pterodactyl/configuration.md +++ b/.docs/pterodactyl/configuration.md @@ -39,7 +39,9 @@ Default value: tellraw @a ["",{"text":".$N ","color":".$C","insertion":"<@.$I>","hoverEvent":{"action":"show_text","contents":"Shift click to mention this user inside Discord"}},{"text":"(DISCORD):","color":"blue","clickEvent":{"action":"open_url","value":".$V"},"hoverEvent":{"action":"show_text","contents":"Click to join the Discord Server"}},{"text":" .$M","color":"white"}] ``` -## `consolechannel` +## `console` + +### `channel` /// admonition | Only give access to the console channel to people you trust! type: danger @@ -63,6 +65,21 @@ This is to prevent the console channel from flooding and getting backed up by Di Default value: `None` +### `commands` + +/// admonition | This has no effect on the `[p]pterodactyl command` text command, or the matching slash command. + type: danger +If you want to disable the ability to execute commands on the server through Discord, use the following commands: +`[p]pterodactyl config console commands False` - this command +`[p]command disable pterodactyl command` - disables the text command that lets you execute commands on the server +`[p]slash disable pterodactyl` - due to how slash commands are laid out, this is the only way to disable the ability to execute commands on the server +`[p]slash sync` - apply above slash command change +/// + +This option determines if commands sent to the console channel will be sent to the Pterodactyl console. + +Default value: `False` + ## `invite` This option determines what url the chat command will substitute in for the Discord invite placeholder. diff --git a/pterodactyl/config.py b/pterodactyl/config.py index 64079fb..28fecd8 100644 --- a/pterodactyl/config.py +++ b/pterodactyl/config.py @@ -7,6 +7,7 @@ def register_config(config_obj: Config) -> None: base_url=None, server_id=None, console_channel=None, + console_commands_enabled=False, current_status='', chat_regex=r"^\[\d{2}:\d{2}:\d{2}\sINFO\]: (?!\[(?:Server|Rcon)\])(?:<|\[)(\w+)(?:>|\]) (.*)", server_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]:(?: \[Not Secure\])? \[(?:Server|Rcon)\] (.*)", diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index 4c6455a..4be23f2 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -70,6 +70,10 @@ class Pterodactyl(commands.Cog): @commands.Cog.listener() async def on_message_without_command(self, message: discord.Message) -> None: if message.channel.id == await config.console_channel() and message.author.bot is False: + if await config.console_commands_enabled() is False: + await message.channel.send("Console commands are disabled.") + logger.debug("Received console command from %s, but console commands are disabled: %s", message.author.id, message.content) + return logger.debug("Received console command from %s: %s", message.author.id, message.content) await message.channel.send(f"Received console command from {message.author.id}: {message.content[:1900]}", allowed_mentions=discord.AllowedMentions.none()) try: @@ -349,12 +353,22 @@ class Pterodactyl(commands.Cog): self.retry_counter = 0 self.task = self.get_task() - @pterodactyl_config.command(name = "consolechannel") + @pterodactyl_config.group(name = "console") + async def pterodactyl_config_console(self, ctx: commands.Context): + """Configure console settings.""" + + @pterodactyl_config_console.command(name = "channel") async def pterodactyl_config_console_channel(self, ctx: commands.Context, channel: discord.TextChannel) -> None: """Set the channel to send console output to.""" await config.console_channel.set(channel.id) await ctx.send(f"Console channel set to {channel.mention}") + @pterodactyl_config_console.command(name = "commands") + async def pterodactyl_config_console_commands(self, ctx: commands.Context, enabled: bool) -> None: + """Enable or disable console commands.""" + await config.console_commands_enabled.set(enabled) + await ctx.send(f"Console commands set to {enabled}") + @pterodactyl_config.command(name = "invite") async def pterodactyl_config_invite(self, ctx: commands.Context, invite: str) -> None: """Set the invite link for your server.""" @@ -544,6 +558,7 @@ class Pterodactyl(commands.Cog): base_url = await config.base_url() server_id = await config.server_id() console_channel = await config.console_channel() + console_commands_enabled = await config.console_commands_enabled() chat_channel = await config.chat_channel() chat_command = await config.chat_command() chat_regex = await config.chat_regex() @@ -566,6 +581,7 @@ class Pterodactyl(commands.Cog): embed.description = f"""**Base URL:** {base_url} **Server ID:** `{server_id}` **Console Channel:** <#{console_channel}> + **Console Commands Enabled:** {self.get_bool_str(console_commands_enabled)} **Chat Channel:** <#{chat_channel}> **Startup Message:** {startup_msg} **Shutdown Message:** {shutdown_msg}