From b99e06acc0a3ecae2857d9225b35424c82c67a2b Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Wed, 19 Feb 2025 04:23:43 +0100 Subject: [PATCH] Fixed: Fallback to Instance Name for Discord notifications --- .../Notifications/Discord/Discord.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index 540b8d420..5e579cab3 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Localization; using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaFiles; @@ -17,11 +18,13 @@ namespace NzbDrone.Core.Notifications.Discord public class Discord : NotificationBase { private readonly IDiscordProxy _proxy; + private readonly IConfigFileProvider _configFileProvider; private readonly ILocalizationService _localizationService; - public Discord(IDiscordProxy proxy, ILocalizationService localizationService) + public Discord(IDiscordProxy proxy, IConfigFileProvider configFileProvider, ILocalizationService localizationService) { _proxy = proxy; + _configFileProvider = configFileProvider; _localizationService = localizationService; } @@ -37,7 +40,7 @@ public override void OnGrab(GrabMessage message) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}", @@ -140,7 +143,7 @@ public override void OnDownload(DownloadMessage message) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}", @@ -254,7 +257,7 @@ public override void OnImportComplete(ImportCompleteMessage message) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}", @@ -361,7 +364,7 @@ public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}", @@ -388,7 +391,7 @@ public override void OnSeriesAdd(SeriesAddMessage message) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}", @@ -427,7 +430,7 @@ public override void OnSeriesDelete(SeriesDeleteMessage deleteMessage) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}", @@ -464,7 +467,7 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Title = healthCheck.Source.Name, @@ -484,7 +487,7 @@ public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Title = "Health Issue Resolved: " + previousCheck.Source.Name, @@ -504,7 +507,7 @@ public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Title = APPLICATION_UPDATE_TITLE, @@ -539,7 +542,7 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag { Author = new DiscordAuthor { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + Name = Settings.Author.IsNullOrWhiteSpace() ? _configFileProvider.InstanceName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png" }, Url = series?.TvdbId > 0 ? $"http://thetvdb.com/?tab=series&id={series.TvdbId}" : null,