mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
shtuff
This commit is contained in:
+29
-10
@@ -1,24 +1,41 @@
|
||||
// import { TOKEN } from "../configs.ts";
|
||||
import { Bot, createBot, createEventHandlers, DiscordChannelTypes, startBot, stopBot } from "../mod.ts";
|
||||
import { createBot, createEventHandlers, DiscordChannelTypes, startBot, stopBot } from "../mod.ts";
|
||||
import { assertEquals, assertExists } from "./deps.ts";
|
||||
import { delayUntil } from "./utils.ts";
|
||||
|
||||
Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
let startedAt = 0;
|
||||
const bot = createBot({
|
||||
// token: TOKEN || Deno.env.get("DISCORD_TOKEN"),
|
||||
token: Deno.env.get("DISCORD_TOKEN")!,
|
||||
botId: 675412054529540107n,
|
||||
botId: 770381961553510451n,
|
||||
events: createEventHandlers({
|
||||
// debug: console.log,
|
||||
ready: () => {
|
||||
startedAt = Date.now();
|
||||
},
|
||||
debug: console.log,
|
||||
}),
|
||||
intents: [],
|
||||
}) as Bot;
|
||||
cache: {
|
||||
isAsync: false,
|
||||
},
|
||||
});
|
||||
|
||||
await startBot(bot);
|
||||
// Delay the execution to allow READY events to be processed
|
||||
await delayUntil(3000, () => true);
|
||||
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 (guild.ownerId === bot.id) await bot.helpers.deleteGuild(bot, guild.id);
|
||||
})
|
||||
}
|
||||
|
||||
// Delay the execution to allow delete guilds to be processed
|
||||
await delayUntil(10000, () => Boolean(startedAt));
|
||||
|
||||
// CREATE ONE GUILD SO WE CAN REUSE LATER TO SAVE RATE LIMITS
|
||||
const guild = await bot.helpers.createGuild(bot, { name: "Discordeno Test" });
|
||||
|
||||
@@ -27,13 +44,14 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
assertExists(guild.id);
|
||||
|
||||
// Delay the execution to allow GUILD_CREATE event to be processed
|
||||
await delayUntil(10000, async () => await bot.cache.guilds.has(guild.id));
|
||||
await delayUntil(10000, () => bot.cache.guilds.has(guild.id));
|
||||
|
||||
// FINAL CHECK TO THROW IF MISSING STILL
|
||||
if (!(await bot.cache.guilds.has(guild.id))) {
|
||||
if (!bot.cache.guilds.has(guild.id)) {
|
||||
throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`);
|
||||
}
|
||||
|
||||
// CHANNEL TESTS GROUPED
|
||||
await t.step("Channel related tests", async (t) => {
|
||||
const channel = await bot.helpers.createChannel(bot, guild.id, { name: "Discordeno-test" });
|
||||
|
||||
@@ -41,16 +59,17 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
|
||||
assertExists(channel);
|
||||
assertEquals(channel.type, DiscordChannelTypes.GuildText);
|
||||
|
||||
// ALL MESSAGE RELATED TESTS THAT DEPEND ON AN EXISTING CHANNEL
|
||||
await t.step("Message related tests", async (t) => {
|
||||
const message = await bot.helpers.sendMessage(bot, channel.id, "Testing");
|
||||
|
||||
// Assertions
|
||||
assertExists(message);
|
||||
|
||||
// Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, async () => await bot.cache.messages.has(message.id));
|
||||
// Delay the execution to allow MESSAGE_CREATE event to be processed
|
||||
await delayUntil(10000, () => bot.cache.messages.has(message.id));
|
||||
|
||||
if (!(await bot.cache.messages.has(message.id))) {
|
||||
if (!bot.cache.messages.has(message.id)) {
|
||||
throw new Error("The message seemed to be sent but it was not cached.");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user