diff --git a/packages/discordeno/gateway/manager/shardManager.ts b/packages/discordeno/gateway/manager/shardManager.ts index bfd48df..91a18f5 100644 --- a/packages/discordeno/gateway/manager/shardManager.ts +++ b/packages/discordeno/gateway/manager/shardManager.ts @@ -60,6 +60,7 @@ export function createShardManager(options: CreateShardManager) { */ identify: async function (shardId: number) { let shard = this.shards.get(shardId); + if (!shard) { shard = createShard({ ...this.createShardOptions, diff --git a/packages/discordeno/gateway/manager/spawnShards.ts b/packages/discordeno/gateway/manager/spawnShards.ts index 21ce7d6..5bd9df1 100644 --- a/packages/discordeno/gateway/manager/spawnShards.ts +++ b/packages/discordeno/gateway/manager/spawnShards.ts @@ -18,14 +18,14 @@ export function spawnShards(gateway: GatewayManager) { gateway.prepareBuckets(); // SPREAD THIS OUT TO DIFFERENT WORKERS TO BEGIN STARTING UP - gateway.buckets.forEach(async (bucket, bucketId) => { + gateway.buckets.forEach((bucket, bucketId) => { // gateway.debug("GW DEBUG", `2. Running forEach loop in spawnShards function.`); for (const worker of bucket.workers) { // gateway.debug("GW DEBUG", `3. Running for of loop in spawnShards function.`); for (const shardId of worker.queue) { - await gateway.tellWorkerToIdentify(worker.id, shardId, bucketId); + gateway.tellWorkerToIdentify(worker.id, shardId, bucketId).catch(console.error); } } }); diff --git a/packages/discordeno/gateway/shard/createShard.ts b/packages/discordeno/gateway/shard/createShard.ts index 1695cf9..d17e220 100644 --- a/packages/discordeno/gateway/shard/createShard.ts +++ b/packages/discordeno/gateway/shard/createShard.ts @@ -59,7 +59,7 @@ export function createShard( compress: options.gatewayConfig.compress ?? false, intents: options.gatewayConfig.intents ?? 0, properties: { - os: options.gatewayConfig?.properties?.os ?? Deno.build.os, + os: options.gatewayConfig?.properties?.os ?? "linux", browser: options.gatewayConfig?.properties?.browser ?? "Discordeno", device: options.gatewayConfig?.properties?.device ?? "Discordeno", }, diff --git a/packages/discordeno/gateway/shard/handleMessage.ts b/packages/discordeno/gateway/shard/handleMessage.ts index cae9839..2189eb4 100644 --- a/packages/discordeno/gateway/shard/handleMessage.ts +++ b/packages/discordeno/gateway/shard/handleMessage.ts @@ -14,7 +14,6 @@ export async function handleMessage(shard: Shard, message_: MessageEvent): // Discord might send zlib compressed payloads. if (shard.gatewayConfig.compress && message instanceof Blob) { message = decoder.decode(decompressWith(new Uint8Array(await message.arrayBuffer()))); - console.log(message); } // Safeguard incase decompression failed to make a string. diff --git a/packages/discordeno/rest/runMethod.ts b/packages/discordeno/rest/runMethod.ts index fcd3332..9a714a7 100644 --- a/packages/discordeno/rest/runMethod.ts +++ b/packages/discordeno/rest/runMethod.ts @@ -24,6 +24,7 @@ export async function runMethod( ); const errorStack = new Error("Location:"); + // @ts-ignore Breaks deno deploy. Luca said add ts-ignore until it's fixed Error.captureStackTrace?.(errorStack); diff --git a/packages/discordeno/rest/sendRequest.ts b/packages/discordeno/rest/sendRequest.ts index f42f5a8..81c72bf 100644 --- a/packages/discordeno/rest/sendRequest.ts +++ b/packages/discordeno/rest/sendRequest.ts @@ -17,18 +17,22 @@ export interface RestSendRequestOptions { } export async function sendRequest(rest: RestManager, options: RestSendRequestOptions): Promise { - try { + try { // CUSTOM HANDLER FOR USER TO LOG OR WHATEVER WHENEVER A FETCH IS MADE rest.debug(`[REST - fetching] URL: ${options.url} | ${JSON.stringify(options)}`); + const newURL = options.url.startsWith(BASE_URL) ? options.url : `${BASE_URL}/v${rest.version}/${options.url}`; + + rest.debug(`[REST - url data] URL: ${newURL}`); + const response = await fetch( - options.url.startsWith(BASE_URL) ? options.url : `${BASE_URL}/v${rest.version}/${options.url}`, - { + new Request(newURL, { method: options.method, headers: options.payload?.headers, body: options.payload?.body, - }, + }), ); + rest.debug(`[REST - fetched] URL: ${options.url} | ${JSON.stringify(options)}`); const bucketIdFromHeaders = rest.processRequestHeaders( diff --git a/tests/bun.js b/tests/bun.js new file mode 100644 index 0000000..0955aff --- /dev/null +++ b/tests/bun.js @@ -0,0 +1,22 @@ +import { GatewayIntents, Session } from "./deps.ts"; + +const token = "lol"; +const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages; +const session = new Session({ token, intents }); + +// uncomment to debug stuff +// session.on("debug", (any) => { +// console.debug(any); +// }) + +session.on("ready", (payload) => { + console.log("Logged in as:", payload.user.username); +}); + +session.on("messageCreate", (message) => { + if (message.content.startsWith("ping")) { + message.reply({ content: "pong!" }).catch((err) => console.error(err)); + } +}); + +await session.start();