VBC-52 Use export default rather than class of the same name #53

Merged
Vylpes merged 4 commits from feature/VBC-52 into develop 2021-09-29 17:53:21 +01:00
7 changed files with 24 additions and 24 deletions

View file

@ -50,7 +50,7 @@ The code below will reply to the user with 'PONG' when they type {PREFIX}ping
import { Command, ICommandContext } from "vylbot-core";
export class Ping extends Command {
export default class Ping extends Command {
constructor() {
super();
this._roles = [ "Moderator" ];

View file

@ -37,9 +37,9 @@ export class Util {
if (existsSync(`${process.cwd()}/${folder}/`)) {
if (existsSync(`${process.cwd()}/${folder}/${name}.ts`)) {
const commandFile = require(`${process.cwd()}/${folder}/${name}.ts`);
const command = new commandFile[name]() as Command;
const commandFile = require(`${process.cwd()}/${folder}/${name}.ts`).default;
const command = new commandFile() as Command;
const requiredRoles = command._roles;
if (!command._category) command._category = "none";

View file

@ -1,7 +1,7 @@
import { Command } from "../../../src/type/command";
export class noCategory extends Command {
export default class noCategory extends Command {
constructor() {
super();
}
}
}

View file

@ -1,8 +1,8 @@
import { Command } from "../../../src/type/command";
export class normal extends Command {
export default class normal extends Command {
constructor() {
super();
this._category = "General";
}
}
}

View file

@ -1,8 +1,8 @@
import { Command } from "../../../src/type/command";
export class roles extends Command {
export default class roles extends Command {
constructor() {
super();
this._roles = [ "Moderator" ];
}
}
}

View file

@ -10,7 +10,7 @@ beforeEach(() => {
});
describe('OnMessage', () => {
test('Given Message Is Valid Expect Message Sent', () => {
test('Given Message Is Valid Expect Message Sent', async () => {
process.env = {
BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!',
@ -30,7 +30,7 @@ describe('OnMessage', () => {
const events = new Events();
const result = events.onMessage(message);
const result = await events.onMessage(message);
expect(result.valid).toBeTruthy();
@ -41,7 +41,7 @@ describe('OnMessage', () => {
expect(result.context?.message).toBe(message);
});
test('Given Guild Is Null, Expect Failed Result', () => {
test('Given Guild Is Null, Expect Failed Result', async () => {
process.env = {
BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!',
@ -61,13 +61,13 @@ describe('OnMessage', () => {
const events = new Events();
const result = events.onMessage(message);
const result = await events.onMessage(message);
expect(result.valid).toBeFalsy();
expect(result.message).toBe("Message was not sent in a guild, ignoring.");
});
test('Given Author Is A Bot, Expect Failed Result', () => {
test('Given Author Is A Bot, Expect Failed Result', async () => {
process.env = {
BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!',
@ -87,13 +87,13 @@ describe('OnMessage', () => {
const events = new Events();
const result = events.onMessage(message);
const result = await events.onMessage(message);
expect(result.valid).toBeFalsy();
expect(result.message).toBe("Message was sent by a bot, ignoring.");
});
test('Given Message Content Was Not A Command, Expect Failed Result', () => {
test('Given Message Content Was Not A Command, Expect Failed Result', async () => {
process.env = {
BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!',
@ -113,13 +113,13 @@ describe('OnMessage', () => {
const events = new Events();
const result = events.onMessage(message);
const result = await events.onMessage(message);
expect(result.valid).toBeFalsy();
expect(result.message).toBe("Message was not a command, ignoring.");
});
test('Given Message Had No Command Name, Expect Failed Result', () => {
test('Given Message Had No Command Name, Expect Failed Result', async () => {
process.env = {
BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!',
@ -139,13 +139,13 @@ describe('OnMessage', () => {
const events = new Events();
const result = events.onMessage(message);
const result = await events.onMessage(message);
expect(result.valid).toBeFalsy();
expect(result.message).toBe("Command name was not found");
});
test('Given Command Failed To Execute, Expect Failed Result', () => {
test('Given Command Failed To Execute, Expect Failed Result', async () => {
process.env = {
BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!',
@ -165,7 +165,7 @@ describe('OnMessage', () => {
const events = new Events();
const result = events.onMessage(message);
const result = await events.onMessage(message);
expect(result.valid).toBeFalsy();
expect(result.message).toBe("Command failed");
@ -182,4 +182,4 @@ describe('OnReady', () => {
expect(console.log).toBeCalledWith("Ready");
});
});
});

View file

@ -418,4 +418,4 @@ describe('LoadEvents', () => {
expect(result.valid).toBeFalsy();
expect(result.message).toBe("Event folder does not exist");
});
});
});