public async Task TestAsync(string command, string name = "Default Name", string msg = "") { switch (command) { case "webhook": ITextChannel t = Context.Channel as ITextChannel; var webhook = await t.CreateWebhookAsync(name); DiscordWebhookClient w = new DiscordWebhookClient(webhook); await w.SendMessageAsync(msg); await w.DeleteWebhookAsync(); await webhook.DeleteAsync(); break; case "box": ulong id = 0; try { ITextChannel here = Context.Channel as ITextChannel; var iBox = await here.CreateWebhookAsync("Touhou Box"); id = iBox.Id; DiscordWebhookClient weeb = new DiscordWebhookClient(iBox); await weeb.ModifyWebhookAsync(x => { x.Image = new Image(GetStreamFromURL("http://img.zeryx.xyz/LewdBoxLogo.jpg")); }); await weeb.SendFileAsync(GetStreamFromURL("http://img.zeryx.xyz/lewdboxes/touhou/cir001.png"), "cir001.png", "You got Cirno!"); await weeb.DeleteWebhookAsync(); break; } catch (Exception e) { Log(e.Message); ITextChannel tempc = Context.Channel as ITextChannel; var tempw = await tempc.GetWebhookAsync(id); await tempw.DeleteAsync(); break; } } }
private async Task <IWebhook> GetWebhook(ITextChannel channel, IGuildUser user) { EmojiWebhook found = (await _container.Query($"SELECT * FROM db WHERE db.UserId = {user.Id}")).FirstOrDefault(); if (found == null) { var webhook = await channel.CreateWebhookAsync(user.Nickname ?? user.Username); EmojiWebhook entry = new EmojiWebhook() { UserId = user.Id, ChannelsAndWebhooks = new Dictionary <ulong, ulong>() { [channel.Id] = webhook.Id } }; await _container.Insert(entry); return(webhook); } else { if (found.ChannelsAndWebhooks.TryGetValue(channel.Id, out var value)) { return(await channel.GetWebhookAsync(value)); } else { var webhook = await channel.CreateWebhookAsync(user.Nickname ?? user.Username); found.ChannelsAndWebhooks.Add(channel.Id, webhook.Id); await _container.Upsert(found); return(webhook); } } }