Files
pixelpoebel/src/structures/Deployer.ts
sarah 40be1e181c
Some checks failed
Auto Build and Push Docker Image / build (push) Failing after 8s
Initial: Pixelpöbel Discord Bot
- Modular Discord Bot mit TypeScript und discord.js
- Grouped Commands (/admin, /owner subcommands)
- SQLite Datenbank mit Persistenz
- Twitch Monitoring mit Stream-ID Tracking
- Konfigurierbares Warn-System (Auto-Kick/Mute/Ban)
- Mute mit verschiedenen Zeiteinheiten (sec, min, hour, day, week, month, year, perm)
- Auto-Deploy beim Start (Option 3)
- Docker Support

Features:
- /ping, /help, /twitch (online, add, remove, list)
- /admin (kick, warn, unwarn, mute, unmute, ban, unban, config)
- /owner (deploy, stats, servers)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 16:29:30 +01:00

59 lines
2.0 KiB
TypeScript

import { REST, Routes } from 'discord.js';
import { readdirSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export class Deployer {
static async deploy(clientId: string, token: string) {
const commands = [];
const rootDir = join(__dirname, '..');
const commandsPath = join(rootDir, 'commands');
const commandFolders = readdirSync(commandsPath);
for (const folder of commandFolders) {
const folderPath = join(commandsPath, folder);
const commandFiles = readdirSync(folderPath).filter(file => file.endsWith('.ts'));
for (const file of commandFiles) {
const filePath = join(folderPath, file);
const fileUrl = pathToFileURL(filePath).href;
const command = (await import(fileUrl)).default;
if (command && 'data' in command) {
commands.push(command.data.toJSON());
}
}
}
const rest = new REST().setToken(token);
console.log(`[DEPLOYER] Refreshing ${commands.length} application (/) commands.`);
const data: any = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`[DEPLOYER] Successfully reloaded ${data.length} application (/) commands.`);
return data.length;
}
static async deployIfMissing(clientId: string, token: string) {
const rest = new REST().setToken(token);
try {
const data: any = await rest.get(Routes.applicationCommands(clientId));
if (data.length > 0) {
console.log('[DEPLOYER] Commands already registered. Skipping deployment.');
return data.length;
}
} catch (error) {
// Commands don't exist yet
}
return this.deploy(clientId, token);
}
}