mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
testing
This commit is contained in:
1 parent
2a2e42efd9
commit
b4790e6948
2 files changed
+58
-31
No files matched your search
@@ -171,8 +171,8 @@ class Remix {
|
|||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`Left channel <#${cleanChannelId}> because of inactivity.\n` +
|
`Left channel <#${cleanChannelId}> because of inactivity.\n` +
|
||||||
`If you want me to stay in voice, use \`${prefix}247 on/auto\``
|
`If you want me to stay in voice, use \`${prefix}247 on/auto\``
|
||||||
)
|
)
|
||||||
.toJSON();
|
.toJSON();
|
||||||
ch.send({ embeds: [embed] }).catch(() => {});
|
ch.send({ embeds: [embed] }).catch(() => {});
|
||||||
@@ -378,21 +378,25 @@ class Remix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guard WS listener registration so it only runs once across all reconnects.
|
try {
|
||||||
// Without this, each reconnect stacks a new listener on the same socket, causing
|
const shard0 = client.ws?.shards?.get?.(0);
|
||||||
// every WS frame to be processed N times after N reconnects.
|
const wsObj = shard0?.ws ?? null;
|
||||||
if (!wsListenerAttached) {
|
|
||||||
wsListenerAttached = true;
|
|
||||||
try {
|
|
||||||
// NOTE: client.ws.shards is declared private in @fluxerjs/ws, but there is
|
|
||||||
// no public API for attaching a raw message listener to the underlying socket.
|
|
||||||
// ws.send(shardId, payload) exists for sending, but not for receiving.
|
|
||||||
// This access is intentional — if @fluxerjs/core ever exposes a public
|
|
||||||
// onRawMessage() hook, replace these two lines with that API instead.
|
|
||||||
const shard0 = client.ws?.shards?.get?.(0);
|
|
||||||
const wsObj = shard0?.ws ?? null;
|
|
||||||
|
|
||||||
const handleRaw = (data) => {
|
// Remove listener from the previous socket if it's a different object
|
||||||
|
if (wsListenerAttached && this._rawGatewayWsObj && this._rawGatewayWsObj !== wsObj) {
|
||||||
|
try {
|
||||||
|
if (typeof this._rawGatewayWsObj.removeEventListener === "function") {
|
||||||
|
this._rawGatewayWsObj.removeEventListener("message", this._rawGatewayHandler);
|
||||||
|
this._rawGatewayWsObj.removeEventListener("error", this._rawGatewayErrorHandler);
|
||||||
|
} else if (typeof this._rawGatewayWsObj.off === "function") {
|
||||||
|
this._rawGatewayWsObj.off("message", this._rawGatewayHandler);
|
||||||
|
this._rawGatewayWsObj.off("error", this._rawGatewayErrorHandler);
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wsObj && wsObj !== this._rawGatewayWsObj) {
|
||||||
|
this._rawGatewayHandler = (data) => {
|
||||||
try {
|
try {
|
||||||
const payload = typeof data === "string" ? JSON.parse(data) : data;
|
const payload = typeof data === "string" ? JSON.parse(data) : data;
|
||||||
|
|
||||||
@@ -457,13 +461,25 @@ class Remix {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof wsObj?.addEventListener === "function") {
|
// Absorb socket-level errors so they don't bubble to uncaughtException.
|
||||||
wsObj.addEventListener("message", (event) => handleRaw(event.data));
|
// The gateway will emit Ready again once it reconnects — we re-attach then.
|
||||||
} else if (typeof wsObj?.on === "function") {
|
this._rawGatewayErrorHandler = (err) => {
|
||||||
wsObj.on("message", handleRaw);
|
logger.warn("[Gateway] Raw WS socket error (will reconnect):", err?.message ?? err);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof wsObj.addEventListener === "function") {
|
||||||
|
wsObj.addEventListener("message", (event) => this._rawGatewayHandler(event.data));
|
||||||
|
wsObj.addEventListener("error", this._rawGatewayErrorHandler);
|
||||||
|
} else if (typeof wsObj.on === "function") {
|
||||||
|
wsObj.on("message", this._rawGatewayHandler);
|
||||||
|
wsObj.on("error", this._rawGatewayErrorHandler);
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
|
||||||
}
|
this._rawGatewayWsObj = wsObj;
|
||||||
|
wsListenerAttached = true;
|
||||||
|
logger.player("[Gateway] Raw WS listener attached to new socket.");
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
botReady = true;
|
botReady = true;
|
||||||
tryAutoJoin();
|
tryAutoJoin();
|
||||||
|
|||||||
+20
-9
@@ -181,22 +181,24 @@ export class MoonlinkManager extends EventEmitter {
|
|||||||
// on gateway reconnects. Without this, each reconnect stacks another handler on the socket.
|
// on gateway reconnects. Without this, each reconnect stacks another handler on the socket.
|
||||||
const attachRawWs = () => {
|
const attachRawWs = () => {
|
||||||
try {
|
try {
|
||||||
// NOTE: client.ws.shards is private in @fluxerjs/ws. There is no public API for
|
|
||||||
// attaching a raw inbound message listener — ws.send() only covers outbound.
|
|
||||||
// This access is intentional. If @fluxerjs/core exposes a public onRawMessage()
|
|
||||||
// hook in a future release, replace shard0/wsObj extraction with that API.
|
|
||||||
const shard0 = client.ws?.shards?.get?.(0);
|
const shard0 = client.ws?.shards?.get?.(0);
|
||||||
const wsObj = shard0?.ws ?? null;
|
const wsObj = shard0?.ws ?? null;
|
||||||
if (!wsObj) return;
|
if (!wsObj) return;
|
||||||
|
if (this._rawWsHandler && this._rawWsObj && this._rawWsObj !== wsObj) {
|
||||||
// Remove previous handler if any
|
|
||||||
if (this._rawWsHandler) {
|
|
||||||
try {
|
try {
|
||||||
if (typeof wsObj.removeEventListener === "function") wsObj.removeEventListener("message", this._rawWsHandler);
|
if (typeof this._rawWsObj.removeEventListener === "function") {
|
||||||
else if (typeof wsObj.off === "function") wsObj.off("message", this._rawWsHandler);
|
this._rawWsObj.removeEventListener("message", this._rawWsHandler);
|
||||||
|
this._rawWsObj.removeEventListener("error", this._rawWsErrorHandler);
|
||||||
|
} else if (typeof this._rawWsObj.off === "function") {
|
||||||
|
this._rawWsObj.off("message", this._rawWsHandler);
|
||||||
|
this._rawWsObj.off("error", this._rawWsErrorHandler);
|
||||||
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip re-attaching if it's the same socket object (spurious Ready re-fire)
|
||||||
|
if (wsObj === this._rawWsObj) return;
|
||||||
|
|
||||||
this._rawWsHandler = (rawData) => {
|
this._rawWsHandler = (rawData) => {
|
||||||
try {
|
try {
|
||||||
const text = typeof rawData === "string" ? rawData : rawData?.data;
|
const text = typeof rawData === "string" ? rawData : rawData?.data;
|
||||||
@@ -211,11 +213,20 @@ export class MoonlinkManager extends EventEmitter {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Absorb socket-level errors so they don't escape to uncaughtException.
|
||||||
|
this._rawWsErrorHandler = (err) => {
|
||||||
|
logger.warn("[MoonlinkManager] Raw WS socket error (will reconnect):", err?.message ?? err);
|
||||||
|
};
|
||||||
|
|
||||||
if (typeof wsObj.addEventListener === "function") {
|
if (typeof wsObj.addEventListener === "function") {
|
||||||
wsObj.addEventListener("message", this._rawWsHandler);
|
wsObj.addEventListener("message", this._rawWsHandler);
|
||||||
|
wsObj.addEventListener("error", this._rawWsErrorHandler);
|
||||||
} else if (typeof wsObj.on === "function") {
|
} else if (typeof wsObj.on === "function") {
|
||||||
wsObj.on("message", this._rawWsHandler);
|
wsObj.on("message", this._rawWsHandler);
|
||||||
|
wsObj.on("error", this._rawWsErrorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._rawWsObj = wsObj;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn("[MoonlinkManager] Raw WS setup error:", e.message);
|
logger.warn("[MoonlinkManager] Raw WS setup error:", e.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user