Initial commit: Gaming Hub foundation

Plugin-based Discord bot framework with web frontend:
- Core: Discord.js client, SSE broadcast, JSON persistence
- Plugin system: lifecycle hooks (init, onReady, routes, snapshot, destroy)
- Web: React 19 + Vite 6 + TypeScript, tab-based navigation
- Docker: multi-stage build (Node 24, static ffmpeg, yt-dlp)
- GitLab CI: Kaniko with LAN registry caching

Ready for plugin development.
This commit is contained in:
Claude Code 2026-03-05 22:52:13 +01:00
parent 1ae431dd2f
commit ae1c41f0ae
19 changed files with 954 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import { Client, GatewayIntentBits } from 'discord.js';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.MessageContent,
],
});
export default client;

View file

@ -0,0 +1,39 @@
import fs from 'node:fs';
import path from 'node:path';
const DATA_DIR = process.env.DATA_DIR ?? '/data';
const stateFile = path.join(DATA_DIR, 'hub-state.json');
let state: Record<string, any> = {};
export function loadState(): void {
try {
if (fs.existsSync(stateFile)) {
state = JSON.parse(fs.readFileSync(stateFile, 'utf-8'));
}
} catch (e) {
console.error('Failed to load state:', e);
}
}
export function saveState(): void {
try {
fs.mkdirSync(path.dirname(stateFile), { recursive: true });
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2));
} catch (e) {
console.error('Failed to save state:', e);
}
}
export function getState<T = any>(key: string, defaultValue?: T): T {
return (state[key] as T) ?? (defaultValue as T);
}
export function setState(key: string, value: any): void {
state[key] = value;
saveState();
}
export function getFullState(): Record<string, any> {
return { ...state };
}

39
server/src/core/plugin.ts Normal file
View file

@ -0,0 +1,39 @@
import { Client } from 'discord.js';
import express from 'express';
export interface Plugin {
name: string;
version: string;
description: string;
/** Called once when plugin is loaded */
init(ctx: PluginContext): Promise<void>;
/** Called when Discord client is ready */
onReady?(ctx: PluginContext): Promise<void>;
/** Called to register Express routes */
registerRoutes?(app: express.Application, ctx: PluginContext): void;
/** Called to build SSE snapshot data for new clients */
getSnapshot?(ctx: PluginContext): Record<string, any>;
/** Called on graceful shutdown */
destroy?(ctx: PluginContext): Promise<void>;
}
export interface PluginContext {
client: Client;
dataDir: string;
}
const loadedPlugins: Plugin[] = [];
export function registerPlugin(plugin: Plugin): void {
loadedPlugins.push(plugin);
console.log(`[Plugin] Registered: ${plugin.name} v${plugin.version}`);
}
export function getPlugins(): Plugin[] {
return [...loadedPlugins];
}

22
server/src/core/sse.ts Normal file
View file

@ -0,0 +1,22 @@
import { Response } from 'express';
const sseClients = new Set<Response>();
export function addSSEClient(res: Response): void {
sseClients.add(res);
}
export function removeSSEClient(res: Response): void {
sseClients.delete(res);
}
export function sseBroadcast(data: Record<string, any>): void {
const msg = `data: ${JSON.stringify(data)}\n\n`;
for (const c of sseClients) {
try { c.write(msg); } catch { sseClients.delete(c); }
}
}
export function getSSEClientCount(): number {
return sseClients.size;
}