Update Bot
This commit is contained in:
@@ -34,19 +34,45 @@ module.exports = {
|
||||
let unbanDate = null;
|
||||
|
||||
if (durationInput) {
|
||||
const regex = /^(\d+)([smhd])$/;
|
||||
const regex = /^(\d+)(s|m|h|d|mo|y)$/;
|
||||
const match = durationInput.match(regex);
|
||||
if (match) {
|
||||
const value = parseInt(match[1]);
|
||||
const unit = match[2];
|
||||
let multiplier = 1000;
|
||||
if (unit === 's') multiplier *= 60 / 60;
|
||||
if (unit === 'm') multiplier *= 60;
|
||||
if (unit === 'h') multiplier *= 60 * 60;
|
||||
if (unit === 'd') multiplier *= 60 * 60 * 24;
|
||||
if (unit === 'mo') multiplier *= 60 * 60 * 24 * 30;
|
||||
if (unit === 'y') multiplier *= 60 * 60 * 24 * 365;
|
||||
unbanDate = Date.now() + value * multiplier;
|
||||
type = 'Temporary';
|
||||
}
|
||||
}
|
||||
// juste avant la création de l'embed
|
||||
let durationText = type;
|
||||
if (type === 'Temporary' && unbanDate) {
|
||||
const initialDurationMs = unbanDate - Date.now() + (Date.now() - Date.now()); // ça reste l'unbanDate - timestamp original
|
||||
function formatInitialDuration(ms) {
|
||||
const seconds = Math.floor(ms / 1000) % 60;
|
||||
const minutes = Math.floor(ms / (1000 * 60)) % 60;
|
||||
const hours = Math.floor(ms / (1000 * 60 * 60)) % 24;
|
||||
const days = Math.floor(ms / (1000 * 60 * 60 * 24));
|
||||
const months = Math.floor(ms / (1000 * 60 * 60 * 24 * 30));
|
||||
const years = Math.floor(ms / (1000 * 60 * 60 * 24 * 365));
|
||||
|
||||
if (years) return `${years} Année${years > 1 ? 's' : ''}`;
|
||||
if (months) return `${months} Mois`;
|
||||
if (days) return `${days} Jour${days > 1 ? 's' : ''}`;
|
||||
if (hours) return `${hours} Heure${hours > 1 ? 's' : ''}`;
|
||||
if (minutes) return `${minutes} Minute${minutes > 1 ? 's' : ''}`;
|
||||
if (seconds) return `${seconds} Seconde${seconds > 1 ? 's' : ''}`;
|
||||
return 'Instantané';
|
||||
}
|
||||
|
||||
durationText = formatInitialDuration(initialDurationMs);
|
||||
}
|
||||
|
||||
try {
|
||||
// Bannissement
|
||||
@@ -54,17 +80,17 @@ module.exports = {
|
||||
|
||||
// Stockage dans MySQL (bans)
|
||||
await db.query(
|
||||
`INSERT INTO bans (userId, reason, modId, timestamp, type, unbanDate)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
`INSERT INTO bans (userId, reason, modId, timestamp, type, unbanDate, guildId)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE reason=VALUES(reason), modId=VALUES(modId), timestamp=VALUES(timestamp), type=VALUES(type), unbanDate=VALUES(unbanDate)`,
|
||||
[target.id, reason, interaction.user.id, Date.now(), type, unbanDate]
|
||||
[target.id, reason, interaction.user.id, Date.now(), type, unbanDate, interaction.guild.id]
|
||||
);
|
||||
|
||||
// Stockage dans logs (ajout guildId)
|
||||
|
||||
await db.query(
|
||||
`INSERT INTO logs (userId, userTag, modId, modTag, action, reason, type, guildId, timestamp)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[target.id, target.tag, interaction.user.id, interaction.user.tag, 'ban', reason, type, interaction.guild.id, Date.now()]
|
||||
[target.id, target.tag, interaction.user.id, interaction.user.tag, 'Bannissement', reason, type, interaction.guild.id, Date.now()]
|
||||
);
|
||||
|
||||
await interaction.editReply(`✅ Successfully banned ${target.tag} (${type})`);
|
||||
@@ -79,7 +105,7 @@ module.exports = {
|
||||
{ name: 'Banned User', value: `<@${target.id}> (${target.tag})`, inline: true },
|
||||
{ name: 'Banned By', value: `<@${interaction.user.id}> (${interaction.user.tag})`, inline: true },
|
||||
{ name: 'Reason', value: reason, inline: false },
|
||||
{ name: 'Type', value: type, inline: true },
|
||||
{ name: 'Duration', value: durationText, inline: true },
|
||||
{ name: 'Date', value: new Date().toLocaleString(), inline: true },
|
||||
{ name: 'Guild', value: interaction.guild.name, inline: true }
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const db = require('../../functions/database/db.js'); // instance mysql2/promise
|
||||
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const db = require('../../functions/database/db.js');
|
||||
|
||||
module.exports = {
|
||||
category: 'moderation',
|
||||
@@ -24,31 +24,59 @@ module.exports = {
|
||||
|
||||
if (!rows.length) return interaction.editReply(`❌ ${member.tag} n’a aucune sanction.`);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`Casier de ${member.tag}`)
|
||||
.setColor('Orange')
|
||||
.setTimestamp();
|
||||
// Découpe les sanctions en pages de 25
|
||||
const pages = [];
|
||||
for (let i = 0; i < rows.length; i += 10) {
|
||||
pages.push(rows.slice(i, i + 10));
|
||||
}
|
||||
|
||||
rows.forEach((row, index) => {
|
||||
const date = new Date(row.timestamp).toLocaleString();
|
||||
const actionCapitalized = row.action.charAt(0).toUpperCase() + row.action.slice(1); // Ban/Unban
|
||||
const embeds = pages.map((page, pageIndex) => {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`Casier de ${member.tag} - Page ${pageIndex + 1}/${pages.length}`)
|
||||
.setColor('Orange')
|
||||
.setTimestamp();
|
||||
|
||||
// Récupère le nom du serveur via l'ID si présent
|
||||
const guildName = row.guildId
|
||||
? interaction.client.guilds.cache.get(row.guildId)?.name || 'Unknown Server'
|
||||
: 'Unknown Server';
|
||||
page.forEach((row, index) => {
|
||||
const date = new Date(row.timestamp).toLocaleString();
|
||||
const actionCapitalized = row.action.charAt(0).toUpperCase() + row.action.slice(1);
|
||||
const action = row.action || 'N/A';
|
||||
const guildName = row.guildId
|
||||
? interaction.client.guilds.cache.get(row.guildId)?.name || 'Unknown Server'
|
||||
: 'Unknown Server';
|
||||
|
||||
embed.addFields({
|
||||
name: `#${index + 1} - ${actionCapitalized}`,
|
||||
value: `**Modérateur:** <@${row.modId}> (${row.modTag || 'N/A'})\n` +
|
||||
`**Raison:** ${row.reason || 'N/A'}\n` +
|
||||
`**Serveur:** ${guildName}\n` +
|
||||
`**Date:** ${date}`,
|
||||
inline: false
|
||||
embed.addFields({
|
||||
name: `#${index + 1 + pageIndex * 10} - ${actionCapitalized}`,
|
||||
value: `**Modérateur:** <@${row.modId}> (${row.modTag || 'N/A'})\n` +
|
||||
`**Raison:** ${row.reason || 'N/A'}\n` +
|
||||
`**Serveur:** ${guildName}\n` +
|
||||
`**Date:** ${date}\n` +
|
||||
`**Type:** ${action}`,
|
||||
inline: false
|
||||
});
|
||||
});
|
||||
|
||||
return embed;
|
||||
});
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
// Composants pour naviguer
|
||||
const row = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder().setCustomId('prev').setLabel('⬅️').setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder().setCustomId('next').setLabel('➡️').setStyle(ButtonStyle.Primary)
|
||||
);
|
||||
|
||||
let currentPage = 0;
|
||||
const message = await interaction.editReply({ embeds: [embeds[currentPage]], components: [row] });
|
||||
|
||||
// Collecteur de boutons
|
||||
const collector = message.createMessageComponentCollector({ time: 60_000 });
|
||||
collector.on('collect', i => {
|
||||
if (i.user.id !== interaction.user.id) return i.reply({ content: 'Ce n’est pas ton menu !', ephemeral: true });
|
||||
|
||||
if (i.customId === 'next') currentPage = (currentPage + 1) % embeds.length;
|
||||
if (i.customId === 'prev') currentPage = (currentPage - 1 + embeds.length) % embeds.length;
|
||||
|
||||
i.update({ embeds: [embeds[currentPage]] });
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
Reference in New Issue
Block a user