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