load env file before the app and deps
This commit is contained in:
parent
d4e2e36f05
commit
3ecb2e8e26
2 changed files with 85 additions and 76 deletions
91
src/index.ts
91
src/index.ts
|
@ -1,78 +1,17 @@
|
|||
import loadClient, { quit } from "./utils/client";
|
||||
import loadEvents from "./events/loader";
|
||||
import loadModals from "./modals/loader";
|
||||
import loadButtons from "./buttons/loader";
|
||||
import loadCommands from "./commands/loader";
|
||||
|
||||
import { logStart } from "./utils/misc";
|
||||
|
||||
/** Run the bot. */
|
||||
const run = async () => {
|
||||
console.log("Starting Botanique...");
|
||||
|
||||
// Load .env if not in prod
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
(await import("dotenv")).config({ path: "./config/.env" });
|
||||
}
|
||||
|
||||
// Client Discord.JS
|
||||
const client_name = "Client";
|
||||
await loadClient()
|
||||
.then(async (client) => {
|
||||
// Events Discord.JS and Player
|
||||
const events_name = "Events";
|
||||
await loadEvents(client)
|
||||
.then(() => console.log(logStart(events_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(events_name, false);
|
||||
});
|
||||
|
||||
// Connect the bot to Discord.com
|
||||
await client.login(client.config.token_discord);
|
||||
|
||||
// Modals Discord.JS
|
||||
const modals_name = "Modals";
|
||||
await loadModals(client)
|
||||
.then(() => console.log(logStart(modals_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(modals_name, false);
|
||||
});
|
||||
|
||||
// Buttons Discord.JS
|
||||
const buttons_name = "Buttons";
|
||||
await loadButtons(client)
|
||||
.then(() => console.log(logStart(buttons_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(buttons_name, false);
|
||||
});
|
||||
|
||||
// Commands Slash Discord.JS
|
||||
const commands_name = "Commands";
|
||||
await loadCommands(client)
|
||||
.then(() => console.log(logStart(commands_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(commands_name, false);
|
||||
});
|
||||
|
||||
console.log(logStart(client_name, true));
|
||||
console.log(`Botanique "${client.user?.username}" v${client.config.version} started!`);
|
||||
|
||||
// ^C
|
||||
process.on("SIGINT", () => quit(client));
|
||||
|
||||
// Container force closed
|
||||
process.on("SIGTERM", () => quit(client));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(client_name, false);
|
||||
});
|
||||
/** Load the app. */
|
||||
const start_app = () => {
|
||||
import("./load").then((l) => l.run().catch((error) => console.error(error)));
|
||||
};
|
||||
|
||||
run().catch((error) => console.error(error));
|
||||
// Load .env if not in prod
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
import("dotenv").then((c) => {
|
||||
c.config({ path: "./config/.env" });
|
||||
|
||||
start_app();
|
||||
});
|
||||
} else {
|
||||
start_app();
|
||||
}
|
||||
|
|
70
src/load.ts
Normal file
70
src/load.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import loadClient, { quit } from "./utils/client";
|
||||
import loadEvents from "./events/loader";
|
||||
import loadModals from "./modals/loader";
|
||||
import loadButtons from "./buttons/loader";
|
||||
import loadCommands from "./commands/loader";
|
||||
|
||||
import { logStart } from "./utils/misc";
|
||||
|
||||
/** Run the bot. */
|
||||
export const run = async () => {
|
||||
console.log("Starting Botanique...");
|
||||
|
||||
console.log(process.env.DP_FORCE_YTDL_MOD);
|
||||
// Client Discord.JS
|
||||
const client_name = "Client";
|
||||
await loadClient()
|
||||
.then(async (client) => {
|
||||
// Events Discord.JS and Player
|
||||
const events_name = "Events";
|
||||
await loadEvents(client)
|
||||
.then(() => console.log(logStart(events_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(events_name, false);
|
||||
});
|
||||
|
||||
// Connect the bot to Discord.com
|
||||
await client.login(client.config.token_discord);
|
||||
|
||||
// Modals Discord.JS
|
||||
const modals_name = "Modals";
|
||||
await loadModals(client)
|
||||
.then(() => console.log(logStart(modals_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(modals_name, false);
|
||||
});
|
||||
|
||||
// Buttons Discord.JS
|
||||
const buttons_name = "Buttons";
|
||||
await loadButtons(client)
|
||||
.then(() => console.log(logStart(buttons_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(buttons_name, false);
|
||||
});
|
||||
|
||||
// Commands Slash Discord.JS
|
||||
const commands_name = "Commands";
|
||||
await loadCommands(client)
|
||||
.then(() => console.log(logStart(commands_name, true)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(commands_name, false);
|
||||
});
|
||||
|
||||
console.log(logStart(client_name, true));
|
||||
console.log(`Botanique "${client.user?.username}" v${client.config.version} started!`);
|
||||
|
||||
// ^C
|
||||
process.on("SIGINT", () => quit(client));
|
||||
|
||||
// Container force closed
|
||||
process.on("SIGTERM", () => quit(client));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw logStart(client_name, false);
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue