Exemple #1
0
        public async Task StartThemeMenu(SocialLinkerCommand command)
        {
            // If there is a cooldown session active for the command type "menu", return the method immediately.
            if (await UserCooldownMethods.IsCooldownActive(command, "menu") == true)
            {
                return;
            }

            // Create two variables to check if there is a menu list entry with either the current channel ID or current user ID.
            var channelSearch = Global.MenuIdList.SingleOrDefault(x => x.MenuMessage.Channel.Id == command.Channel.Id);
            var userSearch    = Global.MenuIdList.SingleOrDefault(x => x.User.Id == command.User.Id);

            // If the channel entry exists and the user is not the same, send an error message.
            if (channelSearch != null && channelSearch.User.Id != command.User.Id)
            {
                // Case 1: Search by channel successful, user ID does not match. Create new entry for new user.
                // Create a new menu in the current channel.
                await SetFirstTheme_Menu.SetFirstThemeMain((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }
            // Else, if the channel entry exists and the user is the same, assume they want to reset the menu and delete the previous entry.
            else if (channelSearch != null && channelSearch.User.Id == command.User.Id)
            {
                // Case 2: Search by channel successful, user ID matches. Resetting menu in same channel.
                // Attempt deleting the message if it hasn't been deleted by the user yet.
                try
                {
                    // Delete the currently active menu.
                    await channelSearch.MenuMessage.DeleteAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

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

                // Remove the menu entry from the global list.
                Global.MenuIdList.Remove(channelSearch);

                // Create a new menu in the current channel.
                await SetFirstTheme_Menu.SetFirstThemeMain((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }
            // Else, if an entry exists where the user is found but they're in a different channel now, delete previous entry and reset the menu.
            else if (userSearch != null && userSearch.MenuMessage.Channel.Id != command.Channel.Id)
            {
                // Case 3: Search by user successful, channel ID does not match. Resetting menu in new channel.
                // Attempt deleting the message if it hasn't been deleted by the user yet.
                try
                {
                    // Delete the currently active menu.
                    await userSearch.MenuMessage.DeleteAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

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

                // Remove the menu entry from the global list.
                Global.MenuIdList.Remove(userSearch);

                // Create a new menu in the current channel.
                await SetFirstTheme_Menu.SetFirstThemeMain((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }
            // For any other condition (if one should exist and not be handled here), create a new menu entry.
            else
            {
                // Case 4: No previous entry found. Create new entry.
                // Create a new menu in the current channel.
                await SetFirstTheme_Menu.SetFirstThemeMain((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }
        }
        public static Task Nav_SetFirstThemeMain(SocketReaction reaction, MenuIdStructure menuSession)
        {
            if (reaction.Emote.Name == "P3")
            {
                // Get the account information of the user.
                var account = UserInfoClasses.GetAccount(menuSession.User);

                // Assign the chosen profile theme to the user's account.
                account.Profile_Theme = "P3";

                //Update the user's account.
                UserInfoClasses.UpdateAccount(account);

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

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

            else if (reaction.Emote.Name == "P4")
            {
                // Get the account information of the user.
                var account = UserInfoClasses.GetAccount(menuSession.User);

                // Assign the chosen profile theme to the user's account.
                account.Profile_Theme = "P4";

                //Update the user's account.
                UserInfoClasses.UpdateAccount(account);

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

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

            else if (reaction.Emote.Name == "P5")
            {
                // Get the account information of the user.
                var account = UserInfoClasses.GetAccount(menuSession.User);

                // Assign the chosen profile theme to the user's account.
                account.Profile_Theme = "P5";

                //Update the user's account.
                UserInfoClasses.UpdateAccount(account);

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

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

            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 from the global list.
                if (menuSession != null)
                {
                    Global.MenuIdList.Remove(menuSession);
                }
                return(Task.CompletedTask);
            }

            return(Task.CompletedTask);
        }