Skip to content

Commit

Permalink
Added INITIALIZED_MSG env var. On initial startup is set to true by d…
Browse files Browse the repository at this point in the history
…efault. But if bot loses connection and docker isn't restarted (but Bot does restart) this won't spam the owner anymore.
  • Loading branch information
donkevlar committed Dec 12, 2024
1 parent a504fcd commit 5f57256
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions Scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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! :)')

Expand Down Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion Scripts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
load_dotenv(override=True)

# Version Info
versionNumber = 'V1.3.0'
versionNumber = 'V1.3.1'

COMMAND_COUNT = 0

Expand Down Expand Up @@ -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}'

Expand Down
3 changes: 2 additions & 1 deletion Scripts/subscription_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.")

0 comments on commit 5f57256

Please sign in to comment.