Add Discord update API route
All checks were successful
Deploy GSM / deploy (push) Successful in 26s
All checks were successful
Deploy GSM / deploy (push) Successful in 26s
Adds POST /api/servers/discord/send-update endpoint that allows superadmins to send announcements to all Discord guild update channels. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { Router } from 'express';
|
||||
import { readFileSync } from 'fs';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { authenticateToken, optionalAuth, requireRole, rejectGuest } from '../middleware/auth.js';
|
||||
import { getServerStatus, startServer, stopServer, restartServer, getConsoleLog, getProcessUptime, listFactorioSaves, createFactorioWorld, deleteFactorioSave, getFactorioCurrentSave, isHostFailed, listZomboidConfigs, readZomboidConfig, writeZomboidConfig, listPalworldConfigs, readPalworldConfig, writePalworldConfig, readTerrariaConfig, writeTerrariaConfig, readOpenTTDConfig, writeOpenTTDConfig } from '../services/ssh.js';
|
||||
import { sendRconCommand, getPlayers, getPlayerList } from '../services/rcon.js';
|
||||
@@ -9,6 +10,7 @@ import { getServerMetricsHistory, getCurrentMetrics } from '../services/promethe
|
||||
import { initWhitelistCache, getCachedWhitelist, setCachedWhitelist, initFactorioTemplates, getFactorioTemplates, createFactorioTemplate, deleteFactorioTemplate, initFactorioWorldSettings, getFactorioWorldSettings, saveFactorioWorldSettings, deleteFactorioWorldSettings, initAutoShutdownSettings, getAutoShutdownSettings, setAutoShutdownSettings, initActivityLog, logActivity, getActivityLog, initServerDisplaySettings, getServerDisplaySettings, getAllServerDisplaySettings, setServerDisplaySettings, initGuildSettings } from '../db/init.js';
|
||||
import { getEmptySince } from '../services/autoshutdown.js';
|
||||
import { getDefaultMapGenSettings, getPresetNames, getPreset } from '../services/factorio.js';
|
||||
import { sendUpdateToAllGuilds } from '../services/discordBot.js';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@@ -825,4 +827,36 @@ router.put("/:id/display-settings", authenticateToken, requireRole("superadmin")
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ============ DISCORD UPDATE ROUTES ============
|
||||
|
||||
// Send update to all Discord guilds (superadmin only)
|
||||
router.post("/discord/send-update", authenticateToken, requireRole("superadmin"), async (req, res) => {
|
||||
const { title, description, color, serverType } = req.body;
|
||||
|
||||
if (!title || !description) {
|
||||
return res.status(400).json({ error: "Title and description required" });
|
||||
}
|
||||
|
||||
try {
|
||||
const serverIcons = {
|
||||
minecraft: '⛏️', factorio: '⚙️', zomboid: '🧟', vrising: '🧛',
|
||||
palworld: '🦎', terraria: '⚔️', openttd: '🚂'
|
||||
};
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle((serverIcons[serverType] || '📢') + ' ' + title)
|
||||
.setDescription(description)
|
||||
.setColor(color || 0x5865F2)
|
||||
.setTimestamp();
|
||||
|
||||
await sendUpdateToAllGuilds(embed);
|
||||
logActivity(req.user.id, req.user.username, 'discord_update', serverType || 'general', title, req.user.discordId, req.user.avatar);
|
||||
res.json({ message: "Update sent to all Discord guilds" });
|
||||
} catch (err) {
|
||||
console.error('[Discord] Error sending update:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user