This commit is contained in:
NoLogicAlan committed 2026-10-06 00:32:48 +03:00
1 parent 2f51b7e1d7
commit 97fe282bb3
29 files changed
+101 -431

No files matched your search

+3 -9
View File
@@ -209,14 +209,12 @@ export class PlayerStateStore {
/**
* Load every snapshot belonging to this bot.
* @returns {Promise<Array<{guildId: string, data: object, positionMs: number, ageMs: number|null}>>}
* ageMs = time since the row was last written, measured by the DATABASE clock (immune to
* bot/DB clock skew); null when it cannot be determined.
* @returns {Promise<Array<{guildId: string, data: object, positionMs: number}>>}
*/
async loadAll() {
await this.init();
const rows = await this._exec(
`SELECT guild_id, data, position_ms, TIMESTAMPDIFF(SECOND, updated_at, NOW()) AS age_s FROM player_state WHERE bot_id = ?`,
`SELECT guild_id, data, position_ms FROM player_state WHERE bot_id = ?`,
[this.botId]
);
const out = [];
@@ -224,11 +222,7 @@ export class PlayerStateStore {
try {
const parsed = typeof row.data === "string" ? JSON.parse(row.data) : row.data;
if (parsed && parsed.channelId) {
const ageS = row.age_s == null ? NaN : Number(row.age_s);
out.push({
guildId: String(row.guild_id), data: parsed, positionMs: Number(row.position_ms) || 0,
ageMs: Number.isFinite(ageS) ? Math.max(0, ageS) * 1000 : null,
});
out.push({ guildId: String(row.guild_id), data: parsed, positionMs: Number(row.position_ms) || 0 });
}
} catch (e) {
logger.warn("[PlayerState] Skipping malformed snapshot for guild", row.guild_id, ":", e?.message);