diff --git a/package.json b/package.json index ebf1c78..14a7b91 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Bot discord", "main": "src/index.js", "scripts": { - "compile": "rm -r dist 2> /dev/null; npx tsc", + "compile": "rm -r dist 2> /dev/null; npx tsc; cp -r ./src/sql ./dist/sql", "main": "npm run compile && node ./dist/index.js", "debug": "npx tsnd --respawn ./src/index.ts", "lint": "npx eslint src", diff --git a/src/events/loader.ts b/src/events/loader.ts index 5557ccf..a6c8bcf 100644 --- a/src/events/loader.ts +++ b/src/events/loader.ts @@ -1,10 +1,10 @@ import { PlayerEvents, useMainPlayer } from "discord-player"; import { Client } from "discord.js"; import { readdir } from "fs/promises"; -import { splitFilenameExtensions } from "../utils/misc"; +import { isDev, splitFilenameExtensions } from "../utils/misc"; /** Load all the events */ -export default async (client: Client, isDev: boolean) => { +export default async (client: Client) => { const events_categories = (await readdir(__dirname, { withFileTypes: true })) .filter((element) => element.isDirectory()) .map((element) => element.name); diff --git a/src/index.ts b/src/index.ts index 835ce0b..6f55a29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -const isDev = process.env.NODE_ENV !== "production"; +import { isDev } from "./utils/misc"; /** Load the app */ const start_app = () => { - import("./load").then((l) => l.run(isDev).catch((error) => console.error(error))); + import("./load").then((l) => l.run().catch((error) => console.error(error))); }; // Load .env if not in prod diff --git a/src/load.ts b/src/load.ts index ff68b03..fbfbedf 100644 --- a/src/load.ts +++ b/src/load.ts @@ -4,15 +4,15 @@ import loadEvents from "./events/loader"; import loadModals from "./modals/loader"; import loadClient, { quit } from "./utils/client"; -import { logStart } from "./utils/misc"; +import { isDev, logStart } from "./utils/misc"; /** Run the bot */ -export const run = async (isDev: boolean) => { +export const run = async () => { console.log("Starting Botanique..."); // Client Discord.JS const client_name = "Client"; - await loadClient(isDev) + await loadClient() .then(async (client) => { if (isDev) { // Attach debugging listeners @@ -21,7 +21,7 @@ export const run = async (isDev: boolean) => { // Events Discord.JS and Player const events_name = "Events"; - await loadEvents(client, isDev) + await loadEvents(client) .then(() => console.log(logStart(events_name, true))) .catch((err) => { console.error(err); diff --git a/src/utils/client.ts b/src/utils/client.ts index 2ab5276..92f25ae 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -6,9 +6,10 @@ import "../modules/client"; import { loadLocales } from "./locales"; import { YoutubeiExtractor } from "discord-player-youtubei"; import { readSQL } from "./db"; +import { isDev } from "./misc"; /** Creation of the client and definition of its properties */ -export default async (isDev: boolean) => { +export default async () => { const activities = isDev ? [] : [{ name: "/help", type: ActivityType.Watching }]; const client: Client = new Client({ diff --git a/src/utils/db.ts b/src/utils/db.ts index 5d3aa4b..9566da6 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -1,7 +1,9 @@ import fs from "node:fs"; +import { isDev } from "./misc"; export const readSQL = (path: string) => { - const dir = "./src/sql/"; + const root = isDev ? "./src" : "./dist"; + const dir = root + "/sql/"; if (!path.startsWith(dir)) { path = dir + path; } diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 79195e9..72342f6 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,5 +1,8 @@ import { GuildMember } from "discord.js"; +/** Check if we are in the dev environnement */ +export const isDev = process.env.NODE_ENV !== "production"; + /** * Log module status * @param {string} name Module name