Ejemplo n.º 1
0
        public static async Task P5S_Set_List(SocialLinkerCommand sl_command)
        {
            // Create two variables for the command user and the command channel, derived from the message object taken in.
            SocketUser        user    = sl_command.User;
            SocketTextChannel channel = (SocketTextChannel)sl_command.Channel;

            // Get the account information of the command's user.
            var account = UserInfoClasses.GetAccount(user);

            var embed  = new EmbedBuilder();
            var author = new EmbedAuthorBuilder
            {
                Name    = "Persona 5 Strikers Conversation Portrait Sets",
                IconUrl = user.GetAvatarUrl()
            };

            embed.WithAuthor(author);

            // Set the color and thumbnail for the embeded message.
            embed.WithColor(EmbedSettings.Get_Game_Color("P5S", null));
            embed.WithThumbnailUrl(EmbedSettings.Get_Game_Logo("P5S"));

            // Create a description with the list of sprite sets available for the title.
            embed.WithDescription($"{OfficialSetMethods.Generate_Normal_Set_List("P5S")}");

            // Send the embeded message to the channel.
            await channel.SendMessageAsync("", false, embed.Build());
        }
Ejemplo n.º 2
0
        public static async Task BBTAG_Set_List(SocialLinkerCommand sl_command)
        {
            // Create two variables for the command user and the command channel, derived from the message object taken in.
            SocketUser        user    = sl_command.User;
            SocketTextChannel channel = (SocketTextChannel)sl_command.Channel;

            // Get the account information of the command's user.
            var account = UserInfoClasses.GetAccount(user);

            var embed  = new EmbedBuilder();
            var author = new EmbedAuthorBuilder
            {
                Name    = "BlazBlue: Cross Tag Battle Sprite Sets",
                IconUrl = user.GetAvatarUrl()
            };

            embed.WithAuthor(author);

            // Assign an embed color and thumbnail based on the user's episode header setting for the BBTAG template.
            embed.WithColor(EmbedSettings.Get_Game_Color("BBTAG", account));
            embed.WithThumbnailUrl(EmbedSettings.Get_Game_Logo("BBTAG"));

            // Create a description with the list of sprite sets available for the title.
            embed.WithDescription($"{OfficialSetMethods.Generate_BBTAG_Set_List()}");

            // Send the embeded message to the channel.
            await channel.SendMessageAsync("", false, embed.Build());
        }
Ejemplo n.º 3
0
        public static async void HugUser(SocialLinkerCommand command, SocketUser command_target)
        {
            var command_user = command.User;
            var channel      = command.Channel;

            // Retrieve the account information of both the command's user and the command's target.
            var command_user_account   = UserInfoClasses.GetAccount(command_user);
            var command_target_account = UserInfoClasses.GetAccount(command_target);

            // Create an embeded message.
            var embed  = new EmbedBuilder();
            var author = new EmbedAuthorBuilder
            {
                Name    = $"{command_user.Username} gave {command_target.Username} a hug!",
                IconUrl = command_user.GetAvatarUrl()
            };

            // Determine color for embeded message based on the command user's profile.
            if (command_user_account.Profile_Theme == "P3")
            {
                embed.WithColor(37, 149, 255);
            }
            else if (command_user_account.Profile_Theme == "P4")
            {
                embed.WithColor(255, 229, 49);
            }
            else if (command_user_account.Profile_Theme == "P5")
            {
                embed.WithColor(213, 27, 4);
            }

            embed.WithAuthor(author);

            // Create a randomized URL based on the command user and command target's content filters.
            string randomized_image = RandomizeHugGif(command_user, command_target);

            // If the command user has a set profile theme and the randomized image URL is empty, OR the command target doesn't have an activated account, add a notification to the embed.
            if ((command_user_account.Profile_Theme != "" && randomized_image == "") || command_target_account.Account_Activated == "No")
            {
                var footer = new EmbedFooterBuilder
                {
                    Text = $"{command_user_account.Profile_Theme} images are filtered out for this user."
                };
                embed.WithFooter(footer);
            }
            // Else, if the command user has a profile theme set, choose a random GIF to display based on it
            else if (command_user_account.Profile_Theme != "")
            {
                embed.WithImageUrl($"{randomized_image}");
            }
            // Else, if the command user doesn't have a profile theme set, add a different notification to the embed instead.
            else if (command_user_account.Profile_Theme == "")
            {
                embed.WithDescription($"You can add GIFs to your social commands by visiting the **`{BotConfig.bot.cmdPrefix}settings`** menu and choosing [Profile Settings] > [Profile Theme].");
            }

            await channel.SendMessageAsync("", false, embed.Build());
        }
        public static void CreateCooldownSession(SocialLinkerCommand command, string command_type)
        {
            // Create a variable for the command user.
            SocketGuildUser user = (SocketGuildUser)command.User;

            // Create an int initialized at zero.
            int timer_duration = 0;

            // Depending on the type of command used, set the recently created int variable to a different value.
            // These values will represent milliseconds for a timer object.
            switch (command_type)
            {
            // If the command type is "menu", set timer_duration to 15 seconds.
            case "menu":
                timer_duration = 15000;
                break;

            // If the command type is "social", set timer_duration to 5 seconds.
            case "social":
                timer_duration = 5000;
                break;

            // If the command type is "status", set timer_duration to 5 seconds.
            case "status":
                timer_duration = 5000;
                break;

            // If the command type is "scene", set timer_duration to 5 seconds.
            case "scene":
                timer_duration = 5000;
                break;
            }

            // Create a new cooldown session for the command user.
            var cooldown_session = new UserCooldownFields()
            {
                User          = user,
                CommandType   = command_type,
                UsageCount    = 1,
                CooldownTimer = new Timer()
                {
                    // Create a timer that expires as a "time out" duration for the user.
                    Interval  = timer_duration,
                    AutoReset = false,
                    Enabled   = true
                },
                MessageSent    = false,
                ExpirationTime = DateTime.UtcNow.AddMilliseconds(timer_duration)
            };

            // Add the cooldown entry to the global list.
            Global.CooldownList.Add(cooldown_session);

            // If the cooldown timer runs out, activate a function.
            cooldown_session.CooldownTimer.Elapsed += (sender, e) => CooldownTimer_Elapsed(sender, e, command, command_type);
        }
Ejemplo n.º 5
0
        public async Task StatusCommandParser3(SocialLinkerCommand command, string param1, string param2)
        {
            //Create a variable for a potential mentioned user
            var mentionedUser = command.Message.MentionedUsers.FirstOrDefault();

            //If the first parameter is the word "detail" and the second parameter is a mentioned user, invoke StatusDetails for the mentioned user
            if (param1.ToLower() == "detail" && mentionedUser != null)
            {
                await StatusDetails(command);
            }
        }
Ejemplo n.º 6
0
        public static async Task ContentCheck(SocialLinkerCommand command)
        {
            // If there is a cooldown session active for the command type "status", return the method immediately.
            if (await UserCooldownMethods.IsCooldownActive(command, "status") == true)
            {
                return;
            }

            // Get the account information of the command's user.
            var command_user_account = UserInfoClasses.GetAccount(command.User);

            // Check if the user's account has been activated. If not, send them to the initial usage setup menu.
            if (command_user_account.Account_Activated == "No")
            {
                await First_Use_Content_Filter_Menu.First_Use_Content_Filter_Start((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }

            // End of initial usage and cooldown checks.

            Status status_object = new Status();

            switch (command.CommandType)
            {
            case "Slash":
                switch (command.CommandName)
                {
                case "status":
                    await status_object.StatusScreen(command);

                    break;

                case "status_text":
                    break;
                }
                break;


            case "Context":
                if (command.Message.Content.ToLower().Contains("detail"))
                {
                    await status_object.StatusDetails(command);
                }
                else
                {
                    await status_object.StatusScreen(command);
                }
                break;
            }
        }
Ejemplo n.º 7
0
        public static int Measure_Word_Pixel_Length(SocialLinkerCommand sl_command, string input_word)
        {
            // Create an int to keep track of how many pixels a glyph is wide in.
            int pixel_counter = 0;

            // Create another int to count the number of times a character comes up null from the font sheet.
            // We'll want to keep track of this number so we can ensure there's only one error message sent.
            int error_counter = 0;

            // Take the input string and turn it into a char array.
            char[] char_array = input_word.ToCharArray();

            // Now, let's iterate through the char array.
            for (int i = 0; i < char_array.Length; i++)
            {
                // Retrieve glyph information for the current character from the JSON file.
                var glyph = ParsingMethods.Get_P2EP_PS1_Glyph(char_array[i]);

                // Make sure that the glyph info doesn't return null.
                if (glyph != null)
                {
                    // Check if the current character is a line break.
                    // If it is, do nothing. Line breaks take up no pixel width space.
                    if (char_array[i] == '\u000a')
                    {
                        // Do nothing
                    }
                    else
                    {
                        // Set the pixel counter to the appropriate width of the string so far.
                        pixel_counter += glyph.RightCut - glyph.LeftCut;
                    }
                }
                // If the character returns null, it's not supported by the template's font set.
                // Send a warning message to the user.
                else
                {
                    // Increase the error counter by one.
                    error_counter++;

                    // If the error counter is at exactly 1, send a warning message to the user.
                    if (error_counter == 1)
                    {
                        _ = ErrorHandling.Unsupported_Character(sl_command);
                    }
                }
            }

            return(pixel_counter);
        }
        public static async Task <bool> IsCooldownActive(SocialLinkerCommand command, string command_type)
        {
            // Create variables for the command user and the channel being used.
            SocketGuildUser       user    = (SocketGuildUser)command.User;
            ISocketMessageChannel channel = command.Channel;

            // Find the cooldown session associated with both the current user and command type.
            var cooldownSession = Global.CooldownList.SingleOrDefault(x => (x.User.Id == user.Id) && (x.CommandType == command_type));

            // If the session exists, perform an action.
            if (cooldownSession != null)
            {
                // Check for the following conditions:
                // If the command type is "menu" and the usage count is at least 1, the cooldown period is still active.
                // If the command type is "social" and the usage count is at least 3, the cooldown period is still active.
                // If the command type is "status" and the usage count is at least 1, the cooldown period is still active.
                // If the command type is "scene" and the usage count is at least 1, the cooldown period is still active.
                if ((command_type == "menu" && cooldownSession.UsageCount >= 1) ||
                    (command_type == "social" && cooldownSession.UsageCount >= 3) ||
                    (command_type == "status" && cooldownSession.UsageCount >= 1) ||
                    (command_type == "scene" && cooldownSession.UsageCount >= 1))
                {
                    // Check if a cooldown message has been sent for this session.
                    if (cooldownSession.MessageSent == false)
                    {
                        // If not, send an embeded message to the channel and set the "MessageSent" variable to "true".
                        cooldownSession.CooldownMessage = await channel.SendMessageAsync("", false, CooldownEmbed(user, CheckTimeRemaining(cooldownSession)).Build());

                        cooldownSession.MessageSent = true;
                    }

                    // Return the method as "true".
                    return(true);
                }
            }
            // If the session does not exist, create one for the command type.
            else
            {
                // Create a new entry and return false.
                CreateCooldownSession(command, command_type);
                return(false);
            }

            // Increase the usage count by 1 on the non-active cooldown session.
            cooldownSession.UsageCount += 1;

            // Return the method as "false", indicating there is not a cooldown session active.
            return(false);
        }
Ejemplo n.º 9
0
        // -----------------------------

        public async Task StatusCommandParser2(SocialLinkerCommand command, string param)
        {
            //Create a variable for a potential mentioned user
            var mentionedUser = command.Message.MentionedUsers.FirstOrDefault();

            //If the mentioned user is not null, invoke StatusScreen for the mentioned user
            if (mentionedUser != null)
            {
                await StatusScreen(command);
            }
            //Else, if the entered parameter is the word "detail", invoke StatusDetails for the command user
            else if (param.ToLower() == "detail")
            {
                await StatusDetails(command);
            }
        }
Ejemplo n.º 10
0
        public static async Task MakerCommandParser(SocialLinkerCommand sl_command)
        {
            // If there is a cooldown session active for the command type "scene", return the method immediately.
            if (await UserCooldownMethods.IsCooldownActive(sl_command, "scene") == true)
            {
                return;
            }

            // Get the account information of the command's user.
            var command_user_account = UserInfoClasses.GetAccount(sl_command.User);

            // Check if the user's account has been activated. If not, send them to the initial usage setup menu.
            if (command_user_account.Account_Activated == "No")
            {
                await First_Use_Content_Filter_Menu.First_Use_Content_Filter_Start((SocketTextChannel)sl_command.Channel, (SocketGuildUser)sl_command.User);

                return;
            }

            // End of initial usage and cooldown checks.

            await CommandParser.Type_Directory(sl_command);
        }
Ejemplo n.º 11
0
        public static async Task P3P_Set_List(SocialLinkerCommand sl_command)
        {
            // Create two variables for the command user and the command channel, derived from the message object taken in.
            SocketUser        user    = sl_command.User;
            SocketTextChannel channel = (SocketTextChannel)sl_command.Channel;

            // Get the account information of the command's user.
            var account = UserInfoClasses.GetAccount(user);

            var embed  = new EmbedBuilder();
            var author = new EmbedAuthorBuilder
            {
                Name    = "Persona 3 Portable Conversation Portrait Sets",
                IconUrl = user.GetAvatarUrl()
            };

            embed.WithAuthor(author);

            // Assign a color based on the user's color setting for the P3P template.
            embed.WithColor(EmbedSettings.Get_Game_Color("P3P", account));
            embed.WithThumbnailUrl(EmbedSettings.Get_Game_Logo("P3P"));

            // Create a description with the list of sprite sets available for the title.
            embed.WithDescription($"{OfficialSetMethods.Generate_Normal_Set_List("P3P")}");

            // Create a footer based on the game version the list is from.
            var footer = new EmbedFooterBuilder
            {
                Text = "Version: P3P"
            };

            // Add the footer to the embed.
            embed.WithFooter(footer);

            // Send the embeded message to the channel.
            await channel.SendMessageAsync("", false, embed.Build());
        }
Ejemplo n.º 12
0
        private static void CooldownTimer_Elapsed(object sender, ElapsedEventArgs e, SocialLinkerCommand command, string command_type)
        {
            // Create a variable for the command user.
            SocketGuildUser user = (SocketGuildUser)command.User;

            // Find the cooldown session associated with both the current user and command type.
            var cooldownSession = Global.CooldownList.SingleOrDefault(x => (x.User.Id == user.Id) && (x.CommandType == command_type));

            // If the cooldown message is not null, try deleting it from the channel if it hasn't been deleted by the user yet.
            if (cooldownSession.CooldownMessage != null)
            {
                try
                {
                    cooldownSession.CooldownMessage.DeleteAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            // Remove the cooldown session from the global list.
            Global.CooldownList.Remove(cooldownSession);
        }
Ejemplo n.º 13
0
        public static async Task SlapCommand(SocialLinkerCommand command)
        {
            // If there is a cooldown session active for the command type "social", return the method immediately.
            if (await UserCooldownMethods.IsCooldownActive(command, "social") == true)
            {
                return;
            }

            // Get the account information of the command's user.
            var command_user_account = UserInfoClasses.GetAccount(command.User);

            // Check if the user's account has been activated. If not, send them to the initial usage setup menu.
            if (command_user_account.Account_Activated == "No")
            {
                await First_Use_Content_Filter_Menu.First_Use_Content_Filter_Start((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }

            // End of initial usage and cooldown checks.

            //Establish variables for both the user of the command and the user who is pinged
            SocketUser commandTarget = null;
            SocketUser commandUser   = null;

            //Retreive the first mentioned user of the message if there is one
            var mentionedUser = command.Message.MentionedUsers.FirstOrDefault();

            //If a mentioned user exists, assign them to commandTarget. If not, set commandTarget to the command user.
            commandTarget = mentionedUser ?? command.User;
            commandUser   = command.User;

            //Check if the mentioned user is null. If so, send an error-tutorial message.
            if (mentionedUser == null)
            {
                SlapError(command.Message);
                return;
            }
            //If the mentioned user is the command user, send a special message and return
            else if (mentionedUser == commandUser)
            {
                SlapSelf(command.Message);
                return;
            }
            //If the mentioned user is the bot itself, send a special message and return
            else if (mentionedUser.Id == BotConfig.bot.id)
            {
                SlapBot(command.Message);
                return;
            }

            //If the previous conditions are false, get the command user's account information
            var account = UserInfoClasses.GetAccount(commandTarget);

            //If a user is mentioned and they're not the command user and not a bot, add Expression to both users
            if ((mentionedUser != null) && (mentionedUser != command.User) && (mentionedUser.IsBot == false))
            {
                Core.LevelSystem.SocialStats.AddExpression(command.Message, commandUser);
                Core.LevelSystem.SocialStats.AddExpression(command.Message, commandTarget);
            }

            //Send a slap message to the mentioned user
            SlapUser(command.Message, commandTarget);

            await Task.CompletedTask;
        }
Ejemplo n.º 14
0
 public async Task StatsCommandDetailMention(SocialLinkerCommand command)
 {
     //Since there are no parameters, invoke StatusScreen for the command user
     await StatusScreen(command);
 }
Ejemplo n.º 15
0
        public async Task StatusDetails(SocialLinkerCommand command)
        {
            // Establish variables for the command user and the command's target.
            SocketUser commandTarget = null;
            SocketUser commandUser   = null;

            // Create a variable for a potential mentioned user.
            var mentionedUser = command.MentionedUser;

            // If there is a mentioned user, they become the command's target. If not, the command's user is also the target.
            commandTarget = mentionedUser ?? command.User;
            commandUser   = command.User;

            // Get the account information of the command's target.
            var account = UserInfoClasses.GetAccount(commandTarget);

            // If a user is mentioned and they're not the command user and not a bot, add Expression to both users.
            if ((mentionedUser != null) && (mentionedUser != command.User) && (mentionedUser.IsBot == false))
            {
                //Core.LevelSystem.SocialStats.AddExpression(command.Message, commandUser);
                //Core.LevelSystem.SocialStats.AddExpression(command.Message, commandTarget);
            }

            // Construct embeded message.
            var embed = new EmbedBuilder();

            // Determine color for 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);
            }

            // Create a pleasant-looking string for Profile Theme section.
            string userProfileTheme = "";

            if (account.Profile_Theme == "")
            {
                userProfileTheme = "None";
            }
            else
            {
                userProfileTheme = account.Profile_Theme.ToUpper();
            }

            // Determine the Next Exp value.
            int next_exp = 0;

            if (account.Level != 99)
            {
                next_exp = Core.LevelSystem.Leveling.CalculateExp(account.Level + 1) - account.Total_Exp;
            }

            embed.WithTitle($"__{commandTarget.Username}'s Status__");
            embed.WithThumbnailUrl($"{commandTarget.GetAvatarUrl()}");

            // Divide the actual stats by 10 for the user view.
            decimal represented_proficiency = decimal.Round((decimal)account.Proficiency / 10, 2, MidpointRounding.AwayFromZero);
            decimal represented_diligence   = decimal.Round((decimal)account.Diligence / 10, 2, MidpointRounding.AwayFromZero);
            decimal represented_expression  = decimal.Round((decimal)account.Expression / 10, 2, MidpointRounding.AwayFromZero);

            // Create a string variable for the embed's description.
            string description_text = "" +
                                      $"**Level:** {account.Level}\n" +
                                      $"**Total Exp:** {account.Total_Exp}\n" +
                                      $"**Next Exp:** {next_exp}\n" +
                                      $"\n" +
                                      $"**Proficiency:** Rank {account.Proficiency_Rank} - *({represented_proficiency}/173)*\n" +
                                      $"**Diligence:** Rank {account.Diligence_Rank} - *({represented_diligence}/280)*\n" +
                                      $"**Expression:** Rank {account.Expression_Rank} - *({represented_expression}/170)*\n" +
                                      $"\n" +
                                      $"**Theme:** {userProfileTheme}\n" +
                                      $"**P-Medals:** {account.P_Medals}\n";

            // Check if the user has reset their level before.
            if (account.Level_Resets > 0)
            {
                // Append a new section to the end of the description text depending on how many times the user has reset their level.
                if (account.Level_Resets == 1)
                {
                    description_text += $":star: **Star Level Rank:** {account.Level_Resets}";
                }
                else if (account.Level_Resets == 2)
                {
                    description_text += $":star2: **Star Level Rank:** {account.Level_Resets}";
                }
                else if (account.Level_Resets == 3)
                {
                    description_text += $":sparkles: **Star Level Rank:** {account.Level_Resets}";
                }
            }

            // Add the description text to the embed.
            embed.WithDescription(description_text);

            await Context.Channel.SendMessageAsync("", false, embed.Build());
        }
Ejemplo n.º 16
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;
            }
        }
Ejemplo n.º 17
0
        public async Task StatusScreen(SocialLinkerCommand command)
        {
            //Establish variables for the command user and the command's target
            SocketUser commandTarget = null;
            SocketUser commandUser   = null;

            //Create a variable for a potential mentioned user
            var mentionedUser = command.MentionedUser;

            //If there is a mentioned user, they become the command's target. If not, the command's user is also the target.
            commandTarget = mentionedUser ?? command.User;
            commandUser   = command.User;

            //Get the account information of the command's target
            var account = UserInfoClasses.GetAccount(commandTarget);

            //If a user is mentioned and they're not the command user and not a bot, add Expression to both users
            if ((mentionedUser != null) && (mentionedUser != command.User) && (mentionedUser.IsBot == false))
            {
                //Core.LevelSystem.SocialStats.AddExpression(command.Message, commandUser);
                //Core.LevelSystem.SocialStats.AddExpression(command.Message, commandTarget);
            }

            // Call different status screen functions depending on the account's profile theme and decor settings.
            if (account.Decor_Setting != "")
            {
                // Attempt to render the user's set décor.
                try
                {
                    // Use the string taken from the user's Décor setting to find the class that generates it.
                    Type type = Type.GetType($"SocialLinker.Core.StatusScreens.Decor.{account.Decor_Setting}");

                    // Specify the RenderImage method of whatever class is chosen to invoke. Every décor class should have this method to construct its image.
                    MethodInfo methodInfo = type.GetMethod("RenderImage");

                    // Store the typical parameters for a RenderImage method within an object array.
                    object[] parametersArray = new object[] { commandTarget, command.Channel };

                    // Call the method to render the user's set décor.
                    methodInfo.Invoke(this, parametersArray);
                }
                // If something goes awry in rendering the décor, send an error message to the user and return.
                catch (Exception ex)
                {
                    await command.Channel.SendMessageAsync($":warning: Oh no! It looks like a mistake was made. Please visit the support server to report this issue and gain access to the décor.");

                    Console.WriteLine(ex);
                    return;
                }
            }
            else if (account.Profile_Theme == "P3")
            {
                StatusScreenP3.RenderImage(commandTarget, command.Channel);
            }
            else if (account.Profile_Theme == "P4")
            {
                StatusScreenP4.RenderImage(commandTarget, command.Channel);
            }
            else if (account.Profile_Theme == "P5")
            {
                StatusScreenP5.RenderImage(commandTarget, command.Channel);
            }
            else if (account.Profile_Theme == "")
            {
                // If the user doesn't have a profile theme set, send a message to do so.
                _ = StartThemeMenu(command);
            }

            await Task.CompletedTask;
        }
Ejemplo n.º 18
0
        public static async Task Render_Quick_Scene_P4D(SocialLinkerCommand sl_command, OfficialSetData set_data, MakerCommandData command_data)
        {
            // Create variables to store the width and height of the template.
            int template_width  = 1920;
            int template_height = 1080;

            // Create two variables for the command user and the command channel, derived from the message object taken in.
            SocketUser        user    = sl_command.User;
            SocketTextChannel channel = (SocketTextChannel)sl_command.Channel;

            // Send a loading message to the channel while the sprite sheet is being made.
            RestUserMessage loader = await channel.SendMessageAsync("", false, P4D_Loading_Message().Build());

            // Get the account information of the command's user.
            var account = UserInfoClasses.GetAccount(user);

            BustupData bustup_data = BustupDataMethods.Get_Bustup_Data(account, set_data, command_data);

            // Create a starting base bitmap to render all graphics on.
            Bitmap base_template = new Bitmap(template_width, template_height);

            // Create another bitmap the same size.
            // In case the user has set a colored bitmap in their settings, we'll need to use this to render it.
            Bitmap colored_background_bitmap = new Bitmap(template_width, template_height);

            // Here, we want to grab any images attached to the message to use it as a background.
            // Create a variable for the message attachment.
            var attachments = sl_command.Attachments;

            // Create an empty string variable to hold the URL of the attachment.
            string url = "";

            // If there are no attachments on the message, set the URL string to "None".
            if (attachments == default || attachments.LongCount() == 0)
            {
                url = "None";
            }
            // Else, assign the URL of the attachment to the URL string.
            else
            {
                url = attachments.ElementAt(0).Url;
            }

            // Initialize a bitmap object for the user's background. It's small now because we'll reassign it depending on our circumstances.
            Bitmap background = new Bitmap(2, 2);

            // If a URL for a message attachment exists, download it and copy its contents to the bitmap variable we just created.
            if (url != "None")
            {
                // Here, we'll want to try and retrieve the user's input image.
                try
                {
                    // Declare variables for a web request to retrieve the image.
                    System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
                    webRequest.AllowWriteStreamBuffering = true;
                    webRequest.Timeout = 30000;

                    // Create a stream and download the image to it.
                    System.Net.WebResponse webResponse = webRequest.GetResponse();
                    System.IO.Stream       stream      = webResponse.GetResponseStream();

                    // Copy the stream's contents to the background bitmap variable.
                    background = (Bitmap)System.Drawing.Image.FromStream(stream);

                    webResponse.Close();
                }
                // If an exception occurs here, the filetype is likely incompatible.
                // Send an error message, delete the loading message, and return.
                catch (System.ArgumentException e)
                {
                    Console.WriteLine(e);
                    await loader.DeleteAsync();

                    _ = ErrorHandling.Incompatible_File_Type(sl_command);
                    return;
                }
            }

            // Render the uploaded image based on the user's background settings.
            switch (account.Setting_BG_Upload)
            {
            case "Maintain Aspect Ratio":
                background = Center_Image(background);
                break;

            case "Stretch to Fit":
                background = Stretch_To_Fit(background);
                break;
            }

            // The user may have a custom mono-colored background designated in their settings. Let's handle that now.
            // Check if the user's background color setting is set to something other than "Transparent".
            // If so, we have a color to render for the background!
            if (account.Setting_BG_Color != "Transparent")
            {
                // Convert the user's HTML color setting to one we can use and assign it to a color variable.
                System.Drawing.Color user_background_color = System.Drawing.ColorTranslator.FromHtml(account.Setting_BG_Color);

                // Color the entirety of the background bitmap the user's selected color.
                using (Graphics graphics = Graphics.FromImage(colored_background_bitmap))
                {
                    graphics.Clear(user_background_color);
                }
            }

            // Next, time for the conversation portrait! Create and initialize a new bitmap variable for it.
            Bitmap bustup = new Bitmap(2, 2);

            // Check if the base sprite number is something other than zero.
            // If it is zero, we have nothing to render. Otherwise, retrieve the bustup.
            if (command_data.Base_Sprite != 0)
            {
                bustup = OfficialSetMethods.Bustup_Selection(sl_command, account, set_data, bustup_data, command_data);
            }

            // If the bustup returns as null, however, something went wrong with rendering the animation frames.
            // An error message has already been sent in the frame rendering method, so delete the loading message and return.
            if (bustup == null)
            {
                await loader.DeleteAsync();

                return;
            }

            // Time to put it all together!
            using (Graphics graphics = Graphics.FromImage(base_template))
            {
                // Draw the layer with the user's colored default background if it exists.
                graphics.DrawImage(colored_background_bitmap, 0, 0, template_width, template_height);

                // Draw the user's background to the base template.
                graphics.DrawImage(background, 0, 0, template_width, template_height);

                // Draw the character bust-up to the template if the base sprite number is not '0'.
                if (command_data.Base_Sprite != 0)
                {
                    graphics.DrawImage(bustup, bustup_data.P4D_Center_Coord_X, bustup_data.P4D_Center_Coord_Y, bustup_data.P4D_Scale_Width, bustup_data.P4D_Scale_Height);
                }

                // Now, it's time to render the text.
                // Render the character's name to the template.
                // Check if the base sprite number is something other than zero.
                if (command_data.Base_Sprite != 0)
                {
                    //graphics.DrawImage(Text_To_Blue(Render_Name(bustup_data)), 0, 0, template_width, template_height);
                }
                // If the base sprite number IS zero, we need a sprite to actually retrieve a display name from.
                else
                {
                    // Change the base sprite number from the command data to one.
                    // This way, we can get the bustup data for the first sprite to retrieve its display name.
                    command_data.Base_Sprite = 1;

                    // Get the bustup data for the first sprite and render the display name to the template.
                    bustup_data = BustupDataMethods.Get_Bustup_Data(account, set_data, command_data);
                    //graphics.DrawImage(Text_To_Blue(Render_Name(bustup_data)), 0, 0, template_width, template_height);
                }

                // Draw the input dialogue to the template.
                //graphics.DrawImage(Render_Dialogue(Line_Parser(sl_command, command_data.Dialogue)), 0, 0, template_width, template_height);
            }

            // Save the entire base template to a data stream.
            MemoryStream memoryStream = new MemoryStream();

            base_template.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
            memoryStream.Seek(0, SeekOrigin.Begin);

            try
            {
                // Send the image.
                await sl_command.Channel.SendFileAsync(memoryStream, $"scene_{sl_command.User.Id}_{DateTime.UtcNow}.png");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                // Send an error message to the user if the image upload fails.
                _ = ErrorHandling.Image_Upload_Failed(sl_command);

                // Clean up resources used by the stream, delete the loading message, and return.
                memoryStream.Dispose();
                await loader.DeleteAsync();

                return;
            }

            // Clean up resources used by the stream and delete the loading message.
            memoryStream.Dispose();
            await loader.DeleteAsync();

            // If the user has auto-delete for their commands set to on, delete their command as well.
            if (account.Auto_Delete_Commands == "On")
            {
                await sl_command.Message.DeleteAsync();
            }
        }
Ejemplo n.º 19
0
        public static List <string>[] Line_Parser(SocialLinkerCommand sl_command, string dialogue)
        {
            // First, let's establish some values.
            // The max pixel length of a line.
            int max_line_length = 1450;

            // The number of pixels in a line remaining. This will gradually decrease as the pixel length of characters are subtracted from it.
            int line_length_remaining = max_line_length;

            // The maximum number of lines on the template.
            int max_lines = 3;

            // Completed word string. Characters will be added to this string one-by-one until a space, line break, or end-of-input is encountered.
            string completed_word = "";

            // Create an array of three string lists and initialize them.
            // These are where our dialogue input will be organized.
            List <string>[] dialogue_list = new List <string> [3];

            dialogue_list[0] = new List <string>();
            dialogue_list[1] = new List <string>();
            dialogue_list[2] = new List <string>();

            // Now that we have our string lists created, we need a variable to dynamically change which line we're currently on.
            // For that, create an int variable and initialize it to zero for starting on the first line.
            int current_line = 0;

            // Take the input dialogue and convert it into a char array. This is how we'll iterate through the dialogue character-by-character.
            char[] dialogue_array = dialogue.ToCharArray();

            // Create a for loop meant to iterate through the dialogue array.
            for (int i = 0; i < dialogue_array.Length; i++)
            {
                // Check if the completed word string is empty, the remaining pixel length of the current line is at the max value, and if the current iterated character is a space.
                if ((completed_word == "") && (line_length_remaining == max_line_length) && (dialogue_array[i] == ' '))
                {
                    // We want to skip any spaces that appear at the start of a line, so do nothing here.
                }
                // Check if the contents of the current index is not a space, not a line break, and not the end of the array.
                else if ((dialogue_array[i] != ' ') && (dialogue_array[i] != '\u000a') && (i != dialogue_array.Length - 1))
                {
                    // If so, add the currently iterated char to the completed word string.
                    completed_word += dialogue_array[i];
                }
                // Next, check if the contents of the current index IS a space, IS a line break, or IS the end of the array.
                else if ((dialogue_array[i] == ' ') || (dialogue_array[i] == '\u000a') || (i == dialogue_array.Length - 1))
                {
                    // If so, add the currently iterated char to the completed word string.
                    completed_word += dialogue_array[i];

                    // Now that we have our word, measure the pixel length of the completed string.
                    int completed_word_length = Measure_Word_Pixel_Length(sl_command, completed_word);

                    // Check if the completed word is under the current line's allowed length.
                    // This is done by subtracting the completed word string's length from the remaining length of the line.
                    // If the result is greater than zero, it's a perfect fit.
                    if ((line_length_remaining - completed_word_length > 0) && (dialogue_array[i] != '\u000a'))
                    {
                        // Subtract the completed word's pixel length from the remaining pixel length of the current line.
                        line_length_remaining = line_length_remaining - completed_word_length;

                        // Add the completed word to the current line.
                        dialogue_list[current_line].Add(completed_word);

                        // Reset the completed word variable to an empty string.
                        completed_word = "";
                    }

                    // Else, check if all three of the following conditions are met:
                    // If there is no more room to add the completed word to the current line.
                    // The completed word's length is less than or equal to a line itself.
                    // The current iterated character is NOT a line break.
                    else if ((line_length_remaining - completed_word_length < 0) && (completed_word_length <= max_line_length) && (dialogue_array[i] != '\u000a'))
                    {
                        // Check if the current line number is less than the max number of lines available.
                        if (current_line < max_lines - 1)
                        {
                            // Increase the current line number.
                            current_line++;

                            // Add the completed word string to the current line.
                            dialogue_list[current_line].Add(completed_word);

                            // Reset the remaining pixel length variable to the start and subtract the pixel length of the completed word string.
                            // This is done because we moved to a new line.
                            line_length_remaining = max_line_length - completed_word_length;

                            // Reset the completed word variable to an empty string.
                            completed_word = "";
                        }
                        // Else, check if the current line number is greater than or equal to the max number of lines available.
                        else if (current_line > max_lines - 1)
                        {
                            // If so, there is no more room to render text.
                            // Break from the for loop.
                            break;
                        }
                    }

                    // Else, check if all three of the following conditions are met:
                    // If there IS room to add the completed word to the current line.
                    // The completed word's length is less than or equal to the length of a line itself.
                    // The current iterated character IS a line break.
                    else if ((line_length_remaining - completed_word_length >= 0) && (completed_word_length <= max_line_length) && (dialogue_array[i] == '\u000a'))
                    {
                        // Check if the current line number is less than the max number of lines available.
                        if (current_line < max_lines - 1)
                        {
                            // Since there is room, add the completed word string to the current line.
                            dialogue_list[current_line].Add(completed_word);

                            // Increase the current line number.
                            current_line++;

                            // Reset the remaining pixel length variable to the max value.
                            // This is done because we moved to a new line.
                            line_length_remaining = max_line_length;

                            // Reset the completed word variable to an empty string.
                            completed_word = "";
                        }
                        // Else, check if the current line number is greater than or equal to the max number of lines available.
                        else if (current_line >= max_lines - 1)
                        {
                            // If so, there is no more room to render text.
                            // Break from the for loop.
                            break;
                        }
                    }

                    // Else, check if there is no more room to add the completed word to the current line AND the completed word's length is greater than the length of a line itself.
                    // This means that we'll need to split the string up on different lines.
                    else if (line_length_remaining - completed_word_length < 0 && completed_word_length > max_line_length)
                    {
                        // Take the completed word and turn it into a char array.
                        // We'll use this to iterate through the word character-by-character to decide where to split the string.
                        char[] completed_word_array = completed_word.ToCharArray();

                        // Create a new string variable and initialize it to an empty string.
                        // Similar to the completed word variable, this string will contain characters that will fit on a single line.
                        // Because we know the word will be split into multiple lines, this will only contain part of the full string at any given time, hence "substring".
                        string substring = "";

                        // Create an int variable and initialize it to zero.
                        // This will contain the pixel length of our substring variable once we measure it.
                        int substring_length = 0;

                        // Create a for loop to iterate through the completed word array.
                        for (int j = 0; j < completed_word_array.Length; j++)
                        {
                            // Add the currently iterated character to the substring.
                            substring += completed_word_array[j];

                            // Measure the pixel length of the substring so far.
                            substring_length = Measure_Word_Pixel_Length(sl_command, substring);

                            // Check if there is no more room to add another character to the current line, OR if the current character is a line break.
                            // Since we are iterating through the string character-by-character, this should trigger the moment the length hits the line boundary.
                            if ((line_length_remaining - substring_length <= 0) || (completed_word_array[j] == '\u000a')) // || (completed_word_array[j] == '\u000a')
                            {
                                // Check if the current line number is less than the max number of lines available.
                                if (current_line < max_lines)
                                {
                                    // Add the substring to the current line.
                                    dialogue_list[current_line].Add(substring);

                                    // Since there is absolutely no more room on the current line left, increase the current line value.
                                    current_line++;

                                    // Reset the remaining pixel length variable to the max value.
                                    // This is done because we moved to a new line.
                                    line_length_remaining = max_line_length;

                                    // Reset the substring variable to an empty string.
                                    substring = "";
                                }
                            }
                            // Else, check if the last index of the completed word array has been reached.
                            else if (j == completed_word_array.Length - 1)
                            {
                                // Add the substring to the current line.
                                dialogue_list[current_line].Add(substring);

                                // Subtract the completed word's pixel length from the remaining pixel length of the current line.
                                line_length_remaining = line_length_remaining - substring_length;

                                // Reset the substring variable to an empty string.
                                substring = "";
                            }
                        }

                        // Reset the completed word string to an empty string.
                        completed_word = "";
                    }
                }
            }

            return(dialogue_list);
        }
Ejemplo n.º 20
0
        public static async Task StartShop(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;
            }

            // Get the account information of the command's user.
            var command_user_account = UserInfoClasses.GetAccount(command.User);

            // Check if the user's account has been activated. If not, send them to the initial usage setup menu.
            if (command_user_account.Account_Activated == "No")
            {
                await First_Use_Content_Filter_Menu.First_Use_Content_Filter_Start((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }

            // End of initial usage and cooldown checks.

            // Check if there is a menu list entry with the current channel 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);

            // Also check if there is an item tracker entry for the current user ID. This should not exist without a menu entry, so you don't need to check for its validity.
            var itemSearch = Global.ItemIdList.SingleOrDefault(x => x.User.Id == command.User.Id);

            // If the entry exists and the user is not the same, send an error message
            if (channelSearch != null && channelSearch.User.Id != command.User.Id)
            {
                // await Context.Channel.SendMessageAsync("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 ShopMenu.ShopStart((SocketTextChannel)command.Channel, (SocketGuildUser)command.User);

                return;
            }
            // Else if the 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)
            {
                // await Context.Channel.SendMessageAsync("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);

                // Remove the item tracker entry from the global list
                Global.ItemIdList.Remove(itemSearch);

                // Create a new menu in the current channel
                await ShopMenu.ShopStart((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)
            {
                // await Context.Channel.SendMessageAsync("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);

                // Remove the item tracker entry from the global list
                Global.ItemIdList.Remove(itemSearch);

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

                return;
            }
            // For any other condition (if one should exist and not be handled here), create new entry
            else
            {
                // await Context.Channel.SendMessageAsync("Case 4: No previous entry found. Create new entry.");

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

                return;
            }
        }