public static async Task ShopSortConfirm(SocketGuildUser user, RestUserMessage message) { // Get the account information of the command's target var account = UserInfoClasses.GetAccount(user); // Find both the menu session and item session associated with the current user and store them in variables. var menuSession = Global.MenuIdList.SingleOrDefault(x => x.User.Id == user.Id); var itemSession = Global.ItemIdList.SingleOrDefault(x => x.User.Id == user.Id); // Create a new embed that will be displayed in the message. var embed = new EmbedBuilder(); var author = new EmbedAuthorBuilder { Name = "Settings Saved", IconUrl = user.GetAvatarUrl() }; var footer = new EmbedFooterBuilder { Text = "💠 Return to Shop" }; embed.WithAuthor(author); embed.WithFooter(footer); embed.WithDescription($"Shop décor will now be sorted **`{DecorInfoMethods.SortSettingToString(account.Shop_Sort)}`**."); // Determine the color and thumbnail for the embeded message. if (account.Profile_Theme == "P3") { embed.WithColor(37, 149, 255); } else if (account.Profile_Theme == "P4") { embed.WithColor(255, 229, 49); } else if (account.Profile_Theme == "P5") { embed.WithColor(213, 27, 4); } // Attempt editing the message if it hasn't been deleted by the user yet. If it has, catch the exception, send an error message, and return. try { // Remove all reactions from the current message. await message.RemoveAllReactionsAsync(); // Edit the current active message by replacing it with the recently created embed. await message.ModifyAsync(x => { x.Embed = embed.Build(); }); } catch (Exception ex) { await ErrorHandling.MissingMessageError((SocketTextChannel)message.Channel); Console.WriteLine(ex); return; } // Edit the menu session according to the current message. menuSession.CurrentMenu = "Shop_Sort_Confirm"; menuSession.MenuTimer = new Timer() { // Create a timer that expires as a "time out" duration for the user. Interval = MenuConfig.menu.timerDuration, AutoReset = false, Enabled = true }; // If the timer runs out, activate a function. menuSession.MenuTimer.Elapsed += (sender, e) => MenuTimer_Elapsed(sender, e, menuSession, itemSession); // Create an empty list for reactions. List <IEmote> reaction_list = new List <IEmote> { }; // Add needed emote reactions for the menu. reaction_list.Add(new Emoji("💠")); // Add the reactions to the message. _ = ReactionHandling.AddReactionsToMenu(message, reaction_list); }
public static async Task ShopSort(SocketGuildUser user, RestUserMessage message) { // Get the account information of the command's target var account = UserInfoClasses.GetAccount(user); // Find both the menu session and item session associated with the current user and store them in variables. var menuSession = Global.MenuIdList.SingleOrDefault(x => x.User.Id == user.Id); var itemSession = Global.ItemIdList.SingleOrDefault(x => x.User.Id == user.Id); // Create a new embed that will be displayed in the message. var embed = new EmbedBuilder(); var author = new EmbedAuthorBuilder { Name = "Sort Décor", IconUrl = user.GetAvatarUrl() }; var footer = new EmbedFooterBuilder { Text = "↩️ Back" }; embed.WithAuthor(author); embed.WithFooter(footer); embed.AddField("Choose a method to sort décor entries by.", $"" + $"⚙️ **Current Setting:** **`{DecorInfoMethods.SortSettingToString(account.Shop_Sort)}`**\n" + $"\n" + $":one: By Title (A - Z)\n" + $":two: By Title (Z - A)\n" + $":three: By Cost (Low - High)\n" + $":four: By Cost (High - Low)\n" + $":five: By Release Order (Old - New)\n" + $":six: By Release Order (New - Old)"); // Determine the color and thumbnail for the embeded message. if (account.Profile_Theme == "P3") { embed.WithColor(37, 149, 255); } else if (account.Profile_Theme == "P4") { embed.WithColor(255, 229, 49); } else if (account.Profile_Theme == "P5") { embed.WithColor(213, 27, 4); } // Attempt deleting the message if it hasn't been deleted by the user yet. try { // Delete the current message from the channel. await message.DeleteAsync(); } catch (Exception ex) { Console.WriteLine(ex); } // If the bot lacks permission to send messages, catch the exception and return. try { // Reassign the menu session's message to a new message generated from the created embed. menuSession.MenuMessage = (RestUserMessage)await message.Channel.SendMessageAsync("", false, embed.Build()); } catch (Exception ex) { Console.WriteLine(ex); return; } // Set the "message" variable to the menu session's message. message = menuSession.MenuMessage; // Edit the menu session according to the current message. menuSession.CurrentMenu = "Shop_Sort"; menuSession.MenuTimer = new Timer() { // Create a timer that expires as a "time out" duration for the user. Interval = MenuConfig.menu.timerDuration, AutoReset = false, Enabled = true }; // If the timer runs out, activate a function. menuSession.MenuTimer.Elapsed += (sender, e) => MenuTimer_Elapsed(sender, e, menuSession, itemSession); // Create an empty list for reactions. List <IEmote> reaction_list = new List <IEmote> { }; // Add needed emote reactions for the menu. reaction_list.Add(new Emoji("↩️")); reaction_list.Add(new Emoji("\u0031\ufe0f\u20e3")); reaction_list.Add(new Emoji("\u0032\ufe0f\u20e3")); reaction_list.Add(new Emoji("\u0033\ufe0f\u20e3")); reaction_list.Add(new Emoji("\u0034\ufe0f\u20e3")); reaction_list.Add(new Emoji("\u0035\ufe0f\u20e3")); reaction_list.Add(new Emoji("\u0036\ufe0f\u20e3")); // Add the reactions to the message. _ = ReactionHandling.AddReactionsToMenu(message, reaction_list); }