From 5f57256bf99a4e9666d97b7400c6fa11af1b99f5 Mon Sep 17 00:00:00 2001 From: donkevlar Date: Thu, 12 Dec 2024 00:23:47 -0500 Subject: [PATCH] Added INITIALIZED_MSG env var. On initial startup is set to true by default. But if bot loses connection and docker isn't restarted (but Bot does restart) this won't spam the owner anymore. --- Scripts/main.py | 15 ++++++++++++--- Scripts/settings.py | 5 ++++- Scripts/subscription_task.py | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Scripts/main.py b/Scripts/main.py index aa8a3d2..e4002ba 100644 --- a/Scripts/main.py +++ b/Scripts/main.py @@ -33,6 +33,8 @@ MULTI_USER = eval(settings.MULTI_USER) AUDIO_ENABLED = eval(settings.AUDIO_ENABLED) DEBUG_MODE = settings.DEBUG_MODE +INITIALIZED_MSG = bool(settings.INITIALIZED_MSG) + # TEMP if DEBUG_MODE == "True": @@ -72,6 +74,8 @@ # Print current config if value is present logger.info("Current config to follow!") +# Should initial msg be sent +logger.info(f"Initialization MSGs Enabled: {INITIALIZED_MSG}") for key, value in current_config.items(): if value != '' and value is not None: logger.info(f"{key}: {value}") @@ -135,14 +139,17 @@ async def on_startup(event: Startup): if username != '': mu.insert_data(discord_id=owner_id, user=username, token=user_token) logger.info(f'Registered initial user {username} successfully') - if not DEBUG_MODE: + if not DEBUG_MODE and INITIALIZED_MSG: await owner.send(f'Bot is ready. Logged in as {bot.user}. ABS user: {username} signed in.') + # Set env to true + os.putenv('INITIALIZED_MSG', "False") else: logger.warning("No initial user registered, please use '/login' to register a user.") await owner.send("No initial user registered, please use '/login' to register a user.") else: - if not DEBUG_MODE: + if not DEBUG_MODE and INITIALIZED_MSG: await owner.send(f'Bot is ready. Logged in as {bot.user}.') + os.putenv('INITIALIZED_MSG', "False") logger.info('Bot has finished loading, it is now safe to use! :)') @@ -191,11 +198,13 @@ async def on_startup(event: Startup): try: from wishlist import wishlist_conn + secondary_command = ''' UPDATE wishlist SET downloaded = 0 WHERE downloaded IS NULL''' - db_additions.add_column_to_db(db_connection=wishlist_conn, table_name='wishlist', column_name='downloaded', secondary_execute=secondary_command) + db_additions.add_column_to_db(db_connection=wishlist_conn, table_name='wishlist', column_name='downloaded', + secondary_execute=secondary_command) except Exception as e: logger.debug(f"Error occured while attempting to alter original databases") diff --git a/Scripts/settings.py b/Scripts/settings.py index 982730b..29c3200 100644 --- a/Scripts/settings.py +++ b/Scripts/settings.py @@ -6,7 +6,7 @@ load_dotenv(override=True) # Version Info -versionNumber = 'V1.3.0' +versionNumber = 'V1.3.1' COMMAND_COUNT = 0 @@ -60,6 +60,9 @@ # Ownership check OWNER_ONLY = os.getenv('OWNER_ONLY', True) +# Initial MSG when not in debug mode +INITIALIZED_MSG = os.getenv('INITIALIZED_MSG', True) + # Used for embed footers bookshelf_traveller_footer = f'Powered by Bookshelf Traveller 🕮 | {versionNumber}' diff --git a/Scripts/subscription_task.py b/Scripts/subscription_task.py index 5ef7fc4..a57e5f7 100644 --- a/Scripts/subscription_task.py +++ b/Scripts/subscription_task.py @@ -554,6 +554,7 @@ async def color_embed_bookcheck(self, ctx: AutocompleteContext): # Auto Start Task if db is populated @listen() async def tasks_startup(self, event: Startup): + init_msg = bool(os.getenv('INITIALIZED_MSG', False)) result = search_task_db( override_response="Initialized subscription task module, verifying if any tasks are enabled...") task_name = "new-book-check" @@ -572,6 +573,6 @@ async def tasks_startup(self, event: Startup): logger.info( f"Subscription Task db was populated, auto enabling tasks on startup. Refresh rate set to {TASK_FREQUENCY} minutes.") # Debug Stuff - if s.DEBUG_MODE != "True": + if s.DEBUG_MODE != "True" and s.INITIALIZED_MSG == "True": await owner.send( f"Subscription Task db was populated, auto enabling tasks on startup. Refresh rate set to {TASK_FREQUENCY} minutes.")