New: Improved Discord add/delete notifications

Closes #5372
This commit is contained in:
jack-mil 2023-07-26 13:38:56 -04:00 committed by GitHub
parent 14bea16aef
commit 1a4403e0ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 133 additions and 88 deletions

View File

@ -214,7 +214,7 @@ namespace NzbDrone.Core.Notifications.Discord
break; break;
case DiscordImportFieldType.Release: case DiscordImportFieldType.Release:
discordField.Name = "Release"; discordField.Name = "Release";
discordField.Value = message.EpisodeFile.SceneName; discordField.Value = string.Format("```{0}```", message.EpisodeFile.SceneName);
break; break;
case DiscordImportFieldType.Links: case DiscordImportFieldType.Links:
discordField.Name = "Links"; discordField.Name = "Links";
@ -252,16 +252,29 @@ namespace NzbDrone.Core.Notifications.Discord
{ {
var series = deleteMessage.Series; var series = deleteMessage.Series;
var episodes = deleteMessage.EpisodeFile.Episodes; var episodes = deleteMessage.EpisodeFile.Episodes;
var deletedFile = deleteMessage.EpisodeFile.Path;
var reason = deleteMessage.Reason;
var attachments = new List<Embed> var embed = new Embed
{ {
new Embed Author = new DiscordAuthor
{ {
Title = GetTitle(series, episodes) Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
} IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png"
},
Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}",
Title = GetTitle(series, episodes),
Description = "Episode Deleted",
Color = (int)DiscordColors.Danger,
Fields = new List<DiscordField>
{
new DiscordField { Name = "Reason", Value = reason.ToString() },
new DiscordField { Name = "File name", Value = string.Format("```{0}```", deletedFile) }
},
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
}; };
var payload = CreatePayload("Episode Deleted", attachments); var payload = CreatePayload(null, new List<Embed> { embed });
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
@ -269,17 +282,37 @@ namespace NzbDrone.Core.Notifications.Discord
public override void OnSeriesAdd(SeriesAddMessage message) public override void OnSeriesAdd(SeriesAddMessage message)
{ {
var series = message.Series; var series = message.Series;
var embed = new Embed
var attachments = new List<Embed>
{ {
new Embed Author = new DiscordAuthor
{ {
Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png"
},
Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}",
Title = series.Title, Title = series.Title,
Description = message.Message Description = "Series Added",
} Color = (int)DiscordColors.Success,
Fields = new List<DiscordField> { new DiscordField { Name = "Links", Value = GetLinksString(series) } }
}; };
var payload = CreatePayload("Series Added", attachments); if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Poster))
{
embed.Thumbnail = new DiscordImage
{
Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl
};
}
if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Fanart))
{
embed.Image = new DiscordImage
{
Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.RemoteUrl
};
}
var payload = CreatePayload(null, new List<Embed> { embed });
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
@ -288,25 +321,44 @@ namespace NzbDrone.Core.Notifications.Discord
{ {
var series = deleteMessage.Series; var series = deleteMessage.Series;
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/Sonarr/Sonarr/develop/Logo/256.png"
},
Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}",
Title = series.Title, Title = series.Title,
Description = deleteMessage.DeletedFilesMessage Description = deleteMessage.DeletedFilesMessage,
} Color = (int)DiscordColors.Danger,
Fields = new List<DiscordField> { new DiscordField { Name = "Links", Value = GetLinksString(series) } }
}; };
var payload = CreatePayload("Series Deleted", attachments); if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Poster))
{
embed.Thumbnail = new DiscordImage
{
Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl
};
}
if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Fanart))
{
embed.Image = new DiscordImage
{
Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.RemoteUrl
};
}
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
{ {
@ -317,19 +369,16 @@ namespace NzbDrone.Core.Notifications.Discord
Description = healthCheck.Message, Description = healthCheck.Message,
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? (int)DiscordColors.Warning : (int)DiscordColors.Danger 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); _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
{ {
@ -340,19 +389,16 @@ namespace NzbDrone.Core.Notifications.Discord
Description = $"The following issue is now resolved: {previousCheck.Message}", Description = $"The following issue is now resolved: {previousCheck.Message}",
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
Color = (int)DiscordColors.Success Color = (int)DiscordColors.Success
}
}; };
var payload = CreatePayload(null, attachments); var payload = CreatePayload(null, new List<Embed> { embed });
_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
{ {
@ -375,10 +421,9 @@ namespace NzbDrone.Core.Notifications.Discord
Value = updateMessage.NewVersion.ToString() Value = updateMessage.NewVersion.ToString()
} }
}, },
}
}; };
var payload = CreatePayload(null, attachments); var payload = CreatePayload(null, new List<Embed> { embed });
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }

View File

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