feat(tickets): guide members in ticket channels and log to the technical salon
CI / quality (push) Has been cancelled

Tickets were opened with three words and members expected an immediate answer,
so the channel now posts a guidance embed: what details to give (context, steps
to reproduce, exact error, OS version) and that a reply can take a while.

The ticket journal moves to CHANNEL_LOGS_ID so the environment keeps one log
salon per purpose: CHANNEL_TICKETS_LOGS_ID held the same entries and nothing
else read it. A wrong CATEGORY_TICKETS_ID now says which case it is, since a
missing category was reported as a mistyped one.
This commit is contained in:
BlackAngelTV committed 2026-10-02 20:13:31 +02:00
1 parent a996065861
commit 1310840215
7 files changed
+187 -23

No files matched your search

-1
View File
@@ -33,7 +33,6 @@ CHANNEL_RULES_ID=
CHANNEL_ANNOUNCEMENTS_ID=
CHANNEL_LOGS_ID=
CHANNEL_MOD_LOGS_ID=
CHANNEL_TICKETS_LOGS_ID=
CHANNEL_NOTIF_ISSUES_ID=
CHANNEL_NOTIF_PULL_REQUESTS_ID=
CHANNEL_NOTIF_COMMITS_ID=
+1 -2
View File
@@ -129,9 +129,8 @@ Full template: [`.env.example`](.env.example). Default values in brackets.
| `CHANNEL_RULES_ID` | Rules: link sent to newcomers, and where the dashboard pins the message. |
| | Later saves edit that same message |
| `CHANNEL_ANNOUNCEMENTS_ID` | FWS announcements |
| `CHANNEL_LOGS_ID` | Functional logs |
| `CHANNEL_LOGS_ID` | Functional and technical logs, ticket journal |
| `CHANNEL_MOD_LOGS_ID` | Moderation logs |
| `CHANNEL_TICKETS_LOGS_ID` | Ticket opening/closing journal |
| `CHANNEL_NOTIF_ISSUES_ID` | Issue notifications |
| `CHANNEL_NOTIF_PULL_REQUESTS_ID` | Pull request notifications |
| `CHANNEL_NOTIF_COMMITS_ID` | Commit notifications |
+1 -2
View File
@@ -130,9 +130,8 @@ Modèle complet : [`.env.example`](.env.example). Valeurs par défaut entre pare
| `CHANNEL_WELCOME_ID` | Messages de bienvenue |
| `CHANNEL_RULES_ID` | Règlement : lien envoyé aux nouveaux, et salon où le tableau de bord publie le message épinglé (les enregistrements suivants le modifient) |
| `CHANNEL_ANNOUNCEMENTS_ID` | Annonces FWS |
| `CHANNEL_LOGS_ID` | Logs fonctionnels |
| `CHANNEL_LOGS_ID` | Logs fonctionnels et techniques, journal des tickets |
| `CHANNEL_MOD_LOGS_ID` | Logs de modération |
| `CHANNEL_TICKETS_LOGS_ID` | Journal d'ouverture/fermeture des tickets |
| `CHANNEL_NOTIF_ISSUES_ID` | Notifications issues |
| `CHANNEL_NOTIF_PULL_REQUESTS_ID` | Notifications pull requests |
| `CHANNEL_NOTIF_COMMITS_ID` | Notifications commits |
-1
View File
@@ -43,7 +43,6 @@ export const env = Object.freeze({
announcements: read('CHANNEL_ANNOUNCEMENTS_ID'),
logs: read('CHANNEL_LOGS_ID'),
modLogs: read('CHANNEL_MOD_LOGS_ID'),
ticketLogs: read('CHANNEL_TICKETS_LOGS_ID'),
notifIssues: read('CHANNEL_NOTIF_ISSUES_ID'),
notifPullRequests: read('CHANNEL_NOTIF_PULL_REQUESTS_ID'),
notifCommits: read('CHANNEL_NOTIF_COMMITS_ID'),
+45 -9
View File
@@ -13,7 +13,7 @@ import {
getTicketByChannel,
} from '../../database/repositories/ticket-repository.js';
import { ticketButtons } from '../../ui/buttons.js';
import { baseEmbed, successEmbed } from '../../ui/embeds.js';
import { TONE, baseEmbed, bullets, successEmbed } from '../../ui/embeds.js';
const log = createLogger('tickets');
@@ -39,10 +39,7 @@ function ticketEmbed(ticket, category) {
const claimed = ticket.claimed_by ? `<@${ticket.claimed_by}>` : 'Personne';
return baseEmbed(COLORS.ticket)
.setTitle(`🎫 Ticket ${category.label} #${ticket.id}`)
.setDescription(
`<@${ticket.author_id}> décris ta demande ici, avec le plus de détails possible : ` +
'contexte, étapes pour reproduire, messages d’erreur. Plus tu en dis, plus vite on t’aide.',
)
.setDescription(`<@${ticket.author_id}> décris ta demande ici, l’équipe lit ce salon.`)
.addFields(
{ name: 'Catégorie', value: category.label, inline: true },
{ name: 'Statut', value: ticket.status === 'open' ? 'Ouvert' : 'Fermé', inline: true },
@@ -50,6 +47,37 @@ function ticketEmbed(ticket, category) {
);
}
/**
* Guidance posted under the ticket header: what to write, and that an answer can
* take a while. Members often open a ticket with three words and wait.
*/
function ticketHelpEmbed() {
return baseEmbed(COLORS.info)
.setTitle(TONE.advice)
.setDescription(
'Détaille au maximum : tout ce que tu écris ici nous évite de te poser des questions pour rien.',
)
.addFields(
{
name: 'Ce qui nous aide',
value: bullets([
'ce que tu voulais faire, et ce qui s’est passé à la place',
'les étapes pour reproduire le problème, une par une',
'le message d’erreur exact, en photo ou recopié tel quel',
'ta version de l’OS, et ce que tu viens d’installer',
]),
},
{
name: 'Ça peut prendre un peu de temps',
value: bullets([
'ce salon est privé : toi, l’équipe et les personnes que vous ajoutez y voient ces messages',
'l’équipe répond ici, donc ne cherche pas ailleurs pour suivre ton ticket',
'une fois ta demande réglée, ferme le ticket avec le bouton **Fermer**',
]),
},
);
}
function channelName(categoryId, username) {
const slug = username
.toLowerCase()
@@ -83,9 +111,10 @@ function buildOverwrites(guild, client, category, authorId) {
return overwrites;
}
/** The ticket journal lives in the technical logs salon (`CHANNEL_LOGS_ID`). */
async function fetchTicketLogChannel(client) {
if (!env.channels.ticketLogs) return null;
const channel = await client.channels.fetch(env.channels.ticketLogs).catch(() => null);
if (!env.channels.logs) return null;
const channel = await client.channels.fetch(env.channels.logs).catch(() => null);
return channel?.isSendable() ? channel : null;
}
@@ -115,7 +144,14 @@ export async function createTicket(interaction, categoryId) {
const guild = interaction.guild;
const parent = await guild.channels.fetch(env.channels.ticketCategory).catch(() => null);
if (parent?.type !== ChannelType.GuildCategory) {
if (!parent) {
log.warn('Ticket category is unreachable', { categoryId: env.channels.ticketCategory });
throw new UserFacingError(
'`CATEGORY_TICKETS_ID` ne pointe vers aucun salon accessible : je ne peux pas y créer de salon. L’équipe doit corriger le `.env`.',
);
}
if (parent.type !== ChannelType.GuildCategory) {
log.warn('Ticket category is not a category', { categoryId: parent.id, type: parent.type });
throw new UserFacingError(
'`CATEGORY_TICKETS_ID` ne pointe pas vers une catégorie Discord : je ne peux pas y créer de salon. L’équipe doit corriger le `.env`.',
);
@@ -157,7 +193,7 @@ export async function createTicket(interaction, categoryId) {
await channel.send({
content: `<@${ticket.author_id}>`,
embeds: [ticketEmbed(ticket, category)],
embeds: [ticketEmbed(ticket, category), ticketHelpEmbed()],
components: ticketButtons(),
});
+1 -8
View File
@@ -223,7 +223,7 @@ export const VARIABLES = Object.freeze([
key: 'CHANNEL_LOGS_ID',
section: 'channels',
label: 'Salon des logs techniques',
help: 'Erreurs et événements techniques du bot.',
help: 'Erreurs, événements techniques du bot et journal des tickets.',
type: 'snowflake',
},
{
@@ -233,13 +233,6 @@ export const VARIABLES = Object.freeze([
help: 'Avertissements, mises en sourdine, bannissements.',
type: 'snowflake',
},
{
key: 'CHANNEL_TICKETS_LOGS_ID',
section: 'channels',
label: 'Salon des logs de tickets',
help: 'Ouverture, prise en charge et clôture des tickets.',
type: 'snowflake',
},
{
key: 'CHANNEL_NOTIF_ISSUES_ID',
section: 'channels',
+139
View File
@@ -0,0 +1,139 @@
import assert from 'node:assert/strict';
import { after, before, beforeEach, describe, it } from 'node:test';
import { ChannelType, Collection } from 'discord.js';
/**
* Ticket channel creation (M6).
*
* The channels are declared before the modules that read them are loaded, hence the
* dynamic imports: `createTicket` refuses to work without a ticket category, and the
* journal goes to the technical logs salon.
*/
process.env.CATEGORY_TICKETS_ID = '1463259435970461925';
process.env.CHANNEL_LOGS_ID = '1237076782453358745';
process.env.ROLE_STAFF_ID = 'role-staff';
const { closeDatabase, getDatabase, initDatabase } = await import('../src/database/index.js');
const { UserFacingError } = await import('../src/core/errors.js');
const { createTicket } = await import('../src/services/tickets/ticket-service.js');
const CATEGORY_ID = process.env.CATEGORY_TICKETS_ID;
const LOGS_CHANNEL = process.env.CHANNEL_LOGS_ID;
const TICKET_CATEGORY = { id: CATEGORY_ID, type: ChannelType.GuildCategory };
const member = (roleIds = []) => ({
id: 'author-1',
guild: { ownerId: 'owner-1' },
roles: { cache: new Collection(roleIds.map((id) => [id, { id }])) },
});
/** Discord reduced to what opening a ticket touches: the category and the new channel. */
function harness({ parent = TICKET_CATEGORY } = {}) {
const state = { created: [], channelMessages: [], journal: [], fetched: [] };
const journalChannel = {
isSendable: () => true,
send: async (payload) => state.journal.push(payload),
};
const channel = {
id: 'channel-1',
send: async (payload) => state.channelMessages.push(payload),
delete: async () => {},
};
const guild = {
id: 'guild-1',
roles: { everyone: { id: 'everyone' } },
channels: {
fetch: async (id) => {
state.fetched.push(id);
if (id === CATEGORY_ID) return parent;
if (id === LOGS_CHANNEL) return journalChannel;
return null;
},
create: async (options) => {
state.created.push(options);
return channel;
},
},
};
const interaction = {
guild,
client: { user: { id: 'bot-1' }, channels: guild.channels },
user: { id: 'author-1', username: 'Léa', tag: 'Léa#0001' },
member: member([process.env.ROLE_STAFF_ID]),
};
return { state, interaction, journalChannel };
}
const open = (harness) => createTicket(harness.interaction, 'bug');
const embedsOf = (payload) => payload.embeds.map((embed) => embed.toJSON());
describe('ticket creation', () => {
before(() => initDatabase(':memory:'));
after(() => closeDatabase());
beforeEach(() => getDatabase().exec('DELETE FROM tickets'));
it('creates the channel inside the category declared in the environment', async () => {
const test = harness();
await open(test);
assert.equal(test.state.fetched.includes(CATEGORY_ID), true);
assert.equal(test.state.created.length, 1);
assert.equal(test.state.created[0].parent, CATEGORY_ID);
assert.equal(test.state.created[0].type, ChannelType.GuildText);
});
it('posts the ticket header and a guidance embed', async () => {
const test = harness();
await open(test);
assert.equal(test.state.channelMessages.length, 1);
const [header, guidance] = embedsOf(test.state.channelMessages[0]);
assert.match(header.title, /^🎫 Ticket Bug #/);
assert.match(guidance.description, /Détaille au maximum/);
assert.match(guidance.fields[0].value, /étapes pour reproduire/);
assert.match(guidance.fields[1].name, /un peu de temps/);
});
it('writes the journal in the technical logs salon', async () => {
const test = harness();
await open(test);
assert.equal(test.state.journal.length, 1);
assert.equal(test.state.journal[0].embeds[0].toJSON().title, '🎫 Ticket ouvert');
});
it('explains how to fix the environment when the category is missing', async () => {
const test = harness({ parent: null });
await assert.rejects(
() => open(test),
(error) => {
assert.ok(error instanceof UserFacingError);
assert.match(error.message, /CATEGORY_TICKETS_ID/);
return true;
},
);
assert.equal(test.state.created.length, 0);
});
it('refuses a category id that points at a plain channel', async () => {
const test = harness({ parent: { id: CATEGORY_ID, type: ChannelType.GuildText } });
await assert.rejects(
() => open(test),
(error) => {
assert.ok(error instanceof UserFacingError);
assert.match(error.message, /catégorie Discord/);
return true;
},
);
});
});