diff --git a/.gitignore b/.gitignore index b5714e7..214fb82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /node_modules .env -~/.gitconfig -db.json +.gitconfig +db.json \ No newline at end of file diff --git a/db.js b/db.js deleted file mode 100644 index 53e176a..0000000 --- a/db.js +++ /dev/null @@ -1,92 +0,0 @@ -import fs from 'fs'; - -const DB_PATH = './db.json'; - -// Valeurs par défaut -const settingsDefaultValues = { - quoiAnswerPercentage: 100, - quoicoubehAnswerPercentage: 100, - feurAnswerPercentage: 100, - mentionAnswerPercentage: 100, - forcedAnswerRoleId: null, - ignoredRoleId: null, -}; - -// Structure de base de la DB en mémoire -let dbData = { - ignoredChannels: [], // Liste d'objets { channelId, guildId } - configs: {} // Objet : guildId -> { settings } -}; - -// --- Fonctions internes (Sauvegarde/Chargement) --- - -function loadDb() { - if (!fs.existsSync(DB_PATH)) { - saveDb(); // Crée le fichier s'il n'existe pas - return; - } - try { - const raw = fs.readFileSync(DB_PATH, 'utf-8'); - dbData = JSON.parse(raw); - - // Sécurité : s'assurer que les structures existent - if (!dbData.ignoredChannels) dbData.ignoredChannels = []; - if (!dbData.configs) dbData.configs = {}; - } catch (e) { - console.error("Erreur lecture DB, réinitialisation :", e); - saveDb(); - } -} - -function saveDb() { - fs.writeFileSync(DB_PATH, JSON.stringify(dbData, null, 2), 'utf-8'); -} - -// Initialisation au démarrage -loadDb(); - -// --- Fonctions exportées (Même signature que l'ancien db.js) --- - -export function addChannelToIgnoreList(channelId, guildId) { - // Vérifier si déjà présent - const exists = dbData.ignoredChannels.some(c => c.channelId === channelId); - if (!exists) { - dbData.ignoredChannels.push({ channelId, guildId }); - saveDb(); - } -} - -export function getIgnoredChannels(guildId) { - return dbData.ignoredChannels.filter(c => c.guildId === guildId); -} - -export function removeChannelFromIgnoreList(channelId) { - const initialLength = dbData.ignoredChannels.length; - dbData.ignoredChannels = dbData.ignoredChannels.filter(c => c.channelId !== channelId); - - if (dbData.ignoredChannels.length !== initialLength) { - saveDb(); - } -} - -export function setSetting(guildId, setting, value) { - // Initialiser la config de la guilde si inexistante - if (!dbData.configs[guildId]) { - dbData.configs[guildId] = { ...settingsDefaultValues }; - } - - // Mettre à jour la valeur - dbData.configs[guildId][setting] = value; - saveDb(); -} - -export function getSetting(guildId, setting) { - const config = dbData.configs[guildId]; - - if (!config) { - return settingsDefaultValues[setting]; - } - - const val = config[setting]; - return val === undefined ? settingsDefaultValues[setting] : val; -} \ No newline at end of file diff --git a/indexOld.js b/indexOld.js deleted file mode 100644 index ae3625b..0000000 --- a/indexOld.js +++ /dev/null @@ -1,66 +0,0 @@ -import { Client, GatewayIntentBits, WebhookClient, AuditLogEvent, OAuth2Scopes, Options, Events } from 'discord.js'; -import firstDetector from './detectors/allDetector.js'; -import 'dotenv/config'; - -console.log("--- DEBUG ---"); -console.log("Test Token:", process.env.DISCORD_TOKEN ? "Présent (Longueur: " + process.env.DISCORD_TOKEN.length + ")" : "ABSENT !"); -console.log("Tentative de connexion à Discord."); - -const client = new Client({ - makeCache: Options.cacheWithLimits({ - MessageManager: 0, // le bot ne se souviendra pas des anciens messages (pas de cache) - }), - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - ] -}); - -// Gestion des Messages (Listeners) -// Fonction locale pour traiter un message (remplace newMessageListener) -async function handleMessage(message) { - try { - const reply = await firstDetector.createReply(message); - if (reply) { - await message.reply(reply); - } - } catch (e) { - console.error('Erreur dans le détecteur:', e); - } -} - -client.on('messageCreate', async (message) => { - if (message.author.bot) return; - await handleMessage(message); -}); - -client.on('messageUpdate', async (oldMessage, newMessage) => { - let message = newMessage; - - if (message.partial) { - try { - message = await message.fetch(); - } catch (e) { - console.error('Error while fetching message', e); - return; - } - } - - if (!message.author || message.author.bot) return; - if (oldMessage.content === message.content) return; // Pas de changement de texte - if (!message.content) return; - - // on évite de spammer - if (oldMessage.content && oldMessage.content.match(/(\b|^)quoi(\b|$)/i)) { - return; - } - - 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/indexTest.js b/indexTest.js deleted file mode 100644 index ffea581..0000000 --- a/indexTest.js +++ /dev/null @@ -1,27 +0,0 @@ -import 'dotenv/config'; -import { Client, GatewayIntentBits, Options, Events } from 'discord.js'; - -console.log("--- DEBUG START ---"); - -const client = new Client({ - makeCache: Options.cacheWithLimits({ - MessageManager: 0, - }), - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - ] -}); - -client.on(Events.ClientReady, async () => { - console.log('-----------------------------------'); - console.log(`[SUCCESS] Logged in as ${client.user?.tag}`); - console.log('--- BOT IS READY ---'); - console.log('-----------------------------------'); -}); - -console.log("Token status check: " + (process.env.DISCORD_TOKEN ? "Présent" : "ABSENT")); -console.log("Attempting login..."); - -client.login(process.env.DISCORD_TOKEN); \ No newline at end of file diff --git a/~/.gitconfig b/~/.gitconfig deleted file mode 100644 index bcd2567..0000000 --- a/~/.gitconfig +++ /dev/null @@ -1,2 +0,0 @@ -[credential "https://https://dev.ldelforge.com"] - username = TRUkae \ No newline at end of file