From e3687241157596ce0d2eeac871b055802eefea73 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 12 Jul 2025 20:44:01 -0400 Subject: [PATCH 01/14] Add button --- DexScript/github/installer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index ab50579..7c1e463 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -177,6 +177,10 @@ async def uninstall_button(self, interaction: discord.Interaction, _: discord.ui await interaction.message.edit(**self.installer.interface.fields) await interaction.response.defer() + @discord.ui.button(style=discord.ButtonStyle.secondary, label="Config") + async def config_button(self, interaction: discord.Interaction, _: discord.ui.Button): + pass + @discord.ui.button(style=discord.ButtonStyle.red, label="Exit") async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Button): self.install_button.disabled = True From 36889886b0c21622465c8b1dbd532ec212a8a13f Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 12 Jul 2025 21:03:25 -0400 Subject: [PATCH 02/14] More work on config revamp --- DexScript/github/installer.py | 39 ++++++++++++++++++++++++----------- DexScript/package/cog.py | 4 ++-- DexScript/package/config.toml | 18 ++++++++++++++++ DexScript/package/parser.py | 4 ++-- DexScript/package/utils.py | 34 +++++++++++++++++++----------- 5 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 DexScript/package/config.toml diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index 7c1e463..c8ccf3f 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -35,7 +35,7 @@ class InstallerConfig: """ github = ["Dotsian/DexScript", "dev"] - files = ["__init__.py", "cog.py", "commands.py", "parser.py", "utils.py"] + files = ["__init__.py", "cog.py", "commands.py", "parser.py", "utils.py", "config.toml"] appearance = { "logo": f"{ASSET_PATH}/DexScriptLogo.png", "logo_error": f"{ASSET_PATH}/DexScriptLogoError.png", @@ -71,15 +71,10 @@ def __init__(self, installer, embed_type="setup"): self.installer = installer - match embed_type: - case "setup": - self.setup() - case "error": - self.error() - case "installed": - self.installed() - case "uninstalled": - self.uninstalled() + if not hasattr(self, embed_type): + return + + getattr(self, embed_type)() def setup(self): self.title = "DexScript Installation" @@ -139,6 +134,15 @@ def uninstalled(self): self.set_thumbnail(url=config.appearance["logo"]) + def config(self): + with open(f"{config.path}/config.toml") as file: + file_contents = file.read() + + self.title = "DexScript Configuration" + self.description = f"```toml\n{file_contents}\n```" + self.color = discord.Color.from_str("#03BAFC") + self.timestamp = datetime.now() + class InstallerView(discord.ui.View): def __init__(self, installer): @@ -177,9 +181,16 @@ async def uninstall_button(self, interaction: discord.Interaction, _: discord.ui await interaction.message.edit(**self.installer.interface.fields) await interaction.response.defer() - @discord.ui.button(style=discord.ButtonStyle.secondary, label="Config") + @discord.ui.button( + style=discord.ButtonStyle.secondary, + label="Config", + disabled=not os.path.isfile(f"{config.path}/config.toml") + ) async def config_button(self, interaction: discord.Interaction, _: discord.ui.Button): - pass + self.installer.interface.embed = InstallerEmbed(self.installer, "config") + + await interaction.message.edit(**self.installer.interface.fields) + await interaction.response.defer() @discord.ui.button(style=discord.ButtonStyle.red, label="Exit") async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Button): @@ -283,6 +294,10 @@ async def install(self): os.makedirs(config.path, exist_ok=True) for file in config.files: + if file.endswith(".toml") and os.path.isfile(f"{config.path}/{file}"): + logger.log(f"{file} already exists, skipping", "INFO") + continue + logger.log(f"Fetching {file} from '{link}/DexScript/package'", "INFO") request = requests.get(f"{link}/DexScript/package/{file}", {"ref": config.github[1]}) diff --git a/DexScript/package/cog.py b/DexScript/package/cog.py index ecd9e5d..dfe3292 100644 --- a/DexScript/package/cog.py +++ b/DexScript/package/cog.py @@ -25,12 +25,12 @@ def __init__(self, bot): @staticmethod def check_version(): - if not config.versioncheck: + if not config.version_warning: return None request = requests.get( "https://api.github.com/repos/Dotsian/DexScript/contents/pyproject.toml", - {"ref": config.reference}, + {"ref": config.branch}, ) if request.status_code != requests.codes.ok: diff --git a/DexScript/package/config.toml b/DexScript/package/config.toml new file mode 100644 index 0000000..616afc4 --- /dev/null +++ b/DexScript/package/config.toml @@ -0,0 +1,18 @@ +# Whether or not DexScript will warn you for running an outdated version. +version-warning = true + +# The command groups that DexScript will load. +command-groups = [ + "Global", + "Emoji", + "Eval", + "File", + "Filter", + "Template" +] + +# Displays additional information for error handling. +debug = false + +# The GitHub branch that will be used for version checking and other misc features. +branch = "main" \ No newline at end of file diff --git a/DexScript/package/parser.py b/DexScript/package/parser.py index f70edd2..36e90db 100644 --- a/DexScript/package/parser.py +++ b/DexScript/package/parser.py @@ -38,13 +38,13 @@ def __init__(self, ctx, bot): and issubclass(o, commands.DexCommand) and not issubclass(o, commands.Global) and o.__name__ != "DexCommand" - and o.__name__ in config.modules + and o.__name__ in config.command_groups ), ) self.global_methods = [x for x in dir(commands.Global) if not x.startswith("__")] - if "Global" not in config.modules: + if "Global" not in config.command_groups: self.global_methods = [] def create_value(self, line): diff --git a/DexScript/package/utils.py b/DexScript/package/utils.py index e563ddd..444f414 100644 --- a/DexScript/package/utils.py +++ b/DexScript/package/utils.py @@ -3,6 +3,7 @@ import inspect import os import re +import tomllib from dataclasses import dataclass, field from difflib import get_close_matches from enum import Enum @@ -58,20 +59,29 @@ class Settings: Settings class for DexScript. """ - debug: bool = False - versioncheck: bool = False - reference: str = "main" - modules: list[str] = field(default_factory=lambda: [ - "Global", - "Emoji", - "Eval", - "File", - "Filter", - "Template" - ]) + def __init__(self, path): + with open(path, "rb") as f: + data = tomllib.load(f) + + if data is None: + return + + self.version_warning = data.get("version-warning", True) + + self.command_groups = data.get("command-groups", [ + "Global", + "Emoji", + "Eval", + "File", + "Filter", + "Template" + ]) + + self.debug = data.get("debug", False) + self.branch = data.get("branch", "main") -config = Settings() +config = Settings(Path(os.path.dirname(os.path.abspath(__file__)), "./config.toml")) @dataclass From 02273e7f2ce3574f0e3e7c712aa066fd19a6a5ff Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 12 Jul 2025 21:07:34 -0400 Subject: [PATCH 03/14] Small changes --- DexScript/github/installer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index c8ccf3f..aa237f4 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -34,7 +34,7 @@ class InstallerConfig: Configuration class for the installer. """ - github = ["Dotsian/DexScript", "dev"] + github = ["Dotsian/DexScript", "installer-config"] files = ["__init__.py", "cog.py", "commands.py", "parser.py", "utils.py", "config.toml"] appearance = { "logo": f"{ASSET_PATH}/DexScriptLogo.png", @@ -289,7 +289,7 @@ async def install(self): await bot.remove_cog("DexScript") # type: ignore - link = f"https://api.github.com/repos/{config.github[0]}/contents/" + link = f"https://api.github.com/repos/{config.github[0]}/contents" os.makedirs(config.path, exist_ok=True) From 061aec0fcbf2afc8d07b02780df8502cf52b33c8 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 12 Jul 2025 21:12:18 -0400 Subject: [PATCH 04/14] Add `ConfigView` --- DexScript/github/installer.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index aa237f4..ccef5a7 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -188,6 +188,7 @@ async def uninstall_button(self, interaction: discord.Interaction, _: discord.ui ) async def config_button(self, interaction: discord.Interaction, _: discord.ui.Button): self.installer.interface.embed = InstallerEmbed(self.installer, "config") + self.installer.interface.view = ConfigView(self.installer) await interaction.message.edit(**self.installer.interface.fields) await interaction.response.defer() @@ -202,6 +203,28 @@ async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Butt await interaction.response.defer() +class ConfigView(discord.ui.View): + def __init__(self, installer): + super().__init__() + self.installer = installer + + @discord.ui.button(style=discord.ButtonStyle.primary, label="Back") + async def back_button(self, interaction: discord.Interaction, _: discord.ui.Button): + self.installer.interface.embed = InstallerEmbed(self.installer, "setup") + self.installer.interface.view = InstallerView(self.installer) + + await interaction.message.edit(**self.installer.interface.fields) + await interaction.response.defer() + + @discord.ui.button(style=discord.ButtonStyle.red, label="Exit") + async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Button): + self.back_button.disabled = True + self.quit_button.disabled = True + + await interaction.message.edit(**self.installer.interface.fields) + await interaction.response.defer() + + class InstallerGUI: def __init__(self, installer): self.loaded = False From 694ef77fcbcbf278c48ede104ed864814325a560 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 26 Jul 2025 22:50:06 -0400 Subject: [PATCH 05/14] work on config selection --- DexScript/github/installer.py | 33 +++++++++++++++++++++++++++++++++ DexScript/package/parser.py | 2 +- DexScript/package/utils.py | 4 ++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index ccef5a7..66d6eb1 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -203,11 +203,44 @@ async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Butt await interaction.response.defer() +class ConfigSelect(discord.ui.Select): + def __init__(self, installer): + self.installer = installer + + options = [] + + with open("ballsdex/packages/dexscript/config.toml") as file: + description = "" + + for line in file.readlines(): + if line in ["\n", ""]: + continue + + if line.startswith("#"): + description = (line[2:]) + continue + + name = line.strip(" ")[0] + + options.append( + discord.SelectOption(label=name, value=name, description=description) + ) + + description = "" + + super().__init__(placeholder="Edit setting", max_values=1, min_values=1, options=options) + + async def callback(self, interaction: discord.Interaction): + pass # self.values[0] + + class ConfigView(discord.ui.View): def __init__(self, installer): super().__init__() self.installer = installer + self.add_item(ConfigSelect(installer)) + @discord.ui.button(style=discord.ButtonStyle.primary, label="Back") async def back_button(self, interaction: discord.Interaction, _: discord.ui.Button): self.installer.interface.embed = InstallerEmbed(self.installer, "setup") diff --git a/DexScript/package/parser.py b/DexScript/package/parser.py index 36e90db..c54d06f 100644 --- a/DexScript/package/parser.py +++ b/DexScript/package/parser.py @@ -62,7 +62,7 @@ def create_value(self, line): Types.BOOLEAN: lower in ["true", "false"], Types.HEX: lower.startswith("#"), Types.ARRAY: lower.startswith("[") and lower.endswith("]"), - Types.NONE: lower == "NIL" + Types.NONE: lower == "nil" } for key, operation in type_dict.items(): diff --git a/DexScript/package/utils.py b/DexScript/package/utils.py index 444f414..bf2b934 100644 --- a/DexScript/package/utils.py +++ b/DexScript/package/utils.py @@ -4,7 +4,7 @@ import os import re import tomllib -from dataclasses import dataclass, field +from dataclasses import dataclass from difflib import get_close_matches from enum import Enum from io import StringIO @@ -81,7 +81,7 @@ def __init__(self, path): self.branch = data.get("branch", "main") -config = Settings(Path(os.path.dirname(os.path.abspath(__file__)), "./config.toml")) +config = Settings("./config.toml") @dataclass From 9557968c16d84a68bafbe70f254e629b37bef477 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 26 Jul 2025 22:57:58 -0400 Subject: [PATCH 06/14] Fix method --- DexScript/github/installer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index 66d6eb1..f64c09b 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -213,14 +213,14 @@ def __init__(self, installer): description = "" for line in file.readlines(): - if line in ["\n", ""]: + if line in ["\n", ""] or line.startswith(" "): continue if line.startswith("#"): - description = (line[2:]) + description = line[2:] continue - name = line.strip(" ")[0] + name = line.split(" ")[0] options.append( discord.SelectOption(label=name, value=name, description=description) From 0d2212a07e02eab7bc1a6e89adc378682ada48b4 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 26 Jul 2025 23:09:05 -0400 Subject: [PATCH 07/14] Add modal --- DexScript/github/installer.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index f64c09b..b03b0bc 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -203,6 +203,20 @@ async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Butt await interaction.response.defer() +class ConfigModal(discord.ui.Modal): + def __init__(self, setting: str): + self.setting = setting + self.value = discord.ui.TextInput(label=f"New {setting} value") + + super().__init__(title=f"Editing `{setting}`") + + async def on_submit(self, interaction: discord.Interaction): + await interaction.response.send_message( + f"Updated `{self.setting}` to `{self.value}`!", + ephemeral=True + ) + + class ConfigSelect(discord.ui.Select): def __init__(self, installer): self.installer = installer @@ -213,7 +227,7 @@ def __init__(self, installer): description = "" for line in file.readlines(): - if line in ["\n", ""] or line.startswith(" "): + if line in ["\n", "", "]"] or line.startswith(" "): continue if line.startswith("#"): @@ -231,7 +245,7 @@ def __init__(self, installer): super().__init__(placeholder="Edit setting", max_values=1, min_values=1, options=options) async def callback(self, interaction: discord.Interaction): - pass # self.values[0] + await interaction.response.send_modal(ConfigModal(self.values[0])) class ConfigView(discord.ui.View): From c155adfb2d17b2a078e82ea6564fd4b663723cd4 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 26 Jul 2025 23:41:51 -0400 Subject: [PATCH 08/14] More development --- DexScript/github/installer.py | 35 +++++++++++++++++++++++++++++------ DexScript/package/config.toml | 11 ++--------- DexScript/package/utils.py | 2 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index b03b0bc..dbb58f3 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -204,15 +204,38 @@ async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Butt class ConfigModal(discord.ui.Modal): - def __init__(self, setting: str): + def __init__(self, installer, setting: str): + self.installer = installer self.setting = setting - self.value = discord.ui.TextInput(label=f"New {setting} value") super().__init__(title=f"Editing `{setting}`") + value = discord.ui.TextInput(label=f"New value", required=True) + async def on_submit(self, interaction: discord.Interaction): + with open(f"{config.path}/config.toml") as file: + lines = [x.strip() for x in file.readlines()] + new_lines = [] + + for line in lines: + if not line.startswith(self.setting): + new_lines.append(line + "\n") + continue + + new_value = f'"{self.value.value}"' + + if self.value.value.lower() in ["true", "false"]: + new_value = bool(self.value.value.title()) + + new_lines.append(f"{self.setting} = {new_value}\n") + + with open(f"{config.path}/config.toml", "w") as write_file: + write_file.writelines(new_lines) + + await interaction.message.edit(**self.installer.interface.fields) + await interaction.response.send_message( - f"Updated `{self.setting}` to `{self.value}`!", + f"Updated `{self.setting}` to `{self.value.value}`!", ephemeral=True ) @@ -223,11 +246,11 @@ def __init__(self, installer): options = [] - with open("ballsdex/packages/dexscript/config.toml") as file: + with open(f"{config.path}/config.toml") as file: description = "" for line in file.readlines(): - if line in ["\n", "", "]"] or line.startswith(" "): + if line.rstrip() in ["\n", "", "]"] or line.startswith(" "): continue if line.startswith("#"): @@ -245,7 +268,7 @@ def __init__(self, installer): super().__init__(placeholder="Edit setting", max_values=1, min_values=1, options=options) async def callback(self, interaction: discord.Interaction): - await interaction.response.send_modal(ConfigModal(self.values[0])) + await interaction.response.send_modal(ConfigModal(self.installer, self.values[0])) class ConfigView(discord.ui.View): diff --git a/DexScript/package/config.toml b/DexScript/package/config.toml index 616afc4..ee62b00 100644 --- a/DexScript/package/config.toml +++ b/DexScript/package/config.toml @@ -2,17 +2,10 @@ version-warning = true # The command groups that DexScript will load. -command-groups = [ - "Global", - "Emoji", - "Eval", - "File", - "Filter", - "Template" -] +command-groups = ["Global", "Emoji", "Eval", "File", "Filter", "Template"] # Displays additional information for error handling. debug = false # The GitHub branch that will be used for version checking and other misc features. -branch = "main" \ No newline at end of file +branch = "main" diff --git a/DexScript/package/utils.py b/DexScript/package/utils.py index bf2b934..4497704 100644 --- a/DexScript/package/utils.py +++ b/DexScript/package/utils.py @@ -81,7 +81,7 @@ def __init__(self, path): self.branch = data.get("branch", "main") -config = Settings("./config.toml") +config = Settings(Path(os.path.dirname(os.path.abspath(__file__)), "./config.toml")) @dataclass From 1ac824c47fca705e3e5a38faba4c240c375afdb5 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sat, 26 Jul 2025 23:58:00 -0400 Subject: [PATCH 09/14] Final touches --- DexScript/github/installer.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index dbb58f3..10919d9 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -195,9 +195,8 @@ async def config_button(self, interaction: discord.Interaction, _: discord.ui.Bu @discord.ui.button(style=discord.ButtonStyle.red, label="Exit") async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Button): - self.install_button.disabled = True - self.uninstall_button.disabled = True - self.quit_button.disabled = True + for item in self.children: + item.disabled = True await interaction.message.edit(**self.installer.interface.fields) await interaction.response.defer() @@ -222,16 +221,21 @@ async def on_submit(self, interaction: discord.Interaction): new_lines.append(line + "\n") continue - new_value = f'"{self.value.value}"' + full_value = self.value.value + new_value = f'"{full_value}"' - if self.value.value.lower() in ["true", "false"]: - new_value = bool(self.value.value.title()) + if full_value.lower() in ["true", "false"]: + new_value = full_value.lower() + elif full_value.startswith("[") and full_value.endswith("]"): + new_value = full_value new_lines.append(f"{self.setting} = {new_value}\n") with open(f"{config.path}/config.toml", "w") as write_file: write_file.writelines(new_lines) + self.installer.interface.embed = InstallerEmbed(self.installer, "config") + await interaction.message.edit(**self.installer.interface.fields) await interaction.response.send_message( @@ -288,8 +292,8 @@ async def back_button(self, interaction: discord.Interaction, _: discord.ui.Butt @discord.ui.button(style=discord.ButtonStyle.red, label="Exit") async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Button): - self.back_button.disabled = True - self.quit_button.disabled = True + for item in self.children: + item.disabled = True await interaction.message.edit(**self.installer.interface.fields) await interaction.response.defer() From 01c66131fa67a7bc9d39edd830437244e23f01ad Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sun, 27 Jul 2025 01:11:27 -0400 Subject: [PATCH 10/14] Finish configuration editing --- DexScript/github/installer.py | 46 ++++++++++++++++++++++++++++++----- DexScript/package/cog.py | 35 +++++--------------------- DexScript/package/config.toml | 3 +++ README.md | 7 +++++- 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index 10919d9..89669e0 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -280,18 +280,52 @@ def __init__(self, installer): super().__init__() self.installer = installer + back_button = discord.ui.Button(label="Back", style=discord.ButtonStyle.primary) + reset_button = discord.ui.Button(label="Reset", style=discord.ButtonStyle.grey) + quit_button = discord.ui.Button(label="Exit", style=discord.ButtonStyle.red) + + back_button.callback = self.back_button + reset_button.callback = self.reset_button + quit_button.callback = self.quit_button + + self.add_item(back_button) self.add_item(ConfigSelect(installer)) + self.add_item(reset_button) + self.add_item(quit_button) - @discord.ui.button(style=discord.ButtonStyle.primary, label="Back") - async def back_button(self, interaction: discord.Interaction, _: discord.ui.Button): + async def back_button(self, interaction: discord.Interaction): self.installer.interface.embed = InstallerEmbed(self.installer, "setup") self.installer.interface.view = InstallerView(self.installer) await interaction.message.edit(**self.installer.interface.fields) await interaction.response.defer() - @discord.ui.button(style=discord.ButtonStyle.red, label="Exit") - async def quit_button(self, interaction: discord.Interaction, _: discord.ui.Button): + async def reset_button(self, interaction: discord.Interaction): + request = requests.get( + f"https://api.github.com/repos/{config.github[0]}/" + "contents/DexScript/package/config.toml", + {"ref": config.github[1]} + ) + + if request.status_code != requests.codes.ok: + await interaction.response.send_message( + f"Failed to reset config file `({request.status_code})`", ephemeral=True + ) + return + + request = request.json() + content = b64decode(request["content"]) + + with open(f"{config.path}/config.toml", "w") as opened_file: + opened_file.write(content.decode()) + + self.installer.interface.embed = InstallerEmbed(self.installer, "config") + + await interaction.message.edit(**self.installer.interface.fields) + + await interaction.response.send_message("Successfully reset config file", ephemeral=True) + + async def quit_button(self, interaction: discord.Interaction): for item in self.children: item.disabled = True @@ -409,7 +443,7 @@ async def install(self): content = b64decode(request["content"]) with open(f"{config.path}/{file}", "w") as opened_file: - opened_file.write(content.decode("UTF-8")) + opened_file.write(content.decode()) logger.log(f"Installed {file} from '{link}/DexScript/package'", "INFO") @@ -450,7 +484,7 @@ def latest_version(self): if pyproject_request.status_code != requests.codes.ok: return - toml_content = b64decode(pyproject_request.json()["content"]).decode("UTF-8") + toml_content = b64decode(pyproject_request.json()["content"]).decode() new_version = re.search(r'version\s*=\s*"(.*?)"', toml_content) if not new_version: diff --git a/DexScript/package/cog.py b/DexScript/package/cog.py index dfe3292..6e273b8 100644 --- a/DexScript/package/cog.py +++ b/DexScript/package/cog.py @@ -15,6 +15,9 @@ ASSET_PATH = "https://raw.githubusercontent.com/Dotsian/DexScript/refs/heads/main/assets" +def check_dexscript_user(ctx): + return ctx.message.author.id in config.dexscript_user_ids + class DexScript(commands.Cog): """ DexScript commands. @@ -50,6 +53,7 @@ def check_version(): @commands.command() @commands.is_owner() + @commands.check(check_dexscript_user) async def run(self, ctx: commands.Context, *, code: str): """ Executes DexScript code. @@ -84,6 +88,7 @@ async def run(self, ctx: commands.Context, *, code: str): @commands.command() @commands.is_owner() + @commands.check(check_dexscript_user) async def about(self, ctx: commands.Context): """ Displays information about DexScript. @@ -120,6 +125,7 @@ async def about(self, ctx: commands.Context): @commands.command() @commands.is_owner() + @commands.check(check_dexscript_user) async def installer(self, ctx: commands.Context, reference: str = "main"): """ Displays the DexScript installer. @@ -148,32 +154,3 @@ async def installer(self, ctx: commands.Context, reference: str = "main"): case _: await ctx.send(f"Request raised error code `{request.status_code}`.") - - @commands.command() - @commands.is_owner() - async def setting(self, ctx: commands.Context, setting: str, value: str | None = None): - """ - Changes a setting based on the value provided. - - Parameters - ---------- - setting: str - The setting you want to toggle. - value: str | None - The value you want to set the setting to. - """ - setting = setting.lower() - - if setting not in vars(config): - await ctx.send(f"`{setting}` is not a valid setting.") - return - - setting_value = vars(config)[setting] - new_value = value - - if isinstance(setting_value, bool): - new_value = bool(value) if value else not setting_value - - setattr(config, setting, new_value) - - await ctx.send(f"`{setting}` has been set to `{new_value}`") diff --git a/DexScript/package/config.toml b/DexScript/package/config.toml index ee62b00..1306048 100644 --- a/DexScript/package/config.toml +++ b/DexScript/package/config.toml @@ -4,6 +4,9 @@ version-warning = true # The command groups that DexScript will load. command-groups = ["Global", "Emoji", "Eval", "File", "Filter", "Template"] +# A list of user IDs that will be able to execute DexScript commands. +dexscript-user-ids = [] + # Displays additional information for error handling. debug = false diff --git a/README.md b/README.md index 1232b01..496878f 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ To install DexScript, you must have the following: ## DexScript Setup -The DexScript installer is a intuitive menu that can allow you to easily update, install, and uninstall DexScript. To bring up the DexScript installer, all you have to do is run one eval command! +The DexScript installer is a intuitive menu that can allow you to easily update, install, configure, and uninstall DexScript. To bring up the DexScript installer, all you have to do is run one eval command! ### Versions @@ -60,6 +60,7 @@ Once you have ran the eval command, the DexScript installer should appear. There * Install [or] Update * Uninstall +* Config * Exit > [!IMPORTANT] @@ -73,6 +74,10 @@ If you are installing DexScript for the first time, you will see a button called If you already have DexScript, you will see a button called "Update". When you click that button, DexScript will update to the latest version. This will instantly update DexScript, which means you don't have to restart your bot. +#### Configuration + +If you have a `config.toml` file already installed within DexScript, the "Config" button will appear. This button will allow you to access the configuration menu, which will let you modify DexScript's internal settings. + #### Uninstalling If you already have DexScript, you will see a button called "Uninstall". Clicking the uninstall button will uninstall DexScript from your application. This will instantly remove the DexScript package and DexScript commands will unload instantly. From 91e702c2ac8d239a9c15a42b774bd6c954469c96 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sun, 27 Jul 2025 01:17:58 -0400 Subject: [PATCH 11/14] Switch back to dev --- DexScript/github/installer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DexScript/github/installer.py b/DexScript/github/installer.py index 89669e0..7a2a4fe 100644 --- a/DexScript/github/installer.py +++ b/DexScript/github/installer.py @@ -34,7 +34,7 @@ class InstallerConfig: Configuration class for the installer. """ - github = ["Dotsian/DexScript", "installer-config"] + github = ["Dotsian/DexScript", "dev"] files = ["__init__.py", "cog.py", "commands.py", "parser.py", "utils.py", "config.toml"] appearance = { "logo": f"{ASSET_PATH}/DexScriptLogo.png", @@ -209,7 +209,7 @@ def __init__(self, installer, setting: str): super().__init__(title=f"Editing `{setting}`") - value = discord.ui.TextInput(label=f"New value", required=True) + value = discord.ui.TextInput(label="New value", required=True) async def on_submit(self, interaction: discord.Interaction): with open(f"{config.path}/config.toml") as file: From d58df9381e002339490a3c5c88baf69433c6e3bb Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sun, 27 Jul 2025 01:20:35 -0400 Subject: [PATCH 12/14] Add missing config field --- DexScript/package/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DexScript/package/utils.py b/DexScript/package/utils.py index 4497704..300024e 100644 --- a/DexScript/package/utils.py +++ b/DexScript/package/utils.py @@ -77,6 +77,8 @@ def __init__(self, path): "Template" ]) + self.dexscript_user_ids = data.get("dexscript-user-ids", []) + self.debug = data.get("debug", False) self.branch = data.get("branch", "main") From 6e8945fac0eb7cd02848b70b12a4cf207b95a449 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sun, 27 Jul 2025 01:21:43 -0400 Subject: [PATCH 13/14] Attempt to fix checks --- DexScript/package/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DexScript/package/utils.py b/DexScript/package/utils.py index 300024e..d020b62 100644 --- a/DexScript/package/utils.py +++ b/DexScript/package/utils.py @@ -14,12 +14,12 @@ import discord import requests from ballsdex.core.models import ( - Ball, # noqa: F401 - BallInstance, # noqa: F401 - Economy, # noqa: F401 - Player, # noqa: F401 - Regime, # noqa: F401 - Special, # noqa: F401 + Ball, # noqa: F401, I001 + BallInstance, # noqa: F401, I001 + Economy, # noqa: F401, I001 + Player, # noqa: F401, I001 + Regime, # noqa: F401, I001 + Special, # noqa: F401, I001 ) from dateutil.parser import parse as parse_date From 1fc116bb040e21a6a3e2703240819488ee4c5e09 Mon Sep 17 00:00:00 2001 From: Dotsian Date: Sun, 27 Jul 2025 01:22:39 -0400 Subject: [PATCH 14/14] Cry --- DexScript/package/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DexScript/package/utils.py b/DexScript/package/utils.py index d020b62..300024e 100644 --- a/DexScript/package/utils.py +++ b/DexScript/package/utils.py @@ -14,12 +14,12 @@ import discord import requests from ballsdex.core.models import ( - Ball, # noqa: F401, I001 - BallInstance, # noqa: F401, I001 - Economy, # noqa: F401, I001 - Player, # noqa: F401, I001 - Regime, # noqa: F401, I001 - Special, # noqa: F401, I001 + Ball, # noqa: F401 + BallInstance, # noqa: F401 + Economy, # noqa: F401 + Player, # noqa: F401 + Regime, # noqa: F401 + Special, # noqa: F401 ) from dateutil.parser import parse as parse_date