Fixes:
- Update dependencies within their ranges: npm audit reported 8
vulnerabilities (proxy-addr, multer, body-parser, undici...), now 0.
- Close open connections on shutdown: an open jukebox page kept its
/api/events stream alive, so every restart waited for the 10 s
forced exit and ended with code 1.
- Restore the ANSI escape characters of the game servers message, lost
in a269824 (the status showed "[2;32mOnline[0m" as plain text). They
are now written as \u001b so they cannot silently disappear again.
- Rename MusicQueue.listeners(), which shadowed EventEmitter's own
listeners(eventName), to humanListeners().
- Deploy: check the VM's SSH host key (new DEPLOY_KNOWN_HOSTS secret)
instead of StrictHostKeyChecking=no; run checks on push only, since
PR branches are already checked by their push.
Commands:
- /listcommand is built from the loaded commands and their descriptions.
- /deletemsgs reports messages older than 14 days that it cannot delete.
- Vocal commands act on the caller's voice channel, falling back to
VOICE_CHANNEL_ID.
- /maketeam accepts comma-separated names, so names can contain spaces.
- The game servers message is edited whenever its content changes, and
a failed first update is retried instead of stopping the refresh.
Cleanup:
- Shared command loader (src/loadCommands.js); drop the unused
"[disabled]" folders mechanism and the NODE_ENV requirement.
- SHINUWA_USER_ID becomes OWNER_USER_ID (the old name still works).
- One shuffle helper instead of three copies; remove dead code
(validateAudioFile, PORT fallback, needless async).
- README: prerequisites first, consistent Node version, deploy secrets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
2.5 KiB
JavaScript
82 lines
2.5 KiB
JavaScript
import { Client, Collection, GatewayIntentBits } from "discord.js";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
import { config } from "./src/config.js";
|
|
import { loadCommands } from "./src/loadCommands.js";
|
|
import { MusicQueue } from "./src/music/queue.js";
|
|
import { createQueuePersistence } from "./src/music/queuePersistence.js";
|
|
import { startWebServer } from "./src/web/server.js";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const client = new Client({
|
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
|
|
});
|
|
|
|
client.commands = new Collection(
|
|
(await loadCommands()).map((command) => [command.data.name, command])
|
|
);
|
|
|
|
const eventsPath = path.join(__dirname, "src/events");
|
|
const eventFiles = fs
|
|
.readdirSync(eventsPath)
|
|
.filter((file) => file.endsWith(".js"));
|
|
|
|
for (const file of eventFiles) {
|
|
const filePath = path.join(eventsPath, file);
|
|
const eventFile = await import(filePath);
|
|
if (eventFile.event.once) {
|
|
client.once(eventFile.event.name, (...args) =>
|
|
eventFile.event.execute(...args)
|
|
);
|
|
} else {
|
|
client.on(eventFile.event.name, (...args) =>
|
|
eventFile.event.execute(...args)
|
|
);
|
|
}
|
|
}
|
|
|
|
const musicQueue = new MusicQueue(client, {
|
|
persistence: createQueuePersistence(
|
|
path.join(process.cwd(), "storage", "runtime", "queue.json")
|
|
),
|
|
});
|
|
// Les commandes du jukebox (/play, /skip, /queue) y accèdent par interaction.client.
|
|
client.musicQueue = musicQueue;
|
|
await client.login(config.token);
|
|
|
|
const { server } = startWebServer({ queue: musicQueue, client });
|
|
|
|
server.on("error", (error) => {
|
|
console.error("HTTP server error", error);
|
|
});
|
|
|
|
let shuttingDown = false;
|
|
async function shutdown(signal) {
|
|
if (shuttingDown) return;
|
|
shuttingDown = true;
|
|
console.log(`[${new Date().toLocaleString()}] Shutting down (${signal})`);
|
|
|
|
musicQueue.shutdown();
|
|
client.destroy();
|
|
|
|
const forceExit = setTimeout(() => process.exit(1), 10_000);
|
|
forceExit.unref();
|
|
|
|
server.close(() => {
|
|
clearTimeout(forceExit);
|
|
});
|
|
// close() n'attend que la fin des requêtes en cours : les flux en direct (/api/events) des
|
|
// pages jukebox ouvertes ne finissent jamais d'eux-mêmes et bloqueraient l'arrêt.
|
|
server.closeAllConnections();
|
|
}
|
|
|
|
process.once("SIGTERM", () => void shutdown("SIGTERM"));
|
|
process.once("SIGINT", () => void shutdown("SIGINT"));
|
|
process.on("unhandledRejection", (error) => {
|
|
console.error("Unhandled promise rejection", error);
|
|
});
|
|
|
|
export { client, musicQueue };
|