2.0.0-beta3 - change console messages appearance + fixed ERROR event bug

This commit is contained in:
mmacierzanka committed 2021-07-06 02:12:06 +02:00
1 parent 6e90ce800b
commit 80d8ce7eab
4 files changed
+25 -20

No files matched your search

+5 -5
View File
@@ -1,6 +1,6 @@
# CommandBot
**2.0.0-beta2**
**2.0.0-beta3**
> [IMPORTANT]
> Upgrading to this version from 1.1.3 may require additional changes in your code since 2.0.0 is not fully backwards compatible
@@ -229,10 +229,10 @@ test
Events are emitted using built-in event emitter **(since version 2.0.0)**. You can handle them using _on_ property
- **ready** - emitted when the client successfully connect to Discord API
- **message** - emitted for every message sent in any text channel (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument)
- **command** - emitted for every message that gets recognized as a command (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument and a CommandMessageStructure object to the second argument)
- **error** - emitted on permission and command errors (an error object is passed to the first argument)
- **READY** - emitted when the client successfully connect to Discord API
- **MESSAGE** - emitted for every message sent in any text channel (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument)
- **COMMAND** - emitted for every message that gets recognized as a command (a [Message](https://discord.js.org/#/docs/main/stable/class/Message) object is passed to the first argument and a CommandMessageStructure object to the second argument)
- **ERROR** - emitted on permission and command errors (an error object is passed to the first argument)
> [IMPORTANT]
> Do not use client.on('message') and client.on('ready') event handler! This handler is a core part of the command system.
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "commandbot",
"version": "2.0.0-beta2b",
"version": "2.0.0-beta3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "commandbot",
"version": "2.0.0-beta2b",
"version": "2.0.0-beta3",
"license": "MIT",
"dependencies": {
"discord.js": "^12.5.3"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "commandbot",
"version": "2.0.0-beta2b",
"version": "2.0.0-beta3",
"description": "A framework that helps you create your own Discord bot easier.",
"type": "module",
"main": "dist/index.js",
+17 -12
View File
@@ -13,13 +13,13 @@ import { EventEmitter } from "events";
//TYPE DEFINITIONS
export declare interface Bot {
on(event: "ready", listener: Function): this;
on(event: "message", listener: (m: Message) => void): this;
on(event: "READY", listener: Function): this;
on(event: "MESSAGE", listener: (m: Message) => void): this;
on(
event: "command",
event: "COMMAND",
listener: (m: Message, cmdMsg: CommandMessageStructure) => void
): this;
on(event: "error", listener: (e: any) => void): this;
on(event: "ERROR", listener: (e: any) => void): this;
}
interface ConstructorOptions {
name: string;
@@ -80,7 +80,7 @@ export class Bot extends EventEmitter {
*/
async start(port?: number, token?: string): Promise<boolean> {
try {
console.log(`Bot name: ${this.name}`);
console.log(`\nBot name: ${this.name}`);
console.log(`Prefix: ${this.commands.prefix} \n`);
this.token = token || this.token;
if (this.token === "") {
@@ -89,10 +89,13 @@ export class Bot extends EventEmitter {
);
}
if (port) {
console.log(`Creating http server on port ${port}...`);
process.stdout.write(
`Creating http server on port ${port}... `
);
http.createServer().listen(port);
console.log("✔");
}
console.log("Starting modules...");
process.stdout.write("Starting modules... ");
if (this.messages.help.enabled === true) {
const helpMsg: Command = new HelpMessage(
this.commands,
@@ -101,20 +104,21 @@ export class Bot extends EventEmitter {
);
this.commands.add(helpMsg);
}
console.log("Connecting to Discord...");
console.log("✔");
process.stdout.write("Connecting to Discord... ");
if (await this.client.login(this.token)) {
this.client.on("ready", () => {
this.emit("ready");
console.log("✔\n");
this.emit("READY");
});
this.client.on("message", async (m) => {
const cmdMsg: CommandMessageStructure | null =
this.commands.fetch(m);
if (cmdMsg?.command) {
this.emit("command", [m, cmdMsg]);
this.emit("COMMAND", [m, cmdMsg]);
try {
await cmdMsg.command.start(m, cmdMsg.arguments);
} catch (e) {
this.emit("error", [e]);
if (e instanceof PermissionsError) {
this.messages.system.send(
"PERMISSION",
@@ -136,6 +140,7 @@ export class Bot extends EventEmitter {
);
console.error(e);
}
this.emit("ERROR", [e]);
return;
}
} else if (cmdMsg) {
@@ -145,7 +150,7 @@ export class Bot extends EventEmitter {
m.channel
);
} else {
this.emit("message", [m]);
this.emit("MESSAGE", [m]);
}
});
} else {