mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(bots/discord): hanging process when disconnecting from API too many times
This commit is contained in:
@@ -21,6 +21,9 @@
|
|||||||
},
|
},
|
||||||
"useNodejsImportProtocol": {
|
"useNodejsImportProtocol": {
|
||||||
"level": "off"
|
"level": "off"
|
||||||
|
},
|
||||||
|
"useNumberNamespace": {
|
||||||
|
"level": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ export default {
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("my-command")
|
.setName("my-command")
|
||||||
.setDescription("My cool command")
|
.setDescription("My cool command")
|
||||||
// Allowing this command to be used in DMs
|
|
||||||
.setDMPermission(true)
|
|
||||||
// DO NOT forget this line!
|
// DO NOT forget this line!
|
||||||
.toJSON(),
|
.toJSON(),
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ withContext(on, 'disconnect', ({ api, config, logger }, reason, msg) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (api.disconnectCount >= (config.api.disconnectLimit ?? 3)) {
|
if (api.disconnectCount >= (config.api.disconnectLimit ?? 3)) {
|
||||||
console.error('Disconnected from bot API too many times')
|
logger.fatal('Disconnected from bot API too many times')
|
||||||
// We don't want the process hanging
|
// We don't want the process hanging
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,19 +49,13 @@ export class ClientWebSocketManager {
|
|||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
this.#socket?.close(DisconnectReason.TooSlow)
|
this.#socket?.close(DisconnectReason.TooSlow)
|
||||||
throw new Error('WebSocket connection was not readied in time')
|
this._handleDisconnect(DisconnectReason.TooSlow, 'WebSocket connection was not readied in time')
|
||||||
}
|
}
|
||||||
}, this.timeout)
|
}, this.timeout)
|
||||||
|
|
||||||
const errorBeforeReadyHandler = (err: Error) => {
|
|
||||||
cleanup()
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
|
|
||||||
const closeBeforeReadyHandler = (code: number, reason: Buffer) => {
|
const closeBeforeReadyHandler = (code: number, reason: Buffer) => {
|
||||||
clearTimeout(timeout)
|
|
||||||
this._handleDisconnect(code, reason.toString())
|
this._handleDisconnect(code, reason.toString())
|
||||||
throw new Error('WebSocket connection closed before ready')
|
cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
const readyHandler = () => {
|
const readyHandler = () => {
|
||||||
@@ -71,15 +65,14 @@ export class ClientWebSocketManager {
|
|||||||
rs()
|
rs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const socket = this.#socket
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
this.#socket.off('open', readyHandler)
|
socket.off('open', readyHandler)
|
||||||
this.#socket.off('close', closeBeforeReadyHandler)
|
socket.off('close', closeBeforeReadyHandler)
|
||||||
this.#socket.off('error', errorBeforeReadyHandler)
|
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#socket.on('open', readyHandler)
|
this.#socket.on('open', readyHandler)
|
||||||
this.#socket.on('error', errorBeforeReadyHandler)
|
|
||||||
this.#socket.on('close', closeBeforeReadyHandler)
|
this.#socket.on('close', closeBeforeReadyHandler)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rj(e)
|
rj(e)
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ const Options = {
|
|||||||
[
|
[
|
||||||
'@semantic-release/npm',
|
'@semantic-release/npm',
|
||||||
{
|
{
|
||||||
npmPublish: false,
|
npmPublish: false,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'@semantic-release/git',
|
'@semantic-release/git',
|
||||||
|
|||||||
Reference in New Issue
Block a user