private static async void MenuTimer_Elapsed(object sender, ElapsedEventArgs e, MenuIdStructure idTracker, ItemListIterator itemSession) { // Attempt deleting the message if it hasn't been deleted by the user yet. // If it has, catch the exception, remove the menu and item entries from the global list, and return. try { // Delete the current message from the channel. await idTracker.MenuMessage.DeleteAsync(); } catch (Exception ex) { Console.WriteLine(ex); // Remove the menu and item entries from the global list. Global.MenuIdList.Remove(idTracker); Global.ItemIdList.Remove(itemSession); return; } // Reassign the menu session's message to a new message generated from the created embed. idTracker.MenuMessage = (RestUserMessage)await idTracker.MenuMessage.Channel.SendMessageAsync("", false, MenuTimedOut(idTracker.User).Build()); // Remove the menu and item entries from the global list Global.MenuIdList.Remove(idTracker); Global.ItemIdList.Remove(itemSession); }
public static async Task Status_Decor_Start(SocketGuildUser user, RestUserMessage message) { //Get the account information of the command's target var account = UserInfoClasses.GetAccount(user); // Find the menu session associated with the current user. var menuSession = Global.MenuIdList.SingleOrDefault(x => x.User.Id == user.Id); var embed = new EmbedBuilder(); var author = new EmbedAuthorBuilder { Name = "Now Loading...", IconUrl = user.GetAvatarUrl() }; embed.WithAuthor(author); // Determine the color and thumbnail for the embeded message. embed.WithColor(EmbedSettings.Get_Profile_Embed_Color(account)); // Create an empty string list. List <string> owned_decor = new List <string> { }; // Check if the user owns any décor. if (account.Decor_Owned != "") { // If so, convert their Decor_Owned value into a string list and assign it to the owned_decor string list. owned_decor = DecorInfoMethods.StringToStringArray(account.Decor_Owned); } // Create another empty string list. List <string> user_content_filter = new List <string> { }; // Check if the user has any titles listed in their content filter. if (account.Content_Filter != "") { // If so, convert their Content_Filter value into a string list and assign it to the user_content_filter string list. user_content_filter = DecorInfoMethods.StringToStringArray(account.Content_Filter); } // Create a new list by removing any décor that contains content specified in the user's content filter and assign it to the owned_decor variable. owned_decor = DecorInfoMethods.RemoveBlockedContentFromList(owned_decor, user_content_filter); // Search for an item list that corresponds to the user's ID. var itemSession = Global.ItemIdList.SingleOrDefault(x => x.User.Id == user.Id); // If an item session already exists, remove it from the global list. if (itemSession != null) { Global.ItemIdList.Remove(itemSession); } // Create a new item identifier entry for this current user to keep track of the position of décor on the menu. itemSession = new ItemListIterator() { User = user, ItemList = owned_decor, ItemIndexBase = 0, MaxItemsDisplayed = 6, CurrentPage = 1 }; // Add the item entry to the global list. Global.ItemIdList.Add(itemSession); // 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 = "Status_Decor_Start"; 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 }; // Create a new menu in the current channel. await Status_Decor_Main(menuSession.User, menuSession.MenuMessage); }
public static async Task ShopStart(SocketTextChannel channel, SocketGuildUser user) { //Get the account information of the command's target var account = UserInfoClasses.GetAccount(user); var embed = new EmbedBuilder(); var author = new EmbedAuthorBuilder { Name = "Now Loading...", IconUrl = user.GetAvatarUrl() }; embed.WithAuthor(author); //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 null variable for the message. RestUserMessage message = null; // Try to send a message to the channel. If the bot lacks permissions, catch the exception and return. try { message = await channel.SendMessageAsync("", false, embed.Build()); } catch (Exception ex) { Console.WriteLine(ex); return; } // Create a string list variable. List <string> original_decor_list; // Depending on the user's settings, fill the string list with an assortment of décor according to how the user wishes for it to be organized. original_decor_list = DecorInfoMethods.CreateSortSettingList(account.Shop_Sort); // Create an empty string list. List <string> owned_decor = new List <string> { }; // Check if the user owns any décor. if (account.Decor_Owned != "") { // If so, convert their Decor_Owned value into a string list and assign it to the owned_decor string list. owned_decor = DecorInfoMethods.StringToStringArray(account.Decor_Owned); } // Start comparing the user's owned_decor list to the created decor_list for the shop. // If the user owns any décor from the decor_list or has content blocked, remove the matching entry from the list var new_decor_list = original_decor_list.Except(owned_decor).ToList(); // Create another empty string list. List <string> user_content_filter = new List <string> { }; // Check if the user has any titles listed in their content filter. if (account.Content_Filter != "") { // If so, convert their Content_Filter value into a string list and assign it to the user_content_filter string list. user_content_filter = DecorInfoMethods.StringToStringArray(account.Content_Filter); } // Create a new list by removing any décor that contains content specified in the user's content filter and assign it to the new_decor_list variable. new_decor_list = DecorInfoMethods.RemoveBlockedContentFromList(new_decor_list, user_content_filter); // Search for an item list that corresponds to the user's ID. var itemSession = Global.ItemIdList.SingleOrDefault(x => x.User.Id == user.Id); // If an item session already exists, remove it from the global list. if (itemSession != null) { Global.ItemIdList.Remove(itemSession); } // Create a new item identifier entry for this current user to keep track of the position of décor on the menu. itemSession = new ItemListIterator() { User = user, ItemList = new_decor_list, ItemIndexBase = 0, MaxItemsDisplayed = 6, CurrentPage = 1 }; // Add the item entry to the global list. Global.ItemIdList.Add(itemSession); // Create a new menu identifier entry for this current message and user to keep track of the overall menu status. var idTracker = new MenuIdStructure() { User = user, MenuMessage = message, CurrentMenu = "Shop_Start", MenuTimer = new Timer() { // Create a timer that expires as a "time out" duration for the user. Interval = MenuConfig.menu.timerDuration, AutoReset = false, Enabled = true } }; // Add the menu entry to the global list. Global.MenuIdList.Add(idTracker); // Create a new menu in the current channel. await ShopMainMenu(idTracker.User, idTracker.MenuMessage); }
public static Bitmap DecorPreviews(ItemListIterator itemSession, int sublist_length) { // First, determine how the items will be rendered on the bitmap based on the size of sublist_length. // This is done by taking the square root of the input sublist_length variable. Notice that the result will be a double at times and not a full integer. double sq_count = Math.Sqrt(sublist_length); // Determine how many columns and rows will be displayed on the bitmap. // Columns are determined by calculating the ceiling of the sq_count double variable. // Rows are calculated by converting the sq_count double straight to an int. int columns = (int)Math.Ceiling(sq_count); int rows = Convert.ToInt32(sq_count); // Create variables for the desired width and height of each décor item to be drawn on the template. int item_width = 475; int item_height = 268; // Set the width and height of the bitmap based on the desired dimensions of each décor thumbnail and the expected amounts of columns and rows. int newWidth = (columns * item_width); int newHeight = (rows * item_height); // Create a bitmap working space from the calculated newWidth and newHeight values. Bitmap base_template = new Bitmap(newWidth, newHeight); // Attempt to edit the bitmap with a graphics object. These operations could fail at times, so make sure it's in a try-catch block. try { // Use a graphics object to edit the bitmap using (Graphics graphics = Graphics.FromImage(base_template)) { // Create two int variables that represent the X and Y values on the base_template bitmap. int x = 0; int y = 0; // Color the entire bitmap with a black color graphics.Clear(System.Drawing.Color.FromArgb(0, 0, 0)); // Create an int to properly display the needed emotes when iterating through the item list. int displayed_list_counter = 0; // Iterate through the item list starting from the ItemBaseIndex and up until sublist_length. for (int i = itemSession.ItemIndexBase; i < (itemSession.ItemIndexBase + sublist_length); i++) { // Increase the displayed_list_counter by one. displayed_list_counter += 1; // Get the information of the current décor iteration. var decor_info = DecorInfoMethods.GetDecorInfo(itemSession.ItemList[i]); // Create a bitmap variable. Bitmap thumbnail = new Bitmap(2, 2); // Attempt to gather the thumbnail associated with the current décor being iterated on and assign it to the bitmap variable. try { thumbnail = (Bitmap)System.Drawing.Image.FromFile($@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//Profile//StatusScreens//Decor//{decor_info.Decor_ID}//_Thumbnails//preview_1.png"); } // If this fails, catch the exception and continue. catch (Exception ex) { Console.WriteLine(ex); } // Draw the thumbnail to the base template at the current X and Y coordinate values. graphics.DrawImage(thumbnail, x, y, item_width, item_height); using (Font rockwell = new Font("Rockwell", 45, FontStyle.Bold)) { // Create a GraphicsPath object. GraphicsPath myPath = new GraphicsPath(); // Set up all the string parameters. string stringText = $"{displayed_list_counter}"; System.Drawing.FontFamily family = new System.Drawing.FontFamily("Rockwell"); int fontStyle = (int)FontStyle.Bold; int emSize = 23; Point origin = new Point(x + 236, y + 237); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; // Add the string to the path. myPath.AddString(stringText, family, fontStyle, emSize = (int)graphics.DpiY * 48 / 72, //47 pt origin, stringFormat); //Draw the path to the screen. graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.FillPath(System.Drawing.Brushes.White, myPath); graphics.DrawPath(new System.Drawing.Pen(System.Drawing.Brushes.Black, 4), myPath); graphics.FillPath(System.Drawing.Brushes.White, myPath); graphics.DrawPath(new System.Drawing.Pen(System.Drawing.Brushes.Black, 0), myPath); } x = x + item_width + 5; if (x >= newWidth) { x = 0; y = y + item_height + 5; } } } } catch (Exception ex) { Console.WriteLine(ex); } return(base_template); }