public async Task GetAnimeAsync(CommandContext ctx, [RemainingText] string name) { var animes = (await Kitsu.GetAnimeAsync(name)).Data.Take(10).ToList(); var embed = new DiscordEmbedBuilder() .WithTitle("Select anime") .WithFooter(ctx.Member.GetFullName(), ctx.Member.AvatarUrl); for (var i = 0; i < animes.Count; i++) { var a = animes[i]; embed.AddField($"[{i + 1}] {a.Attributes.Titles.En}({a.Attributes.Titles.JaJp})", $"{a.Attributes.AverageRating?.ToString() ?? "none"}"); } var index = -1; ToDelete.Add(ctx.Message); ToDelete.Add(await ctx.RespondAsync(embed: embed)); ToDelete.Add((await Interactivity.WaitForMessageAsync( x => int.TryParse(x.Content, out index) && index > 0 && index <= 10 || index == -1, TimeSpan.FromSeconds(30))).Message); if (index == -1) { return; } var anime = animes[index - 1]; embed.WithTitle($"{anime.Attributes.Titles.En}({anime.Attributes.Titles.EnJp})"); embed.ClearFields(); embed.Description = anime.Attributes.Synopsis; await ctx.RespondAsync(embed : embed); }
public async Task SetupAsync(CommandContext ctx) { var hassettings = ctx.GetGuildSettings() != null; DiscordMessage t0; if (hassettings) { t0 = await ctx.SafeRespondUnformattedAsync( "Welcome to ModCore! Looks like you already configured your guild." + "Would you like to go through the setup again? (Y/N)"); } else { t0 = await ctx.SafeRespondUnformattedAsync( "Welcome to ModCore! This server has not been set up yet." + "Would you like to go through the setup? (Y/N)"); } var res = await Interactivity.WaitForMessageAsync(e => e.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(40)); var message = res.TimedOut ? null : res.Result; if (!message.Content.EqualsIgnoreCase("y") && !message.Content.EqualsIgnoreCase("yes") && !message.Content.EqualsIgnoreCase("ya") && !message.Content.EqualsIgnoreCase("ja") && !message.Content.EqualsIgnoreCase("da")) { await ctx.SafeRespondUnformattedAsync( "OK, I won't bother you anymore. Just execute this command again if you need help configuring."); await t0.DeleteAsync("modcore cleanup after itself: welcome message"); await message.DeleteAsync( "modcore cleanup after itself: user response to welcome message"); return; } DiscordChannel channel; try { channel = ctx.Guild.Channels.FirstOrDefault(e => e.Value.Name == "modcore-setup").Value ?? await ctx.Guild.CreateChannelAsync("modcore-setup", ChannelType.Text, reason : "modcore setup channel creation"); } catch { await ctx.SafeRespondUnformattedAsync("Unfortunately, I wasn't able to create the modcore setup channel.\n" + "Could you kindly create a channel called `modcore-setup` and re-run the command?\n" + "I'll set up the rest for you. This will help keep the setup process away from prying eyes."); return; } await channel.AddOverwriteAsync(ctx.Guild.EveryoneRole, Permissions.None, Permissions.AccessChannels, "modcore overwrites for setup channel"); await channel.AddOverwriteAsync(ctx.Member, Permissions.AccessChannels, Permissions.None, "modcore overwrites for setup channel"); await channel.AddOverwriteAsync(ctx.Guild.CurrentMember, Permissions.AccessChannels, Permissions.None, "modcore overwrites for setup channel"); await channel.ElevatedMessageAsync( "OK, now, can you create a webhook for ModCore and give me its URL?\n" + "If you don't know what that is, simply say no and I'll make one for you."); var res2 = await Interactivity.WaitForMessageAsync(e => e.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(40)); var message2 = res2.TimedOut ? null : res2.Result; var mContent = message2.Content; if (!mContent.Contains("discordapp.com/api/webhooks/")) { await channel.ElevatedMessageAsync("Alright, I'll make a webhook for you then. Sit tight..."); DiscordChannel logChannel; try { logChannel = ctx.Guild.Channels.FirstOrDefault(e => e.Value.Name == "modlog").Value ?? await ctx.Guild.CreateChannelAsync("modlog", ChannelType.Text, reason : "ModCore Logging channel."); } catch { await ctx.SafeRespondUnformattedAsync("Unfortunately, I wasn't able to create the modcore logging channel.\n" + "Could you kindly create a channel called `modlog` and re-run the command?\n" + "I'll set up the rest for you. This is to setup a channel for the actionlog to post into."); return; } var webhook = await logChannel.CreateWebhookAsync("ModCore Logging", reason : "Created webhook to post log messages"); var cfg = ctx.GetGuildSettings() ?? new GuildSettings(); cfg.ActionLog.WebhookId = webhook.Id; cfg.ActionLog.WebhookToken = webhook.Token; await ctx.SetGuildSettingsAsync(cfg); } else { var tokens = mContent .Substring(mContent.IndexOfInvariant("/api/webhooks/") + "/api/webhooks/".Length) .Split('/'); var cfg = ctx.GetGuildSettings() ?? new GuildSettings(); cfg.ActionLog.WebhookId = ulong.Parse(tokens[0]); cfg.ActionLog.WebhookToken = tokens[1]; await ctx.SetGuildSettingsAsync(cfg); } await channel.ElevatedMessageAsync( "Webhook configured. Looks like you're all set! ModCore has been set up." + "\nThis channel will be deleted in 30 seconds..."); await Task.Delay(TimeSpan.FromSeconds(30)); try { await channel.DeleteAsync(); } catch (Exception) { await channel.ElevatedMessageAsync("Failed to delete the channel.\nPlease try to do so yourself."); } }
public async Task ExecuteGroupAsync(CommandContext ctx) { await ctx.IfGuildSettingsAsync(async() => { var t0 = await ctx.SafeRespondAsync( "Welcome to ModCore! Looks like you haven't configured your guild yet." + "Would you like to go through a quick setup? (Y/N)"); var res = await Interactivity.WaitForMessageAsync(e => e.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(40)); var message = res.TimedOut ? null : res.Result; if (!message.Content.EqualsIgnoreCase("y") && !message.Content.EqualsIgnoreCase("yes") && !message.Content.EqualsIgnoreCase("ya") && !message.Content.EqualsIgnoreCase("ja") && !message.Content.EqualsIgnoreCase("da")) { await ctx.SafeRespondAsync( "OK, I won't bother you anymore. Just execute this command again if you need help configuring."); await t0.DeleteAsync("modcore cleanup after itself: welcome message"); await message.DeleteAsync( "modcore cleanup after itself: user response to welcome message"); return; } DiscordChannel channel; try { channel = ctx.Guild.Channels.FirstOrDefault(e => e.Value.Name == "modcore-setup").Value ?? await ctx.Guild.CreateChannelAsync("modcore-setup", ChannelType.Text, reason: "modcore setup channel creation"); } catch { await ctx.SafeRespondAsync("Unfortunately, I wasn't able to create the modcore setup channel.\n" + "Could you kindly create a channel called `modcore-setup` and re-run the command?\n" + "I'll set up the rest for you. This will help keep the setup process away from prying eyes."); return; } await channel.AddOverwriteAsync(ctx.Guild.EveryoneRole, Permissions.None, Permissions.AccessChannels, "modcore overwrites for setup channel"); await channel.AddOverwriteAsync(ctx.Member, Permissions.AccessChannels, Permissions.None, "modcore overwrites for setup channel"); await channel.ElevatedMessageAsync( "OK, now, can you create a webhook for ModCore and give me its URL?\n" + "If you don't know what that is, simply say no and I'll make one for you."); var res2 = await Interactivity.WaitForMessageAsync(e => e.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(40)); var message2 = res2.TimedOut ? null : res2.Result; var mContent = message2.Content; if (!mContent.Contains("discordapp.com/api/webhooks/")) { await channel.ElevatedMessageAsync("Alright, I'll make a webhook for you then. Sit tight..."); DiscordChannel logChannel; try { logChannel = ctx.Guild.Channels.FirstOrDefault(e => e.Value.Name == "modlog").Value ?? await ctx.Guild.CreateChannelAsync("modlog", ChannelType.Text, reason: "ModCore Logging channel."); } catch { await ctx.SafeRespondAsync("Unfortunately, I wasn't able to create the modcore logging channel.\n" + "Could you kindly create a channel called `modlog` and re-run the command?\n" + "I'll set up the rest for you. This is to setup a channel for the actionlog to post into."); return; } var webhook = await logChannel.CreateWebhookAsync("ModCore Logging", null, "Created webhook to post log messages"); var cfg = ctx.GetGuildSettings() ?? new GuildSettings(); cfg.ActionLog.WebhookId = webhook.Id; cfg.ActionLog.WebhookToken = webhook.Token; await ctx.SetGuildSettingsAsync(cfg); } else { var tokens = mContent .Substring(mContent.IndexOfInvariant("/api/webhooks/") + "/api/webhooks/".Length) .Split('/'); var cfg = ctx.GetGuildSettings() ?? new GuildSettings(); cfg.ActionLog.WebhookId = ulong.Parse(tokens[0]); cfg.ActionLog.WebhookToken = tokens[1]; await ctx.SetGuildSettingsAsync(cfg); } await ctx.SafeRespondAsync( "Webhook configured. Looks like you're all set! ModCore has been set up."); }, async gcfg => { var embed = new DiscordEmbedBuilder { Title = ctx.Guild.Name, ThumbnailUrl = ctx.Guild.IconUrl, Description = "ModCore configuration for this guild:" }; embed.AddField("Command Prefix", gcfg.Prefix != null ? $"\"{gcfg.Prefix}\"" : "Not configured", true); var muted = gcfg.MuteRoleId != 0 ? ctx.Guild.GetRole(gcfg.MuteRoleId) : null; embed.AddField("Muted Role", muted != null ? muted.Mention : "Not configured or missing", true); var actionlog = gcfg.ActionLog; embed.AddField("Action Log", actionlog.Enable ? "Enabled" + (actionlog.WebhookId == 0 ? ", but not configured!" : "") : "Disabled"); var autorole = gcfg.AutoRole; embed.AddField("Auto Role", autorole.Enable ? $"Enabled with Role ID {autorole.RoleId}." : "Disabled"); var commanderror = gcfg.CommandError; embed.AddField("Command Error logging", $"Chat: {commanderror.Chat}, ActionLog: {commanderror.ActionLog}"); var linkfilterCfg = gcfg.Linkfilter; embed.AddField("Linkfilter", linkfilterCfg.Enable ? "Enabled" : "Disabled", true); if (linkfilterCfg.Enable) { embed.AddField("Linkfilter Modules", $"{(linkfilterCfg.BlockInviteLinks ? "✔" : "✖")}Anti-Invites, " + $"{(linkfilterCfg.BlockBooters ? "✔" : "✖")}Anti-DDoS, " + $"{(linkfilterCfg.BlockIpLoggers ? "✔" : "✖")}Anti-IP Loggers, " + $"{(linkfilterCfg.BlockShockSites ? "✔" : "✖")}Anti-Shock Sites, " + $"{(linkfilterCfg.BlockUrlShorteners ? "✔" : "✖")}Anti-URL Shorteners", true); if (linkfilterCfg.ExemptRoleIds.Any()) { var roles = linkfilterCfg.ExemptRoleIds .Select(ctx.Guild.GetRole) .Where(xr => xr != null) .Select(xr => xr.Mention); embed.AddField("Linkfilter-Exempt Roles", string.Join(", ", roles), true); } if (linkfilterCfg.ExemptUserIds.Any()) { var users = linkfilterCfg.ExemptUserIds .Select(xid => $"<@!{xid}>"); embed.AddField("Linkfilter-Exempt Users", string.Join(", ", users), true); } if (linkfilterCfg.ExemptInviteGuildIds.Any()) { var guilds = string.Join(", ", linkfilterCfg.ExemptInviteGuildIds); embed.AddField("Linkfilter-Exempt Invite Targets", guilds, true); } } var roleCfg = gcfg.RoleState; embed.AddField("Role State", roleCfg.Enable ? "Enabled" : "Disabled", true); if (roleCfg.Enable) { if (roleCfg.IgnoredRoleIds.Any()) { var roles = roleCfg.IgnoredRoleIds .Select(ctx.Guild.GetRole) .Where(xr => xr != null) .Select(xr => xr.Mention); embed.AddField("Role State-Ignored Roles", string.Join(", ", roles), true); } if (roleCfg.IgnoredChannelIds.Any()) { var channels = roleCfg.IgnoredChannelIds .Select(ctx.Guild.GetChannel) .Where(xc => xc != null) .Select(xc => xc.Mention); embed.AddField("Role State-Ignored Channels", string.Join(", ", channels), true); } } var inviscopCfg = gcfg.InvisiCop; embed.AddField("InvisiCop", inviscopCfg.Enable ? "Enabled" : "Disabled", true); if (inviscopCfg.Enable) { if (inviscopCfg.ExemptRoleIds.Any()) { var roles = inviscopCfg.ExemptRoleIds .Select(ctx.Guild.GetRole) .Where(xr => xr != null) .Select(xr => xr.Mention); embed.AddField("InvisiCop-Exempt Roles", string.Join(", ", roles), true); } if (inviscopCfg.ExemptUserIds.Any()) { var users = inviscopCfg.ExemptUserIds .Select(xid => $"<@!{xid}>"); embed.AddField("InvisiCop-Exempt Users", string.Join(", ", users), true); } } embed.AddField("Starboard", gcfg.Starboard.Enable ? $"Enabled\nChannel: <#{gcfg.Starboard.ChannelId}>\nEmoji: {gcfg.Starboard.Emoji.EmojiName}" : "Disabled", true); var suggestions = gcfg.SpellingHelperEnabled; embed.AddField("Command Suggestions", suggestions ? "Enabled" : "Disabled", true); var joinlog = gcfg.JoinLog; embed.AddField("Join Logging", joinlog.Enable ? "Enabled" + (joinlog.ChannelId == 0 ? ", but no channel configured!" : "") : "Disabled", true); if (gcfg.SelfRoles.Any()) { var roles = gcfg.SelfRoles .Select(ctx.Guild.GetRole) .Where(xr => xr != null) .Select(xr => xr.Mention); embed.AddField("Available Selfroles", string.Join(", ", roles), true); } var globalwarn = gcfg.GlobalWarn; embed.AddField("GlobalWarn", globalwarn.Enable ? "Enabled\nMode: " + globalwarn.WarnLevel : "Disabled", true); await ctx.ElevatedRespondAsync(embed: embed.Build()); }); }