This commit is contained in:
Skillz4Killz
2021-11-03 22:32:19 +00:00
committed by GitHub
parent 2a83d8e597
commit 228c71d3bd
2 changed files with 42 additions and 0 deletions

View File

@@ -170,6 +170,8 @@ export type CacheExecutor = (
export function createExecute(cache: Cache): CacheExecutor {
return function (type, options) {
switch (type) {
case "FILTER_CATEGORY_CHILDREN_CHANNELS":
return cache.channels.filter(c => c.parentId === options.parentChannelId);
case "DELETE_MESSAGES_FROM_CHANNEL":
cache.messages.forEach((message) => {
if (message.channelId === options.channelId) {

View File

@@ -0,0 +1,40 @@
import { Bot } from "../../../src/bot.ts";
import { DiscordChannelTypes } from "../../../src/types/channels/channel_types.ts";
import { assertExists } from "../../deps.ts";
import { delayUntil } from "../../utils.ts";
export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
const category = await bot.helpers.createChannel(guildId, {
name: "Discordeno-test",
type: DiscordChannelTypes.GuildCategory,
});
// Assertions
assertExists(category);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => bot.cache.channels.has(category.id));
assertExists(bot.cache.channels.has(category.id));
const channelsToCreate = [1, 2, 3, 4, 5];
const channels = await Promise.all(
channelsToCreate.map((num) =>
bot.helpers.createChannel(guildId, {
name: `Discordeno-test-${num}`,
parentId: category.id,
})
)
);
// Delay the execution to allow event to be processed
await delayUntil(10000, () => channels.every((c) => bot.cache.channels.has(c.id)));
// If every channel is not present in the cache, error out
if (!channels.every((c) => bot.cache.channels.has(c.id))) {
throw new Error("The channels seemed to be created but it was not cached.");
}
const ids = await bot.helpers.categoryChildren(category.id);
if (ids.size !== channelsToCreate.length || !channels.every((c) => ids.has(c.id))) {
throw new Error("The category channel ids did not match with the category channels.");
}
}