diff --git a/src/transformers/voiceRegion.ts b/src/transformers/voiceRegion.ts index 7424d95d7..987220051 100644 --- a/src/transformers/voiceRegion.ts +++ b/src/transformers/voiceRegion.ts @@ -4,7 +4,7 @@ import { VoiceRegion } from "../types/voice/voiceRegion.ts"; export function transformVoiceRegion(bot: Bot, payload: SnakeCasedPropertiesDeep): DiscordenoVoiceRegion { return { - id: bot.transformers.snowflake(payload.id), + id: payload.id, name: payload.name, optimal: payload.optimal, deprecated: payload.deprecated, @@ -13,8 +13,8 @@ export function transformVoiceRegion(bot: Bot, payload: SnakeCasedPropertiesDeep } export interface DiscordenoVoiceRegion { - /** Unique Id for the region */ - id: bigint; + /** Id for the region. This is in the form of like us-west and not a snowflake id. */ + id: string; /** Name of the region */ name: string; /** true for a single server that is closest to the current user's client */ diff --git a/src/ws/handleOnMessage.ts b/src/ws/handleOnMessage.ts index 269fe87df..9a1984c2f 100644 --- a/src/ws/handleOnMessage.ts +++ b/src/ws/handleOnMessage.ts @@ -105,10 +105,12 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha gateway.loadingShards.get(shardId)?.resolve(true); gateway.loadingShards.delete(shardId); // Wait few seconds to spawn next shard - setTimeout(() => { - const bucket = gateway.buckets.get(shardId % gateway.maxConcurrency); - if (bucket) bucket.createNextShard.shift()?.(); - }, gateway.spawnShardDelay); + const bucket = gateway.buckets.get(shardId % gateway.maxConcurrency); + if (bucket?.createNextShard.length) { + setTimeout(() => { + bucket.createNextShard.shift()?.(); + }, gateway.spawnShardDelay); + } } // Update the sequence number if it is present @@ -149,7 +151,9 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha // ADD TO LOCAL CACHE FOR FUTURE EVENTS. gateway.cache.editedMessages.set(id, content); // REMOVE AFTER 10 SECONDS FROM CACHE - setTimeout(() => gateway.cache.editedMessages.delete(id), 10000); + setTimeout(() => { + gateway.cache.editedMessages.delete(id); + }, 10000); } } diff --git a/tests/deps.ts b/tests/deps.ts index 10d3a7f2e..1debc6dd2 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -7,6 +7,4 @@ export { assertThrows, assertThrowsAsync, } from "https://deno.land/std@0.115.1/testing/asserts.ts"; -export * from "https://deno.land/x/discordeno_cache_plugin@0.0.21/mod.ts"; -export * from "https://deno.land/x/discordeno_permissions_plugin@0.0.15/mod.ts"; export { config as dotenv } from "https://deno.land/x/dotenv@v3.2.0/mod.ts"; diff --git a/tests/helpers/channels/deleteChannelOverwrite.ts b/tests/helpers/channels/deleteChannelOverwrite.ts index 3d7820591..72bf0d4f0 100644 --- a/tests/helpers/channels/deleteChannelOverwrite.ts +++ b/tests/helpers/channels/deleteChannelOverwrite.ts @@ -1,5 +1,6 @@ import { ChannelTypes, OverwriteTypes } from "../../../mod.ts"; -import { assertEquals, assertExists, channelOverwriteHasPermission } from "../../deps.ts"; +import { channelOverwriteHasPermission } from "../../../plugins/permissions/src/permissions.ts"; +import { assertEquals, assertExists } from "../../deps.ts"; import { bot } from "../../mod.ts"; import { delayUntil } from "../../utils.ts"; diff --git a/tests/misc/editBotStatus.ts b/tests/misc/editBotStatus.ts index c1e7c6b23..b16c48d9d 100644 --- a/tests/misc/editBotStatus.ts +++ b/tests/misc/editBotStatus.ts @@ -5,14 +5,10 @@ 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({ diff --git a/tests/mod.ts b/tests/mod.ts index 5a36e1a02..c9b0a5fba 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -1,5 +1,6 @@ +import enableCachePlugin from "../plugins/cache/mod.ts"; import { ChannelTypes, createBot, createEventHandlers, startBot } from "../mod.ts"; -import { assertEquals, assertExists, dotenv, enableCachePlugin } from "./deps.ts"; +import { assertEquals, assertExists, dotenv } from "./deps.ts"; import { deleteMessageWithoutReasonTest, deleteMessageWithReasonTest } from "./helpers/messages/deleteMessage.ts"; import { getMessagesTest } from "./helpers/messages/getMessages.ts"; import { deleteMessagesWithoutReasonTest, deleteMessagesWithReasonTest } from "./helpers/messages/deleteMessages.ts"; @@ -9,9 +10,6 @@ import { sendMessageWithEmbedsTest, sendMessageWithTextTest, } from "./helpers/messages/sendMessage.ts"; - -// CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST -import "./local.ts"; import { getMessageTest } from "./helpers/messages/getMessage.ts"; import { editMessageTest } from "./helpers/messages/editMessage.ts"; import { pinMessageTests } from "./helpers/messages/pin.ts"; @@ -29,7 +27,7 @@ import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOve import { editChannelTests } from "./helpers/channels/editChannel.ts"; import { CACHED_COMMUNITY_GUILD_ID, sanitizeMode } from "./constants.ts"; -dotenv({ export: true }); +dotenv({ export: true, path: `${Deno.cwd()}/.env` }); let TOKEN = Deno.env.get("DISCORD_TOKEN"); if (!TOKEN) throw new Error("Token was not provided."); @@ -59,9 +57,7 @@ const baseBot = createBot({ ], }); -// @ts-ignore export const bot = enableCachePlugin(baseBot); -// @ts-ignore await startBot(bot); // Delay the execution to allow READY events to be processed @@ -79,6 +75,7 @@ if (bot.guilds.size <= 10) { // Delay the execution to allow delete guilds to be processed await delayUntil(10000, () => Boolean(startedAt)); +console.log("[SETUP] Preparing the guild where tests will be done."); // CREATE ONE GUILD SO WE CAN REUSE LATER TO SAVE RATE LIMITS export const guild = await bot.helpers.createGuild({ name: "Discordeno Test" }); @@ -92,18 +89,24 @@ await delayUntil(10000, () => bot.guilds.has(guild.id)); // FINAL CHECK TO THROW IF MISSING STILL if (!bot.guilds.has(guild.id)) { - throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`); + throw new Error( + `The guild seemed to be created but it was not cached. ${guild.id.toString()}`, + ); } -export const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" }); +console.log("[SETUP] Preparing the channel where tests will be done."); +export const channel = await bot.helpers.createChannel(guild.id, { + name: "Discordeno-test", +}); // Assertions assertExists(channel); assertEquals(channel.type, ChannelTypes.GuildText); -export const message = await bot.helpers.sendMessage(channel.id, { content: "Hello Skillz" }); - -import "./benchmark.ts"; +console.log("[SETUP] Preparing the message on which tests will be done."); +export const message = await bot.helpers.sendMessage(channel.id, { + content: "Hello Skillz", +}); Deno.test({ name: "[guild] create a guild", @@ -292,7 +295,7 @@ import "./channels/deleteChannel.ts"; import "./channels/getChannel.ts"; import "./channels/getChannels.ts"; import "./channels/stageInstances.ts"; -import "./channels/threads.ts"; +// import "./channels/threads.ts"; // emoji import "./emoji/createEmoji.ts"; @@ -308,10 +311,10 @@ 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"; +// import "./invite/deleteInvite.ts"; +// import "./invite/getChannelInvites.ts"; +// import "./invite/getInvite.ts"; +// import "./invite/getInvites.ts"; // members import "./members/avatarlUrl.ts"; @@ -321,13 +324,13 @@ import "./members/getDmChannel.ts"; import "./members/getMember.ts"; // messages -import "./messages/reactions.ts"; +// import "./messages/reactions.ts"; // misc import "./misc/getApplicationInfo.ts"; import "./misc/getDiscoveryCategories.ts"; import "./misc/getUser.ts"; -import "./misc/getVoiceRegions.ts"; +// import "./misc/getVoiceRegions.ts"; import "./misc/snowflake.ts"; import "./misc/typing.ts"; import "./misc/validateDiscovery.ts"; @@ -350,11 +353,17 @@ import "./scheduledEvents/createStageEventWithEndtime.ts"; import "./scheduledEvents/createStageEventWithoutEndtime.ts"; import "./scheduledEvents/createVoiceEventWithEndtime.ts"; import "./scheduledEvents/createVoiceEventWithoutEndtime.ts"; -import "./scheduledEvents/deleteEvent.ts"; -import "./scheduledEvents/editEvent.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"; +// import "./webhooks/sendWebhook.ts"; +// import "./webhooks/webhooks.ts"; + +// TESTS THAT DON'T REQUIRE API CONNECTION +import "./local.ts"; + +// // BENCHMARK TESTING +import "./benchmark.ts"; diff --git a/tests/utils.ts b/tests/utils.ts index 2d12ce914..4e68c3be2 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -9,7 +9,9 @@ export function delayUntil( if ((await isReady()) || Date.now() >= maxTime) { resolve(); } else { - setTimeout(() => hackyFix(resolve), timeoutTime); + setTimeout(() => { + hackyFix(resolve); + }, timeoutTime); } } diff --git a/tests/webhooks/deleteWebhook.ts b/tests/webhooks/deleteWebhook.ts index 999ae14b1..dd48b461f 100644 --- a/tests/webhooks/deleteWebhook.ts +++ b/tests/webhooks/deleteWebhook.ts @@ -4,5 +4,5 @@ Deno.test("[webhooks] Delete a webhook", async () => { const webhook = await bot.helpers.createWebhook(channel.id, { name: "natico", }); - await bot.helpers.deleteWebhook(channel.id, webhook.id); + await bot.helpers.deleteWebhook(webhook.id); }); diff --git a/tests/webhooks/webhooks.ts b/tests/webhooks/webhooks.ts index 7ea889b74..f055da7aa 100644 --- a/tests/webhooks/webhooks.ts +++ b/tests/webhooks/webhooks.ts @@ -12,7 +12,7 @@ Deno.test("[webhooks] Webhook related tests", async (t) => { }); await t.step("[webhooks] Edit a webhook", async () => { - const edited = await bot.helpers.editWebhook(channel.id, webhook.id, { + const edited = await bot.helpers.editWebhook(webhook.id, { name: "edited", });