Fix vulnerable deps, shutdown and game server colours; tidy commands
All checks were successful
Deploy Palico Bot / check (push) Successful in 9s
Deploy Palico Bot / deploy (push) Successful in 6s

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>
This commit is contained in:
Shinuwa 2026-11-29 19:59:08 +01:00
parent 60080df7dc
commit e08dba41a3
30 changed files with 638 additions and 643 deletions

View file

@ -1,6 +1,5 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
const ENVIRONMENT = {
NODE_ENV: "test",
@ -16,30 +15,37 @@ const ENVIRONMENT = {
};
Object.assign(process.env, ENVIRONMENT);
async function loadCommands() {
const files = fs
.readdirSync("src/commands", { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.flatMap((directory) =>
fs
.readdirSync(`src/commands/${directory.name}`)
.filter((file) => file.endsWith(".js"))
.map((file) => `../src/commands/${directory.name}/${file}`)
);
return Promise.all(files.map((file) => import(file)));
}
const { loadCommands } = await import("../src/loadCommands.js");
test("all Discord commands expose valid command data", async () => {
const modules = await loadCommands();
assert.equal(modules.length, 13);
for (const module of modules) {
assert.doesNotThrow(() => module.command.data.toJSON());
assert.equal(typeof module.command.execute, "function");
const commands = await loadCommands();
assert.equal(commands.length, 13);
for (const command of commands) {
assert.doesNotThrow(() => command.data.toJSON());
assert.equal(typeof command.execute, "function");
assert.ok(command.category, command.data.name);
}
});
test("/listcommand lists every loaded command under its category", async () => {
const commands = await loadCommands();
const { buildCommandList } = await import("../src/commands/utility/listcommand.js");
const message = buildCommandList(commands);
for (const command of commands) {
assert.ok(message.includes(`\`/${command.data.name}\` : ${command.data.description}`));
}
assert.match(message, /__Jukebox__\n`\/play`/);
assert.ok(message.length <= 2000);
});
test("/maketeam splits players on commas when there are any", async () => {
const { parsePlayers } = await import("../src/commands/game/maketeam.js");
assert.deepEqual(parsePlayers(" Alice Bob\tChloé "), ["Alice", "Bob", "Chloé"]);
assert.deepEqual(parsePlayers("Jean Pierre, Marie,, Léo "), ["Jean Pierre", "Marie", "Léo"]);
});
test("administrative commands require Discord permissions", async () => {
const modules = await loadCommands();
const commands = await loadCommands();
const protectedCommands = new Set([
"deletemsgs",
"invitation",
@ -49,8 +55,8 @@ test("administrative commands require Discord permissions", async () => {
"undeafall",
]);
for (const module of modules) {
const data = module.command.data.toJSON();
for (const command of commands) {
const data = command.data.toJSON();
if (protectedCommands.has(data.name)) {
assert.notEqual(data.default_member_permissions, undefined, data.name);
assert.notEqual(data.default_member_permissions, null, data.name);
@ -67,3 +73,42 @@ test("/queue lists the current track and what comes next", async () => {
assert.match(message, /En cours : \*\*Thème \\\*principal\\\* \(3:07\)\*\*/);
assert.match(message, /1\. Suite \(1:05:09\)/);
});
test("vocal commands act on the caller's voice channel, skipping bots", async () => {
const { changeVoiceStatus, commandVoiceChannel } = await import("../src/features/utilities.js");
const { Collection } = await import("discord.js");
const muted = [];
const member = (id, { bot = false, fail = false } = {}) => ({
id,
user: { bot },
voice: {
setMute: async (value) => {
if (fail) throw new Error("left the channel");
muted.push([id, value]);
},
},
});
const callerChannel = {
isVoiceBased: () => true,
members: new Collection([
["a", member("a")],
["bot", member("bot", { bot: true })],
["gone", member("gone", { fail: true })],
["b", member("b")],
]),
};
const configuredChannel = { isVoiceBased: () => true, members: new Collection() };
const client = { channels: { cache: new Map([["1", configuredChannel]]) } };
assert.equal(commandVoiceChannel({ client, member: { voice: { channel: callerChannel } } }), callerChannel);
assert.equal(commandVoiceChannel({ client, member: { voice: { channel: null } } }), configuredChannel);
const originalError = console.error;
console.error = () => {};
try {
await changeVoiceStatus(callerChannel, "mute");
} finally {
console.error = originalError;
}
assert.deepEqual(muted, [["a", true], ["b", true]]);
});

View file

@ -15,7 +15,9 @@ Object.assign(process.env, {
GAME_SERVERS_MESSAGE_ID: "1",
});
const { probeTcp, serverStatus } = await import("../src/features/showGameServers.js");
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());
@ -44,3 +46,17 @@ test("checked servers are probed on checkPort, else on port", async () => {
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>/);
});

View file

@ -152,7 +152,7 @@ test("removing the head of the queue while connecting plays the next track", asy
queue.enqueue(track("a"));
queue.enqueue(track("b"));
await queue.remove("a");
queue.remove("a");
release();
await settle();
@ -169,7 +169,7 @@ test("removing the current track returns it", async () => {
return true;
};
assert.equal((await queue.remove("a"))?.id, "a");
assert.equal((queue.remove("a"))?.id, "a");
queue.shutdown();
});