mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix: bot type and tests bot.cache.x
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ export {
|
||||
assertThrows,
|
||||
assertThrowsAsync
|
||||
} from "https://deno.land/std@0.115.1/testing/asserts.ts";
|
||||
export * from "https://deno.land/x/discordeno_cache_plugin@0.0.9/mod.ts";
|
||||
export * from "https://deno.land/x/discordeno_cache_plugin@0.0.11/mod.ts";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { bot,guild } from "../mod.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test({
|
||||
@@ -10,14 +10,14 @@ Deno.test({
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji);
|
||||
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,17 +15,17 @@ Deno.test({
|
||||
assertExists(emoji);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id, "with a reason");
|
||||
|
||||
await delayUntil(10000, async () => !bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
await delayUntil(10000, async () => !bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
if (bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be deleted but it's still cached.");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -10,22 +10,22 @@ Deno.test({
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
roles: [],
|
||||
});
|
||||
|
||||
|
||||
// Assertions
|
||||
assertExists(emoji);
|
||||
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
|
||||
await bot.helpers.deleteEmoji(guild.id, emoji.id);
|
||||
|
||||
await delayUntil(10000, async () => !bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
|
||||
await delayUntil(10000, async () => !bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be deleted but it's still cached.");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,9 +15,9 @@ Deno.test({
|
||||
assertExists(emoji);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
@@ -25,12 +25,9 @@ Deno.test({
|
||||
name: "blamewolf_infinite",
|
||||
});
|
||||
|
||||
await delayUntil(
|
||||
10000,
|
||||
async () => bot.cache.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name === "blamewolf_infinite"
|
||||
);
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name === "blamewolf_infinite");
|
||||
|
||||
if (bot.cache.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") {
|
||||
if (bot.guilds.get(guild.id)?.emojis?.get(emoji.id)?.name !== "blamewolf_infinite") {
|
||||
throw new Error("The emoji seemed to be edited but the cache was not updated.");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,13 +15,13 @@ Deno.test({
|
||||
assertExists(emoji);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
bot.cache.guilds.get(guild.id)?.emojis?.delete(emoji.id);
|
||||
bot.guilds.get(guild.id)?.emojis?.delete(emoji.id);
|
||||
|
||||
const getEmoji = await bot.helpers.getEmoji(guild.id, emoji.id, true);
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ Deno.test({
|
||||
assertExists(emoji);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
await delayUntil(10000, async () => bot.guilds.get(guild.id)?.emojis?.has(emoji.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
if (!bot.guilds.get(guild.id)?.emojis?.has(emoji.id)) {
|
||||
throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.Te
|
||||
// Assertions
|
||||
assertExists(category);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(category.id));
|
||||
await delayUntil(10000, () => bot.channels.has(category.id));
|
||||
|
||||
assertExists(bot.cache.channels.has(category.id));
|
||||
assertExists(bot.channels.has(category.id));
|
||||
|
||||
const channelsToCreate = [1, 2, 3, 4, 5];
|
||||
const channels = await Promise.all(
|
||||
@@ -26,14 +26,14 @@ export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.Te
|
||||
)
|
||||
);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => channels.every((c) => bot.cache.channels.has(c.id)));
|
||||
await delayUntil(10000, () => channels.every((c) => bot.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))) {
|
||||
if (!channels.every((c) => bot.channels.has(c.id))) {
|
||||
throw new Error("The channels seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
// const ids = bot.cache.channels.filter((c) => c.parentId === category.id);
|
||||
// const ids = bot.channels.filter((c) => c.parentId === category.id);
|
||||
// if (ids.size !== channels.length || !channels.every((c) => ids.has(c.id))) {
|
||||
// console.log("cccc 1", ids.size, channels.length);
|
||||
// console.log(
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Bot, createChannel, ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function channelOverwriteHasPermissionTest(bot: Bot<Cache>, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function channelOverwriteHasPermissionTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "Discordeno-test",
|
||||
permissionOverwrites: [
|
||||
@@ -21,21 +20,18 @@ export async function channelOverwriteHasPermissionTest(bot: Bot<Cache>, guildId
|
||||
assertEquals(channel.type, ChannelTypes.GuildText);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
|
||||
await delayUntil(10000, () => bot.channels.has(channel.id));
|
||||
|
||||
if (!bot.cache.channels.has(channel.id)) {
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
assertEquals(channel.permissionOverwrites.length, 1);
|
||||
|
||||
assertEquals(
|
||||
channelOverwriteHasPermission(
|
||||
channel.guildId,
|
||||
bot.id,
|
||||
bot.cache.channels.get(channel.id)?.permissionOverwrites || [],
|
||||
["VIEW_CHANNEL"]
|
||||
),
|
||||
channelOverwriteHasPermission(channel.guildId, bot.id, bot.channels.get(channel.id)?.permissionOverwrites || [], [
|
||||
"VIEW_CHANNEL",
|
||||
]),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ export async function cloneChannelTests(
|
||||
assertEquals(cloned.type, channel.type);
|
||||
|
||||
// Delay the execution to allow CHANNEL_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(cloned.id));
|
||||
await delayUntil(10000, () => bot.channels.has(cloned.id));
|
||||
|
||||
assertExists(bot.cache.channels.has(cloned.id));
|
||||
assertExists(bot.channels.has(cloned.id));
|
||||
assertEquals(channel.topic, cloned.topic);
|
||||
assertEquals(channel.bitrate, cloned.bitrate);
|
||||
assertEquals(channel.permissionOverwrites.length, cloned.permissionOverwrites.length);
|
||||
|
||||
@@ -4,7 +4,13 @@ import { ChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function createChannelTests(bot: Bot, guildId: bigint, options: CreateGuildChannel, autoDelete: boolean, t: Deno.TestContext) {
|
||||
export async function createChannelTests(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
options: CreateGuildChannel,
|
||||
autoDelete: boolean,
|
||||
t: Deno.TestContext
|
||||
) {
|
||||
const channel = await bot.helpers.createChannel(guildId, options);
|
||||
|
||||
// Assertions
|
||||
@@ -12,9 +18,9 @@ export async function createChannelTests(bot: Bot, guildId: bigint, options: Cre
|
||||
assertEquals(channel.type, options.type || ChannelTypes.GuildText);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
|
||||
await delayUntil(10000, () => bot.channels.has(channel.id));
|
||||
|
||||
if (!bot.cache.channels.has(channel.id)) {
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
|
||||
@@ -9,20 +9,20 @@ export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { r
|
||||
name: "delete-channel",
|
||||
});
|
||||
|
||||
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
|
||||
await delayUntil(10000, () => bot.channels.has(channel.id));
|
||||
// Make sure the channel was created.
|
||||
if (!bot.cache.channels.has(channel.id)) {
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel should have been created but it is not in the cache.");
|
||||
}
|
||||
|
||||
const CHANNEL_DELETE = bot.handlers.CHANNEL_DELETE;
|
||||
|
||||
|
||||
// Delete the channel now without a reason
|
||||
await bot.helpers.deleteChannel(channel.id, options.reason);
|
||||
// wait to give it time for event
|
||||
await delayUntil(10000, () => !bot.cache.channels.has(channel.id));
|
||||
await delayUntil(10000, () => !bot.channels.has(channel.id));
|
||||
// Make sure it is gone from cache
|
||||
if (bot.cache.channels.has(channel.id)) {
|
||||
if (bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel should have been deleted but it is still in cache.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Bot, createChannel, ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { Bot, ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteChannelOverwriteTests(bot: Bot<Cache>, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function deleteChannelOverwriteTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "Discordeno-test",
|
||||
permissionOverwrites: [
|
||||
@@ -21,29 +20,26 @@ export async function deleteChannelOverwriteTests(bot: Bot<Cache>, guildId: bigi
|
||||
assertEquals(channel.type, ChannelTypes.GuildText);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
|
||||
await delayUntil(10000, () => bot.channels.has(channel.id));
|
||||
|
||||
if (!bot.cache.channels.has(channel.id)) {
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
assertEquals(channel.permissionOverwrites.length, 1);
|
||||
|
||||
assertEquals(
|
||||
channelOverwriteHasPermission(
|
||||
channel.guildId,
|
||||
bot.id,
|
||||
bot.cache.channels.get(channel.id)?.permissionOverwrites || [],
|
||||
["VIEW_CHANNEL"]
|
||||
),
|
||||
channelOverwriteHasPermission(channel.guildId, bot.id, bot.channels.get(channel.id)?.permissionOverwrites || [], [
|
||||
"VIEW_CHANNEL",
|
||||
]),
|
||||
true
|
||||
);
|
||||
|
||||
await bot.helpers.deleteChannelOverwrite(channel.id, bot.id);
|
||||
|
||||
await delayUntil(10000, () => bot.cache.channels.get(channel.id)?.permissionOverwrites?.length === 0);
|
||||
await delayUntil(10000, () => bot.channels.get(channel.id)?.permissionOverwrites?.length === 0);
|
||||
|
||||
if (bot.cache.channels.get(channel.id)?.permissionOverwrites?.length !== 0) {
|
||||
if (bot.channels.get(channel.id)?.permissionOverwrites?.length !== 0) {
|
||||
throw new Error("The channel permission overwrite was supposed to be deleted but it does not appear to be.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function editChannelTests(
|
||||
bot: Bot<Cache>,
|
||||
guildId: bigint,
|
||||
options: { reason?: string },
|
||||
t: Deno.TestContext
|
||||
) {
|
||||
export async function editChannelTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
// Create the necessary channels
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "edit-channel",
|
||||
});
|
||||
// wait to give it time for events to process
|
||||
await delayUntil(3000, () => bot.cache.channels.has(channel.id));
|
||||
await delayUntil(3000, () => bot.channels.has(channel.id));
|
||||
// Make sure the channel was created.
|
||||
if (!bot.cache.channels.has(channel.id)) {
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel should have been created but it is not in the cache.");
|
||||
}
|
||||
|
||||
@@ -31,6 +25,6 @@ export async function editChannelTests(
|
||||
);
|
||||
|
||||
// wait to give it time for events to process
|
||||
await delayUntil(3000, () => bot.cache.channels.get(channel.id)?.name === "new-name");
|
||||
assertEquals(bot.cache.channels.get(channel.id)?.name, "new-name");
|
||||
await delayUntil(3000, () => bot.channels.get(channel.id)?.name === "new-name");
|
||||
assertEquals(bot.channels.get(channel.id)?.name, "new-name");
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ export async function createEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestCon
|
||||
assertExists(emoji);
|
||||
|
||||
// // Delay the execution to allow event to be processed
|
||||
// await delayUntil(10000, async () => bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
// await delayUntil(10000, async () => bot.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
|
||||
// if (!bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// if (!bot.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -13,17 +13,17 @@ export async function ifItFailsBlameWolf(bot: Bot, guildId: bigint, reason?: str
|
||||
assertExists(emoji);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
// await delayUntil(10000, async () => bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
// await delayUntil(10000, async () => bot.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
|
||||
// if (!bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// if (!bot.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
// }
|
||||
|
||||
await bot.helpers.deleteEmoji(guildId, emoji.id, reason);
|
||||
|
||||
// await delayUntil(10000, async () => !bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
// await delayUntil(10000, async () => !bot.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
|
||||
// if (bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// if (bot.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// throw new Error("The emoji seemed to be deleted but it's still cached.");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ export async function getEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContex
|
||||
assertExists(emoji);
|
||||
|
||||
// // Delay the execution to allow event to be processed
|
||||
// await delayUntil(10000, async () => bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
// await delayUntil(10000, async () => bot.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
|
||||
// if (!bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// if (!bot.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
// }
|
||||
|
||||
// bot.cache.guilds.get(guildId)?.emojis?.delete(emoji.id);
|
||||
// bot.guilds.get(guildId)?.emojis?.delete(emoji.id);
|
||||
|
||||
// const getEmoji = await bot.helpers.getEmoji(guildId, emoji.id, true);
|
||||
|
||||
@@ -27,9 +27,9 @@ export async function getEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContex
|
||||
// assertExists(getEmoji);
|
||||
|
||||
// // Delay the execution to allow event to be processed
|
||||
// await delayUntil(10000, async () => bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
// await delayUntil(10000, async () => bot.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
|
||||
// if (!bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// if (!bot.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// throw new Error("The emoji didn't got added to cache after using the getEmoji function.");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ export async function getEmojisTest(bot: Bot, guildId: bigint, t: Deno.TestConte
|
||||
assertExists(emoji);
|
||||
|
||||
// // Delay the execution to allow event to be processed
|
||||
// await delayUntil(10000, async () => bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
// await delayUntil(10000, async () => bot.guilds.get(guildId)?.emojis?.has(emoji.id));
|
||||
|
||||
// if (!bot.cache.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// if (!bot.guilds.get(guildId)?.emojis?.has(emoji.id)) {
|
||||
// throw new Error("The emoji seemed to be created but it was not cached.");
|
||||
// }
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ export async function createGuildTests(bot: Bot, t: Deno.TestContext) {
|
||||
assertExists(guild);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.has(guild.id));
|
||||
await delayUntil(10000, () => bot.guilds.has(guild.id));
|
||||
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
if (!bot.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be created but it was not cached.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,18 +11,18 @@ export async function deleteGuildTests(bot: Bot, t: Deno.TestContext) {
|
||||
assertExists(guild);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.has(guild.id));
|
||||
await delayUntil(10000, () => bot.guilds.has(guild.id));
|
||||
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
if (!bot.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be created but it was not cached.`);
|
||||
}
|
||||
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => !bot.cache.guilds.has(guild.id));
|
||||
await delayUntil(10000, () => !bot.guilds.has(guild.id));
|
||||
|
||||
if (bot.cache.guilds.has(guild.id)) {
|
||||
if (bot.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be deleted but it's still cached.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ export async function editGuildTests(bot: Bot, guildId: bigint, t: Deno.TestCont
|
||||
assertExists(guild);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
// await delayUntil(10000, async () => bot.cache.guilds.get(guild.id)?.name === "Discordeno Test 1.0");
|
||||
// await delayUntil(10000, async () => bot.guilds.get(guild.id)?.name === "Discordeno Test 1.0");
|
||||
|
||||
// if (!bot.cache.guilds.has(guild.id)) {
|
||||
// if (!bot.guilds.has(guild.id)) {
|
||||
// throw new Error(`The guild seemed to be edited but the cache didn't got updated.`);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string)
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
// Make sure the message was created.
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached. Reason: ${reason}");
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string)
|
||||
await bot.helpers.deleteMessage(channelId, message.id, reason);
|
||||
|
||||
// Wait to give it time for MESSAGE_DELETE event
|
||||
await delayUntil(10000, () => !bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => !bot.messages.has(message.id));
|
||||
// Make sure it is gone from cache
|
||||
if (bot.cache.messages.has(message.id)) {
|
||||
if (bot.messages.has(message.id)) {
|
||||
throw new Error("The message should have been deleted but it is still in cache.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string)
|
||||
assertExists(message);
|
||||
assertExists(secondMessage);
|
||||
// Delay the execution by to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id) && bot.cache.messages.has(secondMessage.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id) && bot.messages.has(secondMessage.id));
|
||||
// Make sure the message was created.
|
||||
if (!bot.cache.messages.has(message.id) || !bot.cache.messages.has(secondMessage.id)) {
|
||||
if (!bot.messages.has(message.id) || !bot.messages.has(secondMessage.id)) {
|
||||
throw new Error(`The message seemed to be sent but it was not cached. Reason: ${reason}`);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string)
|
||||
await bot.helpers.deleteMessages(channelId, [message.id, secondMessage.id], reason);
|
||||
|
||||
// Wait to give it time for MESSAGE_DELETE event
|
||||
await delayUntil(10000, () => !bot.cache.messages.has(message.id) && !bot.cache.messages.has(secondMessage.id));
|
||||
await delayUntil(10000, () => !bot.messages.has(message.id) && !bot.messages.has(secondMessage.id));
|
||||
// Make sure they are gone from cache
|
||||
if (bot.cache.messages.has(message.id) || bot.cache.messages.has(secondMessage.id)) {
|
||||
if (bot.messages.has(message.id) || bot.messages.has(secondMessage.id)) {
|
||||
throw new Error("The messages should have been deleted but they are still in cache.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ export async function editMessageTest(bot: Bot, channelId: bigint, t: Deno.TestC
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
// Make sure the message was created.
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached. Reason: ${reason}");
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ export async function editMessageTest(bot: Bot, channelId: bigint, t: Deno.TestC
|
||||
await bot.helpers.editMessage(channelId, message.id, "Goodbye World!");
|
||||
|
||||
// Wait to give it time for MESSAGE_UPDATE event
|
||||
// await delayUntil(10000, async () => bot.cache.messages.get(message.id)?.content === "Goodbye World!");
|
||||
// await delayUntil(10000, async () => bot.messages.get(message.id)?.content === "Goodbye World!");
|
||||
// Make sure it was edited
|
||||
// if (bot.cache.messages.get(message.id)?.content !== "Goodbye World!") {
|
||||
// if (bot.messages.get(message.id)?.content !== "Goodbye World!") {
|
||||
// throw new Error("The message should have been edited but it was not.");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ export async function getMessageTest(bot: Bot, channelId: bigint, t: Deno.TestCo
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
// Make sure the message was created.
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached. Reason: ${reason}");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,17 +14,10 @@ export async function getMessagesTest(bot: Bot, channelId: bigint, t: Deno.TestC
|
||||
// Delay the execution by to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(
|
||||
10000,
|
||||
() =>
|
||||
bot.cache.messages.has(message.id) &&
|
||||
bot.cache.messages.has(secondMessage.id) &&
|
||||
bot.cache.messages.has(thirdMessage.id)
|
||||
() => bot.messages.has(message.id) && bot.messages.has(secondMessage.id) && bot.messages.has(thirdMessage.id)
|
||||
);
|
||||
// Make sure the messages was created.
|
||||
if (
|
||||
!bot.cache.messages.has(message.id) ||
|
||||
!bot.cache.messages.has(secondMessage.id) ||
|
||||
!bot.cache.messages.has(thirdMessage.id)
|
||||
) {
|
||||
if (!bot.messages.has(message.id) || !bot.messages.has(secondMessage.id) || !bot.messages.has(thirdMessage.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ export async function addReactionTest(
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ export async function removeAllReactionTests(bot: Bot, channelId: bigint, t: Den
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
|
||||
@@ -124,9 +124,9 @@ export async function removeReactionTest(bot: Bot, channelId: bigint, t: Deno.Te
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
|
||||
@@ -166,15 +166,15 @@ export async function removeReactionEmojiTest(bot: Bot, channelId: bigint, t: De
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
|
||||
reactionCounters.set(message.id, 0);
|
||||
|
||||
bot.events.reactionAdd
|
||||
bot.events.reactionAdd;
|
||||
|
||||
bot.events.reactionRemoveEmoji = function (bot, payload) {
|
||||
reactionCounters.set(payload.messageId, 0);
|
||||
|
||||
@@ -10,9 +10,9 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, content: string |
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
// Delay the execution by to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
// Make sure the message was created.
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function createRoleTests(
|
||||
bot: Bot<Cache>,
|
||||
guildId: bigint,
|
||||
options: { reason?: string },
|
||||
t: Deno.TestContext
|
||||
) {
|
||||
export async function createRoleTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
const role = await bot.helpers.createRole(guildId, { name: "hoti" }, options.reason);
|
||||
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
}
|
||||
|
||||
@@ -1,29 +1,23 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteRoleTests(
|
||||
bot: Bot<Cache>,
|
||||
guildId: bigint,
|
||||
options: { reason?: string },
|
||||
t: Deno.TestContext
|
||||
) {
|
||||
export async function deleteRoleTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
const role = await bot.helpers.createRole(guildId, { name: "hoti" }, options.reason);
|
||||
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
await bot.helpers.deleteRole(guildId, role.id);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => !bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => !bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
if (bot.cache.guilds.get(guildId)?.roles.has(role.id)) {
|
||||
if (bot.guilds.get(guildId)?.roles.has(role.id)) {
|
||||
throw new Error(`The role should have been deleted but it is still in cache.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function editRoleTests(bot: Bot<Cache>, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function editRoleTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const role = await bot.helpers.createRole(guildId, {
|
||||
name: "hoti",
|
||||
});
|
||||
@@ -11,9 +10,9 @@ export async function editRoleTests(bot: Bot<Cache>, guildId: bigint, t: Deno.Te
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guildId)?.roles.has(role.id)) {
|
||||
if (!bot.guilds.get(guildId)?.roles.has(role.id)) {
|
||||
throw new Error(`The role seemed to be created but it was not cached.`);
|
||||
}
|
||||
|
||||
@@ -22,7 +21,7 @@ export async function editRoleTests(bot: Bot<Cache>, guildId: bigint, t: Deno.Te
|
||||
});
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.get(role.id)?.name === "#rememberAyntee");
|
||||
await delayUntil(10000, () => bot.guilds.get(guildId)?.roles.get(role.id)?.name === "#rememberAyntee");
|
||||
|
||||
assertEquals(bot.cache.guilds.get(guildId)?.roles.get(role.id)?.name === "#rememberAyntee", true);
|
||||
assertEquals(bot.guilds.get(guildId)?.roles.get(role.id)?.name === "#rememberAyntee", true);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertEquals } from "../../deps.ts";
|
||||
|
||||
export async function getRolesTest(bot: Bot<Cache>, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getRolesTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
const roles = await bot.helpers.getRoles(guildId);
|
||||
|
||||
assertEquals(bot.cache.guilds.get(guildId)?.roles.size, roles.size);
|
||||
assertEquals(bot.guilds.get(guildId)?.roles.size, roles.size);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
const roleChanges = new Map<bigint, bigint[]>();
|
||||
|
||||
export async function addRoleTest(bot: Bot<Cache>, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
export async function addRoleTest(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
const role = await bot.helpers.createRole(guildId, {
|
||||
name: "hoti",
|
||||
});
|
||||
@@ -13,9 +12,9 @@ export async function addRoleTest(bot: Bot<Cache>, guildId: bigint, options: { r
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guildId)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guildId)?.roles.has(role.id));
|
||||
|
||||
bot.events.guildMemberUpdate = function (bot, member, user) {
|
||||
roleChanges.set(user.id, member.roles);
|
||||
@@ -29,11 +28,4 @@ export async function addRoleTest(bot: Bot<Cache>, guildId: bigint, options: { r
|
||||
assertEquals(roleChanges.get(bot.id)?.includes(role.id), true);
|
||||
}
|
||||
|
||||
export async function removeRoleTest(
|
||||
bot: Bot<Cache>,
|
||||
guildId: bigint,
|
||||
options: { reason?: string },
|
||||
t: Deno.TestContext
|
||||
) {
|
||||
|
||||
}
|
||||
export async function removeRoleTest(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {}
|
||||
|
||||
@@ -66,7 +66,7 @@ Deno.test({
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(bot.cache.members.get(BigInt(`${bot.id}${guild.id}`)));
|
||||
assertExists(bot.members..get(BigInt(`${bot.id}${guild.id}`)));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
+8
-12
@@ -41,7 +41,7 @@ if (!UNITTEST_TOKEN) throw new Error("Token was not provided.");
|
||||
const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
|
||||
|
||||
let startedAt = 0;
|
||||
export const bot = createBot({
|
||||
const baseBot = createBot({
|
||||
token: UNITTEST_TOKEN,
|
||||
botId,
|
||||
events: createEventHandlers({
|
||||
@@ -59,15 +59,11 @@ export const bot = createBot({
|
||||
"GuildMembers",
|
||||
"GuildScheduledEvents",
|
||||
"GuildVoiceStates",
|
||||
"GuildPresences"
|
||||
"GuildPresences",
|
||||
],
|
||||
cache: {
|
||||
isAsync: false,
|
||||
},
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
enableCachePlugin(bot);
|
||||
const bot = enableCachePlugin(baseBot);
|
||||
await startBot(bot);
|
||||
|
||||
// Delay the execution to allow READY events to be processed
|
||||
@@ -75,8 +71,8 @@ await delayUntil(10000, () => Boolean(startedAt));
|
||||
console.log("Bot online");
|
||||
|
||||
// DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE
|
||||
if (bot.cache.guilds.size() <= 10) {
|
||||
bot.cache.guilds.forEach(async (guild) => {
|
||||
if (bot.guilds.size() <= 10) {
|
||||
bot.guilds.forEach(async (guild) => {
|
||||
// DO NOT DELETE OUR CACHED TEST SERVER FOR COMMUNITY FEATURES
|
||||
if (guild.id === CACHED_COMMUNITY_GUILD_ID) return;
|
||||
if (guild.ownerId === bot.id) await bot.helpers.deleteGuild(guild.id);
|
||||
@@ -94,10 +90,10 @@ assertExists(guild);
|
||||
assertExists(guild.id);
|
||||
|
||||
// Delay the execution to allow GUILD_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.has(guild.id));
|
||||
await delayUntil(10000, () => bot.guilds.has(guild.id));
|
||||
|
||||
// FINAL CHECK TO THROW IF MISSING STILL
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
if (!bot.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`);
|
||||
}
|
||||
|
||||
@@ -603,7 +599,7 @@ import "./misc/getVoiceRegions.ts";
|
||||
import "./misc/snowflake.ts";
|
||||
import "./misc/typing.ts";
|
||||
import "./misc/validateDiscovery.ts";
|
||||
import "./misc/editBotStatus.ts"
|
||||
import "./misc/editBotStatus.ts";
|
||||
|
||||
//role
|
||||
import "./role/addRole.ts";
|
||||
|
||||
@@ -3,7 +3,6 @@ import { assertExists, assertEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
|
||||
Deno.test({
|
||||
name: "[Role] add a role to a member",
|
||||
fn: async (t) => {
|
||||
@@ -14,9 +13,9 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
bot.events.guildMemberUpdate = function (bot, member, user) {
|
||||
roleChanges.set(user.id, member.roles);
|
||||
|
||||
@@ -13,8 +13,8 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,8 +13,8 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,16 +10,16 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
await bot.helpers.deleteRole(guild.id, role.id);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => !bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => !bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
if (bot.cache.guilds.get(guild.id)?.roles.has(role.id)) {
|
||||
if (bot.guilds.get(guild.id)?.roles.has(role.id)) {
|
||||
throw new Error(`The role should have been deleted but it is still in cache.`);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -10,16 +10,16 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
await bot.helpers.deleteRole(guild.id, role.id);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => !bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => !bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
if (bot.cache.guilds.get(guild.id)?.roles.has(role.id)) {
|
||||
if (bot.guilds.get(guild.id)?.roles.has(role.id)) {
|
||||
throw new Error(`The role should have been deleted but it is still in cache.`);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertExists,assertEquals } from "../deps.ts";
|
||||
import { assertExists, assertEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
@@ -12,9 +12,9 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
if (!bot.cache.guilds.get(guild.id)?.roles.has(role.id)) {
|
||||
if (!bot.guilds.get(guild.id)?.roles.has(role.id)) {
|
||||
throw new Error(`The role seemed to be created but it was not cached.`);
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ Deno.test({
|
||||
});
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.get(role.id)?.name === "#rememberAyntee");
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.get(role.id)?.name === "#rememberAyntee");
|
||||
|
||||
assertEquals(bot.cache.guilds.get(guild.id)?.roles.get(role.id)?.name === "#rememberAyntee", true);
|
||||
assertEquals(bot.guilds.get(guild.id)?.roles.get(role.id)?.name === "#rememberAyntee", true);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,6 +6,6 @@ Deno.test({
|
||||
fn: async (t) => {
|
||||
const roles = await bot.helpers.getRoles(guild.id);
|
||||
|
||||
assertEquals(bot.cache.guilds.get(guild.id)?.roles.size, roles.size);
|
||||
assertEquals(bot.guilds.get(guild.id)?.roles.size, roles.size);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,9 +13,9 @@ Deno.test({
|
||||
assertExists(role);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
await delayUntil(10000, () => bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
assertExists(bot.cache.guilds.get(guild.id)?.roles.has(role.id));
|
||||
assertExists(bot.guilds.get(guild.id)?.roles.has(role.id));
|
||||
|
||||
bot.events.guildMemberUpdate = function (bot, member, user) {
|
||||
roleChanges.set(user.id, member.roles);
|
||||
|
||||
Reference in New Issue
Block a user