feat(status): rotate an editable list of bot statuses

The presence line was hard-coded, so advertising a different message meant
editing the source and restarting the bot. Statuses now live in the database
and are managed from Discord with /status — add, list, remove, pause and the
rotation interval, which applies without a restart.

An empty list falls back to a neutral "see the commands with /help" line, and
the first status added shows up right away instead of waiting a full turn.
This commit is contained in:
BlackAngelTV committed 2026-09-15 16:12:50 +02:00
1 parent ef8f09da10
commit c785e9abb7
8 files changed
+755 -2

No files matched your search

@@ -0,0 +1,14 @@
-- Rotating presence of the bot, editable from Discord (M15)
-- The presence is global to the bot, so these rows are not tied to a guild.
CREATE TABLE IF NOT EXISTS bot_statuses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT NOT NULL,
type TEXT NOT NULL DEFAULT 'watching',
url TEXT,
enabled INTEGER NOT NULL DEFAULT 1,
created_by TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_bot_statuses_text ON bot_statuses (text);
CREATE INDEX IF NOT EXISTS idx_bot_statuses_enabled ON bot_statuses (enabled, id);
@@ -0,0 +1,42 @@
import { getDatabase } from '../index.js';
/** Adds a status and returns the stored row, so the command can show its id. */
export function addBotStatus({ text, type = 'watching', url = null, createdBy = null }) {
const result = getDatabase()
.prepare('INSERT INTO bot_statuses (text, type, url, created_by) VALUES (?, ?, ?, ?)')
.run(text, type, url, createdBy);
return getBotStatus(Number(result.lastInsertRowid));
}
export function getBotStatus(id) {
return getDatabase().prepare('SELECT * FROM bot_statuses WHERE id = ?').get(id) ?? null;
}
/** Every status, disabled ones included, in the order they were added. */
export function listBotStatuses() {
return getDatabase().prepare('SELECT * FROM bot_statuses ORDER BY id ASC').all();
}
/** The statuses the rotation is allowed to show. */
export function listEnabledBotStatuses() {
return getDatabase().prepare('SELECT * FROM bot_statuses WHERE enabled = 1 ORDER BY id ASC').all();
}
export function setBotStatusEnabled(id, enabled) {
return getDatabase()
.prepare('UPDATE bot_statuses SET enabled = ? WHERE id = ?')
.run(enabled ? 1 : 0, id).changes;
}
export function removeBotStatus(id) {
return getDatabase().prepare('DELETE FROM bot_statuses WHERE id = ?').run(id).changes;
}
export function clearBotStatuses() {
return getDatabase().prepare('DELETE FROM bot_statuses').run().changes;
}
export function countBotStatuses() {
const row = getDatabase().prepare('SELECT COUNT(*) AS count FROM bot_statuses').get();
return row.count;
}