implementing configuration system

This commit is contained in:
Seaswimmer 2023-07-14 11:51:46 -04:00
parent 44f4e56cdc
commit e957d27694
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -38,3 +38,50 @@ class Pterodactyl(commands.Cog):
await interaction.response.send_message(f"Something went wrong.\nError: `{e}`", ephemeral=True) await interaction.response.send_message(f"Something went wrong.\nError: `{e}`", ephemeral=True)
return return
await interaction.response.send_message(url, ephemeral=True) await interaction.response.send_message(url, ephemeral=True)
@app_commands.command()
async def config(self, interaction: discord.Interaction):
"""Configures the Pterodactyl cog."""
await interaction.response.send_modal(self.ConfigModal(interaction.guild))
class ConfigModal(discord.ui.Modal, title="Configuration"):
def __init__(self, guild: discord.guild):
super().__init__()
self.guild = guild
base_url = discord.ui.TextInput(
label="Base URL",
placeholder="Input your Pterodactyl Panel's Base URL here, without `HTTPS` or `HTTP`.\nExample: `pterodactyl.file.properties`",
style=discord.TextStyle.paragraph,
required=False,
max_length=300
)
api_key = discord.ui.TextInput(
label="API Key",
placeholder="Input your Pterodactyl Client API Key here.",
style=discord.TextStyle.short,
required=False,
max_length=300
)
server_id = discord.ui.TextInput(
label="Server ID",
placeholder="Input your Pterodactyl server's Server ID here.",
style=discord.TextStyle.short,
required=False,
max_length=300
)
async def on_submit(self, interaction: discord.Interaction):
message = ""
if self.base_url.value != "":
await Pterodactyl.config.guild(self.guild).base_url.set(self.base_url)
message += f"Base URL set to `{self.base_url.value}`.\n"
if self.api_key.value != "":
await Pterodactyl.config.guild(self.guild).api_key.set(self.api_key)
message += f"API Key set to `{self.api_key.value}`.\n"
if self.server_id.value != "":
await Pterodactyl.config.guild(self.guild).server_id.set(self.server_id)
message += f"Server ID set to `{self.server_id.value}`.\n"
if message == "":
config_list = [await Pterodactyl.config.guild(self.guild).base_url(), await Pterodactyl.config.guild(self.guild).api_key(), await Pterodactyl.config.guild(self.guild).server_id()]
message = f"No changes were made.\nCurrent configuration:\n- Base URL: `{config_list[0]}`\n- API Key: `{config_list[1]}`\n- Server ID: `{config_list[2]}`"
await interaction.response.send_message(message, ephemeral=True)