protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { var instocks = await _mongoService.GetAllInStocks(); if (instocks != null && instocks.Count > 0) { var roleId = _config.GetSection("Workers")["discordRoleId"]; await _webhookClient.SendMessageAsync($"<@&{roleId}> Remember that these items are still in stock!", false); Parallel.ForEach(instocks, async instock => { _logger.LogInformation($"Opening new thread for Product ({instock.EndpointItem.Title}) <ThreadID={Thread.CurrentThread.ManagedThreadId}>."); await _webhookClient.SendMessageAsync("", false, DiscordHelpers.BuildEmbed(instock.EndpointItem)); }); } _logger.LogInformation($"No Product are in stock currently."); } catch (Exception e) { _logger.LogError($"Snatcher Worker failed unexpectedly => {e}", e); // throw; } // 3 Days by Default await Task.Delay(int.Parse(_config.GetSection("Workers")["reminderInterval"]), stoppingToken); } }
public async Task Read() { if (Prev >= Book.Length) { await Webhook.SendMessageAsync("We have reached the end of the book!"); return; } var delay = TimeSpan.FromHours(4) - (DateTime.UtcNow - LastReadTime); if (delay > TimeSpan.Zero) { await Task.Delay(delay); } LastReadTime = DateTime.UtcNow; await File.WriteAllTextAsync("data/book/lastreadtime.garden", LastReadTime.ToString()); int min = Math.Min(2000, Book.Length - Prev); await File.WriteAllTextAsync("data/book/prev.garden", (min + Prev) + ""); string substr = Book.Substring(Prev, min); Prev += min; await Webhook.SendMessageAsync(embeds : new[] { GetEmbed(substr, Prev / 2000) }); await Read(); }
static void Sender() { while (true) { try { string Responce = new WebClient().DownloadString("https://nukacrypt.com"); Regex codes = new Regex(@">\d{8}<"); Regex week = new Regex(@"Week of \d{2}\/\d{2} - \d{2}\/\d{2}"); var MatchesCodes = codes.Matches(Responce); var MatchWeek = week.Match(Responce); if (MatchWeek.Value != Week) { if (MatchesCodes.Count != 3) { Console.WriteLine($"Match codes: {MatchesCodes.Count}"); Thread.Sleep(3600000); continue; } Week = MatchWeek.Value; Alpha = MatchesCodes[0].Value; Bravo = MatchesCodes[1].Value; Charlie = MatchesCodes[2].Value; discord.SendMessageAsync($"New codes!\n\n{Week}\n\nAlpha:\t {Alpha}\nBravo:\t {Bravo}\nCharlie:\t{Charlie}"); } Thread.Sleep(3600000); } catch (Exception ex) { discord.SendMessageAsync($"Error:\n\n{ex.Message}"); } } }
public static void SendMessage(List <string> traces, string dpsReportPermalink, WebhookSettings settings) { if (settings.WebhookURL != null && settings.WebhookURL.Length > 0) { if (!dpsReportPermalink.Contains("https")) { traces.Add("Nothing to send to Webhook"); return; } try { var client = new DiscordWebhookClient(settings.WebhookURL); try { if (settings.Embed == null) { _ = client.SendMessageAsync(text: dpsReportPermalink).Result; } else { _ = client.SendMessageAsync(embeds: new[] { settings.Embed }).Result; } traces.Add("Sent Embed"); } finally { client.Dispose(); } } catch (Exception e) { traces.Add("Couldn't send embed: " + e.Message); } } }
public string SendMessage() { if (_webhookURLValid) { try { var client = new DiscordWebhookClient(_webhookURL); try { if (_embed == null) { _ = client.SendMessageAsync(text: _message).Result; } else { _ = client.SendMessageAsync(embeds: new[] { _embed }).Result; } } finally { client.Dispose(); } return("Sent Embed"); } catch (Exception e) { return("Couldn't send embed: " + e.Message); } } return("Webhook url invalid"); }
public void Emit(LogEvent logEvent) { if (logEvent.Level < _minimumLogLevel) { return; } EmbedBuilder embedBuilder = new(); try { string logMessage = logEvent.RenderMessage(); SpecifyEmbedLevel(logEvent.Level, logMessage, embedBuilder); if (logEvent.Exception is not null) { embedBuilder.WithTitle(logEvent.Exception.Message.Truncate(256)); string?stackTrace = logEvent.Exception.StackTrace; embedBuilder.WithDescription($"**StackTrace:**\n{stackTrace?.Truncate(2030) ?? "NaN"}"); embedBuilder.AddField("Type:", nameof(logEvent.Exception), true); embedBuilder.AddField("Exception message:", logEvent.Exception.Message.Truncate(1024), true); } _webHook.SendMessageAsync(embeds: new[] { embedBuilder.Build() }).GetAwaiter().GetResult(); } catch (Exception ex) { _webHook.SendMessageAsync($"Something went sideways when trying to log through Discord.\n{ex}").GetAwaiter().GetResult(); } }
internal async Task SendMessageAsync(string message) { if (IsEnabled) { await _client.SendMessageAsync(message); } }
public static void SendMessage(ParsedLog log, string[] uploadresult) { if (Properties.Settings.Default.WebhookURL != null && Properties.Settings.Default.WebhookURL.Length > 0) { if (!uploadresult[0].Contains("https")) { log.UpdateProgressWithCancellationCheck("Nothing to send to Webhook"); return; } try { var client = new DiscordWebhookClient(Properties.Settings.Default.WebhookURL); try { if (Properties.Settings.Default.SendSimpleMessageToWebhook) { _ = client.SendMessageAsync(text: uploadresult[0]).Result; } else { _ = client.SendMessageAsync(embeds: new[] { GetEmbed(log, uploadresult) }).Result; } log.UpdateProgressWithCancellationCheck("Sent Embed"); } finally { client.Dispose(); } } catch (Exception e) { log.UpdateProgressWithCancellationCheck("Couldn't send embed: " + e.GetFinalException().Message); } } }
private async void bSend_Click(object sender, EventArgs e) { var match = regexWebhook.Match(tbFullWebhook.Text); if (!match.Success) { return; } var hook = new DiscordWebhookClient(ulong.Parse(match.Groups[1].Value), match.Groups[2].Value); var embed = new EmbedBuilder(); embed.WithDescription(tbBodyMessage.Text); var cnt = 0; if (cbUseColor.Checked && ++cnt > 0) { embed.WithColor(new Color(pColor.BackColor.R, pColor.BackColor.G, pColor.BackColor.B)); } if (!string.IsNullOrEmpty(tbTitle.Text) && ++cnt > 0) { embed.WithTitle(tbTitle.Text); } if (!string.IsNullOrEmpty(tbThumbnailUrl.Text) && ++cnt > 0) { embed.WithThumbnailUrl(tbThumbnailUrl.Text); } if (!string.IsNullOrEmpty(tbImageUrl.Text) && ++cnt > 0) { embed.WithImageUrl(tbImageUrl.Text); } if (!string.IsNullOrEmpty(tbLink.Text) && ++cnt > 0) { embed.WithUrl(tbLink.Text); } if (dtpTimestamp.Checked && ++cnt > 0) { embed.WithTimestamp(new DateTimeOffset(dtpTimestamp.Value.ToUniversalTime())); } if (!string.IsNullOrEmpty(tbAuthorName.Text) && ++cnt > 0) { embed.WithAuthor(tbAuthorName.Text , !string.IsNullOrEmpty(tbAuthorAvatarUrl.Text) ? tbAuthorAvatarUrl.Text : null , !string.IsNullOrEmpty(tbAuthorLink.Text) ? tbAuthorLink.Text : null); } if (!string.IsNullOrEmpty(tbFooterText.Text) && ++cnt > 0) { embed.WithFooter(tbFooterText.Text , !string.IsNullOrEmpty(tbFooterIconUrl.Text) ? tbFooterIconUrl.Text : null); } if (cnt > 0) { await hook.SendMessageAsync("", false, new[] { embed.Build() }, tbSenderName.Text, tbSenderAvatarUrl.Text); } else { await hook.SendMessageAsync(tbBodyMessage.Text, false, null, tbSenderName.Text, tbSenderAvatarUrl.Text); } }
private void SendMessage(LogEvent logEvent) { if (ShouldNotLogMessage(_restrictedToMinimumLevel, logEvent.Level)) { return; } var embedBuilder = new EmbedBuilder(); var webHook = new DiscordWebhookClient(_webhookId, _webhookToken); try { if (logEvent.Exception != null) { embedBuilder.Color = new Color(255, 0, 0); embedBuilder.WithTitle(":o: Exception"); embedBuilder.AddField("Type:", $"```{logEvent.Exception.GetType().FullName}```"); var message = FormatMessage(logEvent.Exception.Message, 1000); embedBuilder.AddField("Message:", message); var stackTrace = FormatMessage(logEvent.Exception.StackTrace, 1000); embedBuilder.AddField("StackTrace:", stackTrace); webHook.SendMessageAsync(null, false, new Embed[] { embedBuilder.Build() }) .GetAwaiter() .GetResult(); } else { var message = logEvent.RenderMessage(_formatProvider); message = FormatMessage(message, 240); SpecifyEmbedLevel(logEvent.Level, embedBuilder); embedBuilder.Description = message; webHook.SendMessageAsync(null, false, new Embed[] { embedBuilder.Build() }) .GetAwaiter() .GetResult(); } } catch (Exception ex) { webHook.SendMessageAsync( $"ooo snap, {ex.Message}", false) .GetAwaiter() .GetResult(); } }
/// <summary> /// Log message to console and webhook /// </summary> public static void Log(string message, bool error = false) { // Replace ` and * because fck that Console.WriteLine(message.Replace("`", "").Replace("*", "")); if (error) { Webhook.SendMessageAsync($"<@376821416105869315> : ```{message}```"); } else { Webhook.SendMessageAsync(message); } }
static async Task Main(string[] args) { CASCConfig.LoadFlags |= LoadFlags.Install; var pcConfig = CASCConfig.LoadOnlineStorageConfig("hsb", "eu"); var androidConfig = CASCConfig.LoadOnlineStorageConfig("hsb", "android_google"); bool updateFile = true; if (File.Exists(Settings.FilePath)) { var text = File.ReadAllLines(Settings.FilePath); bool pc = pcConfig.VersionName != text[0]; bool android = androidConfig.VersionName != text[1]; updateFile = pc || android; if (updateFile) { var tgClient = new TelegramBotClient(Settings.TgToken); var dsClient = new DiscordWebhookClient(Settings.DsWebhookId, Settings.DsWebhookToken); if (pc) { var message = $"🆕New version released\n⚔️Platform: PC🖥️\n#️⃣Version: {pcConfig.VersionName}\n🆔BuildId: {pcConfig.BuildId}"; var tasks = new List <Task>(); tasks.Add(tgClient.SendTextMessageAsync(new Telegram.Bot.Types.ChatId(Settings.TgChatId), message)); tasks.Add(dsClient.SendMessageAsync(message)); var cascHandler = CASCHandler.OpenStorage(pcConfig); cascHandler.Root.SetFlags(LocaleFlags.ruRU, false); cascHandler.Root.MergeInstall(cascHandler.Install); cascHandler.SaveFileTo(Settings.FileName, Settings.SavePath); await Task.WhenAll(tasks); } if (android) { var message = $"🆕New version released\n⚔️Platform: Android📱\n#️⃣Version: {androidConfig.VersionName}\n🆔BuildId: {androidConfig.BuildId}"; var tasks = new List <Task>(); tasks.Add(tgClient.SendTextMessageAsync(new Telegram.Bot.Types.ChatId(Settings.TgChatId), message)); tasks.Add(dsClient.SendMessageAsync(message)); await Task.WhenAll(tasks); } } } if (updateFile) { File.WriteAllText(Settings.FilePath, $"{pcConfig.VersionName}{Environment.NewLine}{androidConfig.VersionName}"); } }
public static async Task AnnounceGainLoseToHouse(SocketReaction emoji, IMessage message, DiscordWebhookClient houseWebhook, bool gain, int amount, int totalPoints) { SocketGuildUser user = emoji.User.Value as SocketGuildUser; EmbedBuilder eb = new EmbedBuilder(); if (gain) { eb.Title = "🎊House points gained!"; string text = "**" + message.Author.Mention + " gained the house __" + amount + " points!__ Current total: __" + totalPoints + " points.__**"; eb.WithDescription(text); eb.WithColor(Color.Green); } else { eb.Title = "😡House points lossed!"; string text = "**" + message.Author.Mention + " lossed the house __" + amount + " points!__ Current total: __" + totalPoints + " points.__**"; eb.WithDescription(text); eb.WithColor(Color.Red); } List <Embed> embeds = new List <Embed>(); embeds.Add(eb.Build()); await houseWebhook.SendMessageAsync("", false, embeds); }
public static void loaded() { string desc = "Loaded the following feeds:"; foreach (RssFeed feed in Program.config.Feeds) { desc += "\n" + feed.FeedUrl; } var embed = new EmbedBuilder { Title = "Bot loaded.", Description = desc, Timestamp = DateTime.Now }; Embed compiled = embed.Build(); foreach (DiscordWebhook webhook in Program.config.Webhooks.Values) { if (webhook.SendDebuggingInfo) { using (var client = new DiscordWebhookClient(webhook.Endpoint)) { client.SendMessageAsync(embeds: new Embed[] { compiled }).Wait(); } } } }
public async Task <ulong> RepostMessageAsync(ITextChannel chan, IMessage msg, Embed embed = null) { using (DiscordWebhookClient webhook = await this.TryGetWebhookAsync(chan)) { if (webhook == null) { return(0); } try { Embed[] embeds = embed == null ? null : new[] { embed }; if (msg.Attachments.Count > 0) { IAttachment attachment = msg.Attachments.First(); using (Stream stream = await this.HttpClient.GetStreamAsync(attachment.ProxyUrl)) return(await webhook.SendFileAsync(stream, attachment.Filename, msg.Content, false, embeds, msg.Author.Username, msg.Author.GetAvatarUrl())); } else { return(await webhook.SendMessageAsync(msg.Content, false, embeds, msg.Author.Username, msg.Author.GetAvatarUrl())); } } catch (Exception ex) { this.Logger.Nice("Webhook", ConsoleColor.Red, $"Could not send a message: {ex.Message}"); return(0); } } }
public static bool SendMessage(MessageOptions options) { DiscordWebhookClient discordWebhookClient = null; try { discordWebhookClient = new DiscordWebhookClient(options.WebHookURL); } catch (Exception ex) { throw new DiscordCommunications.Exceptions.DiscordClientInstantiationException("Failed to Instantiate DiscordWebhookClient", ex.InnerException); } try { ////But a channel has a 30 msg/60 sec limit for webhooks discordWebhookClient.SendMessageAsync( text: options.Text, isTTS: options.IsTTS, embeds: options.Embeds, username: options.Username, avatarUrl: options.AvatarUrl, options: options.Options); } catch (Exception) { return(false); } return(true); }
public IMessagePluginResponse Process(Message inbound) { var resp = new MessagePluginResponse(); if (Disabled) { resp.Success = false; resp.PluginResponse = "Sorry, the bug reporter is currently disabled. We apologize for the inconvenience."; return(resp); } var id = Random.Shared.RandomString(8); // Transmit message to discord, also save locally var now = DateTime.Now; string text = $"**Bug Report Submission**\n\n**Bug ID**: {id}\n**From**: {inbound.Sender}\n**Date**: {now.ToString()}\n\n**Subject**: {inbound.Subject}"; if (inbound.Text.Length > 1800) { text = $"{text}\n\n{inbound.Text.Substring(0, 1800)} ...\n(Truncated. Full message on server)"; } else { text = $"{text}\n\n{inbound.Text}"; } Task.Run(() => client.SendMessageAsync(text)); Task.Run(() => SaveToDisk(inbound.Sender, id, text)); resp.Success = true; resp.PluginResponse = $"Thank you for your bug submission (BUG-{id}). It has been received."; return(resp); }
public async Task Send(Giveaway giveaway, string webhook) { using (var client = new DiscordWebhookClient(webhook)) { var embed = new EmbedBuilder { Title = giveaway.Title, Color = Color.Magenta, ImageUrl = giveaway.PhotoUrl, Url = string.IsNullOrEmpty(giveaway.DirectUrl) ? giveaway.Url : giveaway.DirectUrl, Author = new EmbedAuthorBuilder().WithName(giveaway.Store) }; try { await client.SendMessageAsync( text : $"@everyone \n its free real estate \n add notifier to your [discord server]({MongoConfig.clientUrl})", embeds : new[] { embed.Build() }, isTTS : true ); } catch (Exception e) { throw new DiscordSendException($"failed to send giveaway {giveaway.ExternalId}", e); } finally { await _giveawayRepository.UpdateStatus(giveaway); } } }
public static void PostMessage(string message, Action <string, bool> log, bool error = false) { using var client = new DiscordWebhookClient(error ? ConfigService.ErrorWebhookURL : ConfigService.WebhookURL); client.Log += async arg => { log.Invoke(arg.ToString(), false); await Task.CompletedTask; }; while (message.Length > 0) { string tempMessage = null; if (message.Length >= 1900) { tempMessage = message.Substring(0, 1900); message = message.Substring(1900); } else { tempMessage = message; message = string.Empty; } client.SendMessageAsync(tempMessage).GetAwaiter().GetResult(); } }
public async Task SendMessage(DiscordWebhookClient webhook, Proxy proxy, string text, IReadOnlyCollection <IAttachment> attachments) { var proxyUser = discord.GetUser(proxy.BotUser.DiscordId); var username = $"{proxy.Name} [{proxyUser.Username}]"; var avatarUrl = proxy.HasAvatar ? $"{avatarBaseUrl}/{proxy.AvatarGuid}" : proxyUser.GetAvatarUrl(); if (attachments?.Any() ?? false) { var first = true; foreach (var a in attachments) { // TODO: Single multipart request var stream = await new HttpClient().GetStreamAsync(a.Url); await webhook.SendFileAsync(stream, a.Filename, first?text : String.Empty, username : username, avatarUrl : avatarUrl); first = false; } } else { await webhook.SendMessageAsync(text, username : username, avatarUrl : avatarUrl); } }
public static bool SendMessage(string webHookURL, string messageText, string userName = null, string avatarUrl = null) { DiscordWebhookClient discordWebhookClient = null; try { discordWebhookClient = new DiscordWebhookClient(webHookURL); } catch (Exception ex) { throw new DiscordCommunications.Exceptions.DiscordClientInstantiationException("Failed to Instantiate DiscordWebhookClient", ex.InnerException); } try { ////But a channel has a 30 msg/60 sec limit for webhooks discordWebhookClient.SendMessageAsync( text: messageText, username: userName, avatarUrl: avatarUrl ); } catch (Exception) { return(false); } return(true); }
private static Task TimerEvent() { Console.WriteLine("Fired"); hook.SendMessageAsync("timer eevent", false, null, "Spudule", "http://www.dutchdc.com/wp-content/uploads/2016/12/Potato_shadow.png"); return(Task.CompletedTask); }
private async Task OnMessageReceived(SocketMessage message) { if (message.Source != MessageSource.User) { return; } if (message.Channel.Id != ChannelId) { return; } var authorId = message.Author.Id.ToString(); if (!Config.People.ContainsKey(authorId)) { return; } string name = Config.People[authorId].Name; string avatarUrl = Config.People[authorId].AvatarUrl; using var webhookClient = new DiscordWebhookClient(WebhookUrl); await webhookClient.SendMessageAsync(message.Content, username : name, avatarUrl : avatarUrl); await message.DeleteAsync(DeleteMessageRequestOptions); }
public static async Task BroadcastErrorAsync(string discordWebhook, ILogger logger) { bool errorDiscordClient = false; DiscordWebhookClient client = null; try { client = new DiscordWebhookClient(discordWebhook); } catch (Exception e) { logger.LogInformation(e.Message); errorDiscordClient = true; } Color embedColor = Color.Red; EmbedBuilder builder = new EmbedBuilder(); var b = builder.WithTitle("Latency Alert") .WithDescription("⚠ There have been a connexion issue, it will restart. If this problem persists, please contact administrator.") .WithColor(embedColor) .Build(); List <Embed> embeds = new List <Embed>() { b }; if (!errorDiscordClient) { await client.SendMessageAsync(embeds : embeds, username : "******"); } }
public static ulong SendMessage(string webhookURL, string embed, out string message) { if (IsWebhookURLValid(webhookURL)) { try { var client = new DiscordWebhookClient(webhookURL); ulong id; try { id = client.SendMessageAsync(text: embed).Result; } finally { client.Dispose(); } message = "Sent Embed"; return(id); } catch (Exception e) { message = "Couldn't send embed: " + e.Message; return(0); } } message = "Webhook url invalid"; return(0); }
/// <summary> /// Build an <see cref="Embed"/>. /// </summary> public static void SendEmbed(string product, VersionsInfo oldVersion, VersionsInfo newVersion) { var isEncrypted = (product == "wowdev" || product == "wowv" || product == "wowv2"); var embed = new EmbedBuilder { Title = $"New Build for `{product}`", Description = $"⚠️ There is a new build for `{product}`! **{oldVersion.BuildId}** <:arrowJoin:740705934644609024> **{newVersion.BuildId}**\n" + $"{(isEncrypted ? "\n⛔ This build is **NOT** datamineable\n" : "")}" + $"\n**Build Config**:\n" + $"`{oldVersion.BuildConfig.Substring(0, 6)}` <:arrowJoin:740705934644609024> `{newVersion.BuildConfig.Substring(0, 6)}`" + $"\n**CDN Config**:\n" + $"`{oldVersion.CDNConfig.Substring(0, 6)}` <:arrowJoin:740705934644609024> `{newVersion.CDNConfig.Substring(0, 6)}`" + $"\n**Product Config**:\n" + $"`{oldVersion.ProductConfig.Substring(0, 6)}` <:arrowJoin:740705934644609024> `{newVersion.ProductConfig.Substring(0, 6)}`", Timestamp = DateTime.Now, // ThumbnailUrl = "https://www.clipartmax.com/png/middle/307-3072138_world-of-warcraft-2-discord-emoji-world-of-warcraft-w.png" }; // Send the message. Webhook.SendMessageAsync(embeds: new List <Embed>() { embed.Build() }); MrGMHook?.SendMessageAsync(embeds: new List <Embed>() { embed.Build() }); }
private static void NotifyNewPosts(RssFeed feed, List <Post> posts) { for (int i = 0; i < posts.Count; i += 10) //max 10 embeds per webhook push { List <Embed> embeds = new List <Embed>(); for (int k = i; k < Math.Min(i + 10, posts.Count); k++) { Post p = posts.ElementAt(k); embeds.Add(p.Embed); if (config.OutputToConsole) { Console.WriteLine($"\n{p.Title}"); Console.WriteLine($"Posted in /r/{p.Subreddit} by /u/{p.Author}"); Console.WriteLine($"Timestamp: {p.PublishDate}"); Console.WriteLine($"URL: {p.Url}"); if (p.HasImage) { Console.WriteLine($"Image URL: {p.ImageUrl}"); } } } foreach (String target in feed.WebhookTargets) { DiscordWebhook webhook = config.Webhooks[target]; using (var client = new DiscordWebhookClient(webhook.Endpoint)) { client.SendMessageAsync(text: webhook.PingString.Length > 0 ? webhook.PingString : null, embeds: embeds).Wait(); } } } }
public async Task SendPunishmentWebhook(int punishmentId) { PlayerPunishment punishment = database.GetPunishment(punishmentId); if (punishment == null) { return; } using (var client = new DiscordWebhookClient(webhookUrl)) { EmbedBuilder eb = new EmbedBuilder(); eb.WithColor(Color.Blue); eb.WithTitle($"{CultureInfo.CurrentCulture.TextInfo.ToTitleCase(punishment.Category)}"); eb.AddField("Player", $"[{punishment.Player.PlayerName}](https://steamcommunity.com/profiles/{punishment.PlayerId})"); eb.AddField("Punisher", $"[{punishment.Punisher.PlayerName}](https://steamcommunity.com/profiles/{punishment.PunisherId})"); eb.AddField("Reason", punishment.Reason == null ? "unkown" : punishment.Reason); if (punishment.ExpiryDate.HasValue) { eb.AddField("Expires", punishment.ExpiryDate); } eb.WithTimestamp(punishment.CreateDate); await client.SendMessageAsync(embeds : new List <Embed>() { eb.Build() }); } }
private async Task SendEmojiWithName(string name) { string emoji = name switch { "sans" => "<a:sans:719488632104288286>", "thonk" => "<:thonk:718853430969368637>", "mindblowing" => "<:mindblowing:719492411369324584>", "rotatethink" => "<a:rotatethonk:719491269885427752>", "hyper" => "<a:hyper:719494595313926244>", "xd" => "<:xd:719510255402352690>", "rainbowcat" => "<a:catrainbow1:719513824511656037><a:catrainbow2:719513824553861121>\n<a:catrainbow3:719513824905920603><a:catrainbow4:719513825040400415>", "yes" => "<a:yes:719496630902063149>", "no" => "<a:no:719496639471157288>", "calculated" => "<:calculated:719518217730654218>", _ => "unknown" }; var cxt = base.Context; var webhook = await((ITextChannel)cxt.Channel).CreateWebhookAsync(((IGuildUser)cxt.User).Nickname ?? cxt.User.Username); var webhookClient = new DiscordWebhookClient(webhook); await cxt.Channel.DeleteMessageAsync(base.Context.Message); await webhookClient.SendMessageAsync(emoji, avatarUrl : cxt.User.GetAvatarUrl()); await webhookClient.DeleteWebhookAsync(); } }
public static async Task BroadcastResultsAsync(List <EndPointHealthResult> epResults, string discordWebhook, ILogger logger, bool family = false) { bool errorDiscordClient = false; DiscordWebhookClient client = null; try { client = new DiscordWebhookClient(discordWebhook); } catch (Exception e) { logger.LogInformation(e.Message); errorDiscordClient = true; } List <Embed> embeds = null; if (!family) { embeds = CreateClassicEmbeds(epResults); } else { embeds = CreateFamilyEmbeds(epResults); } if (!errorDiscordClient) { await client.SendMessageAsync(embeds : embeds, username : "******"); } }