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>
This commit is contained in:
Shinuwa 2026-11-29 11:22:10 +01:00
parent 6895d20459
commit 2471b5f6f7
3 changed files with 110 additions and 4 deletions

View file

@ -1,18 +1,30 @@
import { Router } from "express";
import { DirectMessageError, sendDirectMessage } from "../../features/directMessages.js";
const USER_ID_PATTERN = /^\d{17,20}$/;
// Une ligne par demande, sans le texte du message : « DM <identifiant> → <statut> ».
function logDirectMessage(userId, status) {
const target = typeof userId === "string" && USER_ID_PATTERN.test(userId) ? userId : "?";
console.log(`[${new Date().toLocaleString()}] DM ${target} → ${status}`);
}
// Messages privés envoyés pour une application de confiance (clé d'API) : `{ userId, content }`.
function notificationsRouter({ client }) {
const router = Router();
router.post("/dm", async (req, res) => {
const userId = req.body?.userId;
try {
await sendDirectMessage(client, req.body);
logDirectMessage(userId, 204);
res.status(204).end();
} catch (error) {
if (error instanceof DirectMessageError) {
logDirectMessage(userId, `${error.status} ${error.code}`);
return res.status(error.status).json({ error: error.message, code: error.code });
}
logDirectMessage(userId, 500);
throw error;
}
});