From 4d3a01d314b2844e9fac07418bc828f8b7683f75 Mon Sep 17 00:00:00 2001 From: ITOH Date: Wed, 25 May 2022 23:05:40 +0200 Subject: [PATCH 1/6] release: 13.0.0-rc42 Fixed: - pass intents to `gatewayConfig` in the `createBot` function --- util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/constants.ts b/util/constants.ts index 0098708f7..de6dcb039 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -25,7 +25,7 @@ export const GATEWAY_VERSION = 10; // TODO: update this version /** https://github.com/discordeno/discordeno/releases */ -export const DISCORDENO_VERSION = "13.0.0-rc41"; +export const DISCORDENO_VERSION = "13.0.0-rc42"; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`; From 8eeb975161aebd77b8a7ad56b75fefddd06eef9d Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Thu, 26 May 2022 12:55:45 +0000 Subject: [PATCH 2/6] fix: remove confusion, old examples --- gateway/README.md | 142 ++-------------------------------------------- 1 file changed, 4 insertions(+), 138 deletions(-) diff --git a/gateway/README.md b/gateway/README.md index fb5a88f2c..d608547e2 100644 --- a/gateway/README.md +++ b/gateway/README.md @@ -51,145 +51,11 @@ This WS service is meant for ADVANCED DEVELOPERS ONLY! ## Usage ```ts -startGateway({ - /** The bot token. */ - token: "BOT_TOKEN_HERE", - /** Whether or not to use compression for gateway payloads. */ - compress: true, - /** The intents you would like to enable. */ - intents: Intents.Guilds | Intents.GuildMessages, - /** The max amount of shards used for identifying. This can be useful for zero-downtime updates or resharding. */ - maxShards: 885, - /** The first shard Id for this group of shards. */ - firstShardId: 100, - /** The last shard Id for this group. If none is provided, it will default to loading all shards. */ - lastShardId: 124, - /** The url to forward all payloads to. */ - url: "http://urlToYourServerHere", - /** The amount of shards per cluster. By default this is 25. Use this to spread the load from shards to different CPU cores. */ - shardsPerCluster: 25, - /** The maximum amount of clusters available. By default this is 4. Another way to think of cluster is how many CPU cores does your server/machine have. */ - maxClusters: 46, - /** Whether or not you want to allow automated sharding. By default this is true. */ - reshard: true; +createGatewayManager({ + // TODO: (docs) Fill this out }); ``` -## API / Docs +## API/Docs -```ts -// CONTROLLER LIKE INTERFACE FOR WS HANDLING -export const ws = { - /** The url that all discord payloads for the dispatch type should be sent to. */ - url: "", - /** Whether or not to automatically reshard. */ - reshard: true, - /** The percentage at which resharding should occur. */ - reshardPercentage: 80, - /** The maximum shard Id number. Useful for zero-downtime updates or resharding. */ - maxShards: 1, - /** The amount of shards to load per cluster */ - shardsPerCluster: 25, - /** The maximum amount of clusters to use for your bot. */ - maxClusters: 4, - /** The first shard Id to start spawning. */ - firstShardId: 0, - /** The last shard Id for this cluster. */ - lastShardId: 1, - /** This prop decides whether Discord allows our next shard to be started. When 1 starts, this is set to false until it is ready for the next one. */ - createNextShard: true, - /** The identify payload holds the necessary data to connect and stay connected with Discords WSS. */ - identifyPayload: { - token: "", - compress: false, - properties: { - $os: "linux", - $browser: "Discordeno", - $device: "Discordeno", - }, - intents: 0, - shard: [0, 0], - }, - botGatewayData: { - /** The WSS URL that can be used for connecting to the gateway. */ - url: "wss://gateway.discord.gg/?v=8&encoding=json", - /** The recommended number of shards to use when connecting. */ - shards: 1, - /** Info on the current start limit. */ - sessionStartLimit: { - /** The total number of session starts the current user is allowed. */ - total: 1000, - /** The remaining number of session starts the current user is allowed. */ - remaining: 1000, - /** Milliseconds left until limit is reset. */ - resetAfter: 0, - /** The number of identify requests allowed per 5 seconds. - * So, if you had a max concurrency of 16, and 16 shards for example, you could start them all up at the same time. - * Whereas if you had 32 shards, if you tried to start up shard 0 and 16 at the same time for example, it would not work. You can start shards 0-15 concurrently, then 16-31... - */ - maxConcurrency: 1, - }, - }, - shards: new Collection(), - loadingShards: new Collection< - number, - { - shardId: number; - resolve: (value: unknown) => void; - reject: (reason?: unknown) => void; - startedAt: number; - } - >(), - utf8decoder: new TextDecoder(), - - // METHODS - - /** The handler function that starts the gateway. */ - startGateway, - /** The handler for spawning ALL the shards. */ - spawnShards, - /** Create the websocket and adds the proper handlers to the websocket. */ - createShard, - /** Begins identification of the shard to discord */ - identify, - /** Begins heartbeating of the shard to keep it alive */ - heartbeat, - /** Sends the discord payload to another server. */ - handleDiscordPayload, - /** Tell the cluster/worker to begin identifying this shard */ - tellClusterToIdentify, - /** Handle the different logs. Used for debugging. */ - log, - /** Handles resharding the bot when necessary. */ - resharder, -}; - -export interface DiscordenoShard { - /** The shard id number */ - id: number; - /** The websocket for this shard */ - ws: WebSocket; - /** The amount of milliseconds to wait between heartbeats */ - resumeInterval: number; - /** The session id important for resuming connections. */ - sessionId: string; - /** The previous sequence number, important for resuming connections. */ - previousSequenceNumber: number | null; - /** Whether the shard is currently resuming. */ - resuming: boolean; - heartbeat: { - /** The exact timestamp the last heartbeat was sent */ - lastSentAt: number; - /** The timestamp the last heartbeat ACK was received from discord. */ - lastReceivedAt: number; - /** Whether or not the heartbeat was acknowledged by discord in time. */ - acknowledged: boolean; - /** Whether or not to keep heartbeating. Useful for when needing to stop heartbeating. */ - keepAlive: boolean; - /** The interval between heartbeats requested by discord. */ - interval: number; - /** The id of the interval, useful for stopping the interval if ws closed. */ - intervalId: number; - }; -} -``` +// TODO: (docs) Fill this out. List all props/methods. From 19ff286a6d449f99fd0d2418aa247076ef8a324f Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 27 May 2022 18:11:25 +0000 Subject: [PATCH 3/6] fix: rate limited unit tests from createBot async --- testss/channels/createCategory.test.ts | 2 +- testss/channels/createNews.test.ts | 7 ++++++- testss/channels/createText.test.ts | 2 +- testss/channels/createTextWithNsfw.test.ts | 2 +- testss/channels/createTextWithPerms.test.ts | 2 +- .../channels/createTextWithRateLimit.test.ts | 2 +- testss/channels/createVoice.test.ts | 2 +- testss/channels/createVoiceWithBitrate.test.ts | 2 +- .../channels/createVoiceWithUserLimit.test.ts | 2 +- testss/channels/deleteWithReason.test.ts | 2 +- testss/channels/deleteWithoutReason.test.ts | 2 +- testss/channels/getChannel.test.ts | 2 +- testss/channels/getChannels.test.ts | 2 +- testss/channels/stageInstances.test.ts | 2 +- testss/channels/threads/deleteThread.test.ts | 2 +- testss/channels/threads/editThread.test.ts | 2 +- .../channels/threads/getActiveThreads.test.ts | 2 +- .../threads/getArchivedThreads.test.ts | 2 +- .../threads/joinAndLeaveThread.test.ts | 2 +- testss/channels/threads/startThread.test.ts | 2 +- testss/mod.ts | 18 ++++++++++++------ 21 files changed, 37 insertions(+), 26 deletions(-) diff --git a/testss/channels/createCategory.test.ts b/testss/channels/createCategory.test.ts index d12894cee..0f356875e 100644 --- a/testss/channels/createCategory.test.ts +++ b/testss/channels/createCategory.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new category channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildCategory, diff --git a/testss/channels/createNews.test.ts b/testss/channels/createNews.test.ts index bccd5192a..1b086dc03 100644 --- a/testss/channels/createNews.test.ts +++ b/testss/channels/createNews.test.ts @@ -6,11 +6,14 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new news channel", async fn(t) { - const bot = loadBot(); + console.log("news", 1); + const bot = await loadBot(); + console.log("news", 2); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildNews, }); + console.log("news", 3); // Assertions assertExists(channel); @@ -22,7 +25,9 @@ Deno.test({ assertEquals(channel.nsfw, false); assertEquals(channel.permissionOverwrites.length, 0); + console.log("news", 4); // Delete the channel once test is done await bot.helpers.deleteChannel(channel.id); + console.log("news", 5); }, }); diff --git a/testss/channels/createText.test.ts b/testss/channels/createText.test.ts index 127692470..242eb4027 100644 --- a/testss/channels/createText.test.ts +++ b/testss/channels/createText.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test" }); // Assertions diff --git a/testss/channels/createTextWithNsfw.test.ts b/testss/channels/createTextWithNsfw.test.ts index 352d8fe08..f27d3ebc4 100644 --- a/testss/channels/createTextWithNsfw.test.ts +++ b/testss/channels/createTextWithNsfw.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel with NSFW", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", nsfw: true, diff --git a/testss/channels/createTextWithPerms.test.ts b/testss/channels/createTextWithPerms.test.ts index ee1b96b5e..d9e5df961 100644 --- a/testss/channels/createTextWithPerms.test.ts +++ b/testss/channels/createTextWithPerms.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel with permission overwrites", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", permissionOverwrites: [ diff --git a/testss/channels/createTextWithRateLimit.test.ts b/testss/channels/createTextWithRateLimit.test.ts index 597f66167..002c42131 100644 --- a/testss/channels/createTextWithRateLimit.test.ts +++ b/testss/channels/createTextWithRateLimit.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new text channel with a rate limit per user", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", rateLimitPerUser: 2423, diff --git a/testss/channels/createVoice.test.ts b/testss/channels/createVoice.test.ts index 10ab285fc..84f3854c6 100644 --- a/testss/channels/createVoice.test.ts +++ b/testss/channels/createVoice.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new voice channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildVoice, diff --git a/testss/channels/createVoiceWithBitrate.test.ts b/testss/channels/createVoiceWithBitrate.test.ts index da1764350..141909268 100644 --- a/testss/channels/createVoiceWithBitrate.test.ts +++ b/testss/channels/createVoiceWithBitrate.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new voice channel with a bitrate", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", type: ChannelTypes.GuildVoice, diff --git a/testss/channels/createVoiceWithUserLimit.test.ts b/testss/channels/createVoiceWithUserLimit.test.ts index fdc63c331..9936c9906 100644 --- a/testss/channels/createVoiceWithUserLimit.test.ts +++ b/testss/channels/createVoiceWithUserLimit.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new voice channel with a user limit", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "discordeno-test", type: ChannelTypes.GuildVoice, diff --git a/testss/channels/deleteWithReason.test.ts b/testss/channels/deleteWithReason.test.ts index 8f56ced12..48f6a938a 100644 --- a/testss/channels/deleteWithReason.test.ts +++ b/testss/channels/deleteWithReason.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] delete a channel with a reason", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "delete-channel", }); diff --git a/testss/channels/deleteWithoutReason.test.ts b/testss/channels/deleteWithoutReason.test.ts index 9295dfa4b..9b5acdd7c 100644 --- a/testss/channels/deleteWithoutReason.test.ts +++ b/testss/channels/deleteWithoutReason.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] delete a channel without a reason", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); // Create a channel to delete const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "delete-channel", diff --git a/testss/channels/getChannel.test.ts b/testss/channels/getChannel.test.ts index 650e981f2..c59796528 100644 --- a/testss/channels/getChannel.test.ts +++ b/testss/channels/getChannel.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] Get a channel", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "fetching", }); diff --git a/testss/channels/getChannels.test.ts b/testss/channels/getChannels.test.ts index a097ec47d..c78430259 100644 --- a/testss/channels/getChannels.test.ts +++ b/testss/channels/getChannels.test.ts @@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] Get all channels", async fn() { - const bot = loadBot(); + const bot = await loadBot(); const [first, second] = await Promise.all([ bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "first" }), bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "second" }), diff --git a/testss/channels/stageInstances.test.ts b/testss/channels/stageInstances.test.ts index b0980ce9e..ddecdb2a3 100644 --- a/testss/channels/stageInstances.test.ts +++ b/testss/channels/stageInstances.test.ts @@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[stage] Create a stage instance", async fn(t) { - const bot = loadBot(); + const bot = await loadBot(); const stage = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "createinstance", type: ChannelTypes.GuildStageVoice, diff --git a/testss/channels/threads/deleteThread.test.ts b/testss/channels/threads/deleteThread.test.ts index e87552afc..6f7b92e2b 100644 --- a/testss/channels/threads/deleteThread.test.ts +++ b/testss/channels/threads/deleteThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Delete a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/editThread.test.ts b/testss/channels/threads/editThread.test.ts index 1db1d4155..ea8eecd57 100644 --- a/testss/channels/threads/editThread.test.ts +++ b/testss/channels/threads/editThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Edit and archive a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/getActiveThreads.test.ts b/testss/channels/threads/getActiveThreads.test.ts index 4eff80b45..501463f97 100644 --- a/testss/channels/threads/getActiveThreads.test.ts +++ b/testss/channels/threads/getActiveThreads.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Get active threads", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/getArchivedThreads.test.ts b/testss/channels/threads/getArchivedThreads.test.ts index e4af2396b..4a085e0de 100644 --- a/testss/channels/threads/getArchivedThreads.test.ts +++ b/testss/channels/threads/getArchivedThreads.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Get archived threads", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/joinAndLeaveThread.test.ts b/testss/channels/threads/joinAndLeaveThread.test.ts index 9c7acace7..c22f840ce 100644 --- a/testss/channels/threads/joinAndLeaveThread.test.ts +++ b/testss/channels/threads/joinAndLeaveThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] join and leave a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/channels/threads/startThread.test.ts b/testss/channels/threads/startThread.test.ts index fa32babd3..44f016afb 100644 --- a/testss/channels/threads/startThread.test.ts +++ b/testss/channels/threads/startThread.test.ts @@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts"; import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts"; Deno.test("[thread] Start a thread", async (t) => { - const bot = loadBot(); + const bot = await loadBot(); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" }); const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" }); const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, { diff --git a/testss/mod.ts b/testss/mod.ts index 6b7a87eff..01a6d037c 100644 --- a/testss/mod.ts +++ b/testss/mod.ts @@ -3,16 +3,22 @@ import { dotenv } from "./deps.ts"; dotenv({ export: true, path: `${Deno.cwd()}/.env` }); -export function loadBot() { +export async function loadBot() { const token = Deno.env.get("DISCORD_TOKEN"); if (!token) throw new Error("Token was not provided."); - const botId = BigInt(atob(token.split(".")[0])); - const bot = createBot({ - events: {}, - intents: 0, - botId, + const bot = await createBot({ token, + botGatewayData: { + url: "wss://gateway.discord.gg", + shards: 1, + sessionStartLimit: { + maxConcurrency: 1, + remaining: 1000, + resetAfter: Date.now() + 1000 * 60 * 60 * 24, + total: 1000, + }, + }, }); bot.rest = createRestManager({ From 10dff1ca50db1a67db610bbd2213c2743d75f5ff Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 27 May 2022 18:44:49 +0000 Subject: [PATCH 4/6] fix(tests): migrate emoji related unit tests --- tests/emoji/createEmoji.ts | 24 ------------- tests/emoji/deleteEmojiWithReason.ts | 32 ----------------- tests/emoji/deleteEmojiWithoutReason.ts | 32 ----------------- tests/emoji/editEmoji.ts | 34 ------------------- tests/emoji/emojiUrl.ts | 13 ------- tests/emoji/getEmoji.ts | 31 ----------------- tests/emoji/getMultipleEmojis.ts | 30 ---------------- testss/channels/createNews.test.ts | 5 --- testss/emojis/createEmoji.test.ts | 20 +++++++++++ testss/emojis/deleteEmojiWithReason.test.ts | 23 +++++++++++++ .../emojis/deleteEmojiWithoutReason.test.ts | 23 +++++++++++++ testss/emojis/editEmojiName.test.ts | 29 ++++++++++++++++ testss/emojis/editEmojiRoles.test.ts | 33 ++++++++++++++++++ testss/emojis/getEmoji.test.ts | 24 +++++++++++++ testss/emojis/getEmojis.test.ts | 31 +++++++++++++++++ testss/utils.test.ts | 13 +++++++ 16 files changed, 196 insertions(+), 201 deletions(-) delete mode 100644 tests/emoji/createEmoji.ts delete mode 100644 tests/emoji/deleteEmojiWithReason.ts delete mode 100644 tests/emoji/deleteEmojiWithoutReason.ts delete mode 100644 tests/emoji/editEmoji.ts delete mode 100644 tests/emoji/emojiUrl.ts delete mode 100644 tests/emoji/getEmoji.ts delete mode 100644 tests/emoji/getMultipleEmojis.ts create mode 100644 testss/emojis/createEmoji.test.ts create mode 100644 testss/emojis/deleteEmojiWithReason.test.ts create mode 100644 testss/emojis/deleteEmojiWithoutReason.test.ts create mode 100644 testss/emojis/editEmojiName.test.ts create mode 100644 testss/emojis/editEmojiRoles.test.ts create mode 100644 testss/emojis/getEmoji.test.ts create mode 100644 testss/emojis/getEmojis.test.ts diff --git a/tests/emoji/createEmoji.ts b/tests/emoji/createEmoji.ts deleted file mode 100644 index 595fb4140..000000000 --- a/tests/emoji/createEmoji.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] create an emoji", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - name: "blamewolf", - 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.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."); - } - }, -}); diff --git a/tests/emoji/deleteEmojiWithReason.ts b/tests/emoji/deleteEmojiWithReason.ts deleted file mode 100644 index b54549541..000000000 --- a/tests/emoji/deleteEmojiWithReason.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] delete an emoji without a reason", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - name: "blamewolf", - 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.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.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."); - } - }, -}); diff --git a/tests/emoji/deleteEmojiWithoutReason.ts b/tests/emoji/deleteEmojiWithoutReason.ts deleted file mode 100644 index 341ff180a..000000000 --- a/tests/emoji/deleteEmojiWithoutReason.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] delete an emoji without a reason", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - name: "blamewolf", - 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.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.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."); - } - }, -}); diff --git a/tests/emoji/editEmoji.ts b/tests/emoji/editEmoji.ts deleted file mode 100644 index 0351e5dad..000000000 --- a/tests/emoji/editEmoji.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] edit an emoji", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - name: "blamewolf", - 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.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.editEmoji(guild.id, emoji.id, { - name: "blamewolf_infinite", - }); - - await delayUntil(10000, async () => bot.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."); - } - }, -}); diff --git a/tests/emoji/emojiUrl.ts b/tests/emoji/emojiUrl.ts deleted file mode 100644 index 41df85330..000000000 --- a/tests/emoji/emojiUrl.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { assertEquals } from "../deps.ts"; -import { bot } from "../mod.ts"; - -Deno.test("[emoji] Create an emoji url", async () => { - assertEquals( - bot.helpers.emojiUrl(785403373817823272n, false), - "https://cdn.discordapp.com/emojis/785403373817823272.png", - ); - assertEquals( - bot.helpers.emojiUrl(785403373817823272n, true), - "https://cdn.discordapp.com/emojis/785403373817823272.gif", - ); -}); diff --git a/tests/emoji/getEmoji.ts b/tests/emoji/getEmoji.ts deleted file mode 100644 index 856fb05ae..000000000 --- a/tests/emoji/getEmoji.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] get an emoji", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - name: "blamewolf", - 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.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.guilds.get(guild.id)?.emojis?.delete(emoji.id); - - const getEmoji = await bot.helpers.getEmoji(guild.id, emoji.id); - - // Assertions - assertExists(getEmoji); - }, -}); diff --git a/tests/emoji/getMultipleEmojis.ts b/tests/emoji/getMultipleEmojis.ts deleted file mode 100644 index 14d8baefd..000000000 --- a/tests/emoji/getMultipleEmojis.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { assertExists } from "../deps.ts"; -import { bot, guild } from "../mod.ts"; -import { delayUntil } from "../utils.ts"; - -Deno.test({ - name: "[emoji] get multiple emojis", - fn: async (t) => { - const emoji = await bot.helpers.createEmoji(guild.id, { - name: "blamewolf", - 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.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."); - } - - const emojis = await bot.helpers.getEmojis(guild.id); - - if (emojis.size === 0) { - throw new Error("The getEmojis function returned 0 emojis."); - } - }, -}); diff --git a/testss/channels/createNews.test.ts b/testss/channels/createNews.test.ts index 1b086dc03..f10cbda36 100644 --- a/testss/channels/createNews.test.ts +++ b/testss/channels/createNews.test.ts @@ -6,14 +6,11 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; Deno.test({ name: "[channel] create a new news channel", async fn(t) { - console.log("news", 1); const bot = await loadBot(); - console.log("news", 2); const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test", type: ChannelTypes.GuildNews, }); - console.log("news", 3); // Assertions assertExists(channel); @@ -25,9 +22,7 @@ Deno.test({ assertEquals(channel.nsfw, false); assertEquals(channel.permissionOverwrites.length, 0); - console.log("news", 4); // Delete the channel once test is done await bot.helpers.deleteChannel(channel.id); - console.log("news", 5); }, }); diff --git a/testss/emojis/createEmoji.test.ts b/testss/emojis/createEmoji.test.ts new file mode 100644 index 000000000..e77bd376b --- /dev/null +++ b/testss/emojis/createEmoji.test.ts @@ -0,0 +1,20 @@ +import { assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] create an emoji", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + }, +}); diff --git a/testss/emojis/deleteEmojiWithReason.test.ts b/testss/emojis/deleteEmojiWithReason.test.ts new file mode 100644 index 000000000..ce49c25f2 --- /dev/null +++ b/testss/emojis/deleteEmojiWithReason.test.ts @@ -0,0 +1,23 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] delete an emoji with a reason", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, "with a reason"); + + const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + assertEquals(exists.id, undefined); + }, +}); diff --git a/testss/emojis/deleteEmojiWithoutReason.test.ts b/testss/emojis/deleteEmojiWithoutReason.test.ts new file mode 100644 index 000000000..df70aa168 --- /dev/null +++ b/testss/emojis/deleteEmojiWithoutReason.test.ts @@ -0,0 +1,23 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] delete an emoji without a reason", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + + const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + assertEquals(exists.id, undefined); + }, +}); diff --git a/testss/emojis/editEmojiName.test.ts b/testss/emojis/editEmojiName.test.ts new file mode 100644 index 000000000..024b5a8a1 --- /dev/null +++ b/testss/emojis/editEmojiName.test.ts @@ -0,0 +1,29 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] Edit an emoji name", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + assertEquals(emoji.name, "blamewolf"); + + await bot.helpers.editEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, { + name: "edited", + }); + + const edited = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + + assertEquals(edited.name, "edited"); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + }, +}); diff --git a/testss/emojis/editEmojiRoles.test.ts b/testss/emojis/editEmojiRoles.test.ts new file mode 100644 index 000000000..ed30fcefd --- /dev/null +++ b/testss/emojis/editEmojiRoles.test.ts @@ -0,0 +1,33 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] Edit an emoji's roles", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + assertEquals(emoji.name, "blamewolf"); + + const role = await bot.helpers.createRole(CACHED_COMMUNITY_GUILD_ID, { + name: "dd-test-emoji", + }); + await bot.helpers.editEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id, { + roles: [role.id], + }); + + const edited = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + + assertEquals(edited.roles?.length, 1); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + await bot.helpers.deleteRole(CACHED_COMMUNITY_GUILD_ID, role.id); + }, +}); diff --git a/testss/emojis/getEmoji.test.ts b/testss/emojis/getEmoji.test.ts new file mode 100644 index 000000000..817f7f566 --- /dev/null +++ b/testss/emojis/getEmoji.test.ts @@ -0,0 +1,24 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] get an emoji", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + + const exists = await bot.helpers.getEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + assertExists(exists.id); + assertEquals(emoji.id, exists.id) + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + }, +}); diff --git a/testss/emojis/getEmojis.test.ts b/testss/emojis/getEmojis.test.ts new file mode 100644 index 000000000..badf7bb4c --- /dev/null +++ b/testss/emojis/getEmojis.test.ts @@ -0,0 +1,31 @@ +import { assertEquals, assertExists } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID, delayUntil } from "../utils.ts"; + +Deno.test({ + name: "[emoji] get all guild emojis", + fn: async (t) => { + const bot = await loadBot(); + const emoji = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + const emoji2 = await bot.helpers.createEmoji(CACHED_COMMUNITY_GUILD_ID, { + name: "blamewolf2", + image: "https://cdn.discordapp.com/emojis/814955268123000832.png", + roles: [], + }); + + // Assertions + assertExists(emoji.id); + assertExists(emoji2.id); + + const exists = await bot.helpers.getEmojis(CACHED_COMMUNITY_GUILD_ID); + assertEquals(exists.size > 1, true); + + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji.id); + await bot.helpers.deleteEmoji(CACHED_COMMUNITY_GUILD_ID, emoji2.id); + }, +}); diff --git a/testss/utils.test.ts b/testss/utils.test.ts index 87afcf46d..03040e043 100644 --- a/testss/utils.test.ts +++ b/testss/utils.test.ts @@ -2,6 +2,7 @@ import { formatImageURL, iconBigintToHash, iconHashToBigInt, validateLength } fr import { bigintToSnowflake, snowflakeToBigint } from "../util/bigint.ts"; import { removeTokenPrefix } from "../util/token.ts"; import { assertEquals, assertNotEquals } from "./deps.ts"; +import { loadBot } from "./mod.ts"; Deno.test({ name: "[token] Remove token prefix when Bot is prefixed.", @@ -35,6 +36,18 @@ Deno.test("[bigint] - Transform a bigint to a string", () => { assertNotEquals(big, result); }); +Deno.test("[emoji] Create an emoji url", async () => { + const bot = await loadBot(); + assertEquals( + bot.helpers.emojiUrl(785403373817823272n, false), + "https://cdn.discordapp.com/emojis/785403373817823272.png", + ); + assertEquals( + bot.helpers.emojiUrl(785403373817823272n, true), + "https://cdn.discordapp.com/emojis/785403373817823272.gif", + ); +}); + Deno.test({ name: "[utils] format image url", fn() { From 24f77185664cde7a2f64dc7d195a2fc5825f9524 Mon Sep 17 00:00:00 2001 From: ITOH Date: Fri, 27 May 2022 23:48:04 +0200 Subject: [PATCH 5/6] feat!: make createBot sync (#2255) --- bot.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bot.ts b/bot.ts index 1ee3ef547..6e0c0a6dc 100644 --- a/bot.ts +++ b/bot.ts @@ -140,7 +140,7 @@ import { transformComponentToDiscordComponent } from "./transformers/reverse/com import { getBotIdFromToken, removeTokenPrefix } from "./util/token.ts"; import { CreateShardManager } from "./gateway/manager/shardManager.ts"; -export async function createBot(options: CreateBotOptions): Promise { +export function createBot(options: CreateBotOptions): Bot { const bot = { id: options.botId ?? getBotIdFromToken(options.token), applicationId: options.applicationId || options.botId, @@ -168,7 +168,7 @@ export async function createBot(options: CreateBotOptions): Promise { bot.helpers = createHelpers(bot, options.helpers ?? {}); bot.gateway = createGatewayManager({ - gatewayBot: bot.botGatewayData ?? await bot.helpers.getGatewayBot(), + gatewayBot: bot.botGatewayData ?? {} as any, gatewayConfig: { token: options.token, intents: options.intents, @@ -259,7 +259,11 @@ export function createEventHandlers( }; } -export function startBot(bot: Bot) { +export async function startBot(bot: Bot) { + if (!bot.botGatewayData) { + bot.gateway.gatewayBot = await bot.helpers.getGatewayBot(); + } + bot.gateway.spawnShards(); } From 1423df5b8d19f5c87c9b797b3fc71b54db2798ab Mon Sep 17 00:00:00 2001 From: ITOH Date: Fri, 27 May 2022 23:51:58 +0200 Subject: [PATCH 6/6] release: 13.0.0-rc43 --- util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/constants.ts b/util/constants.ts index de6dcb039..786f11ecc 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -25,7 +25,7 @@ export const GATEWAY_VERSION = 10; // TODO: update this version /** https://github.com/discordeno/discordeno/releases */ -export const DISCORDENO_VERSION = "13.0.0-rc42"; +export const DISCORDENO_VERSION = "13.0.0-rc43"; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`;