Remove useless async code
This commit is contained in:
parent
799b04e936
commit
5ce0960606
3 changed files with 25 additions and 25 deletions
|
@ -20,7 +20,7 @@ export class Events {
|
||||||
|
|
||||||
// Emit when a message is sent
|
// Emit when a message is sent
|
||||||
// Used to check for commands
|
// Used to check for commands
|
||||||
public async onMessage(message: Message): Promise<IEventResponse> {
|
public onMessage(message: Message): IEventResponse {
|
||||||
if (!message.guild) return {
|
if (!message.guild) return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: "Message was not sent in a guild, ignoring.",
|
message: "Message was not sent in a guild, ignoring.",
|
||||||
|
@ -42,7 +42,7 @@ export class Events {
|
||||||
message: "Command name was not found",
|
message: "Command name was not found",
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await this._util.loadCommand(name, args, message);
|
const res = this._util.loadCommand(name, args, message);
|
||||||
|
|
||||||
if (!res.valid) {
|
if (!res.valid) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -16,7 +16,7 @@ export interface IUtilResponse extends IBaseResponse {
|
||||||
|
|
||||||
// Util Class
|
// Util Class
|
||||||
export class Util {
|
export class Util {
|
||||||
public async loadCommand(name: string, args: string[], message: Message): Promise<IUtilResponse> {
|
public loadCommand(name: string, args: string[], message: Message): IUtilResponse {
|
||||||
if (!message.member) return {
|
if (!message.member) return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: "Member is not part of message",
|
message: "Member is not part of message",
|
||||||
|
|
|
@ -10,7 +10,7 @@ beforeEach(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('LoadCommand', () => {
|
describe('LoadCommand', () => {
|
||||||
test('Given Successful Exection, Expect Successful Result', async () => {
|
test('Given Successful Exection, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -34,12 +34,12 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given Member Is Null, Expect Failed Result', async () => {
|
test('Given Member Is Null, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -56,13 +56,13 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Member is not part of message");
|
expect(result.message).toBe("Member is not part of message");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given Folder Does Not Exist, Expect Failed Result', async () => {
|
test('Given Folder Does Not Exist, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -86,13 +86,13 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Command folder does not exist");
|
expect(result.message).toBe("Command folder does not exist");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given File Does Not Exist, Expect Failed Result', async () => {
|
test('Given File Does Not Exist, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -117,13 +117,13 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("File does not exist");
|
expect(result.message).toBe("File does not exist");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given User Does Have Role, Expect Successful Result', async () => {
|
test('Given User Does Have Role, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -147,12 +147,12 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("roles", [ "first" ], message);
|
const result = util.loadCommand("roles", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given User Does Not Have Role, Expect Failed Result', async () => {
|
test('Given User Does Not Have Role, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -176,13 +176,13 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("roles", [ "first" ], message);
|
const result = util.loadCommand("roles", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("You require the `Moderator` role to run this command");
|
expect(result.message).toBe("You require the `Moderator` role to run this command");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given Command Category Is Null, Expect Successful Result', async () => {
|
test('Given Command Category Is Null, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -206,12 +206,12 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("noCategory", [ "first" ], message);
|
const result = util.loadCommand("noCategory", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given command is set to disabled, Expect command to not fire', async () => {
|
test('Given command is set to disabled, Expect command to not fire', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -239,14 +239,14 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Command is disabled");
|
expect(result.message).toBe("Command is disabled");
|
||||||
expect(messageReply).toBeCalledWith("disabled");
|
expect(messageReply).toBeCalledWith("disabled");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given command COMMANDS_DISABLED_MESSAGE is empty, Expect default message sent', async () => {
|
test('Given command COMMANDS_DISABLED_MESSAGE is empty, Expect default message sent', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -273,14 +273,14 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Command is disabled");
|
expect(result.message).toBe("Command is disabled");
|
||||||
expect(messageReply).toBeCalledWith("This command is disabled.");
|
expect(messageReply).toBeCalledWith("This command is disabled.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given a different command is disabled, Expect command to still fire', async () => {
|
test('Given a different command is disabled, Expect command to still fire', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -305,12 +305,12 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Given a different command is disabled with this one, Expect command to not fire', async () => {
|
test('Given a different command is disabled with this one, Expect command to not fire', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -335,7 +335,7 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
const result = await util.loadCommand("normal", [ "first" ], message);
|
const result = util.loadCommand("normal", [ "first" ], message);
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Command is disabled");
|
expect(result.message).toBe("Command is disabled");
|
||||||
|
|
Reference in a new issue