From 4b54d9f59fdedc1d3f2eb4b60b5c797b640999f9 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 4 Mar 2023 16:48:28 +0000 Subject: [PATCH 1/3] Add runtime configuration option for toggling replit mode --- api/runtimeconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/runtimeconfig.json b/api/runtimeconfig.json index 6341d307..e7c0a7a0 100644 --- a/api/runtimeconfig.json +++ b/api/runtimeconfig.json @@ -2,5 +2,6 @@ "token": "", "secret": "", "public_key": "", - "runtime_options": [] + "runtime_options": [], + "replit": true } From 5a1f5223680fa5ea01f79a4566635c7be0899eca Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 4 Mar 2023 16:53:35 +0000 Subject: [PATCH 2/3] Add auth library method to return runtime mode --- api/auth.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/auth.py b/api/auth.py index 53e147fc..19d6bcee 100644 --- a/api/auth.py +++ b/api/auth.py @@ -32,3 +32,7 @@ def get_public_key(): """Returns the bot's public key in `runtimeconfig.json`, if it exists.""" if config["public_key"]: return config["public_key"] else: return "Public key has not been set." + +def get_mode() -> bool: + """Returns a boolean of the current runtime mode.\n\nReturns `True` if replit mode is active, returns `False` if replit mode is inactive.""" + return config["replit"] From df2e970cb62e3f429211af42cd9ca7f0cb57906f Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 4 Mar 2023 17:02:28 +0000 Subject: [PATCH 3/3] Add runtime mode fetching and support for bot token environment variable --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 2af20d26..7e4591b7 100644 --- a/main.py +++ b/main.py @@ -482,7 +482,12 @@ async def isocoin_shop(ctx: ApplicationContext): if cog_errors == 0: print(f"[main/Cogs] {colors.green}All cogs successfully loaded.{colors.end}") else: print(f"[main/Cogs] {colors.yellow}{cog_errors}/{len(active_cogs)} cogs failed to load.{colors.end}") print("--------------------") -client.run(api.auth.get_token()) +if api.auth.get_mode(): + print(f"[main/CLIENT] Starting client in {colors.cyan}Replit mode{colors.end}...") + client.run(os.getenv("TOKEN")) +else: + print(f"[main/CLIENT] Starting client in {colors.orange}local mode{colors.end}...") + client.run(api.auth.get_token())