1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 18:02:44 +01:00

New: Improved Discord add/delete notifications

(cherry picked from commit 1a4403e0ab9ab824c97acf97174f894b3770f2ef)

Closes #8886
This commit is contained in:
jack-mil 2023-07-26 13:38:56 -04:00 committed by Bogdan
parent f412228383
commit 328850627a
2 changed files with 134 additions and 90 deletions

View File

@ -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<Embed>
var embed = new Embed
{
new Embed
Author = new DiscordAuthor
{
Title = movie.MovieMetadata.Value.Title,
Description = $"{movie.Title} added to library",
}
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<DiscordField> { new () { Name = "Links", Value = GetLinksString(movie) } }
};
var payload = CreatePayload("Added", 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> { embed });
_proxy.SendPayload(payload, Settings);
}
@ -265,16 +286,37 @@ public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
{
var movie = deleteMessage.Movie;
var attachments = new List<Embed>
var embed = new Embed
{
new Embed
Author = new DiscordAuthor
{
Title = movie.MovieMetadata.Value.Title,
Description = deleteMessage.DeletedFilesMessage
}
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<DiscordField> { 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> { embed });
_proxy.SendPayload(payload, Settings);
}
@ -282,27 +324,36 @@ 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<Embed>
var embed = new 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 = deleteMessage.MovieFile.Path
}
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);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var attachments = new List<Embed>
{
new Embed
var embed = new Embed
{
Author = new DiscordAuthor
{
@ -313,19 +364,16 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
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> { embed });
_proxy.SendPayload(payload, Settings);
}
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
{
var attachments = new List<Embed>
{
new Embed
var embed = new Embed
{
Author = new DiscordAuthor
{
@ -336,19 +384,16 @@ public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
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> { embed });
_proxy.SendPayload(payload, Settings);
}
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var attachments = new List<Embed>
{
new Embed
var embed = new Embed
{
Author = new DiscordAuthor
{
@ -358,23 +403,22 @@ public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
Title = APPLICATION_UPDATE_TITLE,
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
Color = (int)DiscordColors.Standard,
Fields = new List<DiscordField>()
Fields = new List<DiscordField>
{
new DiscordField()
new ()
{
Name = "Previous Version",
Value = updateMessage.PreviousVersion.ToString()
},
new DiscordField()
new ()
{
Name = "New Version",
Value = updateMessage.NewVersion.ToString()
}
},
}
};
var payload = CreatePayload(null, attachments);
var payload = CreatePayload(null, new List<Embed> { embed });
_proxy.SendPayload(payload, Settings);
}

View File

@ -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)]