mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Merge branch 'discordeno:main' into main
This commit is contained in:
+4
-1
@@ -5,7 +5,10 @@ import { sanitizeMode } from "./constants.ts";
|
||||
Deno.test({
|
||||
name: "[Memory] Benchmark memory tests",
|
||||
fn: async (t) => {
|
||||
await memoryBenchmarks(bot, true);
|
||||
await memoryBenchmarks(bot, {
|
||||
log: true,
|
||||
table: true,
|
||||
});
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import { assertEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test("[channel] Connect to voice channel and disconnect.", async () => {
|
||||
Deno.test("[channel] Connect to voice channel.", async () => {
|
||||
const channel = await bot.helpers.createChannel(guild.id, {
|
||||
name: "lumap",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
@@ -22,11 +22,4 @@ Deno.test("[channel] Connect to voice channel and disconnect.", async () => {
|
||||
await delayUntil(10000, () => joined);
|
||||
|
||||
assertEquals(joined, true);
|
||||
|
||||
// DISCONNECT BOT
|
||||
await bot.helpers.disconnectMember(guild.id, bot.id);
|
||||
// WAIT FOR EVENT TO ARRIVE
|
||||
await delayUntil(10000, () => !joined);
|
||||
|
||||
assertEquals(joined, false);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import { ChannelTypes, CreateGuildChannel, OverwriteTypes } from "../../mod.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID } from "../constants.ts";
|
||||
import { assertExists, assertEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
async function createChannelTests(guildId: bigint, options: CreateGuildChannel, autoDelete: boolean) {
|
||||
const channel = await bot.helpers.createChannel(guildId, options);
|
||||
|
||||
// Assertions
|
||||
assertExists(channel);
|
||||
assertEquals(channel.type, options.type || ChannelTypes.GuildText);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.channels.has(channel.id));
|
||||
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel seemed to be created but it was not cached.");
|
||||
}
|
||||
|
||||
if (options.topic && channel.topic !== options.topic) {
|
||||
throw new Error("The channel was supposed to have a topic but it does not appear to be the same topic.");
|
||||
}
|
||||
|
||||
if (options.bitrate && channel.bitrate !== options.bitrate) {
|
||||
throw new Error("The channel was supposed to have a bitrate but it does not appear to be the same bitrate.");
|
||||
}
|
||||
|
||||
if (options.permissionOverwrites && channel.permissionOverwrites?.length !== options.permissionOverwrites.length) {
|
||||
throw new Error(
|
||||
"The channel was supposed to have a permissionOverwrites but it does not appear to be the same permissionOverwrites."
|
||||
);
|
||||
}
|
||||
|
||||
if (autoDelete) {
|
||||
await bot.helpers.deleteChannel(channel.id);
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(guild.id, { name: "Discordeno-test" }, false);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new category channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildCategory,
|
||||
},
|
||||
false
|
||||
);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new news channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
CACHED_COMMUNITY_GUILD_ID,
|
||||
{ name: "Discordeno-test", type: ChannelTypes.GuildNews },
|
||||
true
|
||||
);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new voice channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
},
|
||||
false
|
||||
);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new voice channel with a bitrate",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
guild.id,
|
||||
{
|
||||
name: "discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
bitrate: 32000,
|
||||
},
|
||||
false
|
||||
);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new voice channel with a user limit",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
userLimit: 32,
|
||||
},
|
||||
false
|
||||
);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel with a rate limit per user",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
rateLimitPerUser: 2423,
|
||||
},
|
||||
false
|
||||
);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel with NSFW",
|
||||
async fn(t) {
|
||||
await createChannelTests(guild.id, { name: "Discordeno-test", nsfw: true }, false);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel with permission overwrites",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: bot.id,
|
||||
type: OverwriteTypes.Member,
|
||||
allow: ["VIEW_CHANNEL"],
|
||||
deny: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
false
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { bot, guild } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
async function deleteChannelTests(guildId: bigint, options: { reason?: string }) {
|
||||
// Create the necessary channels
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "delete-channel",
|
||||
});
|
||||
|
||||
await delayUntil(10000, () => bot.channels.has(channel.id));
|
||||
// Make sure the channel was created.
|
||||
if (!bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel should have been created but it is not in the cache.");
|
||||
}
|
||||
|
||||
// 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.channels.has(channel.id));
|
||||
|
||||
// Make sure it is gone from cache
|
||||
if (bot.channels.has(channel.id)) {
|
||||
throw new Error("The channel should have been deleted but it is still in cache.");
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel with a reason",
|
||||
async fn(t) {
|
||||
await deleteChannelTests(guild.id, {
|
||||
reason: "with a reason",
|
||||
});
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel without a reason",
|
||||
async fn(t) {
|
||||
await deleteChannelTests(guild.id, {});
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assertEquals, assertExists, assertNotEquals, assertThrows } from "../deps.ts";
|
||||
import { assertEquals, assertExists, assertNotEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
|
||||
Deno.test("[thread] Start a thread", async (t) => {
|
||||
@@ -34,7 +34,8 @@ Deno.test("[thread] Start a thread", async (t) => {
|
||||
assertEquals(archived.members.size, 0);
|
||||
|
||||
await t.step("[thread] Edit and archive a thread", async () => {
|
||||
const edited = await bot.helpers.editThread(thread.id, {
|
||||
const edited = await bot.helpers.editChannel(thread.id, {
|
||||
// @ts-ignore
|
||||
archived: true,
|
||||
name: "new name",
|
||||
autoArchiveDuration: 1440,
|
||||
@@ -54,6 +55,6 @@ Deno.test("[thread] Start a thread", async (t) => {
|
||||
});
|
||||
|
||||
await t.step("[thread] Delete a thread", async () => {
|
||||
await bot.helpers.deleteThread(thread.id);
|
||||
await bot.helpers.deleteChannel(thread.id);
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@ export const sanitizeMode = {
|
||||
|
||||
// USED FOR ROLE CHANGE EVENTS
|
||||
export const roleChanges = new Map<bigint, bigint[]>();
|
||||
|
||||
export const banCounters = new Map<bigint, boolean>();
|
||||
export const reactionCounters = new Map<bigint, number>();
|
||||
|
||||
+2
-1
@@ -6,4 +6,5 @@ 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.13/mod.ts";
|
||||
export * from "https://deno.land/x/discordeno_permissions_plugin@0.0.7/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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { assertEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] format a guild's icon url",
|
||||
fn: () => {
|
||||
assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildIconURL(785384884197392384n, {
|
||||
icon: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] format a guild's banner url",
|
||||
fn: () => {
|
||||
assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildBannerURL(613425648685547541n, {
|
||||
banner: 3919584870146358272366452115178209474142n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] format a guild's splash url",
|
||||
fn: () => {
|
||||
assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildSplashURL(785384884197392384n, {
|
||||
splash: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { ChannelTypes } from "../../../src/types/channels/channelTypes.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function categoryChildrenTest(guildId: bigint) {
|
||||
const category = await bot.helpers.createChannel(guildId, {
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildCategory,
|
||||
@@ -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,41 +0,0 @@
|
||||
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) {
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "Discordeno-test",
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: bot.id,
|
||||
type: OverwriteTypes.Member,
|
||||
allow: ["VIEW_CHANNEL"],
|
||||
deny: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Assertions
|
||||
assertExists(channel);
|
||||
assertEquals(channel.type, ChannelTypes.GuildText);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.cache.channels.has(channel.id));
|
||||
|
||||
if (!bot.cache.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"]
|
||||
),
|
||||
true
|
||||
);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { DiscordenoChannel } from "../../../src/transformers/channel.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function cloneChannelTests(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
channel: DiscordenoChannel,
|
||||
options: { reason?: string },
|
||||
t: Deno.TestContext
|
||||
) {
|
||||
const cloned = await bot.helpers.cloneChannel(channel, options.reason);
|
||||
|
||||
//Assertations
|
||||
assertExists(cloned);
|
||||
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));
|
||||
|
||||
assertExists(bot.cache.channels.has(cloned.id));
|
||||
assertEquals(channel.topic, cloned.topic);
|
||||
assertEquals(channel.bitrate, cloned.bitrate);
|
||||
assertEquals(channel.permissionOverwrites.length, cloned.permissionOverwrites.length);
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/createGuildChannel.ts";
|
||||
import { ChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { bot } from "../../mod.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(
|
||||
guildId: bigint,
|
||||
options: CreateGuildChannel,
|
||||
autoDelete: boolean,
|
||||
) {
|
||||
const channel = await bot.helpers.createChannel(guildId, options);
|
||||
|
||||
// Assertions
|
||||
@@ -12,9 +16,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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Channel } from "../../../src/types/channels/channel.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../src/types/util.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteChannelTests(bot: Bot, guildId: bigint, options: { reason?: string }, t: Deno.TestContext) {
|
||||
export async function deleteChannelTests(guildId: bigint, options: { reason?: string }) {
|
||||
// Create the necessary channels
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
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,9 @@
|
||||
import { Bot, createChannel, ChannelTypes, channelOverwriteHasPermission, OverwriteTypes } from "../../../mod.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { ChannelTypes, OverwriteTypes } from "../../../mod.ts";
|
||||
import { assertExists, assertEquals, channelOverwriteHasPermission } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteChannelOverwriteTests(bot: Bot<Cache>, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function deleteChannelOverwriteTests(guildId: bigint) {
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "Discordeno-test",
|
||||
permissionOverwrites: [
|
||||
@@ -21,29 +21,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 { bot } from "../../mod.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(guildId: bigint, options: { reason?: string }) {
|
||||
// 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");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function createEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function createEmojiTest(guildId: bigint) {
|
||||
const emoji = await bot.helpers.createEmoji(guildId, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
@@ -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,25 +13,25 @@ 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.");
|
||||
// }
|
||||
}
|
||||
|
||||
export async function deleteEmojiWithReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function deleteEmojiWithReasonTest(guildId: bigint) {
|
||||
await ifItFailsBlameWolf(bot, guildId);
|
||||
}
|
||||
|
||||
export async function deleteEmojiWithoutReasonTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function deleteEmojiWithoutReasonTest(guildId: bigint) {
|
||||
await ifItFailsBlameWolf(bot, guildId, "with a reason");
|
||||
}
|
||||
|
||||
@@ -2,6 +2,4 @@ import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function editEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
|
||||
}
|
||||
export async function editEmojiTest(guildId: bigint) {}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function getEmojiTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getEmojiTest(guildId: bigint) {
|
||||
const emoji = await bot.helpers.createEmoji(guildId, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
@@ -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.");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function getEmojisTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getEmojisTest(guildId: bigint) {
|
||||
const emoji = await bot.helpers.createEmoji(guildId, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
@@ -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.");
|
||||
// }
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/createGuildChannel.ts";
|
||||
import { ChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function createGuildTests(bot: Bot, t: Deno.TestContext) {
|
||||
export async function createGuildTests() {
|
||||
const guild = await bot.helpers.createGuild({
|
||||
name: "Isekai Maid Fake Server",
|
||||
});
|
||||
@@ -13,9 +11,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.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function deleteGuildTests(bot: Bot, t: Deno.TestContext) {
|
||||
export async function deleteGuildTests() {
|
||||
const guild = await bot.helpers.createGuild({
|
||||
name: "Isekai Maid Fake Server",
|
||||
});
|
||||
@@ -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.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
export async function editGuildTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function editGuildTests(guildId: bigint) {
|
||||
const guild = await bot.helpers.editGuild(
|
||||
guildId,
|
||||
{
|
||||
@@ -15,9 +14,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.`);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
export async function getAuditLogsTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getAuditLogsTests(guildId: bigint) {
|
||||
const logs = await bot.helpers.getAuditLogs(guildId);
|
||||
|
||||
// Assertions
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
export async function getAvailableVoiceRegionsTests(bot: Bot, t: Deno.TestContext) {
|
||||
export async function getAvailableVoiceRegionsTests() {
|
||||
const regions = await bot.helpers.getAvailableVoiceRegions();
|
||||
|
||||
// Assertions
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
export async function getBanTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getBanTests(guildId: bigint) {
|
||||
await bot.helpers.banMember(guildId, 379643682984296448n);
|
||||
|
||||
const fetchedBan = await bot.helpers.getBan(guildId, 379643682984296448n);
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { CreateGuildChannel } from "../../../src/types/guilds/createGuildChannel.ts";
|
||||
import { ChannelTypes } from "../../../src/types/mod.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { getAvailableVoiceRegions } from "../../../src/helpers/guilds/getAvailableVoiceRegions.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
export async function getBansTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getBansTests(guildId: bigint) {
|
||||
await bot.helpers.banMember(guildId, 416477607966670869n);
|
||||
await bot.helpers.banMember(guildId, 635383782576357407n);
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
export async function getGuildTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getGuildTests(guildId: bigint) {
|
||||
const fetchedGuild = await bot.helpers.getGuild(guildId);
|
||||
|
||||
// Assertions
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists, assertEquals } from "../../deps.ts";
|
||||
|
||||
export async function getVanityURLTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function getVanityURLTests(guildId: bigint) {
|
||||
// TODO: VANITY IS BROKEN ATM FROM DISCORDS SIDE
|
||||
return;
|
||||
// const fetchedVanityURL = await bot.helpers.getVanityURL(guildId);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Bot } from "../../../../src/bot.ts";
|
||||
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../../src/types/guilds/scheduledEvents.ts";
|
||||
|
||||
export async function deleteScheduledEventTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
|
||||
}
|
||||
export async function deleteScheduledEventTests(guildId: bigint) {}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { Bot } from "../../../../src/bot.ts";
|
||||
import { ChannelTypes } from "../../../../src/types/channels/channelTypes.ts";
|
||||
import { CreateScheduledEvent, ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../../src/types/guilds/scheduledEvents.ts";
|
||||
import {
|
||||
ScheduledEventEntityType,
|
||||
ScheduledEventPrivacyLevel,
|
||||
} from "../../../../src/types/guilds/scheduledEvents.ts";
|
||||
import { assertEquals } from "../../../deps.ts";
|
||||
import { bot } from "../../../mod.ts";
|
||||
|
||||
export async function editScheduledEventTests(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
export async function editScheduledEventTests(guildId: bigint) {
|
||||
const channel = await bot.helpers.createChannel(guildId, {
|
||||
name: "entity",
|
||||
type: ChannelTypes.GuildStageVoice,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
|
||||
export async function createInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function createInviteTest(channelId: bigint) {
|
||||
const invite = await bot.helpers.createInvite(channelId, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
|
||||
export async function deleteInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function deleteInviteTest(channelId: bigint) {
|
||||
const invite = await bot.helpers.createInvite(channelId, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
|
||||
export async function getChannelInvitesTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function getChannelInvitesTest(channelId: bigint) {
|
||||
const invite = await bot.helpers.createInvite(channelId, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
|
||||
export async function getInviteTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function getInviteTest(channelId: bigint) {
|
||||
const invite = await bot.helpers.createInvite(channelId, {
|
||||
maxAge: 86400,
|
||||
maxUses: 0,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
|
||||
export async function fetchSingleMemberTest(bot: Bot, guildId: bigint, t: Deno.TestContext) {
|
||||
|
||||
}
|
||||
export async function fetchSingleMemberTest(guildId: bigint) {}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) {
|
||||
async function ifItFailsBlameWolf(channelId: bigint, reason?: string) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// 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,17 +18,17 @@ 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.");
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteMessageWithoutReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId);
|
||||
export async function deleteMessageWithoutReasonTest(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId);
|
||||
}
|
||||
|
||||
export async function deleteMessageWithReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId, "with a reason");
|
||||
export async function deleteMessageWithReasonTest(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId, "with a reason");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) {
|
||||
async function ifItFailsBlameWolf(channelId: bigint, reason?: string) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!");
|
||||
|
||||
@@ -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,17 +20,17 @@ 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.");
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteMessagesWithoutReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId);
|
||||
export async function deleteMessagesWithoutReasonTest(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId);
|
||||
}
|
||||
|
||||
export async function deleteMessagesWithReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId, "with a reason");
|
||||
export async function deleteMessagesWithReasonTest(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId, "with a reason");
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function editMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function editMessageTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// 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.");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function getMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function getMessageTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// 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}");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function getMessagesTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function getMessagesTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!");
|
||||
const thirdMessage = await bot.helpers.sendMessage(channelId, "Hello World 3!");
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertEquals } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
export async function pinMessageTests(bot: Bot, channelId: bigint, messageId: bigint, t: Deno.TestContext) {
|
||||
export async function pinMessageTests(channelId: bigint, messageId: bigint) {
|
||||
let pinned = false;
|
||||
|
||||
bot.events.channelPinsUpdate = function (bot, payload) {
|
||||
bot.events.channelPinsUpdate = function (_, payload) {
|
||||
if (payload.channelId === channelId) pinned = !pinned;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertEquals, assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
|
||||
const reactionCounters = new Map<bigint, number>();
|
||||
|
||||
export async function addReactionTest(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
options: { custom: boolean; single: boolean; ordered: boolean },
|
||||
t: Deno.TestContext
|
||||
options: { custom: boolean; single: boolean; ordered: boolean }
|
||||
) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
@@ -17,9 +16,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.");
|
||||
}
|
||||
|
||||
@@ -76,16 +75,16 @@ export async function addReactionTest(
|
||||
assertEquals(reactionCounters.get(message.id), options.single ? 1 : emojiIds.length);
|
||||
}
|
||||
|
||||
export async function removeAllReactionTests(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function removeAllReactionTests(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
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.");
|
||||
}
|
||||
|
||||
@@ -117,16 +116,16 @@ export async function removeAllReactionTests(bot: Bot, channelId: bigint, t: Den
|
||||
assertEquals(reactionCounters.get(message.id), 0);
|
||||
}
|
||||
|
||||
export async function removeReactionTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function removeReactionTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
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.");
|
||||
}
|
||||
|
||||
@@ -159,22 +158,22 @@ export async function removeReactionTest(bot: Bot, channelId: bigint, t: Deno.Te
|
||||
assertEquals(reactionCounters.get(message.id), 2);
|
||||
}
|
||||
|
||||
export async function removeReactionEmojiTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
export async function removeReactionEmojiTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
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);
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { delayUntil } from "../../utils.ts";
|
||||
import { CreateMessage } from "../../../src/types/messages/createMessage.ts";
|
||||
import { MessageComponentTypes } from "../../../src/types/messages/components/messageComponentTypes.ts";
|
||||
import { ButtonStyles } from "../../../src/types/messages/components/buttonStyles.ts";
|
||||
import { bot } from "../../mod.ts";
|
||||
|
||||
async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, content: string | CreateMessage) {
|
||||
async function ifItFailsBlameWolf(channelId: bigint, content: string | CreateMessage) {
|
||||
const message = await bot.helpers.sendMessage(channelId, content);
|
||||
// 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.");
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendMessageWithTextTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId, "Hello World!");
|
||||
export async function sendMessageWithTextTest(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId, "Hello World!");
|
||||
}
|
||||
|
||||
export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId, {
|
||||
export async function sendMessageWithComponents(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId, {
|
||||
content: "Hello World!",
|
||||
components: [
|
||||
{
|
||||
@@ -57,8 +57,8 @@ export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t:
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendMessageWithEmbedsTest(bot: Bot, channelId: bigint, t: Deno.TestContext) {
|
||||
await ifItFailsBlameWolf(bot, channelId, {
|
||||
export async function sendMessageWithEmbedsTest(channelId: bigint) {
|
||||
await ifItFailsBlameWolf(channelId, {
|
||||
embeds: [
|
||||
{
|
||||
title: "Hello World",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
|
||||
export async function getUserTests(bot: Bot, t: Deno.TestContext) {
|
||||
export async function getUserTests() {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
import { Bot } from "../../../src/bot.ts";
|
||||
import { Cache } from "../../../src/cache.ts";
|
||||
import { assertExists } from "../../deps.ts";
|
||||
import { bot } from "../../mod.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(guildId: bigint, options: { reason?: string }) {
|
||||
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(guildId: bigint) {
|
||||
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(guildId: bigint) {
|
||||
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}`)));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { assertEquals } from "../deps.ts";
|
||||
import { bot, guild } from "../mod.ts";
|
||||
|
||||
Deno.test("[misc] edit a bot's nickname", async function () {
|
||||
const nick = "lts20050703";
|
||||
const nickname = await bot.helpers.editBotNickname(guild.id, { nick });
|
||||
assertEquals(nickname, nick);
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { bot } from "../mod.ts";
|
||||
|
||||
Deno.test("[member] get dm channel and send a message", async () => {
|
||||
// Skillz ID
|
||||
const channel = await bot.helpers.getDmChannel(130136895395987456n);
|
||||
// Itoh Alt ID
|
||||
const channel = await bot.helpers.getDmChannel(750661528360845322n);
|
||||
await bot.helpers.sendMessage(channel.id, "https://i.imgur.com/doG55NR.png");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
import { Bot } from "../../mod.ts";
|
||||
import { reactionCounters } from "../constants.ts";
|
||||
import { assertExists, assertEquals } from "../deps.ts";
|
||||
// import {
|
||||
// addReactionTest,
|
||||
// removeReactionTest,
|
||||
// removeAllReactionTests,
|
||||
// removeReactionEmojiTest,
|
||||
// } from "../helpers/messages/reactions.ts";
|
||||
import { bot, guild, channel } from "../mod.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
export async function addReactionTest(
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
options: { custom: boolean; single: boolean; ordered: boolean },
|
||||
) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.messages.has(message.id));
|
||||
|
||||
if (!bot.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
|
||||
let emojiId = "❤";
|
||||
let emojiIds = ["❤", "😃"];
|
||||
|
||||
if (options.custom) {
|
||||
if (options.single) {
|
||||
emojiId = `<:blamewolf:${
|
||||
(
|
||||
await bot.helpers.createEmoji(guildId, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
// roles: [],
|
||||
})
|
||||
).id
|
||||
}>`;
|
||||
} else {
|
||||
emojiIds = [
|
||||
`<:blamewolf:${
|
||||
(
|
||||
await bot.helpers.createEmoji(guildId, {
|
||||
name: "blamewolf",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
// roles: [],
|
||||
})
|
||||
).id
|
||||
}>`,
|
||||
`<:blamewolf2:${
|
||||
(
|
||||
await bot.helpers.createEmoji(guildId, {
|
||||
name: "blamewolf2",
|
||||
image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
|
||||
// roles: [],
|
||||
})
|
||||
).id
|
||||
}>`,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
reactionCounters.set(message.id, 0);
|
||||
|
||||
bot.events.reactionAdd = function (bot, payload) {
|
||||
const current = reactionCounters.get(payload.messageId) || 0;
|
||||
reactionCounters.set(payload.messageId, current + 1);
|
||||
};
|
||||
|
||||
if (options.single) await bot.helpers.addReaction(message.channelId, message.id, emojiId);
|
||||
else await bot.helpers.addReactions(message.channelId, message.id, emojiIds, options.ordered);
|
||||
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === (options.single ? 1 : emojiIds.length));
|
||||
|
||||
assertEquals(reactionCounters.get(message.id), options.single ? 1 : emojiIds.length);
|
||||
}
|
||||
|
||||
export async function removeAllReactionTests(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.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.reactionRemoveAll = function (_, payload) {
|
||||
reactionCounters.set(payload.messageId, 0);
|
||||
};
|
||||
|
||||
bot.events.reactionAdd = function (_, payload) {
|
||||
const current = reactionCounters.get(payload.messageId) || 0;
|
||||
reactionCounters.set(payload.messageId, current + 1);
|
||||
};
|
||||
|
||||
// Add reactions to the message
|
||||
await bot.helpers.addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === 3);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(reactionCounters.get(message.id), 3);
|
||||
|
||||
await bot.helpers.removeAllReactions(message.channelId, message.id);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === 0);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(reactionCounters.get(message.id), 0);
|
||||
}
|
||||
|
||||
export async function removeReactionTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.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.reactionRemove = function (bot, payload) {
|
||||
const current = reactionCounters.get(message.id);
|
||||
reactionCounters.set(payload.messageId, (current || 0) - 1);
|
||||
};
|
||||
|
||||
bot.events.reactionAdd = function (bot, payload) {
|
||||
const current = reactionCounters.get(payload.messageId) || 0;
|
||||
reactionCounters.set(payload.messageId, current + 1);
|
||||
};
|
||||
|
||||
// Add reactions to the message
|
||||
await bot.helpers.addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === 3);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(reactionCounters.get(message.id), 3);
|
||||
|
||||
await bot.helpers.removeReaction(message.channelId, message.id, "😃");
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === 2);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(reactionCounters.get(message.id), 2);
|
||||
}
|
||||
|
||||
export async function removeReactionEmojiTest(channelId: bigint) {
|
||||
const message = await bot.helpers.sendMessage(channelId, "Hello World!");
|
||||
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => bot.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.reactionRemoveEmoji = function (bot, payload) {
|
||||
reactionCounters.set(payload.messageId, 0);
|
||||
};
|
||||
|
||||
bot.events.reactionAdd = function (bot, payload) {
|
||||
const current = reactionCounters.get(payload.messageId) || 0;
|
||||
reactionCounters.set(payload.messageId, current + 1);
|
||||
};
|
||||
|
||||
// Add reactions to the message
|
||||
await bot.helpers.addReactions(message.channelId, message.id, ["❤", "😃"]);
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === 2);
|
||||
|
||||
// Be sure that the message has the reactions
|
||||
assertEquals(reactionCounters.get(message.id), 2);
|
||||
|
||||
await bot.helpers.removeReactionEmoji(message.channelId, message.id, "😃");
|
||||
|
||||
// Delay the execution to allow event to be processed
|
||||
await delayUntil(10000, () => reactionCounters.get(message.id) === 0);
|
||||
|
||||
// Check if the reactions has been deleted
|
||||
assertEquals(reactionCounters.get(message.id), 0);
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "[message] add a reaction",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(guild.id, channel.id, { custom: false, single: true, ordered: false });
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add a custom reaction",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(guild.id, channel.id, { custom: true, single: true, ordered: false });
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple reactions",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(guild.id, channel.id, { custom: false, single: false, ordered: false });
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple custom reactions",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(guild.id, channel.id, { custom: true, single: false, ordered: false });
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple reactions in order",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(guild.id, channel.id, { custom: false, single: false, ordered: true });
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple custom reactions in order",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(guild.id, channel.id, { custom: true, single: false, ordered: true });
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] remove a reaction.",
|
||||
fn: async (t) => {
|
||||
await removeReactionTest(channel.id);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] remove all reactions.",
|
||||
fn: async (t) => {
|
||||
await removeAllReactionTests(channel.id);
|
||||
},
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] remove emoji reactions.",
|
||||
fn: async (t) => {
|
||||
await removeReactionEmojiTest(channel.id);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import { assertExists } from "../deps.ts";
|
||||
import { bot } from "../mod.ts";
|
||||
import { ActivityTypes } from "../../src/types/activity/activityTypes.ts";
|
||||
import { delayUntil } from "../utils.ts";
|
||||
|
||||
Deno.test("[misc] edit the bot's status", async function () {
|
||||
bot.events.presenceUpdate = function (_bot, presense, _oldPresense) {
|
||||
console.log('in pu')
|
||||
console.log('in pu')
|
||||
assertExists(presense);
|
||||
};
|
||||
|
||||
bot.events.botUpdate = function (bot, user) {
|
||||
console.log('in bu')
|
||||
console.log('in bu')
|
||||
}
|
||||
|
||||
bot.helpers.editBotStatus({
|
||||
status: "dnd",
|
||||
activities: [{ name: "lts20050703", type: ActivityTypes.Game, createdAt: Date.now() }],
|
||||
});
|
||||
|
||||
await delayUntil(10000, () => false)
|
||||
});
|
||||
+61
-314
@@ -30,8 +30,6 @@ import { getBansTests } from "./helpers/guilds/getBans.ts";
|
||||
import { getGuildTests } from "./helpers/guilds/getGuild.ts";
|
||||
import { getVanityURLTests } from "./helpers/guilds/getVanityUrl.ts";
|
||||
import { categoryChildrenTest } from "./helpers/channels/categoryChannels.ts";
|
||||
import { channelOverwriteHasPermissionTest } from "./helpers/channels/channelOverwriteHasPermission.ts";
|
||||
import { cloneChannelTests } from "./helpers/channels/cloneChannel.ts";
|
||||
import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOverwrite.ts";
|
||||
import { editChannelTests } from "./helpers/channels/editChannel.ts";
|
||||
import { CACHED_COMMUNITY_GUILD_ID, sanitizeMode } from "./constants.ts";
|
||||
@@ -41,7 +39,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,14 +57,13 @@ export const bot = createBot({
|
||||
"GuildMembers",
|
||||
"GuildScheduledEvents",
|
||||
"GuildVoiceStates",
|
||||
"GuildPresences",
|
||||
],
|
||||
cache: {
|
||||
isAsync: false,
|
||||
},
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
enableCachePlugin(bot);
|
||||
export const bot = enableCachePlugin(baseBot);
|
||||
// @ts-ignore
|
||||
await startBot(bot);
|
||||
|
||||
// Delay the execution to allow READY events to be processed
|
||||
@@ -74,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);
|
||||
@@ -93,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()}`);
|
||||
}
|
||||
|
||||
@@ -110,105 +107,66 @@ export const message = await bot.helpers.sendMessage(channel.id, "Hello Skillz")
|
||||
|
||||
import "./benchmark.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] format a guild's icon url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildIconURL(785384884197392384n, {
|
||||
icon: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] format a guild's banner url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildBannerURL(613425648685547541n, {
|
||||
banner: 3919584870146358272366452115178209474142n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] format a guild's splash url",
|
||||
fn: async (t) => {
|
||||
assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined);
|
||||
assertEquals(
|
||||
bot.helpers.guildSplashURL(785384884197392384n, {
|
||||
splash: 3837424427068676005442449262648382018748n,
|
||||
}),
|
||||
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] create a guild",
|
||||
fn: async (t) => {
|
||||
await createGuildTests(bot, t);
|
||||
await createGuildTests();
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] delete a guild",
|
||||
fn: async (t) => {
|
||||
await deleteGuildTests(bot, t);
|
||||
await deleteGuildTests();
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] edit a guild",
|
||||
fn: async (t) => {
|
||||
await editGuildTests(bot, guild.id, t);
|
||||
await editGuildTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] get audit logs",
|
||||
fn: async (t) => {
|
||||
await getAuditLogsTests(bot, guild.id, t);
|
||||
await getAuditLogsTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] get available voice regions",
|
||||
fn: async (t) => {
|
||||
await getAvailableVoiceRegionsTests(bot, t);
|
||||
await getAvailableVoiceRegionsTests();
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] get a ban",
|
||||
fn: async (t) => {
|
||||
await getBanTests(bot, guild.id, t);
|
||||
await getBanTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] get bans",
|
||||
fn: async (t) => {
|
||||
await getBansTests(bot, guild.id, t);
|
||||
await getBansTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] get guilds",
|
||||
fn: async (t) => {
|
||||
await getGuildTests(bot, guild.id, t);
|
||||
await getGuildTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[guild] get vanity url",
|
||||
fn: async (t) => {
|
||||
await getVanityURLTests(bot, guild.id, t);
|
||||
await getVanityURLTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
@@ -216,140 +174,78 @@ Deno.test({
|
||||
Deno.test({
|
||||
name: "[message] send message with text",
|
||||
fn: async (t) => {
|
||||
await sendMessageWithTextTest(bot, channel.id, t);
|
||||
await sendMessageWithTextTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] send message with embeds",
|
||||
fn: async (t) => {
|
||||
await sendMessageWithEmbedsTest(bot, channel.id, t);
|
||||
await sendMessageWithEmbedsTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] send message with components",
|
||||
fn: async (t) => {
|
||||
await sendMessageWithComponents(bot, channel.id, t);
|
||||
await sendMessageWithComponents(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] edit message",
|
||||
fn: async (t) => {
|
||||
await editMessageTest(bot, channel.id, t);
|
||||
await editMessageTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] delete message without a reason",
|
||||
fn: async (t) => {
|
||||
await deleteMessageWithoutReasonTest(bot, channel.id, t);
|
||||
await deleteMessageWithoutReasonTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] delete message with a reason",
|
||||
fn: async (t) => {
|
||||
await deleteMessageWithReasonTest(bot, channel.id, t);
|
||||
await deleteMessageWithReasonTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] delete messages without a reason",
|
||||
fn: async (t) => {
|
||||
await deleteMessagesWithoutReasonTest(bot, channel.id, t);
|
||||
await deleteMessagesWithoutReasonTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] delete messages with a reason",
|
||||
fn: async (t) => {
|
||||
await deleteMessagesWithReasonTest(bot, channel.id, t);
|
||||
await deleteMessagesWithReasonTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] fetch a message",
|
||||
fn: async (t) => {
|
||||
await getMessageTest(bot, channel.id, t);
|
||||
await getMessageTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] fetch messages",
|
||||
fn: async (t) => {
|
||||
await getMessagesTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add a reaction",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add a custom reaction",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple reactions",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple custom reactions",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple reactions in order",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] add multiple custom reactions in order",
|
||||
fn: async (t) => {
|
||||
await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] remove a reaction.",
|
||||
fn: async (t) => {
|
||||
await removeReactionTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] remove all reactions.",
|
||||
fn: async (t) => {
|
||||
await removeAllReactionTests(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[message] remove emoji reactions.",
|
||||
fn: async (t) => {
|
||||
await removeReactionEmojiTest(bot, channel.id, t);
|
||||
await getMessagesTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[message] pin a message",
|
||||
fn: async (t) => {
|
||||
await pinMessageTests(bot, channel.id, message.id, t);
|
||||
await pinMessageTests(channel.id, message.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
@@ -357,218 +253,51 @@ Deno.test({
|
||||
Deno.test({
|
||||
name: "[channel] send message with text",
|
||||
fn: async (t) => {
|
||||
await sendMessageWithTextTest(bot, channel.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(bot, guild.id, { name: "Discordeno-test" }, false, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new category channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildCategory,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new news channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
CACHED_COMMUNITY_GUILD_ID,
|
||||
{ name: "Discordeno-test", type: ChannelTypes.GuildNews },
|
||||
true,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new voice channel",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new voice channel with a bitrate",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
name: "discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
bitrate: 32000,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new voice channel with a user limit",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
type: ChannelTypes.GuildVoice,
|
||||
userLimit: 32,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel with a rate limit per user",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
rateLimitPerUser: 2423,
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel with NSFW",
|
||||
async fn(t) {
|
||||
await createChannelTests(bot, guild.id, { name: "Discordeno-test", nsfw: true }, false, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] create a new text channel with permission overwrites",
|
||||
async fn(t) {
|
||||
await createChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
name: "Discordeno-test",
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: bot.id,
|
||||
type: OverwriteTypes.Member,
|
||||
allow: ["VIEW_CHANNEL"],
|
||||
deny: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
false,
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel with a reason",
|
||||
async fn(t) {
|
||||
await deleteChannelTests(
|
||||
bot,
|
||||
guild.id,
|
||||
{
|
||||
reason: "with a reason",
|
||||
},
|
||||
t
|
||||
);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel without a reason",
|
||||
async fn(t) {
|
||||
await deleteChannelTests(bot, guild.id, {}, t);
|
||||
await sendMessageWithTextTest(channel.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
|
||||
|
||||
Deno.test({
|
||||
name: "[channel] filter all category channels",
|
||||
async fn(t) {
|
||||
await categoryChildrenTest(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] edit a channel permission overwrite",
|
||||
async fn(t) {
|
||||
await channelOverwriteHasPermissionTest(bot, guild.id, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] clone a channel w/o a reason",
|
||||
async fn(t) {
|
||||
await cloneChannelTests(bot, guild.id, channel, {}, t);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] clone a channel w/ a reason",
|
||||
async fn(t) {
|
||||
await cloneChannelTests(bot, guild.id, channel, { reason: "Blame wolf" }, t);
|
||||
await categoryChildrenTest(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] delete a channel overwrite",
|
||||
async fn(t) {
|
||||
await deleteChannelOverwriteTests(bot, guild.id, t);
|
||||
await deleteChannelOverwriteTests(guild.id);
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] edit a channel w/o a reason",
|
||||
async fn(t) {
|
||||
await editChannelTests(bot, guild.id, {}, t);
|
||||
await editChannelTests(guild.id, {});
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
Deno.test({
|
||||
name: "[channel] edit a channel w/ a reason",
|
||||
async fn(t) {
|
||||
await editChannelTests(bot, guild.id, { reason: "Blame wolf" }, t);
|
||||
await editChannelTests(guild.id, { reason: "Blame wolf" });
|
||||
},
|
||||
...sanitizeMode,
|
||||
});
|
||||
|
||||
// channels
|
||||
import "./channels/connectToVoice.ts";
|
||||
import "./channels/createChannel.ts";
|
||||
import "./channels/deleteChannel.ts";
|
||||
import "./channels/getChannel.ts";
|
||||
import "./channels/getChannels.ts";
|
||||
import "./channels/stageInstances.ts";
|
||||
import "./channels/threads.ts";
|
||||
|
||||
// emoji
|
||||
import "./emoji/createEmoji.ts";
|
||||
import "./emoji/deleteEmojiWithReason.ts";
|
||||
import "./emoji/deleteEmojiWithoutReason.ts";
|
||||
@@ -576,15 +305,28 @@ import "./emoji/editEmoji.ts";
|
||||
import "./emoji/emojiUrl.ts";
|
||||
import "./emoji/getEmoji.ts";
|
||||
import "./emoji/getMultipleEmojis.ts";
|
||||
|
||||
// guilds
|
||||
import "./guilds/urls.ts";
|
||||
|
||||
// invite
|
||||
import "./invite/createInvite.ts";
|
||||
import "./invite/deleteInvite.ts";
|
||||
import "./invite/getChannelInvites.ts";
|
||||
import "./invite/getInvite.ts";
|
||||
import "./invite/getInvites.ts";
|
||||
|
||||
// members
|
||||
import "./members/avatarlUrl.ts";
|
||||
import "./members/ban.ts";
|
||||
import "./members/editBotNickname.ts";
|
||||
import "./members/getDmChannel.ts";
|
||||
import "./members/getMember.ts";
|
||||
|
||||
// messages
|
||||
import "./messages/reactions.ts";
|
||||
|
||||
// misc
|
||||
import "./misc/getApplicationInfo.ts";
|
||||
import "./misc/getDiscoveryCategories.ts";
|
||||
import "./misc/getUser.ts";
|
||||
@@ -592,6 +334,9 @@ import "./misc/getVoiceRegions.ts";
|
||||
import "./misc/snowflake.ts";
|
||||
import "./misc/typing.ts";
|
||||
import "./misc/validateDiscovery.ts";
|
||||
import "./misc/editBotStatus.ts";
|
||||
|
||||
// role
|
||||
import "./role/addRole.ts";
|
||||
import "./role/createRoleWithoutReason.ts";
|
||||
import "./role/createRoleWithReason.ts";
|
||||
@@ -600,6 +345,8 @@ import "./role/deleteRoleWithReason.ts";
|
||||
import "./role/editRole.ts";
|
||||
import "./role/getAllRoles.ts";
|
||||
import "./role/removeRole.ts";
|
||||
|
||||
// scheduledEvents
|
||||
import "./scheduledEvents/createExternalEventWithEndtime.ts";
|
||||
import "./scheduledEvents/createExternalEventWithoutEndtime.ts";
|
||||
import "./scheduledEvents/createStageEventWithEndtime.ts";
|
||||
@@ -608,10 +355,10 @@ import "./scheduledEvents/createVoiceEventWithEndtime.ts";
|
||||
import "./scheduledEvents/createVoiceEventWithoutEndtime.ts";
|
||||
import "./scheduledEvents/deleteEvent.ts";
|
||||
import "./scheduledEvents/editEvent.ts";
|
||||
|
||||
// webhooks
|
||||
import "./webhooks/deleteWebhook.ts";
|
||||
import "./webhooks/deleteWebhookWithToken.ts";
|
||||
import "./webhooks/sendWebhook.ts";
|
||||
import "./webhooks/webhooks.ts";
|
||||
// await bot.helpers.deleteGuild(guild.id);
|
||||
|
||||
// await stopBot(bot);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,15 +6,15 @@ import { delayUntil } from "../utils.ts";
|
||||
Deno.test({
|
||||
name: "[Role] create a role with a reason",
|
||||
fn: async (t) => {
|
||||
await createRoleTests(bot, guild.id, { reason: "Blame wolfy" }, t);
|
||||
await createRoleTests(guild.id, { reason: "Blame wolfy" });
|
||||
|
||||
const role = await bot.helpers.createRole(guild.id, { name: "hoti" }, "Blame wolfy");
|
||||
|
||||
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));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,15 +6,15 @@ import { delayUntil } from "../utils.ts";
|
||||
Deno.test({
|
||||
name: "[Role] create a role without a reason",
|
||||
fn: async (t) => {
|
||||
await createRoleTests(bot, guild.id, {}, t);
|
||||
await createRoleTests(guild.id, {});
|
||||
|
||||
const role = await bot.helpers.createRole(guild.id, { name: "hoti" });
|
||||
|
||||
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