DB: Switch to better-sqlite3
This commit is contained in:
108
main.js
108
main.js
@@ -2,65 +2,71 @@ const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { Client, Collection, Events, GatewayIntentBits, Options, Partials } = require('discord.js');
|
||||
const { token } = require('./config.json');
|
||||
const createDbConnection = require('./core/db.js');
|
||||
|
||||
const localDB = require('./core/db');
|
||||
|
||||
const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions],
|
||||
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
||||
sweepers: {
|
||||
...Options.DefaultSweeperSettings,
|
||||
reactions: { interval: 300, filter: () => () => { return true } }
|
||||
}
|
||||
});
|
||||
async function entrypoint() {
|
||||
const localDB = await createDbConnection();
|
||||
|
||||
const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions],
|
||||
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
||||
sweepers: {
|
||||
...Options.DefaultSweeperSettings,
|
||||
reactions: { interval: 300, filter: () => () => { return true } }
|
||||
}
|
||||
});
|
||||
|
||||
client.localDB = localDB;
|
||||
client.commands = new Collection();
|
||||
const foldersPath = path.join(__dirname, 'commands');
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
client.localDB = localDB;
|
||||
client.commands = new Collection();
|
||||
const foldersPath = path.join(__dirname, 'commands');
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
if ('data' in command && 'execute' in command) {
|
||||
client.commands.set(command.data.name, command);
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
if ('data' in command && 'execute' in command) {
|
||||
client.commands.set(command.data.name, command);
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const eventsPath = path.join(__dirname, 'events');
|
||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||
const eventsPath = path.join(__dirname, 'events');
|
||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
} else {
|
||||
console.log(`Registered event ${event.name} ${file}`);
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
} else {
|
||||
console.log(`Registered event ${event.name} ${file}`);
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client.on(Events.ClientReady, () => {
|
||||
//setup timers
|
||||
const timersPath = path.join(__dirname, 'timers');
|
||||
const timerFiles = fs.readdirSync(timersPath).filter(file => file.endsWith('.js'));
|
||||
for (const file of timerFiles) {
|
||||
const filePath = path.join(timersPath, file);
|
||||
const timer = require(filePath);
|
||||
console.log(`Started Timer ${timer.name}`);
|
||||
let timerInstance = setInterval(() => {
|
||||
timer.tick(client, timer);
|
||||
}, timer.timeout);
|
||||
timer.instance = timerInstance;
|
||||
if (timer.immediate) { timer.tick(client, timer) }
|
||||
}
|
||||
});
|
||||
client.on(Events.ClientReady, () => {
|
||||
//setup timers
|
||||
const timersPath = path.join(__dirname, 'timers');
|
||||
const timerFiles = fs.readdirSync(timersPath).filter(file => file.endsWith('.js'));
|
||||
for (const file of timerFiles) {
|
||||
const filePath = path.join(timersPath, file);
|
||||
const timer = require(filePath);
|
||||
console.log(`Started Timer ${timer.name}`);
|
||||
let timerInstance = setInterval(() => {
|
||||
timer.tick(client, timer);
|
||||
}, timer.timeout);
|
||||
timer.instance = timerInstance;
|
||||
if (timer.immediate) { timer.tick(client, timer) }
|
||||
}
|
||||
});
|
||||
|
||||
client.login(token);
|
||||
client.login(token);
|
||||
};
|
||||
|
||||
entrypoint();
|
||||
|
||||
Reference in New Issue
Block a user