public async Task ShowInventory(CommandMessage message) { // Shop items List <ShopItem> items = new List <ShopItem>(); User user = await UserService.GetUser(message.Author); EmbedBuilder embed = new EmbedBuilder(); embed.Title = message.Author.GetName() + "'s Inventory"; embed.Color = Color.Blue; StringBuilder desc = new StringBuilder(); if (user.Inventory.Count == 0) { desc.AppendLine("Nothing to show here. Visit our shop, _kupo!_"); } else { // Load shop items items = await ShopItemDatabase.LoadAll(new Dictionary <string, object>() { { "GuildId", message.Guild.Id }, }); // Restrict items to only held items = items.Where(x => user.Inventory.ContainsKey(x.Name)).ToList(); foreach (KeyValuePair <string, int> item in user.Inventory) { desc.AppendLine(item.Value + "x - " + item.Key); } } desc.AppendLine(Utils.Characters.Tab); embed.Description = desc.ToString(); string prefix = CommandsService.GetPrefix(message.Guild.Id); embed.WithFooter("Use " + prefix + "shop to see items to buy. Select a reaction to redeem."); RestUserMessage userMessage = await message.Channel.SendMessageAsync(embed : embed.Build(), messageReference : message.MessageReference); // Add reacts await userMessage.AddReactionsAsync(items.Select(x => x.ReactionEmote).ToArray()); // Handle reacts Program.DiscordClient.ReactionAdded += this.OnReactionAddedInventory; // Add to active windows this.activeInventoryWindows.Add(userMessage.Id, DateTime.Now); // Clear reacts _ = Task.Run(async() => await this.StopInventoryListener(userMessage)); }
public async Task ViewContentCreators(CommandMessage message) { // Load streamers List <ContentCreator> streamers = await ContentCreatorDatabase.LoadAll(new Dictionary <string, object> { { "DiscordGuildId", message.Guild.Id } }); EmbedBuilder embed = new EmbedBuilder() .WithTitle("Content Creators"); // Add thumbnail embed.AddThumbnail(message.Guild.IconUrl); if (streamers == null || streamers.Count == 0) { // TODO: Add YT when implemented string prefix = CommandsService.GetPrefix(message.Guild.Id); embed.Description = $"No streamers found!\nUsers can add themselves with {prefix}ICreatorTwitch or {prefix}ICreatorYoutube command"; } else { StringBuilder desc = new StringBuilder(); foreach (ContentCreator streamer in streamers) { desc.Append($"{FC.Utils.DiscordMarkdownUtils.BulletPoint} {streamer.GuildNickName} | "); if (streamer.Twitch != null) { desc.Append($"Twitch: {streamer.Twitch.Link}"); } if (streamer.Youtube != null) { if (streamer.Twitch != null) { desc.Append(" | "); } desc.Append($"Youtube: {streamer.Youtube.Link}"); } desc.AppendLine(); } embed.Description = desc.ToString(); } // Send Embed await message.Channel.SendMessageAsync(embed : embed.Build(), messageReference : message.MessageReference); }
private static string?GetHelp(IGuild guild, string commandStr, Permissions permissions) { StringBuilder builder = new StringBuilder(); List <Command> commands = CommandsService.GetCommands(commandStr); int count = 0; foreach (Command command in commands) { // Don't show commands users cannot access if (command.Permission > permissions) { continue; } count++; } if (count <= 0) { return(null); } builder.Append("__"); ////builder.Append(CommandsService.CommandPrefix); builder.Append(commandStr); builder.AppendLine("__"); foreach (Command command in commands) { // Don't show commands users cannot access if (command.Permission > permissions) { continue; } builder.Append(Utils.Characters.Tab); builder.Append(command.Permission); builder.Append(" - *"); builder.Append(command.Help); builder.AppendLine("*"); List <ParameterInfo> parameters = command.GetNeededParams(); builder.Append("**"); builder.Append(Utils.Characters.Tab); builder.Append(CommandsService.GetPrefix(guild)); builder.Append(commandStr); builder.Append(" "); for (int i = 0; i < parameters.Count; i++) { if (i != 0) { builder.Append(" "); } builder.Append(GetParam(parameters[i], command.RequiresQuotes)); } builder.Append("**"); builder.AppendLine(); builder.AppendLine(); } return(builder.ToString()); }
private static Embed GetHelp(IGuild guild, Permissions permissions, int startIndex, out int page) { // Get all help commands IEnumerable <HelpCommand> helpCommands = CommandsService.GetGroupedHelpCommands() .Where(x => x.Permission <= permissions); int numberOfPages = 0; int pagesForGroup = 0; foreach (IGrouping <CommandCategory, HelpCommand> group in helpCommands.GroupBy(x => x.CommandCategory)) { pagesForGroup = (int)Math.Ceiling((decimal)group.Count() / PageSize); numberOfPages += pagesForGroup; // Create spacer commands int spacerCommandsRequired = (PageSize * pagesForGroup) - group.Count(); for (int i = 0; i < spacerCommandsRequired; i++) { helpCommands = helpCommands.Append(new HelpCommand("Spacer", group.Key, string.Empty, Permissions.Everyone)); } } helpCommands = helpCommands.OrderBy(x => x.CommandCategory) .ThenBy(x => x.CommandName) .AsEnumerable(); // page is 0-indexed page = startIndex + 1; // If page is greater than last page, wrap to start if (page > numberOfPages) { page = 1; startIndex = 0; } // Moving to last page if (startIndex == -1) { page = numberOfPages; helpCommands = helpCommands.TakeLast(PageSize); startIndex = 0; } // Restrict to page size helpCommands = helpCommands.Skip(startIndex * PageSize).Take(PageSize); // Start Embed EmbedBuilder embed = new EmbedBuilder(); StringBuilder builder = new StringBuilder(); // Category name embed.Title = helpCommands.FirstOrDefault().CommandCategory.ToDisplayString() + " Commands"; // Iterate commands foreach (HelpCommand category in helpCommands) { if (category.CommandName.ToLower() == "spacer") { continue; } builder.Append("**" + category.CommandName + "**"); builder.Append(" - "); if (category.CommandCount > 1) { builder.Append("*+" + category.CommandCount + "* - "); } builder.Append(category.Help); builder.AppendLine(); if (category.CommandShortcuts.Count > 0) { builder.Append("Shortcut: "); foreach (string shortcutString in category.CommandShortcuts) { builder.Append(shortcutString + ", "); } builder.Remove(builder.Length - 2, 2); builder.AppendLine(); } builder.AppendLine(); } builder.AppendLine(); string prefix = CommandsService.GetPrefix(guild); embed.WithThumbnailUrl("https://cdn.discordapp.com/attachments/825936704023691284/828491389838426121/think3.png") .WithDescription(builder.ToString()) .WithAuthor(string.Format("Page {0} of {1}", page, numberOfPages)) .WithFooter("To get more information on a command, look it up directly, like \"" + prefix + "help time\" or \"" + prefix + "et ?\""); // Return page to 0-index page -= 1; return(embed.Build()); }
public static async Task <bool> GetHelp(CommandMessage message, Permissions permissions) { EmbedBuilder embed = new EmbedBuilder(); StringBuilder builder = new StringBuilder(); List <string> commandStrings = new List <string>(CommandsService.GetCommands()); commandStrings.Sort(); int commandCount = 0; foreach (string commandString in commandStrings) { if (commandString == "help") { continue; } int count = 0; List <Command> commands = CommandsService.GetCommands(commandString); foreach (Command command in commands) { if (command.Permission > permissions) { continue; } count++; } if (count <= 0) { continue; } builder.Append("__"); builder.Append(commandString); builder.Append("__ - *+"); builder.Append(count); builder.Append("* - "); builder.Append(commands[0].Help); builder.AppendLine(); commandCount++; if (commandCount >= 20) { embed = new EmbedBuilder(); embed.Description = builder.ToString(); await message.Channel.SendMessageAsync(null, false, embed.Build()); builder.Clear(); commandCount = 0; } } builder.AppendLine(); builder.AppendLine(); builder.AppendLine("To get more information on a command, look it up directly, like `" + CommandsService.GetPrefix(message.Guild) + "help \"time\"` or `" + CommandsService.GetPrefix(message.Guild) + "et ?`"); embed = new EmbedBuilder(); embed.Description = builder.ToString(); await message.Channel.SendMessageAsync(null, false, embed.Build()); return(true); }