From 9dd92de581e20f2aa5576949e4d07dd21ae132b4 Mon Sep 17 00:00:00 2001 From: Arhur Date: Tue, 16 Apr 2024 23:46:16 +0200 Subject: [PATCH] update --- commands/automatisation/addautovoc.ts | 1 - commands/automatisation/addrainbowrole.ts | 20 ++++++++++++ commands/automatisation/removerainbowrole.ts | 20 ++++++++++++ commands/automatisation/settimerainbowrole.ts | 19 +++++++++++ events/ready.ts | 32 +++++++++++++++++++ fonctions/initDB.ts | 9 ++++++ 6 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 commands/automatisation/addrainbowrole.ts create mode 100644 commands/automatisation/removerainbowrole.ts create mode 100644 commands/automatisation/settimerainbowrole.ts diff --git a/commands/automatisation/addautovoc.ts b/commands/automatisation/addautovoc.ts index 0890433..0994026 100644 --- a/commands/automatisation/addautovoc.ts +++ b/commands/automatisation/addautovoc.ts @@ -1,7 +1,6 @@ import { Message, Client } from 'discord.js'; import db from '../../fonctions/instanceDB'; require('dotenv').config(); -const joinVC = require('../../fonctions/joinVC'); module.exports = { aliases: ['autovocadd'], diff --git a/commands/automatisation/addrainbowrole.ts b/commands/automatisation/addrainbowrole.ts new file mode 100644 index 0000000..57281a1 --- /dev/null +++ b/commands/automatisation/addrainbowrole.ts @@ -0,0 +1,20 @@ +import { Message, Client } from 'discord.js'; +import db from '../../fonctions/instanceDB'; + +module.exports = { + aliases: [], + description: 'Met un rôle multi-couleur', + emote: '⏱', + utilisation: '<@role>', + + async execute(message: Message, args: string[], client: Client) { + const role = message.mentions.roles.first(); + if (!role) return message.channel.send('Veuillez mentionner un rôle.'); + db.run('INSERT INTO rainbowroles (roleID) VALUES (?)', [role.id], (err: any) => { + if (err) { + console.error(err.message); + } + }); + message.channel.send(`Le rôle ${role} a été ajouté à la liste des rôles arc-en-ciel.`); + } +}; diff --git a/commands/automatisation/removerainbowrole.ts b/commands/automatisation/removerainbowrole.ts new file mode 100644 index 0000000..f85b34f --- /dev/null +++ b/commands/automatisation/removerainbowrole.ts @@ -0,0 +1,20 @@ +import { Message, Client } from 'discord.js'; +import db from '../../fonctions/instanceDB'; + +module.exports = { + aliases: [], + description: 'Retire un rôle multi-couleur', + emote: '⏱', + utilisation: '<@role>', + + async execute(message: Message, args: string[], client: Client) { + const role = message.mentions.roles.first(); + if (!role) return message.channel.send('Veuillez mentionner un rôle.'); + db.run('DELETE FROM rainbowroles WHERE roleID = ?', [role.id], (err: any) => { + if (err) { + console.error(err.message); + } + }); + message.channel.send(`Le rôle ${role} a été retiré de la liste des rôles arc-en-ciel.`); + } +}; diff --git a/commands/automatisation/settimerainbowrole.ts b/commands/automatisation/settimerainbowrole.ts new file mode 100644 index 0000000..4a38302 --- /dev/null +++ b/commands/automatisation/settimerainbowrole.ts @@ -0,0 +1,19 @@ +import { Message, Client } from 'discord.js'; +import db from '../../fonctions/instanceDB'; + +module.exports = { + aliases: [], + description: 'Met un rôle multi-couleur', + emote: '⏱', + utilisation: '', + + async execute(message: Message, args: string[], client: Client) { + const time = args[0]; + db.run(`INSERT OR REPLACE INTO config (name, value) VALUES ('timeRainbowRole', ${time})`, (err) => { + if (err) { + console.error(err.message); + } + }); + message.channel.send(`Le temps de ${time} secondes a été ajouté à la liste des temps pour le rôle arc-en-ciel.`); + } + }; diff --git a/events/ready.ts b/events/ready.ts index 9e23dd8..b86174e 100644 --- a/events/ready.ts +++ b/events/ready.ts @@ -138,6 +138,38 @@ module.exports = { }, 60000); + let intervalTime = 10000; + + setInterval(() => { + db.get('SELECT value FROM config WHERE name = "timeRainbowRole"', (err: any, row: any) => { + if (err) { + console.error(err.message); + } + const time = row ? row.value : 10; + intervalTime = time * 1000; + }); + let roles: any = []; + db.all('SELECT * FROM rainbowroles', (err: any, rows: any) => { + if (err) { + console.error(err.message); + } + rows.forEach((row: any) => { + roles.push(row); + }); + roles.forEach((role: any) => { + const guilds = client.guilds.cache; + guilds.forEach((guild: any) => { + const roleToEdit = guild.roles.cache.get(role.roleID); + if (roleToEdit) { + const randomColor = Math.floor(Math.random() * 16777215).toString(16); + roleToEdit.setColor(randomColor); + } + }); + }); + }); + }, intervalTime); + + process.on('unhandledRejection', (reason, p) => { console.log(' [antiCrash] :: Unhandled Rejection/Catch'); console.log(reason, p); diff --git a/fonctions/initDB.ts b/fonctions/initDB.ts index a78ea59..91e9a3a 100644 --- a/fonctions/initDB.ts +++ b/fonctions/initDB.ts @@ -41,4 +41,13 @@ module.exports = function initDB() { console.error(err.message); } }); + + db.run(`CREATE TABLE IF NOT EXISTS rainbowroles( + id INTEGER PRIMARY KEY AUTOINCREMENT, + roleID TEXT NOT NULL + )`, (err: Error) => { + if (err) { + console.error(err.message); + } + }); } \ No newline at end of file