mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-17 16:09:27 +02:00
bot passer sous TS
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
let buyer = 0;
|
||||
import sqlite3 from 'sqlite3';
|
||||
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) => {
|
||||
if (err) {
|
||||
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) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
@@ -18,13 +18,13 @@ module.exports = function addBaseInDB(client) {
|
||||
});
|
||||
|
||||
|
||||
client.guilds.cache.forEach(guild => {
|
||||
guild.members.cache.forEach(member => {
|
||||
client.guilds.cache.forEach((guild: any) => {
|
||||
guild.members.cache.forEach((member: any) => {
|
||||
if (member.user.bot) return;
|
||||
if (member.id === '671763971803447298') {
|
||||
buyer = 1;
|
||||
buyer = true;
|
||||
} 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) => {
|
||||
if (err) {
|
||||
@@ -35,8 +35,8 @@ module.exports = function addBaseInDB(client) {
|
||||
});
|
||||
|
||||
|
||||
client.commands.forEach(command => {
|
||||
client.guilds.cache.forEach(guild => {
|
||||
client.commands.forEach((command: any) => {
|
||||
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) => {
|
||||
if (err) {
|
||||
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) => {
|
||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
|
||||
if (err) {
|
||||
@@ -9,12 +9,12 @@ module.exports = async function getPermissionLevel(member, guild) {
|
||||
}
|
||||
});
|
||||
|
||||
let buyerId = [];
|
||||
let ownerId = [];
|
||||
let buyerId: string[] = [];
|
||||
let ownerId: string[] = [];
|
||||
let highestPermission = 0;
|
||||
|
||||
db.each('SELECT userID FROM users WHERE serverID = ? AND buyer = 1', [guild.id],
|
||||
(err, row) => {
|
||||
(err, row: any) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
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],
|
||||
(err, row) => {
|
||||
(err, row: any) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
@@ -33,7 +33,7 @@ module.exports = async function getPermissionLevel(member, guild) {
|
||||
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
db.each('SELECT roleID FROM permissions WHERE serverID = ? AND permission = ?', [guild.id, i],
|
||||
(err, row) => {
|
||||
(err, row: any) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
@@ -1,7 +1,7 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
import sqlite3 from 'sqlite3';
|
||||
require('dotenv').config();
|
||||
|
||||
function getServerPrefix(serverID) {
|
||||
function getServerPrefix(serverID: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (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) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
@@ -2,7 +2,7 @@ const sqlite3 = require('sqlite3').verbose();
|
||||
require('dotenv').config();
|
||||
|
||||
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) {
|
||||
console.error(err.message);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ module.exports = function initDB() {
|
||||
db.run(`CREATE TABLE IF NOT EXISTS prefix(
|
||||
prefix TEXT NOT NULL DEFAULT '${process.env.DEFAULT_PREFIX}',
|
||||
serverID TEXT NOT NULL UNIQUE
|
||||
)`, (err) => {
|
||||
)`, (err: Error) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ module.exports = function initDB() {
|
||||
owner BOOLEAN NOT NULL DEFAULT 0,
|
||||
whitelist BOOLEAN NOT NULL DEFAULT 0,
|
||||
blacklist BOOLEAN NOT NULL DEFAULT 0
|
||||
)`, (err) => {
|
||||
)`, (err: Error) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ module.exports = function initDB() {
|
||||
command TEXT NOT NULL,
|
||||
permission INTEGER NOT NULL DEFAULT 11,
|
||||
serverID TEXT NOT NULL
|
||||
)`, (err) => {
|
||||
)`, (err: Error) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
@@ -53,14 +53,14 @@ module.exports = function initDB() {
|
||||
permission INTEGER NOT NULL UNIQUE,
|
||||
roleID TEXT NOT NULL,
|
||||
serverID TEXT NOT NULL
|
||||
)`, (err) => {
|
||||
)`, (err: Error) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
db.close((err) => {
|
||||
db.close((err: Error) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
module.exports = function loadEvents(client, dir) {
|
||||
module.exports = function loadEvents(client: any, dir: string) {
|
||||
let count = 0;
|
||||
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);
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
count += loadCommands(path.join(dir, file));
|
||||
} else if (file.endsWith('.js')) {
|
||||
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
|
||||
try {
|
||||
delete require.cache[require.resolve(filePath)];
|
||||
const command = require(filePath);
|
||||
const fileName = file.replace('.js', '');
|
||||
const fileName = file.replace(/\.js|\.ts/g, '');
|
||||
command.name = fileName;
|
||||
const parentDir = path.basename(path.dirname(filePath));
|
||||
command.category = parentDir === 'commands' ? 'other' : parentDir;
|
||||
client.commands.set(fileName, command);
|
||||
if (command.aliases) {
|
||||
command.aliases.forEach(alias => {
|
||||
command.aliases.forEach((alias: string) => {
|
||||
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 loadCommands = require("./loadCommands");
|
||||
|
||||
module.exports = function run(token) {
|
||||
module.exports = function run(token: string) {
|
||||
const client = new Client({intents: new IntentsBitField(3276799)});
|
||||
|
||||
client.events = new Collection();
|
||||
Reference in New Issue
Block a user