diff --git a/db.json b/db.json new file mode 100644 index 0000000..9f63d2d --- /dev/null +++ b/db.json @@ -0,0 +1,4 @@ +{ + "ignoredChannels": [], + "configs": {} +} \ No newline at end of file diff --git a/detectors/allDetector.js b/detectors/allDetector.js index ce42b91..11ae585 100644 --- a/detectors/allDetector.js +++ b/detectors/allDetector.js @@ -3,9 +3,9 @@ import feurDetector from "./feurDetector.js"; import pingDetector from "./pingDetector.js"; import quoicoubehDetector from "./quoicoubehDetector.js"; import suffixPrefixDetector from "./suffixPrefixDetector.js"; -import withPronounDetector from "./withPronounDetector.js"; // Nom aligné +import withPronounDetector from "./withPronounDetector.js"; -const firstDetector = new WithPronounDetector(); // Utilisation du bon nom +const firstDetector = new withPronounDetector(); firstDetector .setNextDetector(new suffixPrefixDetector()) diff --git a/detectors/coubehDetector.js b/detectors/quoicoubehDetector.js similarity index 100% rename from detectors/coubehDetector.js rename to detectors/quoicoubehDetector.js diff --git a/detectors/suffixDetector.js b/detectors/suffixPrefixDetector.js similarity index 100% rename from detectors/suffixDetector.js rename to detectors/suffixPrefixDetector.js diff --git a/index.js b/index.js index b75e81c..4becf0b 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ import { Client, GatewayIntentBits, WebhookClient, AuditLogEvent, OAuth2Scopes, Options } from 'discord.js'; -import commands from './commands.js'; -import firstDetector from './detectors/allDetector.js'; // On importe la chaine de détecteurs +// import commands from './commands.js'; +import firstDetector from './detectors/allDetector.js'; -const webhookClient = process.env.LOGS_WEBHOOK ? new WebhookClient({ url: process.env.LOGS_WEBHOOK }) : null; +// const webhookClient = process.env.LOGS_WEBHOOK ? new WebhookClient({ url: process.env.LOGS_WEBHOOK }) : null; const client = new Client({ makeCache: Options.cacheWithLimits({ @@ -15,31 +15,7 @@ const client = new Client({ ] }); -// Gestion des Logs Guild (Join/Leave) - -client.on('guildCreate', async (guild) => { - const logs = await guild.fetchAuditLogs().catch(() => null); - const inviter = logs?.entries - .find((l) => l.action === AuditLogEvent.BotAdd && l.targetId === client.user?.id)?.executor; - - webhookClient?.send({ - content: `Joined guild: -\`\`\` -name: ${guild.name} (${guild.id}) -inviter: ${inviter != null ? ` invited by ${inviter.tag} (${inviter.id})` : ' (unknown inviter)'} -member count: ${guild.memberCount} -\`\`\`` - }); -}); - -client.on('guildDelete', async (guild) => { - webhookClient?.send({ - content: `Left guild ${guild.name} (${guild.id})` - }); -}); - // Démarrage - client.on('ready', async () => { console.log(`Logged in as ${client.user?.tag ?? 'unknown'}`); @@ -61,40 +37,6 @@ client.on('ready', async () => { 'ReadMessageHistory' ] })); - - // Enregistrement des commandes slash - if (client.application) { - await client.application.commands.set([ - commands['channel-ignore'].command, - commands['retire-role'].command, - commands['get-config'].command, - commands['set-config'].command, - ]); - console.log('Commandes Slash enregistrées.'); - } -}); - -// Gestion des Commandes (/slash) - -client.on('interactionCreate', async (interaction) => { - if (!interaction.guild || !interaction.member || !interaction.isChatInputCommand()) { - return; - } - - const command = commands[interaction.commandName]; - if (command) { - try { - await command.run(interaction); - } catch (error) { - console.error('Erreur commande:', error); - const replyObj = { content: 'Une erreur est survenue.', ephemeral: true }; - if (interaction.replied || interaction.deferred) { - await interaction.followUp(replyObj); - } else { - await interaction.reply(replyObj); - } - } - } }); // Gestion des Messages (Listeners) @@ -140,4 +82,8 @@ client.on('messageUpdate', async (oldMessage, newMessage) => { await handleMessage(message); }); +client.on(Events.ClientReady, () => { + console.log(`Hello World !`); +}); + client.login(process.env.DISCORD_TOKEN); \ No newline at end of file diff --git a/package.json b/package.json index 299bf02..3f2bd9a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "license": "ISC", "author": "", - "type": "commonjs", + "type": "module", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/utils/strings.js b/utils/strings.js new file mode 100644 index 0000000..1f5a817 --- /dev/null +++ b/utils/strings.js @@ -0,0 +1,16 @@ +/** + * Nettoie le contenu d'un message pour faciliter la détection. + * - Utilise 'cleanContent' si dispo (remplace les <@123> par @Pseudo) + * - Sinon utilise 'content' brut + * - Retire les espaces superflus au début et à la fin + */ + +export function cleanMessageContent(message) { + // Sécurité si le message est vide ou bizarre + if (!message) return ""; + + // On privilégie cleanContent qui est plus propre pour la lecture humaine + const text = message.cleanContent || message.content || ""; + + return text.trim(); +} \ No newline at end of file