diff --git a/packages/api-types/CHANGELOG.md b/packages/api-types/CHANGELOG.md index 8b40116..c73cdde 100644 --- a/packages/api-types/CHANGELOG.md +++ b/packages/api-types/CHANGELOG.md @@ -1,6 +1,6 @@ # @biscuitland/api-types -## 2.0.3 +## 2.0.4 ### Major Changes diff --git a/packages/api-types/README.md b/packages/api-types/README.md index b267850..220c94e 100644 --- a/packages/api-types/README.md +++ b/packages/api-types/README.md @@ -25,7 +25,7 @@ import type { DiscordUser } from '@biscuitland/api-types'; ## Example for [Deno](https://deno.land/) ```ts -import type { DiscordUser } from "https://unpkg.com/@biscuitland/api-types@2.0.3/dist/index.d.ts"; +import type { DiscordUser } from "https://unpkg.com/@biscuitland/api-types@2.0.4/dist/index.d.ts"; ``` We deliver this package through [unpkg](https://unpkg.com/) and it does contain constants and routes too diff --git a/packages/api-types/package.json b/packages/api-types/package.json index 6c9fa31..dac4930 100644 --- a/packages/api-types/package.json +++ b/packages/api-types/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/api-types", - "version": "2.0.3", + "version": "2.0.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/api-types/src/utils/constants.ts b/packages/api-types/src/utils/constants.ts index 4dce845..4a85383 100644 --- a/packages/api-types/src/utils/constants.ts +++ b/packages/api-types/src/utils/constants.ts @@ -5,7 +5,7 @@ export const BASE_URL = 'https://discord.com/api'; export const API_VERSION = 10; /** https://github.com/oasisjs/biscuit/releases */ -export const BISCUIT_VERSION = '2.0.3'; +export const BISCUIT_VERSION = '2.0.4'; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = `DiscordBot (https://github.com/oasisjs/biscuit, v${BISCUIT_VERSION})`; diff --git a/packages/cache/CHANGELOG.md b/packages/cache/CHANGELOG.md index adce616..1a214c6 100644 --- a/packages/cache/CHANGELOG.md +++ b/packages/cache/CHANGELOG.md @@ -1,6 +1,6 @@ # @biscuitland/cache -## 2.0.3 +## 2.0.4 ### Major Changes @@ -9,4 +9,4 @@ ### Patch Changes - Updated dependencies - - @biscuitland/api-types@2.0.3 + - @biscuitland/api-types@2.0.4 diff --git a/packages/cache/package.json b/packages/cache/package.json index 8f12850..f9f62ca 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/cache", - "version": "2.0.3", + "version": "2.0.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -23,7 +23,7 @@ } }, "dependencies": { - "@biscuitland/api-types": "^2.0.3", + "@biscuitland/api-types": "^2.0.4", "ioredis": "^5.2.2" }, "devDependencies": { diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 0fd2cb7..60af055 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,6 +1,6 @@ # @biscuitland/core -## 2.0.3 +## 2.0.4 ### Major Changes @@ -9,6 +9,6 @@ ### Patch Changes - Updated dependencies - - @biscuitland/api-types@2.0.3 - - @biscuitland/rest@2.0.3 - - @biscuitland/ws@2.0.3 + - @biscuitland/api-types@2.0.4 + - @biscuitland/rest@2.0.4 + - @biscuitland/ws@2.0.4 diff --git a/packages/core/package.json b/packages/core/package.json index 30abf86..f667f98 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/core", - "version": "2.0.3", + "version": "2.0.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -23,9 +23,9 @@ } }, "dependencies": { - "@biscuitland/api-types": "^2.0.3", - "@biscuitland/rest": "^2.0.3", - "@biscuitland/ws": "^2.0.3" + "@biscuitland/api-types": "^2.0.4", + "@biscuitland/rest": "^2.0.4", + "@biscuitland/ws": "^2.0.4" }, "devDependencies": { "tsup": "^6.1.3" diff --git a/packages/helpers/CHANGELOG.md b/packages/helpers/CHANGELOG.md index 6746245..e460369 100644 --- a/packages/helpers/CHANGELOG.md +++ b/packages/helpers/CHANGELOG.md @@ -1,9 +1,9 @@ # @biscuitland/helpers -## 2.0.3 +## 2.0.4 ### Patch Changes - Updated dependencies - - @biscuitland/api-types@2.0.3 - - @biscuitland/core@2.0.3 + - @biscuitland/api-types@2.0.4 + - @biscuitland/core@2.0.4 diff --git a/packages/helpers/package.json b/packages/helpers/package.json index e8d6af4..07fcfb8 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/helpers", - "version": "2.0.3", + "version": "2.0.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -23,8 +23,8 @@ } }, "dependencies": { - "@biscuitland/api-types": "^2.0.3", - "@biscuitland/core": "^2.0.3" + "@biscuitland/api-types": "^2.0.4", + "@biscuitland/core": "^2.0.4" }, "devDependencies": { "tsup": "^6.1.3" diff --git a/packages/rest/CHANGELOG.md b/packages/rest/CHANGELOG.md index 2835e94..eb3895f 100644 --- a/packages/rest/CHANGELOG.md +++ b/packages/rest/CHANGELOG.md @@ -1,6 +1,6 @@ # @biscuitland/rest -## 2.0.3 +## 2.0.4 ### Major Changes @@ -9,4 +9,4 @@ ### Patch Changes - Updated dependencies - - @biscuitland/api-types@2.0.3 + - @biscuitland/api-types@2.0.4 diff --git a/packages/rest/package.json b/packages/rest/package.json index 5e58003..7700d43 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/rest", - "version": "2.0.3", + "version": "2.0.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -23,7 +23,7 @@ } }, "dependencies": { - "@biscuitland/api-types": "^2.0.3" + "@biscuitland/api-types": "^2.0.4" }, "devDependencies": { "tsup": "^6.1.3" diff --git a/packages/ws/CHANGELOG.md b/packages/ws/CHANGELOG.md index 7572bd4..b717ce3 100644 --- a/packages/ws/CHANGELOG.md +++ b/packages/ws/CHANGELOG.md @@ -1,6 +1,6 @@ # @biscuitland/ws -## 2.0.3 +## 2.0.4 ### Major Changes @@ -9,4 +9,4 @@ ### Patch Changes - Updated dependencies - - @biscuitland/api-types@2.0.3 + - @biscuitland/api-types@2.0.4 diff --git a/packages/ws/package.json b/packages/ws/package.json index ff9959d..7c0973c 100644 --- a/packages/ws/package.json +++ b/packages/ws/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/ws", - "version": "2.0.3", + "version": "2.0.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -23,7 +23,7 @@ } }, "dependencies": { - "@biscuitland/api-types": "^2.0.3", + "@biscuitland/api-types": "^2.0.4", "ws": "^8.8.1" }, "devDependencies": { diff --git a/packages/ws/src/adapters/default-ws-adapter.ts b/packages/ws/src/adapters/default-ws-adapter.ts index 2fe7660..15e95a8 100644 --- a/packages/ws/src/adapters/default-ws-adapter.ts +++ b/packages/ws/src/adapters/default-ws-adapter.ts @@ -65,7 +65,6 @@ export class DefaultWsAdapter implements WsAdapter { }, handleIdentify: (id: number) => { - // console.log(id % this.options.gatewayBot.sessionStartLimit.maxConcurrency, id, this.options.gatewayBot.sessionStartLimit.maxConcurrency); return this.buckets.get(id % this.options.gatewayBot.sessionStartLimit.maxConcurrency)!.leak.acquire(1); }, }); diff --git a/packages/ws/src/services/shard.ts b/packages/ws/src/services/shard.ts index 6ce92ae..0d80bea 100644 --- a/packages/ws/src/services/shard.ts +++ b/packages/ws/src/services/shard.ts @@ -319,28 +319,7 @@ export class Shard { const jitter = Math.ceil(this.heart.interval * (Math.random() || 0.5)); const it1: any = setTimeout(() => { - this.socket?.send( - JSON.stringify({ - op: GatewayOpcodes.Heartbeat, - d: this.options.previousSequenceNumber, - }) - ); - - this.heart.lastBeat = Date.now(); - this.heart.acknowledged = false; - - const it: any = setInterval(async () => { - if (!this.heart.acknowledged) { - this.close( - ShardSocketCloseCodes.ZombiedConnection, - 'Zombied connection, did not receive an heartbeat ACK in time.' - ); - - return await this.identify(); - } - - this.heart.acknowledged = false; - + if (this.state === ShardState.Connected) { this.socket?.send( JSON.stringify({ op: GatewayOpcodes.Heartbeat, @@ -349,11 +328,36 @@ export class Shard { ); this.heart.lastBeat = Date.now(); + this.heart.acknowledged = false; - this.events.heartbeat?.(this); - }, this.heart.interval); + const it: any = setInterval(async () => { + if (!this.heart.acknowledged) { + this.close( + ShardSocketCloseCodes.ZombiedConnection, + 'Zombied connection, did not receive an heartbeat ACK in time.' + ); - this.heart.intervalId = it; + return await this.identify(); + } + + this.heart.acknowledged = false; + + if (this.state === ShardState.Connected) { + this.socket?.send( + JSON.stringify({ + op: GatewayOpcodes.Heartbeat, + d: this.options.previousSequenceNumber, + }) + ); + + this.heart.lastBeat = Date.now(); + + this.events.heartbeat?.(this); + } + }, this.heart.interval); + + this.heart.intervalId = it; + } }, jitter); this.heart.timeoutId = it1; @@ -395,13 +399,15 @@ export class Shard { this.heart.lastBeat = Date.now(); - this.socket?.send( - JSON.stringify({ - op: GatewayOpcodes.Heartbeat, - d: this.options.previousSequenceNumber, - }), - ); - this.events.heartbeat?.(this); + if (this.state === ShardState.Connected) { + this.socket?.send( + JSON.stringify({ + op: GatewayOpcodes.Heartbeat, + d: this.options.previousSequenceNumber, + }), + ); + this.events.heartbeat?.(this); + } break; }