|
|
|
@ -0,0 +1,206 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Ombi.Api.Discord;
|
|
|
|
|
using Ombi.Api.Discord.Models;
|
|
|
|
|
using Ombi.Api.Notifications;
|
|
|
|
|
using Ombi.Core.Settings;
|
|
|
|
|
using Ombi.Helpers;
|
|
|
|
|
using Ombi.Notifications.Interfaces;
|
|
|
|
|
using Ombi.Notifications.Models;
|
|
|
|
|
using Ombi.Settings.Settings.Models;
|
|
|
|
|
using Ombi.Settings.Settings.Models.Notifications;
|
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
|
using Ombi.Store.Repository;
|
|
|
|
|
using Ombi.Store.Repository.Requests;
|
|
|
|
|
|
|
|
|
|
namespace Ombi.Notifications.Agents
|
|
|
|
|
{
|
|
|
|
|
public class MobileNotification : BaseNotification<MobileNotificationSettings>
|
|
|
|
|
{
|
|
|
|
|
public MobileNotification(IOneSignalApi api, ISettingsService<MobileNotificationSettings> sn, ILogger<MobileNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s) : base(sn, r, m, t, s)
|
|
|
|
|
{
|
|
|
|
|
Api = api;
|
|
|
|
|
Logger = log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string NotificationName => "DiscordNotification";
|
|
|
|
|
|
|
|
|
|
private IOneSignalApi Api { get; }
|
|
|
|
|
private ILogger<MobileNotification> Logger { get; }
|
|
|
|
|
|
|
|
|
|
protected override bool ValidateConfiguration(MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task NewRequest(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.NewRequest, model);
|
|
|
|
|
if (parsed.Disabled)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Discord}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = parsed.Message,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
notification.Other.Add("image", parsed.Image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task NewIssue(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.Issue, model);
|
|
|
|
|
if (parsed.Disabled)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Discord}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = parsed.Message,
|
|
|
|
|
};
|
|
|
|
|
notification.Other.Add("image", parsed.Image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task IssueResolved(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.IssueResolved, model);
|
|
|
|
|
if (parsed.Disabled)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Discord}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = parsed.Message,
|
|
|
|
|
};
|
|
|
|
|
notification.Other.Add("image", parsed.Image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task AddedToRequestQueue(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var user = string.Empty;
|
|
|
|
|
var title = string.Empty;
|
|
|
|
|
var image = string.Empty;
|
|
|
|
|
if (model.RequestType == RequestType.Movie)
|
|
|
|
|
{
|
|
|
|
|
user = MovieRequest.RequestedUser.UserAlias;
|
|
|
|
|
title = MovieRequest.Title;
|
|
|
|
|
image = MovieRequest.PosterPath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
user = TvRequest.RequestedUser.UserAlias;
|
|
|
|
|
title = TvRequest.ParentRequest.Title;
|
|
|
|
|
image = TvRequest.ParentRequest.PosterPath;
|
|
|
|
|
}
|
|
|
|
|
var message = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = message
|
|
|
|
|
};
|
|
|
|
|
notification.Other.Add("image", image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task RequestDeclined(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestDeclined, model);
|
|
|
|
|
if (parsed.Disabled)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Discord}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = parsed.Message,
|
|
|
|
|
};
|
|
|
|
|
notification.Other.Add("image", parsed.Image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task RequestApproved(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestApproved, model);
|
|
|
|
|
if (parsed.Disabled)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Discord}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = parsed.Message,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
notification.Other.Add("image", parsed.Image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task AvailableRequest(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestAvailable, model);
|
|
|
|
|
if (parsed.Disabled)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Discord}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = parsed.Message,
|
|
|
|
|
};
|
|
|
|
|
notification.Other.Add("image", parsed.Image);
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task Send(NotificationMessage model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var discordBody = new DiscordWebhookBody
|
|
|
|
|
{
|
|
|
|
|
content = model.Message,
|
|
|
|
|
//username = settings.Username,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string image;
|
|
|
|
|
if (model.Other.TryGetValue("image", out image))
|
|
|
|
|
{
|
|
|
|
|
discordBody.embeds = new List<DiscordEmbeds>
|
|
|
|
|
{
|
|
|
|
|
new DiscordEmbeds
|
|
|
|
|
{
|
|
|
|
|
image = new DiscordImage
|
|
|
|
|
{
|
|
|
|
|
url = image
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//await Api.SendMessage(discordBody, settings.WebHookId, settings.Token);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError(LoggingEvents.DiscordNotification, e, "Failed to send Discord Notification");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task Test(NotificationOptions model, MobileNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var message = $"This is a test from Ombi, if you can see this then we have successfully pushed a notification!";
|
|
|
|
|
var notification = new NotificationMessage
|
|
|
|
|
{
|
|
|
|
|
Message = message,
|
|
|
|
|
};
|
|
|
|
|
await Send(notification, settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|