23
loading...
This website collects cookies to deliver better user experience
const main = () => {
const prisma = new PrismaClient();
const client = new Client();
const control = new CommandControl(client, prisma);
client.once(Constants.Events.CLIENT_READY, () => {
prisma
.$connect()
.then(() => console.log("Prisma Connected"))
.finally(() => console.log("Application Ready"));
});
client.on(Constants.Events.DISCONNECT, () => {
prisma
.$disconnect()
.then(() => console.log("Prisma Disconnected"))
.finally(() => console.log("Application Disconnected"));
});
client.on(Constants.Events.MESSAGE_CREATE, (message) => {
control.handleMessage(message);
});
client.login(process.env.Bot_Token);
};
main();
client
and control
. All commands come in as Messages and are handled when the message event is listened to. If you are unfamiliar with the EventListener
in node check out this link.handleMessage(message: Message) {
if (this.isAdmissableMessage(message)) {
const command = this.parseForCommand(message);
switch (command) {
case UserEconomyCmds.LIST:
this.Economy.listCommands(message);
break;
case UserEconomyCmds.CREATE_WALLET:
this.Economy.createCommand(message);
break;
case UserEconomyCmds.BALANCE:
this.Economy.balanceCommand(message);
break;
case UserEconomyCmds.MERCHANDISE:
this.Economy.getMerchandiseCommand(message);
break;
case UserEconomyCmds.POSSESSIONS:
this.Economy.getPossessionsCommand(message);
break;
case UserEconomyCmds.PURCHASE:
break;
case AdminEconomyCmds.SUMMARY:
this.Economy.summaryWalletCommand(message);
break;
default:
console.log(command);
}
}
}
isAdmissableMessage
checks to make sure that the message the bot is listening to is going into a guild channel, not coming from the bot, starts with the command prefix, and is coming from a member of the guild. Secondly, the message is parsed to get the string connected to prefix, optimistically that is one of the commands being handled, but if it is not then it is ignored.parser.ts
is what holds all this. There are three functions in the file, parseForArguments
, hasAdminPermission
, and argumentsFulfilled
. These functions ensure that the message comes in like cli arguments.$deposit amount=10 @person
.