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>
62 lines
2.4 KiB
JavaScript
62 lines
2.4 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import net from "node:net";
|
|
|
|
Object.assign(process.env, {
|
|
NODE_ENV: "test",
|
|
DISCORD_GUILD_ID: "1",
|
|
SHINUWA_USER_ID: "1",
|
|
WEB_SERVER_PORT: "3000",
|
|
WEB_API_KEY: "test-key",
|
|
DISCORD_APPLICATION_ID: "1",
|
|
DISCORD_TOKEN: "test-token",
|
|
VOICE_CHANNEL_ID: "1",
|
|
TEXT_CHANNEL_ID: "1",
|
|
GAME_SERVERS_MESSAGE_ID: "1",
|
|
});
|
|
|
|
const { buildMessage, probeTcp, serverStatus } = await import(
|
|
"../src/features/showGameServers.js"
|
|
);
|
|
|
|
test("a listening TCP port is online, a closed one offline", async () => {
|
|
const server = net.createServer((socket) => socket.end());
|
|
server.listen(0, "127.0.0.1");
|
|
await new Promise((resolve) => server.once("listening", resolve));
|
|
const { port } = server.address();
|
|
try {
|
|
assert.equal(await probeTcp("127.0.0.1", port), true);
|
|
} finally {
|
|
await new Promise((resolve) => server.close(resolve));
|
|
}
|
|
assert.equal(await probeTcp("127.0.0.1", port), false);
|
|
});
|
|
|
|
test("servers without check keep their manual status", async () => {
|
|
const probe = () => assert.fail("must not probe");
|
|
assert.equal(await serverStatus({ active: true }, probe), true);
|
|
assert.equal(await serverStatus({ active: false }, probe), false);
|
|
});
|
|
|
|
test("checked servers are probed on checkPort, else on port", async () => {
|
|
const probed = [];
|
|
const probe = async (host, port) => probed.push(`${host}:${port}`) && true;
|
|
await serverStatus({ address: "games.example.com:8211", port: 8211, check: true, checkPort: 25575 }, probe);
|
|
await serverStatus({ address: "games.example.com:25566", port: 25566, check: true }, probe);
|
|
assert.deepEqual(probed, ["games.example.com:25575", "games.example.com:25566"]);
|
|
assert.equal(await serverStatus({ address: "x", check: true }, probe), false);
|
|
});
|
|
|
|
test("the status message is coloured and mentions the owner", () => {
|
|
const message = buildMessage({
|
|
servers: [
|
|
{ game: "Minecraft", address: "games.example.com:25565", active: true },
|
|
{ game: "Palworld", address: "games.example.com:8211", active: false },
|
|
],
|
|
});
|
|
// Les couleurs des blocs ansi de Discord demandent le caractère ESC lui-même.
|
|
assert.ok(message.includes("Minecraft : \u001b[2;32mOnline\u001b[0m"));
|
|
assert.ok(message.includes("Palworld : \u001b[2;31mOffline\u001b[0m"));
|
|
// OWNER_USER_ID absent : l'ancien nom SHINUWA_USER_ID est encore accepté.
|
|
assert.match(message, /<@1>/);
|
|
});
|