Exemplo n.º 1
0
        public static Task Nav_ShopMainMenu(SocketReaction reaction, MenuIdStructure menuSession)
        {
            // Search for an item list that corresponds to the user's ID. If a menu entry was found, this should also exist alongside it.
            var itemSession = Global.ItemIdList.SingleOrDefault(x => x.User.Id == reaction.UserId);

            // Perform various actions based on what type of reaction was given to the message.
            // Previous Page
            if (reaction.Emote.Name == "◀️")
            {
                try
                {
                    // Decrease the item index by the maximum number of items that should be displayed to the user at once.
                    itemSession.ItemIndexBase -= itemSession.MaxItemsDisplayed;

                    // Decrease the page counter by one.
                    itemSession.CurrentPage--;

                    // Stop the timeout timer associated with the menu.
                    menuSession.MenuTimer.Stop();

                    // Go to a new menu.
                    _ = ShopMenu.ShopMainMenu(menuSession.User, menuSession.MenuMessage);
                    return(Task.CompletedTask);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            // Next Page
            else if (reaction.Emote.Name == "▶️")
            {
                try
                {
                    // Increase the item index by the maximum number of items that should be displayed to the user at once.
                    itemSession.ItemIndexBase += itemSession.MaxItemsDisplayed;

                    // Increase the page counter by one.
                    itemSession.CurrentPage++;

                    // Stop the timeout timer associated with the menu.
                    menuSession.MenuTimer.Stop();

                    // Go to a new menu.
                    _ = ShopMenu.ShopMainMenu(menuSession.User, menuSession.MenuMessage);
                    return(Task.CompletedTask);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            // Keycap One
            else if (reaction.Emote.Name == "\u0031\ufe0f\u20e3")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopDecorPreview(menuSession.User, menuSession.MenuMessage, itemSession.ItemIndexBase);
                return(Task.CompletedTask);
            }

            // Keycap Two
            else if (reaction.Emote.Name == "\u0032\ufe0f\u20e3")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopDecorPreview(menuSession.User, menuSession.MenuMessage, itemSession.ItemIndexBase + 1);
                return(Task.CompletedTask);
            }

            // Keycap Three
            else if (reaction.Emote.Name == "\u0033\ufe0f\u20e3")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopDecorPreview(menuSession.User, menuSession.MenuMessage, itemSession.ItemIndexBase + 2);
                return(Task.CompletedTask);
            }

            // Keycap Four
            else if (reaction.Emote.Name == "\u0034\ufe0f\u20e3")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopDecorPreview(menuSession.User, menuSession.MenuMessage, itemSession.ItemIndexBase + 3);
                return(Task.CompletedTask);
            }

            // Keycap Five
            else if (reaction.Emote.Name == "\u0035\ufe0f\u20e3")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopDecorPreview(menuSession.User, menuSession.MenuMessage, itemSession.ItemIndexBase + 4);
                return(Task.CompletedTask);
            }

            // Keycap Six
            else if (reaction.Emote.Name == "\u0036\ufe0f\u20e3")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopDecorPreview(menuSession.User, menuSession.MenuMessage, itemSession.ItemIndexBase + 5);
                return(Task.CompletedTask);
            }

            // Sort Shop
            else if (reaction.Emote.Name == "⚙️")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Go to a new menu.
                _ = ShopMenu.ShopSort(menuSession.User, menuSession.MenuMessage);
                return(Task.CompletedTask);
            }

            // Exit Shop
            else if (reaction.Emote.Name == "❌")
            {
                // Stop the timeout timer associated with the menu.
                menuSession.MenuTimer.Stop();

                // Attempt to delete the menu message from the channel if it hasn't been deleted by the user yet. If this fails, catch the exception.
                try
                {
                    _ = menuSession.MenuMessage.DeleteAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                // If the menu session is not null, remove it and the item entries from the global list.
                if (menuSession != null)
                {
                    Global.MenuIdList.Remove(menuSession);
                    Global.ItemIdList.Remove(itemSession);
                }
                return(Task.CompletedTask);
            }

            return(Task.CompletedTask);
        }