protected async Task RespondSuccess(string message) { await Ctx.CreateResponseAsync(DSharpPlus.InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder() .AddEmbed(CommandModule.SuccessBase() .WithDescription(message))); }
public async Task UrbanDictionaryCommandAsync(CommandContext ctx, [Description("What do you want to serach for?")] string searchTerm) { var res = await UrbanDictionary.Search(searchTerm); if (res is null) { await RespondBasicErrorAsync("Bad API Request."); return; } var item = res.FirstOrDefault(); if (item.Word?.Equals("") ?? false) { await RespondBasicErrorAsync("Failed to reterive any results!"); return; } var embed = CommandModule.SuccessBase() .WithTitle(item.Word) .WithAuthor(item.DefId.ToString(), item.PermaLink) .WithDescription(item.Definition) .AddField("Example:", item.Example) .WithFooter($"\U0001F44D {item.ThumbsUp} | \U0001F44E {item.ThumbsDown}") .WithTimestamp(DateTime.TryParse(item.WrittenOn, out var time) ? time : new DateTime()); await ctx.RespondAsync(embed : embed); }
public async Task ListFiltersCommandAsync(CommandContext ctx) { var filter = await this._model.FindAsync <GuildFilters>(ctx.Guild.Id); if (filter is null || filter.Filters.Count <= 0) { await RespondBasicErrorAsync("No filter found."); return; } var interact = ctx.Client.GetInteractivity(); var data = ""; foreach (var item in filter.Filters) { data += $"{item.Key} [{item.Value.Item1}]: `{string.Join("`, `", item.Value.Item2)}`\n"; } var embed = CommandModule.SuccessBase() .WithTitle("Filter Name [Filter Severity]: Filter Words"); var pages = interact.GeneratePagesInEmbed(data, DSharpPlus.Interactivity.Enums.SplitType.Line, embed); await interact.SendPaginatedMessageAsync(ctx.Channel, ctx.Member, pages); }
public async Task MusicListCommandAsync(CommandContext ctx) { var conn = await this._voice.GetGuildConnection(ctx); if (conn is null) { await RespondBasicErrorAsync("I'm not connected to any Voice Channels!"); return; } var nowPlaying = conn.CurrentState.CurrentTrack; string data = $":green_circle: :notes:] {nowPlaying.Title} by {nowPlaying.Author} - `{conn.CurrentState.PlaybackPosition:mm\\:ss}/{nowPlaying.Length:mm\\:ss}`"; if (this._voice.GuildQueues.TryGetValue(ctx.Guild.Id, out var queue)) { int i = 1; int last = queue.Count; foreach (var track in queue) { if (i == 1) { data += $"\n:yellow_circle: **{i}]** {track.Title} by {track.Author} - `{track.Length:mm\\:ss}`"; } else if (i == last) { data += $"\n:red_circle: **{i}]** {track.Title} by {track.Author} - `{track.Length:mm\\:ss}`"; } else { data += $"\n:black_circle: **{i}]** {track.Title} by {track.Author} - `{track.Length:mm\\:ss}`"; } i++; } } var interact = ctx.Client.GetInteractivity(); var pages = interact.GeneratePagesInEmbed(data, SplitType.Line, CommandModule.SuccessBase()); var emojis = new PaginationEmojis() { Left = DiscordEmoji.FromName(ctx.Client, ":arrow_up_small:"), SkipLeft = DiscordEmoji.FromName(ctx.Client, ":arrow_double_up:"), Right = DiscordEmoji.FromName(ctx.Client, ":arrow_down_small:"), SkipRight = DiscordEmoji.FromName(ctx.Client, ":arrow_double_down:"), Stop = DiscordEmoji.FromName(ctx.Client, ":stop_button:"), }; await interact.SendPaginatedMessageAsync(ctx.Channel, ctx.Member, pages, emojis); }
public async Task PingCommandAsync(CommandContext ctx) { Stopwatch timer = new Stopwatch(); var pingEmbed = CommandModule.SuccessBase().WithTitle($"Ping for Shard {ctx.Client.ShardId}"); pingEmbed.AddField("WS Latency:", $"{ctx.Client.Ping}ms"); timer.Start(); DiscordMessage msg = await ctx.RespondAsync(pingEmbed); await msg.ModifyAsync(null, pingEmbed.AddField("Response Time: (:ping_pong:)", $"{timer.ElapsedMilliseconds}ms").Build()); timer.Stop(); }
public async Task JoinDmCommandAsync(CommandContext ctx, [Description("Message to send, `info` to see more information about this command, or `disable` to disable the join DMs.")] [RemainingText] string message) { string msg = message?.Trim().ToLower() ?? "info"; if (msg.Equals("info")) { var embed = CommandModule.SuccessBase() .WithTitle("Join DM Message Information") .WithDescription("Certain words wrapped in brackets `{ }` can be used to replace parts of your message progrmatically.\n" + "**```http\n" + "server, guild :: Gets replaced with your server name.\n" + "user, member :: Gets replaced with the name of the user who just joined.\n" + "membercount :: Gets replaced with the total member count at the time.\n" + "```**\n" + "Ex: Welcome to {server}, {member}! You are the {membercount} person to join!"); await ctx.RespondAsync(embed : embed); return; } var guild = this._model.Find <GuildMemberlogs>(ctx.Guild.Id); if (guild is null) { guild = new GuildMemberlogs(ctx.Guild.Id); this._model.Add(guild); } if (msg.Equals("disable")) { guild.JoinDmMessage = null; await RespondBasicSuccessAsync("Disabled Join DMs"); } else { guild.JoinDmMessage = message; await RespondBasicSuccessAsync($"Set the join DM message to: \n```\n{message}```"); } await this._model.SaveChangesAsync(); }
public async Task BalanceCommandAsync(CommandContext ctx, DiscordMember?member = null) { bool save = false; DiscordMember m; if (member is null) { m = ctx.Member; } else { m = member; } var wallet = this._model.Wallets.Find(m.Id); if (wallet is null) { wallet = new Wallet(m.Id, ctx.User.Username); // Save the new wallet to the database. this._model.Wallets.Add(wallet); save = true; } else { if (wallet.Username != ctx.Member.Username) { wallet.Username = ctx.Member.Username; save = true; } } if (save) { _ = await this._model.SaveChangesAsync(); } var b = CommandModule.SuccessBase() .WithTitle($"{m.DisplayName}'s Balance") .WithDescription(Formatter.Bold(wallet.Balance.ToMoney())); await ctx.RespondAsync(embed : b.Build()); }
public async Task FortuneCommandAsync(CommandContext ctx) { var fortune = await Fortune.GetFortuneCookie(); if (fortune is null) { await RespondBasicErrorAsync("Bad Cookie!"); } else { var embed = CommandModule.SuccessBase() .WithTitle("Fortune Cookie!") .AddField("Fortune", fortune.Data.Messge) .AddField("Lesson", $"{fortune.Lesson.English}\n{fortune.Lesson.Chinese}\n{fortune.Lesson.Pronunciation}") .AddField("Lotto", string.Join(", ", fortune.Lotto.Numbers)); await ctx.RespondAsync(embed : embed); } }
public async Task UserInfoCommandAsync(CommandContext ctx, DiscordMember m) { var roles = m.Roles.Where(x => !x.Name.Contains("everyone")); List <string> roleStrings = new List <string>(); foreach (var role in roles) { roleStrings.Add(role.Mention); } var embed = CommandModule.SuccessBase() .WithTitle(m.Username + "#" + m.Discriminator) .WithDescription(m.Nickname ?? "No Nickname") .AddField("Roles", string.Join(", ", roleStrings)) .WithAuthor(m.Id.ToString(), null, m.AvatarUrl) .AddField("Joined", m.JoinedAt.ToString("f"), true) .AddField("Account Created", m.CreationTimestamp.ToString("f"), true); await ctx.RespondAsync(embed : embed); }
public async Task ServerInfoCommandAsync(CommandContext ctx) { int users = 0, bots = 0; var memberStats = ""; var members = await ctx.Guild.GetAllMembersAsync(); foreach (var m in members) { try { if (m.IsBot) { bots++; } else { users++; } } catch { users++; } } int total = bots + users; memberStats += $"Total: {total}\nMembers: {users}\nBots: {bots}"; var embed = CommandModule.SuccessBase() .WithAuthor(ctx.Guild.Name, null, ctx.Guild.IconUrl) .WithTitle("Server Statistics") .AddField("Members", memberStats) .AddField("Created On", ctx.Guild.CreationTimestamp.ToString("f"), true) .AddField("Roles:", ctx.Guild.Roles.Count.ToString(), true); await ctx.RespondAsync(embed : embed); }
public async Task TriviaLeaderboardCommandAsync(CommandContext ctx, [Description("Filter the leaderboards in various ways! Use the keyword `info` to see more filtering options.")] [RemainingText] string args) { LeaderboardType leaderboardType = LeaderboardType.Global; bool sortByPercentCorrect = false; bool displayPersonalData = false; // Look at the args and see if any fliters need to be applied. if (!(args is null) && args.Length > 0) { var lowerArgs = args.ToLower().Split(' ', System.StringSplitOptions.RemoveEmptyEntries); if (lowerArgs.Contains("info")) { // Display argmuent information here. var infoEmbed = CommandModule.SuccessBase() .WithTitle("Trivia Leaderboards") .WithDescription("Additional Arguments for the Trivia Leadboards.\n" + $"Example: `{ctx.Prefix}triviatop server") .AddField("server", "Show only leaderboards for this server.") .AddField("percent", "Show the people with the highest correct answer percent rather than highest score. " + "Only users with at least 25 questions answered are shown.") .AddField("me", "Shows only your stats for Trivia"); await ctx.RespondAsync(embed : infoEmbed); return; } else { // Complie the search filters here. foreach (var arg in lowerArgs) { if (arg == "server") { leaderboardType = LeaderboardType.Server; } if (arg == "percent") { sortByPercentCorrect = true; } if (arg == "me") { displayPersonalData = true; } } } } if (displayPersonalData) { var player = this._model.TriviaPlayers.Find(ctx.Member.Id); if (player is null) { await ctx.RespondAsync($"No statistic found! Play a game of trivia with {ctx.Prefix}trivia"); } else { var embed = new DiscordEmbedBuilder() .WithColor(DiscordColor.Purple) .WithTitle("Personal Trivia Stats") .AddField("Total Questions:", player.TotalQuestions.ToString(), true) .AddField("Percent Correct:", player.PercentCorrect.ToString("0.##") + "%", false) .AddField("Correct Answers:", player.QuestionsCorrect.ToString(), true) .AddField("Incorrect Answers:", player.QuestionsIncorrect.ToString(), false) .AddField("Total Points:", player.Points.ToString()); await ctx.RespondAsync(embed : embed); } } else { List <TriviaPlayer> players; players = this._model.TriviaPlayers .AsNoTracking() .ToList(); if (leaderboardType == LeaderboardType.Server) { var users = await ctx.Guild.GetAllMembersAsync(); players = players.Where(x => users.Any(y => y.Id == x.UserId)).ToList(); } if (sortByPercentCorrect) { players = players.Where(x => (x.QuestionsCorrect + x.QuestionsIncorrect) >= 25).ToList(); players.Sort((x, y) => x.PercentCorrect.CompareTo(y.PercentCorrect)); } else { players.Sort((x, y) => x.Points.CompareTo(y.Points)); } var interact = ctx.Client.GetInteractivity(); string data = ""; int i = 1; players.Reverse(); foreach (var player in players) { data += $"{i}. {(player.Username == "" ? player.UserId.ToString() : player.Username)} - " + $"{(sortByPercentCorrect ? player.PercentCorrect.ToString("0.##") + "%" : player.Points + " points\n")}"; } if (data == "") { data += "No leaderboards found!"; } var embed = new DiscordEmbedBuilder() .WithTitle($"{(leaderboardType == LeaderboardType.Global ? "Global" : ctx.Guild.Name)} Trivia Leaderboard") .WithColor(DiscordColor.Purple); var pages = interact.GeneratePagesInEmbed(data, SplitType.Line, embed); await interact.SendPaginatedMessageAsync(ctx.Channel, ctx.Member, pages); } }