feat: FluxerList integration, log channel, and stability fixes

FluxerList:
- Auto server-count sync (posts on startup, then every 30 min, budget-aware)
- Vote check wired into the vote command (60s per-user cache)
- 429/Retry-After aware rate limiting with typed actionable errors
- Enable via config.fluxerlist.apiKey (fl_ key from FluxerList dashboard)

Log channel (ErrorChannel):
- Forwards all errors/warnings + crash reports to a Fluxer channel
- Startup confirmation message + owner-only logtest command
- Fix: @fluxerjs REST needs { body: { content } } shape (empty-message bug)
This commit is contained in:
NoLogicAlan committed 2026-09-23 02:25:53 +03:00
1 parent d9b529edd7
commit 2fbbdf0322
13 files changed
+534 -94

No files matched your search

+40 -9
View File
@@ -11,11 +11,20 @@ export const FLUXERLIST = {
/** Public FluxerList website URL. @type {string} */
SITE_URL: "https://fluxerlist.com",
/** API endpoint path templates. @type {{ SERVER_VOTERS: string, BOT_VOTERS: string }} */
/** API endpoint path templates. @type {{ SERVER_VOTERS: string, BOT_VOTERS: string, BOT_STATS: string, BOT_CHECK: string, BOT_INFO: string }} */
ENDPOINTS: {
SERVER_VOTERS: "/servers/:id/voters",
BOT_VOTERS: "/bots/:id/voters",
/** POST server count for a bot listing (body: { serverCount }). */
BOT_STATS: "/bots/:id/stats",
/** GET a user's vote status for a bot (query: fluxerId). */
BOT_CHECK: "/bots/:id/check",
/** GET a bot's public listing data. */
BOT_INFO: "/bots/:id",
},
/** Accepted resource type identifiers. @type {string[]} */
@@ -50,7 +59,7 @@ export const FLUXERLIST_AUTH = {
};
/**
* FluxerList pagination and cache limits.
* FluxerList pagination, cache and rate-limit limits (per docs.fluxerlist.com).
* @namespace FLUXERLIST_LIMITS
*/
export const FLUXERLIST_LIMITS = {
@@ -63,25 +72,47 @@ export const FLUXERLIST_LIMITS = {
/** Maximum allowed items-per-page. @type {number} */
MAX_LIMIT: 100,
/** Cache time-to-live in milliseconds. @type {number} */
/** Cache time-to-live in milliseconds for voter lists. @type {number} */
CACHE_TTL_MS: 5 * 60 * 1000,
/** Minimum spacing between stats posts (docs: limit is 12/hour). @type {number} */
STATS_MIN_INTERVAL_MS: 5 * 60 * 1000,
/** Recommended stats cadence (docs: "post on startup, then roughly every 30 minutes"). @type {number} */
STATS_DEFAULT_INTERVAL_MS: 30 * 60 * 1000,
/** Cache TTL for per-user vote checks (docs limit 60/min; cache on our side). @type {number} */
VOTE_CHECK_TTL_MS: 60 * 1000,
/** Cache TTL for the bot's own listing info (default 20/min bucket). @type {number} */
BOT_INFO_TTL_MS: 5 * 60 * 1000,
/** Hard cap on scheduled stats intervals accepted from config, in ms. @type {number} */
STATS_MAX_INTERVAL_MS: 6 * 60 * 60 * 1000,
};
/**
* Build a full FluxerList API URL by substituting `:id` in the endpoint and appending query params.
* @param {string} endpoint - Endpoint template (e.g. `"/servers/:id/voters"`).
* `page`/`limit` keep their clamping behavior; any other params are passed through verbatim.
* @param {string} endpoint - Endpoint template (e.g. `"/bots/:id/check"`).
* @param {string} resourceId - Value to substitute for `:id`.
* @param {{ page?: number, limit?: number }} [queryParams={}]
* @param {Record<string, string|number>} [queryParams={}]
* @returns {string} Fully qualified URL.
*/
export function buildFluxerListUrl(endpoint, resourceId, queryParams = {}) {
const path = endpoint.replace(":id", encodeURIComponent(resourceId));
const params = new URLSearchParams();
if (queryParams.page) params.set("page", String(queryParams.page));
if (queryParams.limit) {
const clamped = Math.min(Math.max(1, queryParams.limit), FLUXERLIST_LIMITS.MAX_LIMIT);
params.set("limit", String(clamped));
for (const [key, value] of Object.entries(queryParams)) {
if (value === undefined || value === null) continue;
if (key === "limit") {
const clamped = Math.min(Math.max(1, Number(value) || 1), FLUXERLIST_LIMITS.MAX_LIMIT);
params.set("limit", String(clamped));
} else if (key === "page") {
params.set("page", String(Math.max(1, Number(value) || 1)));
} else {
params.set(key, String(value));
}
}
const qs = params.toString();