Commit graph

17 commits

Author SHA1 Message Date
793765fb79 Resume interrupted tracks where they stopped
A track cut off without anyone asking (voice connection lost, bot
leaving an empty channel, restart) used to start over from the
beginning; on an hour-long mix, a drop near the end replayed it all.

- The requeued track keeps resumeAt and ffmpeg seeks to it (-ss before
  -i, so it jumps there without decoding the start). It resumes 2 s
  before the cut; a track cut in its first 2 s starts over.
- The player keeps playing without a connection
  (NoSubscriberBehavior.Play), so the position of a voice drop is taken
  when the connection drops, not 5 s later when it is given up.
- The saved queue holds the current position, and it is saved every
  30 s while playing: after a crash the track resumes at most 30 s
  earlier.
- Loop mode replays a resumed track from the beginning; skip and stop
  are unchanged.
- The web page and /queue show "Reprise à 49:15" for such a track, and
  the progress bar counts from the resume point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 23:11:05 +01:00
11ee972636 Add library sections and track covers
All checks were successful
Deploy Palico Bot / check (push) Successful in 9s
Deploy Palico Bot / deploy (push) Successful in 7s
Sections:
- The library can be split into named, ordered sections, stored in
  storage/runtime/sections.json; each track keeps its sectionId.
- Sections are created, renamed, reordered and deleted from the page
  (/api/library/sections). Deleting one keeps its tracks, without a
  section.
- A section, or the tracks without one, can be queued in one go,
  shuffled or not (enqueue-all takes a sectionId).
- The upload form (file or link) picks the section of a kept track.
- Without any section, the library stays a plain list.

Covers:
- A kept track takes the cover embedded in its file (MP3, FLAC...),
  from the web page or /play garder:. Older tracks are looked at once
  on startup; a track without one keeps cover: null.
- "Renommer" becomes "Modifier": a dialog to change the title, the
  section and the cover (upload with preview, or removal).
- ffmpeg turns covers into JPEGs of at most 512 px, stored in
  storage/covers and deleted with their track. An uploaded image is
  only passed to ffmpeg after its signature is checked (PNG, JPEG,
  WebP, GIF), with that decoder forced, so ffmpeg never guesses the
  format of an unknown file.
- Covers are served under /covers without authentication, since an
  <img> cannot send the key; their random names are only given by the
  API and never change content (one-year cache).
- The current track and the queue show the cover of their library
  track.

Docs: README lists the new data to back up; storage/covers is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 21:27:49 +01:00
3795ee06cb Add file headers, tidy the stylesheet and document the conventions
Headers:
- Every JavaScript file (sources, front, scripts, tests) starts with a
  /** @file … */ header, in the three levels used by sokko-g: a short
  description for simple files; Utilisé par / Attention / @see for
  shared modules; a full header (context, entry points, callers,
  dependencies, pitfalls) for index.js, the music queue, the web
  server, the storage manager and the jukebox page script.
- No @author, @version or @since: git already knows.
- test/fileHeaders.test.js fails `npm run check` when a header is
  missing or a central file's header is incomplete.

Stylesheet (no visual change, checked by comparing every element's
computed styles in Chromium at 1280, 800 and 400 px, hover included):
- Role header and section comments.
- Transparent shades derive from the colour variables with
  color-mix() instead of copied rgba() values; new tokens for repeated
  values (text, text on accent, accent gradient, white veils, shadow).
- Native nesting for buttons, the live indicator, upload rows and
  home cards; drop the unused .hero__visual--large and redundant rules.
- Utility classes move to the end so they win over components. The
  library list's u-mt-1, which never applied (.list reset it), is
  removed to keep the layout as it was.

Docs: CONTRIBUTING.md describes the language, header and stylesheet
conventions; CLAUDE.md points to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 21:05:59 +01:00
e08dba41a3 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>
2026-11-29 19:59:08 +01:00
8cf0a8eb5b Stop listening when an events client disconnects; warn on partial OAuth setup
All checks were successful
Deploy Palico Bot / check (push) Successful in 10s
Deploy Palico Bot / deploy (push) Successful in 7s
- Detach the events stream from the queue on the response's close event,
  which fires when the client goes away whatever the Node version.
- Log a warning when only some of the Discord login variables are set,
  instead of silently leaving the login disabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:23:28 +01:00
a269824e2a Optionally check game servers' status instead of editing it by hand
A server with "check": true in gameservers-list.json is probed over TCP
every two minutes, on "checkPort" or its game port; games played over UDP
can be checked on a TCP side port such as RCON. Servers without it keep
their manual "active" status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:22:25 +01:00
399e851178 Let guild members log in to the jukebox with Discord
- Optional Discord OAuth2 login (identify scope), enabled by
  DISCORD_CLIENT_SECRET, WEB_PUBLIC_URL and SESSION_SECRET; restricted to
  members of the configured guild, checked at login.
- Stateless 30-day session in a signed HttpOnly SameSite=Lax cookie; the
  OAuth state is checked against its own short-lived cookie.
- The jukebox API accepts the key or the session; with the session,
  changes must come from the site's own origin. The member's server name
  becomes the uploader name.
- GET /auth/me tells the page whether the login is enabled and who is
  logged in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:17:48 +01:00
9fb54798dd Keep the queue across restarts; add shuffle, loop, renaming and live events
- Save the queue to storage/runtime/queue.json and restore it at startup,
  the interrupted track first; playback resumes once someone is in the
  voice channel. Shutdown keeps the queued files instead of deleting them.
- Shuffle the upcoming tracks; loop mode sends finished tracks back to the
  end of the queue, except removed or failed ones.
- Rename library tracks (queued copies follow), enqueue the whole library,
  optionally shuffled.
- Stream queue and library changes to the web page with Server-Sent Events
  (GET /api/events).
- Sanitise the requester name sent when queueing a library track.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:15:25 +01:00
39d2b6acfb Add tracks from a direct link and from Discord with /play, /skip, /queue
- Download direct audio links server side (web page and /play), refusing
  internal and special addresses at connection time and after every
  redirect, with size and time limits.
- /play takes an attachment, a direct link or a library track
  (autocomplete), and can keep the file in the library; /skip and /queue
  control and show the shared queue.
- Share one ingest path between uploads, links and Discord attachments.
- Answer 413 instead of 500 when the library is full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:13:12 +01:00
98f4d29ac7 Encode jukebox audio with native ffmpeg, normalise loudness, read metadata
- Play every track through an ffmpeg process that normalises loudness
  (EBU R128) and outputs Ogg Opus, handed to Discord as is: no more Opus
  encoding in JavaScript with opusscript. Measured at over 40x real time,
  about 2% of a core while playing. Closing the stream kills ffmpeg.
- Encoding at upload instead was ruled out: over two minutes for an 85-minute
  mix, during which the upload would hang.
- Read duration, title and artist with ffprobe at upload; default the title
  to "Artist - Title" or the file name without extension.
- Fill the duration of existing library entries at startup.
- Expose the position of the current track in queue snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:10:49 +01:00
362c7772ba Make Discord commands and the deploy pipeline sturdier
- Defer the voice commands' reply: updating every member can take longer
  than the 3 seconds Discord allows; one member leaving no longer fails the
  whole operation.
- Replace the deprecated ephemeral option with MessageFlags, answer command
  errors in French and log when that answer itself fails; route
  autocomplete interactions to the command.
- Add /readyz, which answers 503 while the bot is not connected to Discord.
- Run npm ci and npm run check on every push; deploy main only when they
  pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:04:43 +01:00
a1cefe6da5 Fix jukebox playback getting stuck and make the web page reflect actions
- Adding a track or someone joining the voice channel now resumes a queue
  suspended because the bot was alone; before, only the Play button did.
- Retry the voice connection with backoff instead of giving up after one
  failed attempt.
- Keep playing when the head of the queue changes while connecting.
- Requeue the interrupted track when the bot leaves an empty channel or
  loses its voice connection.
- Removing the current track no longer answers 404; other bots no longer
  count as listeners.
- Accept uploads whatever MIME type the browser sends (ffprobe validates the
  content) and clean temporary files hourly, sparing queued ones.
- Web page: refresh again after an action instead of reusing a stale
  request, disable buttons while a request runs, show the real start time and
  custom titles, and support drag and drop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 11:59:58 +01:00
6ca17264e0 Let trusted apps add an embed and a link button to Discord direct messages
All checks were successful
Deploy Palico Bot / deploy (push) Successful in 7s
- POST /api/notifications/dm accepts optional embed (title, description, url, color, thumbnail, fields, footer, timestamp) and link fields; plain text stays required for phone notifications.
- Every value is checked against Discord's limits, and urls and thumbnails must use https; a refused embed answers 400 INVALID_EMBED.
- Sokko TCG uses it to show the destination, the result and the loot of its expedition alerts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 11:24:20 +01:00
2471b5f6f7 Explain missing channel access in /invitation; log DM requests
All checks were successful
Deploy Palico Bot / deploy (push) Successful in 6s
- /invitation checks the bot can view and post in the channel, and turns
  Discord's 50001/50013 into a clear reply instead of a generic error
- The DM route logs one line per request (user ID and status, never the text)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 11:22:10 +01:00
6895d20459 Fix deploy and lock down the DM route; add /invitation
All checks were successful
Deploy Palico Bot / deploy (push) Successful in 32s
- Deploy workflow: pin node:24-bookworm; install openssh-client only if missing
- Auth failure limiter counts only 401s (422/404 no longer lock out clients)
- trust proxy configurable (WEB_TRUSTED_PROXIES), never "true"
- DM route: loopback connections only, dedicated NOTIFICATIONS_API_KEY, 503 when unset
- Jukebox: no polling without a key, stop on 401
- /invitation: posts the temporary invite message after checking the link
- Stop tracking storage/library.json; README describes the real deployment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 10:57:22 +01:00
3655b1ad74 Add an authenticated route that sends Discord direct messages for trusted apps
Some checks failed
Deploy Palico Bot / deploy (push) Failing after 3s
- POST /api/notifications/dm takes a user id and a text, sends it as a direct message with no active mentions, and answers 204, 400, 404 or 422.
- The send logic lives in src/features/directMessages.js with its own tests; the route gets its own per-minute rate limit behind the existing API key.
- Sokko TCG uses it for its opt-in Expedition alerts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 17:09:32 +01:00
20624a5c9c Harden bot, storage and web API 2026-06-30 17:25:00 +02:00