hopefully fixed modal this time

This commit is contained in:
Seaswimmer 2023-07-14 12:22:28 -04:00
parent f678595016
commit 68cbabb7df
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -42,12 +42,13 @@ class Pterodactyl(commands.Cog):
@app_commands.command() @app_commands.command()
async def config(self, interaction: discord.Interaction): async def config(self, interaction: discord.Interaction):
"""Configures the Pterodactyl cog.""" """Configures the Pterodactyl cog."""
await interaction.response.send_modal(self.ConfigModal(interaction.guild)) config_list = [await self.config.guild(interaction.guild).base_url(), await self.config.guild(interaction.guild).api_key(), await self.config.guild(interaction.guild).server_id()]
await interaction.response.send_modal(self.ConfigModal(config_list))
class ConfigModal(discord.ui.Modal, title="Pterodactyl Manager Configuration"): class ConfigModal(discord.ui.Modal, title="Pterodactyl Manager Configuration"):
def __init__(self, guild: discord.guild): def __init__(self, config: list):
super().__init__() super().__init__()
self.guild = guild self.config = config
base_url = discord.ui.TextInput( base_url = discord.ui.TextInput(
label="Base URL", label="Base URL",
placeholder="Input your Pterodactyl Panel's Base URL here, without HTTPS or HTTP.", placeholder="Input your Pterodactyl Panel's Base URL here, without HTTPS or HTTP.",
@ -71,17 +72,16 @@ class Pterodactyl(commands.Cog):
) )
async def on_submit(self, interaction: discord.Interaction): async def on_submit(self, interaction: discord.Interaction):
config_list = [await Pterodactyl.config.guild(interaction.guild).base_url(), await Pterodactyl.config.guild(interaction.guild).api_key(), await Pterodactyl.config.guild(interaction.guild).server_id()]
message = "" message = ""
if self.base_url.value != "": if self.base_url.value != "":
config_list[0].set(self.base_url) self.config[0].set(self.base_url)
message += f"Base URL set to `{self.base_url.value}`.\n" message += f"Base URL set to `{self.base_url.value}`.\n"
if self.api_key.value != "": if self.api_key.value != "":
config_list[1].set(self.api_key) self.config[1].set(self.api_key)
message += f"API Key set to `{self.api_key.value}`.\n" message += f"API Key set to `{self.api_key.value}`.\n"
if self.server_id.value != "": if self.server_id.value != "":
config_list[2].set(self.server_id) self.config[2].set(self.server_id)
message += f"Server ID set to `{self.server_id.value}`.\n" message += f"Server ID set to `{self.server_id.value}`.\n"
if message == "": if message == "":
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]}`" message = f"No changes were made.\nCurrent configuration:\n- Base URL: `{self.config[0]}`\n- API Key: `{self.config[1]}`\n- Server ID: `{self.config[2]}`"
await interaction.response.send_message(message, ephemeral=True) await interaction.response.send_message(message, ephemeral=True)