diff --git a/src/Ombi.Api.Discord/DiscordApi.cs b/src/Ombi.Api.Discord/DiscordApi.cs index 11cdc267e..34342e559 100644 --- a/src/Ombi.Api.Discord/DiscordApi.cs +++ b/src/Ombi.Api.Discord/DiscordApi.cs @@ -1,5 +1,6 @@ using System.Net.Http; using System.Threading.Tasks; +using Newtonsoft.Json; using Ombi.Api.Discord.Models; namespace Ombi.Api.Discord @@ -17,7 +18,7 @@ namespace Ombi.Api.Discord public async Task SendMessage(DiscordWebhookBody body, string webhookId, string webhookToken) { var request = new Request($"webhooks/{webhookId}/{webhookToken}", BaseUrl, HttpMethod.Post); - + request.AddJsonBody(body); request.ApplicationJsonContentType(); diff --git a/src/Ombi.Api.Discord/Models/DiscordWebhookBody.cs b/src/Ombi.Api.Discord/Models/DiscordWebhookBody.cs index 2d74087fb..7700005c8 100644 --- a/src/Ombi.Api.Discord/Models/DiscordWebhookBody.cs +++ b/src/Ombi.Api.Discord/Models/DiscordWebhookBody.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Ombi.Api.Discord.Models { @@ -13,8 +14,32 @@ namespace Ombi.Api.Discord.Models { public string title { get; set; } public string type => "rich"; // Always rich or embedded content - public string description { get; set; } // Don't really need to set this - public DiscordImage image { get; set; } + public string description { get; set; } + public DateTime timestamp => DateTime.Now; + public string color { get; set; } + public DiscordFooter footer { get; set; } + public DiscordImage thumbnail { get; set; } + public DiscordAuthor author { get; set; } + public List fields { get; set; } + } + + public class DiscordFooter + { + public string text { get; set; } + } + + public class DiscordAuthor + { + public string name { get; set; } + public string url { get; set; } + public string iconurl { get; set; } + } + + public class DiscordField + { + public string name { get; set; } + public string value { get; set; } + public bool inline { get; set; } } public class DiscordImage diff --git a/src/Ombi.Notifications/Agents/DiscordNotification.cs b/src/Ombi.Notifications/Agents/DiscordNotification.cs index 77580e5e4..b013fbf07 100644 --- a/src/Ombi.Notifications/Agents/DiscordNotification.cs +++ b/src/Ombi.Notifications/Agents/DiscordNotification.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Ombi.Api.Discord; @@ -104,21 +105,65 @@ namespace Ombi.Notifications.Agents username = settings.Username, }; + var fields = new List(); + + if (model.Data.TryGetValue("RequestedUser", out var requestedUser)) + { + if (requestedUser.HasValue()) + { + fields.Add(new DiscordField { name = "Requsted By", value = requestedUser, inline = true }); + } + } + if (model.Data.TryGetValue("DenyReason", out var denyReason)) + { + if (denyReason.HasValue()) + { + fields.Add(new DiscordField { name = "Denied Reason", value = denyReason, inline = true }); + } + } + if (model.Data.TryGetValue("RequestStatus", out var status)) + { + if (status.HasValue()) + { + fields.Add(new DiscordField { name = "Status", value = status, inline = true }); + } + } + + var author = new DiscordAuthor + { + }; + + if (model.Data.TryGetValue("ApplicationUrl", out var appUrl)) + { + author.url = appUrl; + } + if (model.Data.TryGetValue("ApplicationName", out var appName)) + { + author.name = appName; + } + + var embed = new DiscordEmbeds + { + fields = fields, + author = author + }; + + if (model.Data.TryGetValue("Title", out var title)) + { + embed.title = title; + } + if (model.Data.TryGetValue("Overview", out var overview)) + { + embed.description = overview; + } string image; if (model.Other.TryGetValue("image", out image)) { - discordBody.embeds = new List - { - new DiscordEmbeds - { - image = new DiscordImage - { - url = image - } - } - }; + embed.thumbnail = new DiscordImage { url = image }; } + discordBody.embeds = new List { embed }; + await Api.SendMessage(discordBody, settings.WebHookId, settings.Token); } catch (Exception e) @@ -148,6 +193,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = parsed.Data.ToDictionary(x => x.Key, x => x.Value) }; notification.Other.Add("image", parsed.Image); await Send(notification, settings); diff --git a/src/Ombi.Notifications/NotificationMessageCurlys.cs b/src/Ombi.Notifications/NotificationMessageCurlys.cs index 8140a4d3f..57a36cd87 100644 --- a/src/Ombi.Notifications/NotificationMessageCurlys.cs +++ b/src/Ombi.Notifications/NotificationMessageCurlys.cs @@ -64,6 +64,8 @@ namespace Ombi.Notifications } AdditionalInformation = opts?.AdditionalInformation ?? string.Empty; + + CalculateRequestStatus(req); } public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s, UserNotificationPreferences pref) @@ -107,6 +109,7 @@ namespace Ombi.Notifications PosterImage = (req?.Cover.HasValue() ?? false) ? req.Cover : req?.Disk ?? string.Empty; AdditionalInformation = opts?.AdditionalInformation ?? string.Empty; + CalculateRequestStatus(req); } public void SetupNewsletter(CustomizationSettings s) @@ -197,6 +200,7 @@ namespace Ombi.Notifications EpisodesList = epSb.ToString(); SeasonsList = seasonSb.ToString(); + CalculateRequestStatus(req); } public void Setup(OmbiUser user, CustomizationSettings s) @@ -220,6 +224,30 @@ namespace Ombi.Notifications Type = opts.Substitutes.TryGetValue("RequestType", out val) ? val.Humanize() : string.Empty; } + private void CalculateRequestStatus(BaseRequest req) + { + RequestStatus = string.Empty; + if (req != null) + { + if (req.Available) + { + RequestStatus = "Available"; + return; + } + if (req.Denied ?? false) + { + RequestStatus = "Denied"; + return; + } + if (!req.Available && req.Approved) + { + RequestStatus = "Processing Request"; + return; + } + RequestStatus = "Pending Approval"; + } + } + // User Defined public string RequestId { get; set; } public string RequestedUser { get; set; } @@ -245,6 +273,7 @@ namespace Ombi.Notifications public string UserPreference { get; set; } public string DenyReason { get; set; } public string AvailableDate { get; set; } + public string RequestStatus { get; set; } // System Defined private string LongDate => DateTime.Now.ToString("D"); @@ -282,6 +311,7 @@ namespace Ombi.Notifications {nameof(UserPreference),UserPreference}, {nameof(DenyReason),DenyReason}, {nameof(AvailableDate),AvailableDate}, + {nameof(RequestStatus),RequestStatus}, }; } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/settings/notifications/discord.component.html b/src/Ombi/ClientApp/src/app/settings/notifications/discord.component.html index ed5c524d3..97900daf0 100644 --- a/src/Ombi/ClientApp/src/app/settings/notifications/discord.component.html +++ b/src/Ombi/ClientApp/src/app/settings/notifications/discord.component.html @@ -1,56 +1,55 @@ - - +
-
+
Discord Notifications -
-
- -
-
- - +
+
+ +
+
+
+
+ Enable +
+
+
-
- - -
- - - The Webhook Url is required -
- -
- -
- +
+
+ + Webhook Url + + + + Username + + +
-
- - - -
-
- +
+ +
+
+ +
+
+ +
+
+ +
+
-
- - - -
-
- -
-
- -
+ +
-
- +
+ +
\ No newline at end of file