feat: add unified Discord bot and dashboard

This commit is contained in:
Snipzil committed 2026-10-20 22:13:50 -04:00
1 parent 113bf9342e
commit b11ae1dfa8
14 files changed
+1708 -14

No files matched your search

+20 -2
View File
@@ -18,13 +18,23 @@ const SCHEMA = `
`;
const MAX_DETAIL = 400;
const SHOWN = 300;
const listeners = new Set();
const load = () => accounts.database().exec(SCHEMA);
const record = (by, action, target = "", detail = "") => {
const entry = {at: Math.floor(Date.now() / 1000), by: String(by), action: String(action), target: String(target), detail: String(detail).slice(0, MAX_DETAIL)};
accounts.database().prepare("INSERT INTO mod_log (at, by, action, target, detail) VALUES (?, ?, ?, ?, ?)")
.run(Math.floor(Date.now() / 1000), by, action, String(target), String(detail).slice(0, MAX_DETAIL));
.run(entry.at, entry.by, entry.action, entry.target, entry.detail);
console.log(`[mod] ${logText(by)}: ${logText(action)}${logText(target ? ` "${target}"` : "")}`);
for (const listener of listeners) {
try {
listener(entry);
}
catch (err) {
console.error(`[modlog] listener failed: ${logText(err.message)}`);
}
}
};
const recent = () => accounts.database().prepare("SELECT at, by, action, target, detail FROM mod_log ORDER BY id DESC LIMIT ?").all(SHOWN);
@@ -33,4 +43,12 @@ const recent = () => accounts.database().prepare("SELECT at, by, action, target,
const about = username => accounts.database().prepare("SELECT at, by, action, target, detail FROM mod_log WHERE target = ? COLLATE NOCASE ORDER BY id DESC LIMIT 100")
.all(String(username));
module.exports = {load, record, recent, about};
// Optional integrations subscribe here rather than wrapping record(), so an
// unavailable Discord channel can never stop a moderation action or its DB
// audit record from being written.
const onRecord = listener => {
listeners.add(listener);
return () => listeners.delete(listener);
};
module.exports = {load, record, recent, about, onRecord};