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; }