Пример #1
0
        private async Task SendDiscordMessageToAllActiveWebhooksAsync(SessionTextConstructor.DiscordEmbeds discordEmbeds, string contentText)
        {
            string jsonContentSuccessFailure = JsonConvert.SerializeObject(new DiscordAPIJSONContent()
            {
                Content = contentText,
                Embeds  = discordEmbeds.SuccessFailure
            });
            string jsonContentSuccess = JsonConvert.SerializeObject(new DiscordAPIJSONContent()
            {
                Content = contentText,
                Embeds  = discordEmbeds.Success
            });
            string jsonContentFailure = JsonConvert.SerializeObject(new DiscordAPIJSONContent()
            {
                Content = contentText,
                Embeds  = discordEmbeds.Failure
            });

            try
            {
                foreach (int key in allWebhooks.Keys)
                {
                    DiscordWebhookData webhook = allWebhooks[key];
                    if (!webhook.Active)
                    {
                        continue;
                    }
                    string jsonContent =
                        (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessAndFailure)) ? jsonContentSuccessFailure :
                        ((webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessOnly) ? jsonContentSuccess : jsonContentFailure));
                    Uri uri = new Uri(webhook.URL);
                    using (StringContent content = new StringContent(jsonContent, Encoding.UTF8, "application/json"))
                    {
                        using (await mainLink.HttpClientController.PostAsync(uri, content)) { }
                    }
                }
            }
            catch
            {
                mainLink.AddToText(">:> Unable to execute active webhooks with a finished log session.");
            }
        }
Пример #2
0
 public async Task ExecuteSessionWebhooksAsync(List <DPSReportJSON> reportsJSON, LogSessionSettings logSessionSettings)
 {
     SessionTextConstructor.DiscordEmbeds discordEmbeds = SessionTextConstructor.ConstructSessionEmbeds(reportsJSON, logSessionSettings);
     if (logSessionSettings.UseSelectedWebhooksInstead)
     {
         await SendDiscordMessageToSelectedWebhooksAsync(logSessionSettings.SelectedWebhooks, discordEmbeds, logSessionSettings.ContentText);
     }
     else
     {
         await SendDiscordMessageToAllActiveWebhooksAsync(discordEmbeds, logSessionSettings.ContentText);
     }
     if (logSessionSettings.UseSelectedWebhooksInstead && logSessionSettings.SelectedWebhooks.Count > 0)
     {
         mainLink.AddToText(">:> All selected webhooks successfully executed with finished log session.");
     }
     else if (allWebhooks.Count > 0)
     {
         mainLink.AddToText(">:> All active webhooks successfully executed with finished log session.");
     }
 }
Пример #3
0
        private async Task SendDiscordMessageWebhooksAsync(DiscordWebhookData webhook, SessionTextConstructor.DiscordEmbeds discordEmbeds, string contentText)
        {
            var jsonContentSuccessFailure = JsonConvert.SerializeObject(new DiscordAPIJSONContent()
            {
                Content = contentText,
                Embeds  = discordEmbeds.SuccessFailure
            });
            var jsonContentSuccess = JsonConvert.SerializeObject(new DiscordAPIJSONContent()
            {
                Content = contentText,
                Embeds  = discordEmbeds.Success
            });
            var jsonContentFailure = JsonConvert.SerializeObject(new DiscordAPIJSONContent()
            {
                Content = contentText,
                Embeds  = discordEmbeds.Failure
            });

            try
            {
                var jsonContent =
                    (webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessAndFailure)) ? jsonContentSuccessFailure :
                    ((webhook.SuccessFailToggle.Equals(DiscordWebhookDataSuccessToggle.OnSuccessOnly) ? jsonContentSuccess : jsonContentFailure));
                var uri = new Uri(webhook.URL);
                using var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
                using (await mainLink.HttpClientController.PostAsync(uri, content)) { }
            }
            catch
            {
                mainLink.AddToText($">:> Unable to execute webhook \"{webhook.Name}\" with a finished log session.");
            }
        }