Standalone bot/ service (its own package.json/Dockerfile) managed entirely through a new admin-only Discord Bot panel — token stored encrypted in the DB and pushed to the bot process in-memory, never an env var. Built in phases, each independently verified against a live Discord guild: - Bot skeleton: gateway connection, internal shared-secret API, self-heals on its own restart by pulling config from the site - Moderation core: /ban /kick /mute /warn /warnings + mod-log channel - Word/invite/spam filtering with leetspeak-resistant normalization and a staff role/channel allowlist - Scheduled messages: recurring (cron) and one-off channel posts - Role assignment: button role menus, auto-role on join, temp roles, bulk role ops - Auto-rotating primary invite with an audit log - Site integration: news-publish -> Discord announce webhook, manual /announce, read-only /wiki search Also fixes a pre-existing bug in both DB pools (server + bot): the mariadb driver defaulted to timezone 'local', silently mis-serializing bound Date params by the host's local offset instead of the DB's UTC session. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
// Read-only client for the main site's PUBLIC API (no shared secret — this is
|
|
// the same unauthenticated data any visitor's browser can fetch). Used by
|
|
// /wiki (search) and /announce (re-post an existing news item). Distinct from
|
|
// botInternalClient.js, which is the shared-secret-gated server<->bot channel.
|
|
const createLogger = require('../utils/logger')
|
|
|
|
const log = createLogger('site-api')
|
|
|
|
const BASE_URL = (process.env.SITE_PUBLIC_URL || 'http://localhost:3000/api/v1/public').replace(/\/+$/, '')
|
|
const TIMEOUT_MS = 5000
|
|
|
|
async function call(path) {
|
|
const controller = new AbortController()
|
|
const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS)
|
|
try {
|
|
const res = await fetch(`${BASE_URL}${path}`, { signal: controller.signal })
|
|
const data = await res.json().catch(() => null)
|
|
// Public content routes 503 with this shape while the site is in
|
|
// maintenance mode (see server/src/middleware/siteMode.js) — surface it
|
|
// distinctly so commands can show a clear message instead of a generic error.
|
|
if (res.status === 503 && data?.mode === 'maintenance') {
|
|
return { ok: false, maintenance: true, message: data.message }
|
|
}
|
|
if (!res.ok) return { ok: false, error: `site responded ${res.status}` }
|
|
return { ok: true, data }
|
|
} catch (err) {
|
|
log.warn('site API call failed', { path, message: err.message })
|
|
return { ok: false, error: err.message }
|
|
} finally {
|
|
clearTimeout(timeout)
|
|
}
|
|
}
|
|
|
|
function getNewsPost(idOrSlug) {
|
|
return call(`/posts/news/${encodeURIComponent(idOrSlug)}`)
|
|
}
|
|
|
|
function searchWiki(query) {
|
|
return call(`/wiki?q=${encodeURIComponent(query)}`)
|
|
}
|
|
|
|
module.exports = { getNewsPost, searchWiki }
|