private async Task <Response> TestDiscordNotification() { var settings = this.BindAndValidate <DiscordNotificationSettings>(); if (!ModelValidationResult.IsValid) { return(Response.AsJson(ModelValidationResult.SendJsonError())); } var notificationModel = new NotificationModel { NotificationType = NotificationType.Test, DateTime = DateTime.Now }; var currentDicordSettings = await DiscordSettings.GetSettingsAsync(); try { NotificationService.Subscribe(new DiscordNotification(DiscordApi, DiscordSettings)); settings.Enabled = true; await NotificationService.Publish(notificationModel, settings); Log.Info("Sent Discord notification test"); } catch (Exception e) { Log.Error(e, "Failed to subscribe and publish test Discord Notification"); } finally { if (!currentDicordSettings.Enabled) { NotificationService.UnSubscribe(new DiscordNotification(DiscordApi, DiscordSettings)); } } return(Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Discord Notification! If you do not receive it please check the logs." })); }
private async Task <Negotiator> DiscordNotification() { var settings = await DiscordSettings.GetSettingsAsync(); return(View["DiscordNotification", settings]); }