#5 replace all console.logs with debugger
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
import { DebugBuilder } from "../modules/debugger.mjs";
|
||||
import { Client, GatewayIntentBits, Collection } from 'discord.js';
|
||||
import { registerActiveCommands, unregisterAllCommands } from './modules/registerCommands.mjs'
|
||||
import { RSSController } from '../rss-manager/rssController.mjs'
|
||||
import { join, dirname } from 'path';
|
||||
import { readdirSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
|
||||
const log = new DebugBuilder("server", "discordBot");
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
|
||||
/**
|
||||
* Add the enabled commands to the bot to be used by users in discord
|
||||
@@ -25,18 +30,18 @@ export const addEnabledCommands = async (serverClient, _commandsPath = "./comman
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = await join(commandsPath, file);
|
||||
console.log(`Adding enabled command: ${filePath}`);
|
||||
log.INFO(`Adding enabled command: ${filePath}`);
|
||||
await import(`file://${filePath}`).then(command => {
|
||||
if (command.data instanceof Promise) {
|
||||
command.data.then(async (builder) => {
|
||||
command.data = builder;
|
||||
console.log("Importing command: ", command.data.name, command);
|
||||
log.DEBUG("Importing command: ", command.data.name, command);
|
||||
// Set a new item in the Collection
|
||||
// With the key as the command name and the value as the exported module
|
||||
serverClient.commands.set(command.data.name, command);
|
||||
});
|
||||
} else {
|
||||
console.log("Importing command: ", command.data.name, command);
|
||||
log.DEBUG("Importing command: ", command.data.name, command);
|
||||
// Set a new item in the Collection
|
||||
// With the key as the command name and the value as the exported module
|
||||
serverClient.commands.set(command.data.name, command);
|
||||
@@ -61,9 +66,9 @@ export function addEnabledEventListeners(serverClient, _eventsPath = "./events")
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const filePath = join(eventsPath, file);
|
||||
console.log(`Adding enabled event listener: ${filePath}`);
|
||||
log.INFO(`Adding enabled event listener: ${filePath}`);
|
||||
import(`file://${filePath}`).then(event => {
|
||||
console.log("Adding event: ", event);
|
||||
log.DEBUG("Adding event: ", event);
|
||||
if (event.once) {
|
||||
serverClient.once(event.name, (...args) => event.execute(serverClient.nodeIo, ...args));
|
||||
} else {
|
||||
@@ -78,15 +83,21 @@ export const serverClient = new Client({ intents: [GatewayIntentBits.Guilds, Gat
|
||||
|
||||
// Run when the bot is ready
|
||||
serverClient.on('ready', async () => {
|
||||
console.log(`Logged in as ${serverClient.user.tag}!`);
|
||||
log.INFO(`Logged in as ${serverClient.user.tag}!`);
|
||||
|
||||
// Add and register commands
|
||||
await addEnabledCommands(serverClient);
|
||||
|
||||
// Config the discord bot with events
|
||||
await addEnabledEventListeners(serverClient);
|
||||
|
||||
// Start the RSS Controller
|
||||
serverClient.RSSController = await new RSSController(serverClient);
|
||||
serverClient.RSSController.start();
|
||||
|
||||
log.INFO("RSS Controller:", serverClient.RSSController);
|
||||
});
|
||||
|
||||
// Startup the discord bot
|
||||
console.log(`Logging into discord with ID: ${process.env.DISCORD_TOKEN}`);
|
||||
log.INFO(`Logging into discord with ID: ${process.env.DISCORD_TOKEN}`);
|
||||
serverClient.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
Reference in New Issue
Block a user