updated profile and centralized functions
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
const {
|
||||
Client,
|
||||
GatewayIntentBits,
|
||||
Collection,
|
||||
Partials
|
||||
Client,
|
||||
GatewayIntentBits,
|
||||
Collection,
|
||||
Partials
|
||||
} = require("discord.js");
|
||||
|
||||
const {
|
||||
MongoClient
|
||||
MongoClient
|
||||
} = require("mongodb");
|
||||
|
||||
const fs = require("node:fs");
|
||||
@@ -19,12 +19,12 @@ require("dotenv").config();
|
||||
*/
|
||||
|
||||
const mClient =
|
||||
new MongoClient(
|
||||
process.env.M_URI
|
||||
);
|
||||
new MongoClient(
|
||||
process.env.M_URI
|
||||
);
|
||||
|
||||
exports.mClient =
|
||||
mClient;
|
||||
mClient;
|
||||
|
||||
|
||||
/*
|
||||
@@ -32,30 +32,29 @@ exports.mClient =
|
||||
*/
|
||||
|
||||
const client =
|
||||
new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.GuildPresences,
|
||||
GatewayIntentBits.GuildMessageReactions,
|
||||
GatewayIntentBits.GuildVoiceStates,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.MessageContent
|
||||
],
|
||||
|
||||
partials: [
|
||||
Partials.Channel,
|
||||
Partials.Message,
|
||||
Partials.User,
|
||||
Partials.GuildMember,
|
||||
Partials.Reaction
|
||||
]
|
||||
});
|
||||
new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.GuildPresences,
|
||||
GatewayIntentBits.GuildMessageReactions,
|
||||
GatewayIntentBits.GuildVoiceStates,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.MessageContent
|
||||
],
|
||||
|
||||
partials: [
|
||||
Partials.Channel,
|
||||
Partials.Message,
|
||||
Partials.User,
|
||||
Partials.GuildMember,
|
||||
Partials.Reaction
|
||||
]
|
||||
});
|
||||
|
||||
exports.client =
|
||||
client;
|
||||
client;
|
||||
|
||||
|
||||
/*
|
||||
@@ -63,22 +62,22 @@ exports.client =
|
||||
*/
|
||||
|
||||
client.commands =
|
||||
new Collection();
|
||||
new Collection();
|
||||
|
||||
client.legacyCommands =
|
||||
new Collection();
|
||||
new Collection();
|
||||
|
||||
client.aliases =
|
||||
new Collection();
|
||||
new Collection();
|
||||
|
||||
client.buttons =
|
||||
new Collection();
|
||||
new Collection();
|
||||
|
||||
client.selectMenus =
|
||||
new Collection();
|
||||
new Collection();
|
||||
|
||||
client.modals =
|
||||
new Collection();
|
||||
new Collection();
|
||||
|
||||
|
||||
/*
|
||||
@@ -86,56 +85,84 @@ client.modals =
|
||||
*/
|
||||
|
||||
async function start() {
|
||||
try {
|
||||
try {
|
||||
/*
|
||||
* Connect Mongo first.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Connect Mongo first.
|
||||
*/
|
||||
await mClient.connect();
|
||||
|
||||
await mClient.connect();
|
||||
|
||||
console.log(
|
||||
"MongoDB connected"
|
||||
);
|
||||
console.log(
|
||||
"MongoDB connected"
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Load handlers.
|
||||
*/
|
||||
/*
|
||||
* Initialize database indexes before handlers are
|
||||
* exposed to Discord interactions.
|
||||
*
|
||||
* Requiring these after mClient is exported avoids
|
||||
* circular-import initialization problems because the
|
||||
* shared utilities import mClient from index.js.
|
||||
*/
|
||||
|
||||
const handlerFiles =
|
||||
fs.readdirSync(
|
||||
"./handlers"
|
||||
);
|
||||
const {
|
||||
ensureCookieIndexes
|
||||
} = require(
|
||||
"./utils/cookieEconomy"
|
||||
);
|
||||
|
||||
const {
|
||||
ensureProfileSystem
|
||||
} = require(
|
||||
"./utils/profileSystem"
|
||||
);
|
||||
|
||||
await Promise.all([
|
||||
ensureCookieIndexes(),
|
||||
ensureProfileSystem()
|
||||
]);
|
||||
|
||||
console.log(
|
||||
"Database indexes initialized"
|
||||
);
|
||||
|
||||
|
||||
for (
|
||||
const handler
|
||||
of handlerFiles
|
||||
) {
|
||||
require(
|
||||
`./handlers/${handler}`
|
||||
)(client);
|
||||
}
|
||||
/*
|
||||
* Load handlers.
|
||||
*/
|
||||
|
||||
const handlerFiles =
|
||||
fs.readdirSync(
|
||||
"./handlers"
|
||||
);
|
||||
|
||||
for (
|
||||
const handler
|
||||
of handlerFiles
|
||||
) {
|
||||
require(
|
||||
`./handlers/${handler}`
|
||||
)(client);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Login Discord.
|
||||
*/
|
||||
/*
|
||||
* Login Discord.
|
||||
*/
|
||||
|
||||
await client.login(
|
||||
process.env.D_TOKEN
|
||||
);
|
||||
await client.login(
|
||||
process.env.D_TOKEN
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Failed to start ShaiBot:",
|
||||
error
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Failed to start ShaiBot:",
|
||||
error
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
start();
|
||||
start();
|
||||
|
||||
Reference in New Issue
Block a user