From b8550269e2e1224edb5fd7d8d0b4dd617058cb56 Mon Sep 17 00:00:00 2001 From: Drazzilb <65743746+Drazzilb08@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:56:37 -0800 Subject: [PATCH] bug fix/formatting change --- modules/poster_renamerr.py | 2 +- util/discord.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/poster_renamerr.py b/modules/poster_renamerr.py index 10e7190..e720e1c 100755 --- a/modules/poster_renamerr.py +++ b/modules/poster_renamerr.py @@ -574,7 +574,7 @@ def notification(output): for key, value in discord_dict.items(): print(f"Sending message {key} of {len(discord_dict)}") # Display message sending status # Actual function to send messages to Discord (which is currently represented by a 'print' statement) - discord(fields=value, logger=logger, script_name="Poster Renamerr", description=f"{'__**Dry Run**__' if dry_run else ''}", color=0x00ff00, content=None) + discord(fields=value, logger=logger, script_name=script_name, description=f"{'__**Dry Run**__' if dry_run else ''}", color=0x00ff00, content=None) # Pauses for 5 seconds each 5th message if key % 5 == 0: print("Pausing for 5 seconds to let Discord catch up...") diff --git a/util/discord.py b/util/discord.py index b039fb2..a69f821 100755 --- a/util/discord.py +++ b/util/discord.py @@ -31,17 +31,22 @@ def get_discord_data(script_name, logger): # Get the 'notifiarr_webhook' from the config notifiarr_webhook = discord.get('notifiarr_webhook', None) - + # Get the script-specific notification info from the config based on the script name script_notification_info = discord.get(script_name, {}) + # Get the 'channel_id' and 'discord_webhook' from the script-specific notification info channel_id = script_notification_info.get('channel_id', None) + + # Get the 'discord_webhook' from the script-specific notification info discord_webhook = script_notification_info.get('discord_webhook', None) + # If notifiarr_webhook is missing, log an error and return if notifiarr_webhook: + # If channel_id is missing, log an error and return if not channel_id: logger.error("Discord channel ID is missing. Cannot send Discord notification.") - return + return None, None else: return notifiarr_webhook, channel_id else: @@ -97,7 +102,10 @@ def discord_check(script_name): # Get the script-specific notification info from the config based on the script name script_notification_info = discord.get(script_name, {}) + # Get the 'channel_id' and 'discord_webhook' from the script-specific notification info channel_id = script_notification_info.get('channel_id', None) + + # Get the 'discord_webhook' from the script-specific notification info discord_webhook = script_notification_info.get('discord_webhook', None) if discord_webhook or channel_id and notifiarr_webhook: @@ -125,6 +133,7 @@ def discord(fields, logger, script_name, description, color, content): """ # Get the webhook and channel_id from the config webhook, channel_id = get_discord_data(script_name, logger) + script_name = script_name.replace("_", " ").title() if webhook: # Get the random joke and timestamp random_joke, timestamp = get_message_data(logger) @@ -140,7 +149,7 @@ def discord(fields, logger, script_name, description, color, content): payload = { "notification": { "update": False, - "name": f"{script_name.capitalize()}", + "name": f"{script_name}", }, "discord": { "color": f"{color}",