using System; using System.Collections.Generic; using System.Threading.Tasks; using DSharpPlus.Entities; namespace SupportChild; public static class Utilities { private static readonly Random rng = new Random(); public static void Shuffle(this IList list) { int n = list.Count; while (n > 1) { n--; int k = rng.Next(n + 1); (list[k], list[n]) = (list[n], list[k]); } } public static LinkedList ParseListIntoMessages(List listItems) { LinkedList messages = new LinkedList(); foreach (string listItem in listItems) { if (messages.Last?.Value?.Length + listItem?.Length < 2048) { messages.Last.Value += listItem; } else { messages.AddLast(listItem); } } return messages; } public static async Task> GetVerifiedChannels() { List verifiedCategories = new List(); foreach (Database.Category category in Database.GetAllCategories()) { DiscordChannel channel = null; try { channel = await SupportChild.discordClient.GetChannelAsync(category.id); } catch (Exception) { /*ignored*/ } if (channel != null) { verifiedCategories.Add(category); } else { Logger.Warn("Category '" + category.name + "' (" + category.id + ") no longer exists! Ignoring..."); } } return verifiedCategories; } }