New: Improved Discord add/delete notifications

(cherry picked from commit 1a4403e0ab9ab824c97acf97174f894b3770f2ef)

Closes #8886
pull/9020/head
jack-mil 2 years ago committed by Bogdan
parent f412228383
commit 328850627a

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -230,16 +229,38 @@ namespace NzbDrone.Core.Notifications.Discord
public override void OnMovieAdded(Movie movie) public override void OnMovieAdded(Movie movie)
{ {
var attachments = new List<Embed> var embed = new Embed
{ {
new Embed Author = new DiscordAuthor
{ {
Title = movie.MovieMetadata.Value.Title, Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
Description = $"{movie.Title} added to library", IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png"
} },
}; Url = $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}",
Title = movie.Title,
var payload = CreatePayload("Added", attachments); Description = "Movie Added",
Color = (int)DiscordColors.Success,
Fields = new List<DiscordField> { 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> { embed });
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
@ -265,16 +286,37 @@ namespace NzbDrone.Core.Notifications.Discord
{ {
var movie = deleteMessage.Movie; var movie = deleteMessage.Movie;
var attachments = new List<Embed> var embed = new Embed
{ {
new Embed Author = new DiscordAuthor
{ {
Title = movie.MovieMetadata.Value.Title, Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
Description = deleteMessage.DeletedFilesMessage 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<DiscordField> { 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("Movie Deleted", attachments); var payload = CreatePayload(null, new List<Embed> { embed });
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
@ -282,99 +324,101 @@ namespace NzbDrone.Core.Notifications.Discord
public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage) public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
{ {
var movie = deleteMessage.Movie; var movie = deleteMessage.Movie;
var deletedFile = deleteMessage.MovieFile.Path;
var reason = deleteMessage.Reason;
var fullPath = Path.Combine(deleteMessage.Movie.Path, deleteMessage.MovieFile.RelativePath); var embed = new Embed
var attachments = new List<Embed> {
{ Author = new DiscordAuthor
new Embed {
{ Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
Title = GetTitle(movie), IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png"
Description = deleteMessage.MovieFile.Path },
} Url = $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}",
}; Title = GetTitle(movie),
Description = "Movie File Deleted",
Color = (int)DiscordColors.Danger,
Fields = new List<DiscordField>
{
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> { embed });
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{ {
var attachments = new List<Embed> var embed = new Embed
{ {
new Embed Author = new DiscordAuthor
{ {
Author = new DiscordAuthor Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
{ IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png"
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,
Title = healthCheck.Source.Name, Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
Description = healthCheck.Message, Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? (int)DiscordColors.Warning : (int)DiscordColors.Danger
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, new List<Embed> { embed });
};
var payload = CreatePayload(null, attachments);
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
{ {
var attachments = new List<Embed> var embed = new Embed
{ {
new Embed Author = new DiscordAuthor
{ {
Author = new DiscordAuthor Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
{ IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png"
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}",
Title = "Health Issue Resolved: " + previousCheck.Source.Name, Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
Description = $"The following issue is now resolved: {previousCheck.Message}", Color = (int)DiscordColors.Success
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), };
Color = (int)DiscordColors.Success
} var payload = CreatePayload(null, new List<Embed> { embed });
};
var payload = CreatePayload(null, attachments);
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{ {
var attachments = new List<Embed> var embed = new Embed
{ {
new Embed Author = new DiscordAuthor
{ {
Author = new DiscordAuthor Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
{ IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png"
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"),
Title = APPLICATION_UPDATE_TITLE, Color = (int)DiscordColors.Standard,
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), Fields = new List<DiscordField>
Color = (int)DiscordColors.Standard, {
Fields = new List<DiscordField>() new ()
{ {
new DiscordField() Name = "Previous Version",
{ Value = updateMessage.PreviousVersion.ToString()
Name = "Previous Version", },
Value = updateMessage.PreviousVersion.ToString() new ()
}, {
new DiscordField() Name = "New Version",
{ Value = updateMessage.NewVersion.ToString()
Name = "New Version", }
Value = updateMessage.NewVersion.ToString() },
} };
},
} var payload = CreatePayload(null, new List<Embed> { embed });
};
var payload = CreatePayload(null, attachments);
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Notifications.Discord
[FieldDefinition(2, Label = "Avatar", HelpText = "Change the avatar that is used for messages from this integration", Type = FieldType.Textbox)] [FieldDefinition(2, Label = "Avatar", HelpText = "Change the avatar that is used for messages from this integration", Type = FieldType.Textbox)]
public string Avatar { get; set; } 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; } 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)] [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)]

Loading…
Cancel
Save