diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index fd7682accb..951a61f69d 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; @@ -230,16 +229,38 @@ public override void OnDownload(DownloadMessage message) public override void OnMovieAdded(Movie movie) { - var attachments = new List - { - new Embed - { - Title = movie.MovieMetadata.Value.Title, - Description = $"{movie.Title} added to library", - } - }; + var embed = new Embed + { + Author = new DiscordAuthor + { + Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" + }, + Url = $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}", + Title = movie.Title, + Description = "Movie Added", + Color = (int)DiscordColors.Success, + Fields = new List { new () { Name = "Links", Value = GetLinksString(movie) } } + }; + + if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Poster)) + { + embed.Thumbnail = new DiscordImage + { + Url = movie.MovieMetadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url + }; + } + + if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Fanart)) + { + embed.Image = new DiscordImage + { + Url = movie.MovieMetadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url + }; + } + + var payload = CreatePayload(null, new List { embed }); - var payload = CreatePayload("Added", attachments); _proxy.SendPayload(payload, Settings); } @@ -265,16 +286,37 @@ public override void OnMovieDelete(MovieDeleteMessage deleteMessage) { var movie = deleteMessage.Movie; - var attachments = new List - { - new Embed - { - Title = movie.MovieMetadata.Value.Title, - Description = deleteMessage.DeletedFilesMessage - } - }; + var embed = new Embed + { + Author = new DiscordAuthor + { + Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" + }, + Url = $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}", + Title = movie.Title, + Description = deleteMessage.DeletedFilesMessage, + Color = (int)DiscordColors.Danger, + Fields = new List { new () { Name = "Links", Value = GetLinksString(movie) } } + }; - var payload = CreatePayload("Movie Deleted", attachments); + if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Poster)) + { + embed.Thumbnail = new DiscordImage + { + Url = movie.MovieMetadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url + }; + } + + if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Fanart)) + { + embed.Image = new DiscordImage + { + Url = movie.MovieMetadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url + }; + } + + var payload = CreatePayload(null, new List { embed }); _proxy.SendPayload(payload, Settings); } @@ -282,99 +324,101 @@ public override void OnMovieDelete(MovieDeleteMessage deleteMessage) public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage) { var movie = deleteMessage.Movie; + var deletedFile = deleteMessage.MovieFile.Path; + var reason = deleteMessage.Reason; - var fullPath = Path.Combine(deleteMessage.Movie.Path, deleteMessage.MovieFile.RelativePath); - var attachments = new List - { - new Embed - { - Title = GetTitle(movie), - Description = deleteMessage.MovieFile.Path - } - }; + var embed = new Embed + { + Author = new DiscordAuthor + { + Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" + }, + Url = $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}", + Title = GetTitle(movie), + Description = "Movie File Deleted", + Color = (int)DiscordColors.Danger, + Fields = new List + { + new () { Name = "Reason", Value = reason.ToString() }, + new () { Name = "File name", Value = string.Format("```{0}```", deletedFile) } + }, + Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), + }; - var payload = CreatePayload("Movie File Deleted", attachments); + var payload = CreatePayload(null, new List { embed }); _proxy.SendPayload(payload, Settings); } public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) { - var attachments = new List - { - new Embed - { - Author = new DiscordAuthor - { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, - IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" - }, - Title = healthCheck.Source.Name, - Description = healthCheck.Message, - Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), - Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? (int)DiscordColors.Warning : (int)DiscordColors.Danger - } - }; + var embed = new Embed + { + Author = new DiscordAuthor + { + Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" + }, + Title = healthCheck.Source.Name, + Description = healthCheck.Message, + Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), + Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? (int)DiscordColors.Warning : (int)DiscordColors.Danger + }; - var payload = CreatePayload(null, attachments); + var payload = CreatePayload(null, new List { embed }); _proxy.SendPayload(payload, Settings); } public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) { - var attachments = new List - { - new Embed - { - Author = new DiscordAuthor - { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, - IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" - }, - Title = "Health Issue Resolved: " + previousCheck.Source.Name, - Description = $"The following issue is now resolved: {previousCheck.Message}", - Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), - Color = (int)DiscordColors.Success - } - }; + var embed = new Embed + { + Author = new DiscordAuthor + { + Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" + }, + Title = "Health Issue Resolved: " + previousCheck.Source.Name, + Description = $"The following issue is now resolved: {previousCheck.Message}", + Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), + Color = (int)DiscordColors.Success + }; - var payload = CreatePayload(null, attachments); + var payload = CreatePayload(null, new List { embed }); _proxy.SendPayload(payload, Settings); } public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) { - var attachments = new List - { - new Embed - { - Author = new DiscordAuthor - { - Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, - IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" - }, - Title = APPLICATION_UPDATE_TITLE, - Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), - Color = (int)DiscordColors.Standard, - Fields = new List() - { - new DiscordField() - { - Name = "Previous Version", - Value = updateMessage.PreviousVersion.ToString() - }, - new DiscordField() - { - Name = "New Version", - Value = updateMessage.NewVersion.ToString() - } - }, - } - }; + var embed = new Embed + { + Author = new DiscordAuthor + { + Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, + IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" + }, + Title = APPLICATION_UPDATE_TITLE, + Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), + Color = (int)DiscordColors.Standard, + Fields = new List + { + new () + { + Name = "Previous Version", + Value = updateMessage.PreviousVersion.ToString() + }, + new () + { + Name = "New Version", + Value = updateMessage.NewVersion.ToString() + } + }, + }; - var payload = CreatePayload(null, attachments); + var payload = CreatePayload(null, new List { embed }); _proxy.SendPayload(payload, Settings); } diff --git a/src/NzbDrone.Core/Notifications/Discord/DiscordSettings.cs b/src/NzbDrone.Core/Notifications/Discord/DiscordSettings.cs index 08c427fbf1..c4af59f45d 100644 --- a/src/NzbDrone.Core/Notifications/Discord/DiscordSettings.cs +++ b/src/NzbDrone.Core/Notifications/Discord/DiscordSettings.cs @@ -35,7 +35,7 @@ public DiscordSettings() [FieldDefinition(2, Label = "Avatar", HelpText = "Change the avatar that is used for messages from this integration", Type = FieldType.Textbox)] public string Avatar { get; set; } - [FieldDefinition(3, Label = "Host", Advanced = true, HelpText = "Override the Host that shows for this notification, Blank is machine name", Type = FieldType.Textbox)] + [FieldDefinition(3, Label = "Author", Advanced = true, HelpText = "Override the embed author that shows for this notification, Blank is instance name", Type = FieldType.Textbox)] public string Author { get; set; } [FieldDefinition(4, Label = "On Grab Fields", Advanced = true, SelectOptions = typeof(DiscordGrabFieldType), HelpText = "Change the fields that are passed in for this 'on grab' notification", Type = FieldType.TagSelect)]