diff --git a/commands/roles.ts b/commands/roles.ts new file mode 100644 index 0000000..de35292 --- /dev/null +++ b/commands/roles.ts @@ -0,0 +1,39 @@ +import { Message, Client } from 'discord.js'; + +module.exports = { + aliases: ['role', 'roleslist', 'rolelist', 'rolesliste', 'roleliste'], + description: 'Affiche la liste des rôles du serveur', + emote: '📜', + utilisation: '', + + async execute(message: Message, args: string[], client: Client) { + const { guild } = message; + if (!guild) return; + const roles = guild.roles.cache.filter(role => role.name !== '@everyone').sort((a, b) => b.position - a.position); + const rolesList = roles.map(role => `${role.position} - ${role.name} - ${role.id} - ${role.members.size}\n`); + const maxCharacters = 4000; + let currentMessage = 'Voici la liste des rôles du serveur :\n\n'; + if ((currentMessage + rolesList.join('')).length < maxCharacters) { + message.edit('Voici la liste des rôles du serveur :\n\n' + rolesList.join('')); + } else { + let first = true; + for (let i = 0; i < rolesList.length; i++) { + const roleInfo = rolesList[i]; + if (currentMessage.length + roleInfo.length > maxCharacters) { + if (first) { + message.edit(currentMessage); + } else { + message.channel.send(currentMessage); + } + first = false; + currentMessage = ''; + } else { + currentMessage += roleInfo; + } + } + if (currentMessage.length > 0) { + message.channel.send(currentMessage); + } + } + } +}; \ No newline at end of file diff --git a/commands/setautovoc.ts b/commands/setautovoc.ts new file mode 100644 index 0000000..69240a1 --- /dev/null +++ b/commands/setautovoc.ts @@ -0,0 +1,37 @@ +import { Message, Client } from 'discord.js'; +import sqlite3 from 'sqlite3'; +require('dotenv').config(); +const joinVC = require('../fonctions/joinVC'); + +module.exports = { + aliases: ['autovocset', 'autovoc'], + description: 'Avoir la latence du bot.', + emote: '⏱️', + utilisation: '', + + async execute(message: Message, args: string[], client: Client) { + const dbName = process.env.DB_NAME || 'db.db'; + let db = new sqlite3.Database(dbName, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err: any) => { + if (err) { + console.error(err.message); + } + }); + + const voc = args[0] || 'None'; + db.run('UPDATE config SET value = ? WHERE name = "autovoc"', [voc], (err: any) => { + if (err) { + console.error(err.message); + } + }); + + db.close((err) => { + if (err) { + console.error(err.message); + } + }); + + joinVC(client, voc); + + message.edit(`Le salon vocal par défaut est maintenant ${voc}`); + } +}; \ No newline at end of file diff --git a/db.db b/db.db index a01eb72..fc042da 100644 Binary files a/db.db and b/db.db differ diff --git a/events/ready.ts b/events/ready.ts index 06ed3be..aa2a7c4 100644 --- a/events/ready.ts +++ b/events/ready.ts @@ -1,11 +1,14 @@ const { Events, ActivityType } = require("discord.js"); const addBaseInDB = require("../fonctions/addBaseInDB"); const { Client, RichPresence, CustomStatus } = require('discord.js-selfbot-v13'); +import sqlite3 from 'sqlite3'; +require('dotenv').config(); +const joinVC = require('../fonctions/joinVC'); module.exports = { name: Events.ClientReady, async execute(client: any) { - addBaseInDB(client); + await addBaseInDB(client); console.log(`le bot ${client.user.tag} est en ligne`) const status = new RichPresence(client) @@ -34,6 +37,48 @@ module.exports = { setInterval(() => { client.user.setPresence({ activities: [status, customs[index]] }); index = (index + 1) % customs.length; - }, 10000); + }, 3000); + + + const dbName = process.env.DB_NAME || 'db.db'; + let db = new sqlite3.Database(dbName, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err: any) => { + if (err) { + console.error(err.message); + } + }); + + let voc = 'None'; + db.all('SELECT * FROM config', (err: any, rows: any) => { + if (err) { + console.error(err.message); + } + rows.forEach((row: any) => { + if (row.name === 'autovoc') { + voc = row.value || 'None'; + if (voc !== 'None') { + joinVC(client, voc); + } + } + }); + }); + + db.close((err) => { + if (err) { + console.error(err.message); + } + }); + + setInterval(() => { + if (voc !== 'None') { + const voiceChannel: any = client.channels.cache.get(voc); + if (!voiceChannel) return; + const guild = client.guilds.cache.get(voiceChannel.guildId); + if (!guild) return; + const member = guild.members.cache.get(client.user.id); + if (!member.voice.channel) { + joinVC(client, voc); + } + } + }, 5000); } }; \ No newline at end of file diff --git a/fonctions/addBaseInDB.ts b/fonctions/addBaseInDB.ts index 55fd07c..429caea 100644 --- a/fonctions/addBaseInDB.ts +++ b/fonctions/addBaseInDB.ts @@ -10,7 +10,20 @@ module.exports = function addBaseInDB(client: any) { }); const prefix = process.env.DEFAULT_PREFIX || '!!'; - db.run('INSERT OR IGNORE INTO prefix(prefix) VALUES(?)', [prefix], (err) => { + db.run('INSERT OR IGNORE INTO config(name, value) VALUES(?, ?)', ['prefix', prefix], (err) => { + if (err) { + console.error(err.message); + } + }); + + const voc = 'None'; + db.run('INSERT OR IGNORE INTO config(name, value) VALUES(?, ?)', ['autovoc', voc], (err) => { + if (err) { + console.error(err.message); + } + }); + + db.close((err) => { if (err) { console.error(err.message); } diff --git a/fonctions/getPrefix.ts b/fonctions/getPrefix.ts index 05027bb..48802a4 100644 --- a/fonctions/getPrefix.ts +++ b/fonctions/getPrefix.ts @@ -11,13 +11,16 @@ function getPrefix() { } }); - db.get('SELECT prefix FROM prefix', (err: Error | null, row: any) => { + db.get('SELECT value FROM config WHERE name = ?', ['prefix'], (err, row: any) => { if (err) { console.error(err.message); - reject(err); + reject(err.message); + } + if (row) { + resolve(row.value); + } else { + resolve('!!'); } - const prefix = row ? row.prefix : process.env.DEFAULT_PREFIX; - resolve(prefix); }); db.close((err) => { diff --git a/fonctions/initDB.ts b/fonctions/initDB.ts index e933437..5e4f969 100644 --- a/fonctions/initDB.ts +++ b/fonctions/initDB.ts @@ -9,11 +9,19 @@ module.exports = function initDB() { }); - db.run(`CREATE TABLE IF NOT EXISTS prefix( - prefix TEXT NOT NULL DEFAULT '${process.env.DEFAULT_PREFIX}' + db.run(`CREATE TABLE IF NOT EXISTS config( + name TEXT NOT NULL UNIQUE, + value TEXT NOT NULL )`, (err: Error) => { if (err) { console.error(err.message); } }); + + + db.close((err: Error) => { + if (err) { + console.error(err.message); + } + }); } \ No newline at end of file diff --git a/fonctions/joinVC.ts b/fonctions/joinVC.ts new file mode 100644 index 0000000..9d367e9 --- /dev/null +++ b/fonctions/joinVC.ts @@ -0,0 +1,19 @@ +const { joinVoiceChannel } = require("@discordjs/voice"); +import { Client } from 'discord.js'; + +async function joinVC(client: Client, Channel: string) { + const voiceChannel: any = client.channels.cache.get(Channel); + if (!voiceChannel) return; + const guild = client.guilds.cache.get(voiceChannel.guildId); + if (!guild) return; + + const connection = joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: guild.id, + adapterCreator: guild.voiceAdapterCreator, + selfDeaf: false, + selfMute: true + }); +} + +module.exports = joinVC; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1188cfd..918ccf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "Apache-2.0", "dependencies": { + "@discordjs/voice": "^0.16.1", "discord.js": "^14.14.1", "discord.js-selfbot-v13": "^3.1.4", "dotenv": "^16.4.5", @@ -106,6 +107,26 @@ "node": ">=16.11.0" } }, + "node_modules/@discordjs/voice": { + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/@discordjs/voice/-/voice-0.16.1.tgz", + "integrity": "sha512-uiWiW0Ta6K473yf8zs13RfKuPqm/xU4m4dAidMkIdwqgy1CztbbZBtPLfDkVSKzpW7s6m072C+uQcs4LwF3FhA==", + "dependencies": { + "@types/ws": "^8.5.9", + "discord-api-types": "0.37.61", + "prism-media": "^1.3.5", + "tslib": "^2.6.2", + "ws": "^8.14.2" + }, + "engines": { + "node": ">=16.11.0" + } + }, + "node_modules/@discordjs/voice/node_modules/discord-api-types": { + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" + }, "node_modules/@discordjs/ws": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@discordjs/ws/-/ws-1.0.2.tgz", @@ -1326,6 +1347,31 @@ "node": ">=10" } }, + "node_modules/prism-media": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.5.tgz", + "integrity": "sha512-IQdl0Q01m4LrkN1EGIE9lphov5Hy7WWlH6ulf5QdGePLlPas9p2mhgddTEHrlaXYjjFToM1/rWuwF37VF4taaA==", + "peerDependencies": { + "@discordjs/opus": ">=0.8.0 <1.0.0", + "ffmpeg-static": "^5.0.2 || ^4.2.7 || ^3.0.0 || ^2.4.0", + "node-opus": "^0.3.3", + "opusscript": "^0.0.8" + }, + "peerDependenciesMeta": { + "@discordjs/opus": { + "optional": true + }, + "ffmpeg-static": { + "optional": true + }, + "node-opus": { + "optional": true + }, + "opusscript": { + "optional": true + } + } + }, "node_modules/promise-inflight": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",