private async Task SendToWebhook(string url, string textFieldName, Image.ChatMessage message)
        {
            dynamic jsonMessage = new ExpandoObject();

            ((IDictionary <string, object>)jsonMessage)[textFieldName] = message.Name + ": " + message.Text;
            StringContent content  = new StringContent(JsonConvert.SerializeObject(jsonMessage), System.Text.Encoding.UTF8, "application/json");
            var           response = await this.client.PostAsync(url, content);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                Logger.Write("Notification error: " + response.ToString());
            }
        }
        public async Task <bool> Send(Image.ChatMessage message)
        {
            var throttle = this.Throttle();

            if (!throttle)
            {
                if (Properties.Settings.Default.SendNotificationsToSlack)
                {
                    await this.SendToWebhook(Properties.Settings.Default.SlackWebhookURL, "text", message);
                }

                if (Properties.Settings.Default.SendNotificationsToDiscord)
                {
                    await this.SendToWebhook(Properties.Settings.Default.DiscordWebhookURL, "content", message);
                }
            }

            return(!throttle);
        }
Exemplo n.º 3
0
 public void ShowNotification(Image.ChatMessage message)
 {
     this.newLines.Enqueue(message);
 }