feat(pterodactyl): allow disabling console commands from being sent through discord

This commit is contained in:
Seaswimmer 2024-03-21 15:27:29 -04:00
parent 39808f1766
commit 74f58162de
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063
3 changed files with 36 additions and 2 deletions

View file

@ -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.

View file

@ -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)\] (.*)",

View file

@ -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}