feat(voice): add temporary voice channel manager

Joining the trigger channel must feel instant and never leave orphan channels behind, so the ownership is stored in SQLite, empty channels are deleted after a short grace period and a startup sweep cleans up whatever a restart left behind.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:51:17 +02:00
1 parent ef1bedbc65
commit 5191942d5a
12 files changed
+1277 -1

No files matched your search

@@ -0,0 +1,14 @@
-- Temporary voice channels created by joining the trigger channel (M14)
CREATE TABLE IF NOT EXISTS voice_channels (
channel_id TEXT PRIMARY KEY,
guild_id TEXT NOT NULL,
owner_id TEXT NOT NULL,
trigger_id TEXT,
name TEXT NOT NULL,
locked INTEGER NOT NULL DEFAULT 0,
user_limit INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_voice_channels_guild ON voice_channels (guild_id);
CREATE INDEX IF NOT EXISTS idx_voice_channels_owner ON voice_channels (guild_id, owner_id);
@@ -0,0 +1,64 @@
import { getDatabase } from '../index.js';
export function addVoiceChannel({ channelId, guildId, ownerId, triggerId = null, name, userLimit = 0 }) {
getDatabase()
.prepare(
`INSERT INTO voice_channels (channel_id, guild_id, owner_id, trigger_id, name, user_limit)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT (channel_id) DO UPDATE SET
owner_id = excluded.owner_id,
name = excluded.name`,
)
.run(channelId, guildId, ownerId, triggerId, name, userLimit);
}
export function getVoiceChannel(channelId) {
return getDatabase().prepare('SELECT * FROM voice_channels WHERE channel_id = ?').get(channelId) ?? null;
}
export function listVoiceChannels(guildId) {
return getDatabase()
.prepare('SELECT * FROM voice_channels WHERE guild_id = ? ORDER BY created_at ASC')
.all(guildId);
}
/** Channels still owned by a member, used to move them back instead of creating another (M14-T03). */
export function listOwnedVoiceChannels(guildId, ownerId) {
return getDatabase()
.prepare('SELECT * FROM voice_channels WHERE guild_id = ? AND owner_id = ? ORDER BY created_at ASC')
.all(guildId, ownerId);
}
export function setVoiceOwner(channelId, ownerId) {
return getDatabase()
.prepare('UPDATE voice_channels SET owner_id = ? WHERE channel_id = ?')
.run(ownerId, channelId).changes;
}
export function setVoiceName(channelId, name) {
return getDatabase().prepare('UPDATE voice_channels SET name = ? WHERE channel_id = ?').run(name, channelId)
.changes;
}
export function setVoiceLocked(channelId, locked) {
return getDatabase()
.prepare('UPDATE voice_channels SET locked = ? WHERE channel_id = ?')
.run(locked ? 1 : 0, channelId).changes;
}
export function setVoiceLimit(channelId, userLimit) {
return getDatabase()
.prepare('UPDATE voice_channels SET user_limit = ? WHERE channel_id = ?')
.run(userLimit, channelId).changes;
}
export function removeVoiceChannel(channelId) {
return getDatabase().prepare('DELETE FROM voice_channels WHERE channel_id = ?').run(channelId).changes;
}
export function countVoiceChannels(guildId) {
const row = getDatabase()
.prepare('SELECT COUNT(*) AS count FROM voice_channels WHERE guild_id = ?')
.get(guildId);
return row.count;
}