mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
dashboard
This commit is contained in:
1 parent
37c29ca6cd
commit
09580cebf5
2 files changed
+36
-6
No files matched your search
@@ -41,9 +41,15 @@ export class Dashboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "sharedServers": {
|
case "sharedServers": {
|
||||||
const sharedUser = await this.remix.client.users.fetch(data.key).catch(() => null);
|
try {
|
||||||
if (!sharedUser) return { error: "User not found" };
|
const sharedUser = await this.remix.client.users.fetch(data.key).catch(() => null);
|
||||||
return await this.remix.getSharedServers(sharedUser);
|
if (!sharedUser) return { error: "User not found" };
|
||||||
|
return await this.remix.getSharedServers(sharedUser);
|
||||||
|
} catch (e) {
|
||||||
|
const id = Utils.uid();
|
||||||
|
logger.dashboard("[Dashboard] sharedServers error:", id, e);
|
||||||
|
return { error: "Failed to fetch shared servers. Id: " + id };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "server": {
|
case "server": {
|
||||||
@@ -73,6 +79,10 @@ export class Dashboard {
|
|||||||
|
|
||||||
case "function":
|
case "function":
|
||||||
return await this.runFunction(data.params);
|
return await this.runFunction(data.params);
|
||||||
|
|
||||||
|
default:
|
||||||
|
logger.dashboard("[Dashboard] Unknown request type:", data.type);
|
||||||
|
return { error: "Unknown request type: " + (data.type ?? "(none)") };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ export class RedisHandler {
|
|||||||
try {
|
try {
|
||||||
await this.client.connect();
|
await this.client.connect();
|
||||||
logger.redis("[Redis/Main] Connected");
|
logger.redis("[Redis/Main] Connected");
|
||||||
this.readyMessage();
|
// Do NOT call readyMessage() here — the subscriber is not yet listening
|
||||||
|
// on the "request" channel. If we announce before subscribing, the
|
||||||
|
// backend will send requests that we miss, causing a timeout.
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("[Redis/Main] Initial connection failed:", e.message);
|
logger.error("[Redis/Main] Initial connection failed:", e.message);
|
||||||
}
|
}
|
||||||
@@ -70,7 +72,10 @@ export class RedisHandler {
|
|||||||
await this.subscriber.connect();
|
await this.subscriber.connect();
|
||||||
logger.redis("[Redis/Subscriber] Connected");
|
logger.redis("[Redis/Subscriber] Connected");
|
||||||
|
|
||||||
this.subscriber.subscribe("request", async (m) => {
|
// CRITICAL: Await both subscriptions so they are guaranteed to be active
|
||||||
|
// before we announce readiness. Without awaiting, there is a window
|
||||||
|
// where the backend sends requests that this bot cannot yet receive.
|
||||||
|
await this.subscriber.subscribe("request", async (m) => {
|
||||||
if (this._destroyed) return;
|
if (this._destroyed) return;
|
||||||
try {
|
try {
|
||||||
const payload = JSON.parse(m);
|
const payload = JSON.parse(m);
|
||||||
@@ -83,10 +88,20 @@ export class RedisHandler {
|
|||||||
}));
|
}));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("[Redis/Subscriber] Request handler error:", e.message);
|
logger.error("[Redis/Subscriber] Request handler error:", e.message);
|
||||||
|
// Always send a response so the backend doesn't time out.
|
||||||
|
// Parse the id from the raw message so we can reply even when
|
||||||
|
// the handler threw before producing a result.
|
||||||
|
try {
|
||||||
|
const payload = JSON.parse(m);
|
||||||
|
this.send("response", JSON.stringify({
|
||||||
|
id: payload.id,
|
||||||
|
content: { error: "Internal bot error: " + e.message },
|
||||||
|
}));
|
||||||
|
} catch (_) { /* payload was unparseable — nothing we can do */ }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.subscriber.subscribe("info", (m) => {
|
await this.subscriber.subscribe("info", (m) => {
|
||||||
if (this._destroyed) return;
|
if (this._destroyed) return;
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(m);
|
const data = JSON.parse(m);
|
||||||
@@ -97,6 +112,11 @@ export class RedisHandler {
|
|||||||
logger.warn("[Redis/Subscriber] Info handler error:", e.message);
|
logger.warn("[Redis/Subscriber] Info handler error:", e.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// NOW announce readiness — the subscriber is guaranteed to be listening
|
||||||
|
// on both "request" and "info", so the backend's requests will be
|
||||||
|
// received and handled.
|
||||||
|
this.readyMessage();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("[Redis/Subscriber] Initial connection failed:", e.message);
|
logger.error("[Redis/Subscriber] Initial connection failed:", e.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user