Merge pull request #53 from Vylpes/feature/VBC-52
VBC-52 Use export default rather than class of the same name
This commit is contained in:
commit
d3f9fc4fa0
7 changed files with 24 additions and 24 deletions
|
@ -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" ];
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class noCategory extends Command {
|
||||
export default class noCategory extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -418,4 +418,4 @@ describe('LoadEvents', () => {
|
|||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Event folder does not exist");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue