mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-03 15:07:27 +02:00
bot passer sous TS
This commit is contained in:
@@ -1,26 +1,13 @@
|
|||||||
const { EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } = require("discord.js")
|
import { Message, EmbedBuilder } from "discord.js";
|
||||||
/*
|
|
||||||
module.exports = {
|
|
||||||
aliases: ['h', 'aide'],
|
|
||||||
description: 'Affiche la liste des commandes',
|
|
||||||
emote: '📚',
|
|
||||||
utilisation: '[commande]',
|
|
||||||
|
|
||||||
async execute(message, args, client) {
|
|
||||||
console.log("Liste des commandes :");
|
|
||||||
let commands = [];
|
|
||||||
for (const command of client.commands.values()) {
|
|
||||||
const existingCommand = commands.find(cmd => cmd.name === command.name);
|
|
||||||
if (!existingCommand) {
|
|
||||||
commands.push(command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(commands);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
interface Command {
|
||||||
|
name: string;
|
||||||
|
aliases?: string[];
|
||||||
|
description: string;
|
||||||
|
emote?: string;
|
||||||
|
utilisation?: string;
|
||||||
|
category?: string;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
aliases: ['h', 'aide'],
|
aliases: ['h', 'aide'],
|
||||||
@@ -28,15 +15,16 @@ module.exports = {
|
|||||||
emote: '📚',
|
emote: '📚',
|
||||||
utilisation: '[commande]',
|
utilisation: '[commande]',
|
||||||
|
|
||||||
async execute(message, args, client) {
|
async execute(message: Message, args: string[], client: any) {
|
||||||
const prefix = '+'
|
const prefix = '+';
|
||||||
|
|
||||||
if (args[0]) {
|
if (args[0]) {
|
||||||
const command = client.commands.get(args[0]);
|
const command = client.commands.get(args[0]);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
return message.reply(`Je n'ai pas trouvé de commande nommée "${args[0]}".`);
|
return message.reply(`Je n'ai pas trouvé de commande nommée "${args[0]}".`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const commandPerm = 'None'
|
const commandPerm = 'None';
|
||||||
|
|
||||||
const embed_command = new EmbedBuilder()
|
const embed_command = new EmbedBuilder()
|
||||||
.setColor('#0099ff')
|
.setColor('#0099ff')
|
||||||
@@ -45,30 +33,30 @@ module.exports = {
|
|||||||
.addFields(
|
.addFields(
|
||||||
{ name: 'Utilisation', value: `\`${prefix}${command.utilisation ? `${command.utilisation}` : ''}\``, inline: true },
|
{ name: 'Utilisation', value: `\`${prefix}${command.utilisation ? `${command.utilisation}` : ''}\``, inline: true },
|
||||||
{ name: 'Catégorie', value: command.category || 'Non spécifiée', inline: true },
|
{ name: 'Catégorie', value: command.category || 'Non spécifiée', inline: true },
|
||||||
{ name: 'Alias', value: command.aliases ? command.aliases.map(alias => `\`${alias}\``).join(', ') : 'Aucun', inline: true },
|
{ name: 'Alias', value: command.aliases ? command.aliases.map((alias: string) => `\`${alias}\``).join(', ') : 'Aucun', inline: true },
|
||||||
{ name: 'Permissions', value: `Perm level: ${commandPerm}` || 'Indéfini', inline: true },
|
{ name: 'Permissions', value: `Perm level: ${commandPerm}` || 'Indéfini', inline: true },
|
||||||
)
|
)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})})
|
.setFooter({ text: `${client.user?.tag} © 2024`, iconURL: client.user?.displayAvatarURL({ dynamic: true })});
|
||||||
|
|
||||||
return message.reply({ embeds: [embed_command] });
|
return message.reply({ embeds: [embed_command] });
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let commands = [];
|
let commands: Command[] = [];
|
||||||
for (const command of client.commands.values()) {
|
for (const command of client.commands?.values() || []) {
|
||||||
const existingCommand = commands.find(cmd => cmd.name === command.name);
|
const existingCommand = commands.find(cmd => cmd.name === command.name);
|
||||||
if (!existingCommand) {
|
if (!existingCommand) {
|
||||||
commands.push(command);
|
commands.push(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let categories = {};
|
let categories: { [key: string]: Command[] } = {};
|
||||||
commands.forEach((command) => {
|
commands.forEach((command: any) => {
|
||||||
if (!categories[command.category]) {
|
if (!categories[command.category]) {
|
||||||
categories[command.category] = [];
|
categories[command.category] = [];
|
||||||
}
|
}
|
||||||
categories[command.category].push(command);
|
categories[command.category]?.push(command);
|
||||||
});
|
});
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
@@ -79,7 +67,7 @@ module.exports = {
|
|||||||
for (const [category, commands] of Object.entries(categories)) {
|
for (const [category, commands] of Object.entries(categories)) {
|
||||||
embed.addFields({
|
embed.addFields({
|
||||||
name: `Catégorie ${category}`,
|
name: `Catégorie ${category}`,
|
||||||
value: commands.map(command => `\`${command.name}\` - ${command.description}`).join('\n')
|
value: commands.map((command: Command) => `\`${command.name}\` - ${command.description}`).join('\n')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
aliases: ['latence'],
|
aliases: ['latence'],
|
||||||
description: 'Avoir la latence du bot.',
|
description: 'Avoir la latence du bot.',
|
||||||
@@ -7,7 +5,7 @@ module.exports = {
|
|||||||
utilisation: '',
|
utilisation: '',
|
||||||
permission: 0,
|
permission: 0,
|
||||||
|
|
||||||
async execute(message, args, client) {
|
async execute(message: any, args: any, client: any) {
|
||||||
message.reply('Pong !');
|
message.reply('Pong !');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
|
import sqlite3 from 'sqlite3';
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
import { Message } from 'discord.js';
|
||||||
require('dotenv').config();
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
aliases: ['prefixset'],
|
aliases: ['prefixset'],
|
||||||
@@ -9,16 +8,16 @@ module.exports = {
|
|||||||
utilisation: '',
|
utilisation: '',
|
||||||
permission: 10,
|
permission: 10,
|
||||||
|
|
||||||
async execute(message, args, client) {
|
async execute(message: Message, args: string[]) {
|
||||||
if (args.length < 1) return message.reply('Veuillez entrer un préfixe.');
|
if (args.length < 1) return message.reply('Veuillez entrer un préfixe.');
|
||||||
|
|
||||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err: Error | null) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
db.run('INSERT OR REPLACE INTO prefix (serverID, prefix) VALUES (?, ?)', [message.guild.id, args[0]], (err) => {
|
db.run('INSERT OR REPLACE INTO prefix (serverID, prefix) VALUES (?, ?)', [message.guild?.id, args[0]], (err: Error | null) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
message.reply('Erreur lors de la modification du préfixe.');
|
message.reply('Erreur lors de la modification du préfixe.');
|
||||||
@@ -27,7 +26,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
db.close((err) => {
|
db.close((err: Error | null) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
const { Events } = require("discord.js");
|
import { Message, Events } from "discord.js";
|
||||||
const getServerPrefix = require("../fonctions/getServerPrefix");
|
const getServerPrefix = require("../fonctions/getServerPrefix");
|
||||||
const getPermissionLevel = require("../fonctions/getPermissionLevel");
|
const getPermissionLevel = require("../fonctions/getPermissionLevel");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.MessageCreate,
|
name: Events.MessageCreate,
|
||||||
async execute(message, client) {
|
async execute(message: Message, client: any) {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
const prefix = await getServerPrefix(message.guild.id);
|
const prefix = await getServerPrefix(message.guild?.id);
|
||||||
if (message.content.startsWith(prefix)) {
|
if (message.content.startsWith(prefix)) {
|
||||||
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
||||||
const commandName = args.shift().toLowerCase();
|
const commandName = args.shift()?.toLowerCase();
|
||||||
|
|
||||||
const command = client.commands.get(commandName);
|
const command = client.commands.get(commandName);
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
@@ -25,7 +25,7 @@ module.exports = {
|
|||||||
message.reply("Erreur lors de l'exécution de la commande");
|
message.reply("Erreur lors de l'exécution de la commande");
|
||||||
}
|
}
|
||||||
} else if (message.content === `<@!${client.user.id}>` || message.content === `<@${client.user.id}>`) {
|
} else if (message.content === `<@!${client.user.id}>` || message.content === `<@${client.user.id}>`) {
|
||||||
message.reply(`Mon préfixe sur ce serveur est \`${prefix}\``);
|
message.reply(`Mon préfixe sur ce serveur est \`${prefix}\``);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -3,7 +3,7 @@ const addBaseInDB = require("../fonctions/addBaseInDB");
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
async execute(client) {
|
async execute(client: any) {
|
||||||
addBaseInDB(client);
|
addBaseInDB(client);
|
||||||
console.log(`le bot ${client.user.tag} est en ligne`)
|
console.log(`le bot ${client.user.tag} est en ligne`)
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const sqlite3 = require('sqlite3').verbose();
|
import sqlite3 from 'sqlite3';
|
||||||
let buyer = 0;
|
let buyer: boolean = false;
|
||||||
|
|
||||||
module.exports = function addBaseInDB(client) {
|
module.exports = function addBaseInDB(client: any) {
|
||||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
|
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
@@ -9,7 +9,7 @@ module.exports = function addBaseInDB(client) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
client.guilds.cache.forEach(guild => {
|
client.guilds.cache.forEach((guild: any) => {
|
||||||
db.run('INSERT OR IGNORE INTO prefix (serverID) VALUES (?)', [guild.id], (err) => {
|
db.run('INSERT OR IGNORE INTO prefix (serverID) VALUES (?)', [guild.id], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
@@ -18,13 +18,13 @@ module.exports = function addBaseInDB(client) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
client.guilds.cache.forEach(guild => {
|
client.guilds.cache.forEach((guild: any) => {
|
||||||
guild.members.cache.forEach(member => {
|
guild.members.cache.forEach((member: any) => {
|
||||||
if (member.user.bot) return;
|
if (member.user.bot) return;
|
||||||
if (member.id === '671763971803447298') {
|
if (member.id === '671763971803447298') {
|
||||||
buyer = 1;
|
buyer = true;
|
||||||
} else {
|
} else {
|
||||||
buyer = 0;
|
buyer = false;
|
||||||
};
|
};
|
||||||
db.run('INSERT OR IGNORE INTO users (serverID, userID, buyer) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE serverID = ? AND userID = ?)', [guild.id, member.id, buyer, guild.id, member.id], (err) => {
|
db.run('INSERT OR IGNORE INTO users (serverID, userID, buyer) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE serverID = ? AND userID = ?)', [guild.id, member.id, buyer, guild.id, member.id], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -35,8 +35,8 @@ module.exports = function addBaseInDB(client) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
client.commands.forEach(command => {
|
client.commands.forEach((command: any) => {
|
||||||
client.guilds.cache.forEach(guild => {
|
client.guilds.cache.forEach((guild: any) => {
|
||||||
db.run('INSERT OR IGNORE INTO commands (command, permission, serverID) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM commands WHERE command = ? AND serverID = ?)', [command.name, command.permission, guild.id, command.name, guild.id], (err) => {
|
db.run('INSERT OR IGNORE INTO commands (command, permission, serverID) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM commands WHERE command = ? AND serverID = ?)', [command.name, command.permission, guild.id, command.name, guild.id], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const sqlite3 = require('sqlite3').verbose();
|
import sqlite3 from 'sqlite3';
|
||||||
|
|
||||||
module.exports = async function getPermissionLevel(member, guild) {
|
module.exports = async function getPermissionLevel(member: any, guild: any) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -9,12 +9,12 @@ module.exports = async function getPermissionLevel(member, guild) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let buyerId = [];
|
let buyerId: string[] = [];
|
||||||
let ownerId = [];
|
let ownerId: string[] = [];
|
||||||
let highestPermission = 0;
|
let highestPermission = 0;
|
||||||
|
|
||||||
db.each('SELECT userID FROM users WHERE serverID = ? AND buyer = 1', [guild.id],
|
db.each('SELECT userID FROM users WHERE serverID = ? AND buyer = 1', [guild.id],
|
||||||
(err, row) => {
|
(err, row: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -23,7 +23,7 @@ module.exports = async function getPermissionLevel(member, guild) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
db.each('SELECT userID FROM users WHERE serverID = ? AND owner = 1', [guild.id],
|
db.each('SELECT userID FROM users WHERE serverID = ? AND owner = 1', [guild.id],
|
||||||
(err, row) => {
|
(err, row: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -33,7 +33,7 @@ module.exports = async function getPermissionLevel(member, guild) {
|
|||||||
|
|
||||||
for (let i = 1; i <= 9; i++) {
|
for (let i = 1; i <= 9; i++) {
|
||||||
db.each('SELECT roleID FROM permissions WHERE serverID = ? AND permission = ?', [guild.id, i],
|
db.each('SELECT roleID FROM permissions WHERE serverID = ? AND permission = ?', [guild.id, i],
|
||||||
(err, row) => {
|
(err, row: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const sqlite3 = require('sqlite3').verbose();
|
import sqlite3 from 'sqlite3';
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
function getServerPrefix(serverID) {
|
function getServerPrefix(serverID: string) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -10,7 +10,7 @@ function getServerPrefix(serverID) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
db.get('SELECT prefix FROM prefix WHERE serverID = ?', [serverID], (err, row) => {
|
db.get('SELECT prefix FROM prefix WHERE serverID = ?', [serverID], (err, row: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -2,7 +2,7 @@ const sqlite3 = require('sqlite3').verbose();
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
module.exports = function initDB() {
|
module.exports = function initDB() {
|
||||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
|
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err: Error) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ module.exports = function initDB() {
|
|||||||
db.run(`CREATE TABLE IF NOT EXISTS prefix(
|
db.run(`CREATE TABLE IF NOT EXISTS prefix(
|
||||||
prefix TEXT NOT NULL DEFAULT '${process.env.DEFAULT_PREFIX}',
|
prefix TEXT NOT NULL DEFAULT '${process.env.DEFAULT_PREFIX}',
|
||||||
serverID TEXT NOT NULL UNIQUE
|
serverID TEXT NOT NULL UNIQUE
|
||||||
)`, (err) => {
|
)`, (err: Error) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ module.exports = function initDB() {
|
|||||||
owner BOOLEAN NOT NULL DEFAULT 0,
|
owner BOOLEAN NOT NULL DEFAULT 0,
|
||||||
whitelist BOOLEAN NOT NULL DEFAULT 0,
|
whitelist BOOLEAN NOT NULL DEFAULT 0,
|
||||||
blacklist BOOLEAN NOT NULL DEFAULT 0
|
blacklist BOOLEAN NOT NULL DEFAULT 0
|
||||||
)`, (err) => {
|
)`, (err: Error) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ module.exports = function initDB() {
|
|||||||
command TEXT NOT NULL,
|
command TEXT NOT NULL,
|
||||||
permission INTEGER NOT NULL DEFAULT 11,
|
permission INTEGER NOT NULL DEFAULT 11,
|
||||||
serverID TEXT NOT NULL
|
serverID TEXT NOT NULL
|
||||||
)`, (err) => {
|
)`, (err: Error) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
@@ -53,14 +53,14 @@ module.exports = function initDB() {
|
|||||||
permission INTEGER NOT NULL UNIQUE,
|
permission INTEGER NOT NULL UNIQUE,
|
||||||
roleID TEXT NOT NULL,
|
roleID TEXT NOT NULL,
|
||||||
serverID TEXT NOT NULL
|
serverID TEXT NOT NULL
|
||||||
)`, (err) => {
|
)`, (err: Error) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
db.close((err) => {
|
db.close((err: Error) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
|
|
||||||
module.exports = function loadEvents(client, dir) {
|
module.exports = function loadEvents(client: any, dir: string) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
dir = `../${dir}`
|
dir = `../${dir}`
|
||||||
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
|
||||||
const filePath = path.join(__dirname, dir, file);
|
const filePath = path.join(__dirname, dir, file);
|
||||||
if (fs.statSync(filePath).isDirectory()) {
|
if (fs.statSync(filePath).isDirectory()) {
|
||||||
count += loadCommands(path.join(dir, file));
|
count += loadCommands(path.join(dir, file));
|
||||||
} else if (file.endsWith('.js')) {
|
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
|
||||||
try {
|
try {
|
||||||
delete require.cache[require.resolve(filePath)];
|
delete require.cache[require.resolve(filePath)];
|
||||||
const command = require(filePath);
|
const command = require(filePath);
|
||||||
const fileName = file.replace('.js', '');
|
const fileName = file.replace(/\.js|\.ts/g, '');
|
||||||
command.name = fileName;
|
command.name = fileName;
|
||||||
const parentDir = path.basename(path.dirname(filePath));
|
const parentDir = path.basename(path.dirname(filePath));
|
||||||
command.category = parentDir === 'commands' ? 'other' : parentDir;
|
command.category = parentDir === 'commands' ? 'other' : parentDir;
|
||||||
client.commands.set(fileName, command);
|
client.commands.set(fileName, command);
|
||||||
if (command.aliases) {
|
if (command.aliases) {
|
||||||
command.aliases.forEach(alias => {
|
command.aliases.forEach((alias: string) => {
|
||||||
client.commands.set(alias, command);
|
client.commands.set(alias, command);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = function loadEvents(client, dir) {
|
|
||||||
let count = 0;
|
|
||||||
dir = `../${dir}`
|
|
||||||
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
|
||||||
const filePath = path.join(__dirname, dir, file);
|
|
||||||
if (fs.statSync(filePath).isDirectory()) {
|
|
||||||
loadEvents(path.join(dir, file));
|
|
||||||
} else if (file.endsWith('.js')) {
|
|
||||||
delete require.cache[require.resolve(filePath)];
|
|
||||||
const event = require(filePath);
|
|
||||||
if (typeof event.execute === 'function') {
|
|
||||||
client.on(event.name, (...args) => event.execute(...args, client));
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
console.error(`Event ${event.name} does not have an execute method.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { Client } from 'discord.js';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
module.exports = function loadEvents(client: Client, dir: string): number {
|
||||||
|
let count = 0;
|
||||||
|
dir = `../${dir}`
|
||||||
|
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
|
||||||
|
const filePath = path.join(__dirname, dir, file);
|
||||||
|
if (fs.statSync(filePath).isDirectory()) {
|
||||||
|
loadEvents(client, path.join(dir, file));
|
||||||
|
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
|
||||||
|
delete require.cache[require.resolve(filePath)];
|
||||||
|
const event = require(filePath);
|
||||||
|
if (typeof event.execute === 'function') {
|
||||||
|
client.on(event.name, (...args: any[]) => event.execute(...args, client)); // Specify the type of 'args' as an array of any type
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
console.error(`Event ${event.name} does not have an execute method.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ const { Client, IntentsBitField, Collection } = require('discord.js')
|
|||||||
const loadEvents = require("./loadEvents");
|
const loadEvents = require("./loadEvents");
|
||||||
const loadCommands = require("./loadCommands");
|
const loadCommands = require("./loadCommands");
|
||||||
|
|
||||||
module.exports = function run(token) {
|
module.exports = function run(token: string) {
|
||||||
const client = new Client({intents: new IntentsBitField(3276799)});
|
const client = new Client({intents: new IntentsBitField(3276799)});
|
||||||
|
|
||||||
client.events = new Collection();
|
client.events = new Collection();
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
require('dotenv').config()
|
|
||||||
const run = require("./fonctions/run");
|
|
||||||
const initDB = require("./fonctions/initDB");
|
|
||||||
tokens = process.env.TOKENS.split(',')
|
|
||||||
|
|
||||||
initDB();
|
|
||||||
|
|
||||||
const runAsync = async () => {
|
|
||||||
Promise.all(tokens.map(token => run(token)));
|
|
||||||
};
|
|
||||||
|
|
||||||
runAsync();
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
require('dotenv').config()
|
||||||
|
const run = require("./fonctions/run");
|
||||||
|
const initDB = require("./fonctions/initDB");
|
||||||
|
|
||||||
|
initDB();
|
||||||
|
|
||||||
|
const runAsync = async () => {
|
||||||
|
if (process.env.TOKENS) {
|
||||||
|
const tokens = process.env.TOKENS.split(',');
|
||||||
|
Promise.all(tokens.map(token => run(token)));
|
||||||
|
} else {
|
||||||
|
console.error("Environment variable 'TOKENS' is not defined.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
runAsync();
|
||||||
+111
@@ -0,0 +1,111 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||||
|
|
||||||
|
/* Projects */
|
||||||
|
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||||
|
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||||
|
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||||
|
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||||
|
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||||
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||||
|
|
||||||
|
/* Language and Environment */
|
||||||
|
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||||
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||||
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||||
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||||
|
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||||
|
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||||
|
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||||
|
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||||
|
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||||
|
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||||
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||||
|
|
||||||
|
/* Modules */
|
||||||
|
"module": "commonjs", /* Specify what module code is generated. */
|
||||||
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||||
|
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||||
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||||
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||||
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||||
|
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||||
|
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||||
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||||
|
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||||
|
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||||
|
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||||
|
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||||
|
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||||
|
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||||
|
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||||
|
|
||||||
|
/* JavaScript Support */
|
||||||
|
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||||
|
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||||
|
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||||
|
|
||||||
|
/* Emit */
|
||||||
|
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||||
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||||
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||||
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||||
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||||
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||||
|
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||||
|
// "removeComments": true, /* Disable emitting comments. */
|
||||||
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||||
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||||
|
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||||
|
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||||
|
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||||
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
|
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||||
|
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||||
|
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||||
|
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||||
|
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||||
|
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||||
|
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||||
|
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||||
|
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||||
|
|
||||||
|
/* Interop Constraints */
|
||||||
|
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||||
|
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||||
|
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||||
|
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||||
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||||
|
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||||
|
|
||||||
|
/* Type Checking */
|
||||||
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
|
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||||
|
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||||
|
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||||
|
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||||
|
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||||
|
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||||
|
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||||
|
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||||
|
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||||
|
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||||
|
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||||
|
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||||
|
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||||
|
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||||
|
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||||
|
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||||
|
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||||
|
|
||||||
|
/* Completeness */
|
||||||
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
|
},
|
||||||
|
"include": ["**/*"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user