diff --git a/src/client/client.ts b/src/client/client.ts index f59cf1f..36f738f 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -11,17 +11,17 @@ import { Events } from "./events"; import { Util } from "./util"; export class CoreClient extends Client { - private _commandItems: ICommandItem[]; - private _eventItems: IEventItem[]; + private static _commandItems: ICommandItem[]; + private static _eventItems: IEventItem[]; private _events: Events; private _util: Util; - public get commandItems(): ICommandItem[] { + public static get commandItems(): ICommandItem[] { return this._commandItems; } - public get eventItems(): IEventItem[] { + public static get eventItems(): IEventItem[] { return this._eventItems; } @@ -31,8 +31,8 @@ export class CoreClient extends Client { DefaultValues.useDevPrefix = devmode; - this._commandItems = []; - this._eventItems = []; + CoreClient._commandItems = []; + CoreClient._eventItems = []; this._events = new Events(); this._util = new Util(); @@ -49,31 +49,31 @@ export class CoreClient extends Client { return; }); - super.on("message", (message) => { - this._events.onMessage(message, this._commandItems) + super.on("messageCreate", (message) => { + this._events.onMessageCreate(message, CoreClient._commandItems) }); super.on("ready", this._events.onReady); super.login(process.env.BOT_TOKEN); - this._util.loadEvents(this, this._eventItems); + this._util.loadEvents(this, CoreClient._eventItems); } - public RegisterCommand(name: string, command: Command, serverId?: string) { + public static RegisterCommand(name: string, command: Command, serverId?: string) { const item: ICommandItem = { Name: name, Command: command, ServerId: serverId, }; - this._commandItems.push(item); + CoreClient._commandItems.push(item); } - public RegisterEvent(event: Event) { + public static RegisterEvent(event: Event) { const item: IEventItem = { Event: event, }; - this._eventItems.push(item); + CoreClient._eventItems.push(item); } } diff --git a/src/client/events.ts b/src/client/events.ts index 5c81e42..059df52 100644 --- a/src/client/events.ts +++ b/src/client/events.ts @@ -12,7 +12,7 @@ export class Events { // Emit when a message is sent // Used to check for commands - public async onMessage(message: Message, commands: ICommandItem[]) { + public async onMessageCreate(message: Message, commands: ICommandItem[]) { if (!message.guild) return; if (message.author.bot) return; diff --git a/src/client/util.ts b/src/client/util.ts index 7c73776..e67b6d8 100644 --- a/src/client/util.ts +++ b/src/client/util.ts @@ -38,7 +38,7 @@ export class Util { itemToUse = itemForServer; } - const requiredRoles = itemToUse.Command._roles; + const requiredRoles = itemToUse.Command.Roles; for (const i in requiredRoles) { if (message.guild) { @@ -90,7 +90,7 @@ export class Util { client.on('guildMemberAdd', e.Event.guildMemberAdd); client.on('guildMemberRemove', e.Event.guildMemberRemove); client.on('guildMemberUpdate', e.Event.guildMemberUpdate); - client.on('message', e.Event.message); + client.on('messageCreate', e.Event.messageCreate); client.on('messageDelete', e.Event.messageDelete); client.on('messageUpdate', e.Event.messageUpdate); client.on('ready', e.Event.ready); diff --git a/src/commands/501231711271780357/entry.ts b/src/commands/501231711271780357/entry.ts index f70f9d3..6f9dd83 100644 --- a/src/commands/501231711271780357/entry.ts +++ b/src/commands/501231711271780357/entry.ts @@ -7,8 +7,8 @@ export default class Entry extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/501231711271780357/lobby.ts b/src/commands/501231711271780357/lobby.ts index e002338..78ca89b 100644 --- a/src/commands/501231711271780357/lobby.ts +++ b/src/commands/501231711271780357/lobby.ts @@ -12,7 +12,7 @@ export default class Lobby extends Command { constructor() { super(); - super._category = "General"; + super.Category = "General"; } public override async execute(context: ICommandContext) { diff --git a/src/commands/about.ts b/src/commands/about.ts index e2c5dda..0e2b7bf 100644 --- a/src/commands/about.ts +++ b/src/commands/about.ts @@ -6,7 +6,7 @@ import { Command } from "../type/command"; export default class About extends Command { constructor() { super(); - super._category = "General"; + super.Category = "General"; } public override execute(context: ICommandContext): ICommandReturnContext { diff --git a/src/commands/ban.ts b/src/commands/ban.ts index 435730d..8656921 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -10,8 +10,8 @@ export default class Ban extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/clear.ts b/src/commands/clear.ts index f8e1534..243454a 100644 --- a/src/commands/clear.ts +++ b/src/commands/clear.ts @@ -9,8 +9,8 @@ export default class Clear extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/code.ts b/src/commands/code.ts index d2438fb..7c5c7da 100644 --- a/src/commands/code.ts +++ b/src/commands/code.ts @@ -10,8 +10,8 @@ export default class Code extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/config.ts b/src/commands/config.ts index 5a6a6ef..aa46263 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -13,8 +13,8 @@ import { Command } from "../type/command"; export default class Config extends Command { constructor() { super(); - super._category = "Administration"; - super._roles = [ + super.Category = "Administration"; + super.Roles = [ "administrator" ] } diff --git a/src/commands/disable.ts b/src/commands/disable.ts index 7cbd7e0..b1d9f36 100644 --- a/src/commands/disable.ts +++ b/src/commands/disable.ts @@ -7,8 +7,8 @@ export default class Disable extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/eval.ts b/src/commands/eval.ts deleted file mode 100644 index 222367d..0000000 --- a/src/commands/eval.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { ICommandContext } from "../contracts/ICommandContext"; -import ICommandReturnContext from "../contracts/ICommandReturnContext"; -import ErrorEmbed from "../helpers/embeds/ErrorEmbed"; -import PublicEmbed from "../helpers/embeds/PublicEmbed"; -import { Command } from "../type/command"; - -export default class Evaluate extends Command { - constructor() { - super(); - - super._category = "Owner"; - } - - public override execute(context: ICommandContext): ICommandReturnContext { - if (context.message.author.id != process.env.BOT_OWNERID) { - return { - commandContext: context, - embeds: [] - }; - } - - const stmt = context.args; - - console.log(`Eval Statement: ${stmt.join(" ")}`); - - try { - const result = eval(stmt.join(" ")); - - const embed = new PublicEmbed(context, "", result); - embed.SendToCurrentChannel(); - - return { - commandContext: context, - embeds: [embed] - }; - } - catch (err: any) { - const errorEmbed = new ErrorEmbed(context, err); - errorEmbed.SendToCurrentChannel(); - - return { - commandContext: context, - embeds: [errorEmbed] - }; - } - } -} \ No newline at end of file diff --git a/src/commands/help.ts b/src/commands/help.ts index aaf8f7e..876299c 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,9 +1,9 @@ import { existsSync, readdirSync } from "fs"; +import { CoreClient } from "../client/client"; import { ICommandContext } from "../contracts/ICommandContext"; import ErrorEmbed from "../helpers/embeds/ErrorEmbed"; import PublicEmbed from "../helpers/embeds/PublicEmbed"; import StringTools from "../helpers/StringTools"; -import ICommandReturnContext from "../contracts/ICommandReturnContext"; import { Command } from "../type/command"; export interface ICommandData { @@ -17,106 +17,46 @@ export default class Help extends Command { constructor() { super(); - super._category = "General"; + super.Category = "General"; } - public override execute(context: ICommandContext): ICommandReturnContext { + public override execute(context: ICommandContext) { if (context.args.length == 0) { - return this.SendAll(context); + this.SendAll(context); } else { - return this.SendSingle(context); + this.SendSingle(context); } } - public SendAll(context: ICommandContext): ICommandReturnContext { - const allCommands = this.GetAllCommandData(); - const cateogries = [...new Set(allCommands.map(x => x.Category!))];; + public SendAll(context: ICommandContext) { + const allCommands = CoreClient.commandItems; + const cateogries = [...new Set(allCommands.map(x => x.Command.Category))];; const embed = new PublicEmbed(context, "Commands", ""); cateogries.forEach(category => { - let filtered = allCommands.filter(x => x.Category == category); + let filtered = allCommands.filter(x => x.Command.Category == category); - embed.addField(StringTools.Capitalise(category), filtered.flatMap(x => x.Name).join(", ")); + embed.addField(StringTools.Capitalise(category || "Uncategorised"), StringTools.CapitaliseArray(filtered.flatMap(x => x.Name)).join(", ")); }); embed.SendToCurrentChannel(); - - return { - commandContext: context, - embeds: [ embed ] - }; } - public SendSingle(context: ICommandContext): ICommandReturnContext { - const command = this.GetCommandData(context.args[0]); + public SendSingle(context: ICommandContext) { + const command = CoreClient.commandItems.find(x => x.Name == context.args[0]); - if (!command.Exists) { + if (!command) { const errorEmbed = new ErrorEmbed(context, "Command does not exist"); errorEmbed.SendToCurrentChannel(); - - return { - commandContext: context, - embeds: [ errorEmbed ] - }; + + return; } - const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name!), ""); - embed.addField("Category", StringTools.Capitalise(command.Category!)); - embed.addField("Required Roles", StringTools.Capitalise(command.Roles!.join(", ")) || "*none*"); + const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), ""); + embed.addField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised")); + embed.addField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone"); embed.SendToCurrentChannel(); - - return { - commandContext: context, - embeds: [ embed ] - }; - } - - public GetAllCommandData(): ICommandData[] { - const result: ICommandData[] = []; - - const folder = process.env.FOLDERS_COMMANDS!; - - const contents = readdirSync(`${process.cwd()}/${folder}`); - - contents.forEach(name => { - const file = require(`${process.cwd()}/${folder}/${name}`).default; - const command = new file() as Command; - - const data: ICommandData = { - Exists: true, - Name: name.replace(".ts", ""), - Category: command._category || "none", - Roles: command._roles, - }; - - result.push(data); - }); - - return result; - } - - public GetCommandData(name: string): ICommandData { - const folder = process.env.FOLDERS_COMMANDS!; - const path = `${process.cwd()}/${folder}/${name}.ts`; - - if (!existsSync(path)) { - return { - Exists: false - }; - } - - const file = require(path).default; - const command = new file() as Command; - - const data: ICommandData = { - Exists: true, - Name: name, - Category: command._category || "none", - Roles: command._roles - }; - - return data; } } diff --git a/src/commands/kick.ts b/src/commands/kick.ts index 43a7546..9f75080 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -10,8 +10,8 @@ export default class Kick extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/mute.ts b/src/commands/mute.ts index e673684..fbf0bcf 100644 --- a/src/commands/mute.ts +++ b/src/commands/mute.ts @@ -10,8 +10,8 @@ export default class Mute extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/poll.ts b/src/commands/poll.ts index 8eafd3e..be88869 100644 --- a/src/commands/poll.ts +++ b/src/commands/poll.ts @@ -8,7 +8,7 @@ export default class Poll extends Command { constructor() { super(); - super._category = "General"; + super.Category = "General"; } public override async execute(context: ICommandContext): Promise { diff --git a/src/commands/role.ts b/src/commands/role.ts index 88bd5b8..28586ed 100644 --- a/src/commands/role.ts +++ b/src/commands/role.ts @@ -9,7 +9,7 @@ export default class Role extends Command { constructor() { super(); - super._category = "General"; + super.Category = "General"; } public override async execute(context: ICommandContext) { diff --git a/src/commands/rules.ts b/src/commands/rules.ts index 7860288..414b141 100644 --- a/src/commands/rules.ts +++ b/src/commands/rules.ts @@ -16,8 +16,8 @@ export default class Rules extends Command { constructor() { super(); - super._category = "Admin"; - super._roles = [ + super.Category = "Admin"; + super.Roles = [ "administrator" ]; } diff --git a/src/commands/setup.ts b/src/commands/setup.ts index a38d2a3..87be5a5 100644 --- a/src/commands/setup.ts +++ b/src/commands/setup.ts @@ -7,8 +7,8 @@ import { Command } from "../type/command"; export default class Setup extends Command { constructor() { super(); - super._category = "Administration"; - super._roles = [ + super.Category = "Administration"; + super.Roles = [ "moderator" ] } diff --git a/src/commands/unmute.ts b/src/commands/unmute.ts index ce4dab2..26b82a2 100644 --- a/src/commands/unmute.ts +++ b/src/commands/unmute.ts @@ -10,8 +10,8 @@ export default class Unmute extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/commands/warn.ts b/src/commands/warn.ts index adc82bd..3f42318 100644 --- a/src/commands/warn.ts +++ b/src/commands/warn.ts @@ -9,8 +9,8 @@ export default class Warn extends Command { constructor() { super(); - super._category = "Moderation"; - super._roles = [ + super.Category = "Moderation"; + super.Roles = [ "moderator" ]; } diff --git a/src/events/MessageEvents.ts b/src/events/MessageEvents.ts index 28beda1..6f1d2f5 100644 --- a/src/events/MessageEvents.ts +++ b/src/events/MessageEvents.ts @@ -71,7 +71,7 @@ export default class MessageEvents extends Event { }; } - public override async message(message: Message) { + public override async messageCreate(message: Message) { if (!message.guild) return; if (message.author.bot) return; diff --git a/src/helpers/StringTools.ts b/src/helpers/StringTools.ts index dab3571..5119f94 100644 --- a/src/helpers/StringTools.ts +++ b/src/helpers/StringTools.ts @@ -13,6 +13,16 @@ export default class StringTools { return result.join(" "); } + public static CapitaliseArray(str: string[]): string[] { + const res: string[] = []; + + str.forEach(s => { + res.push(StringTools.Capitalise(s)); + }); + + return res; + } + public static RandomString(length: number) { let result = ""; diff --git a/src/registry.ts b/src/registry.ts index 43632fc..19a673a 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -7,7 +7,6 @@ import Clear from "./commands/clear"; import Code from "./commands/code"; import Config from "./commands/config"; import Disable from "./commands/disable"; -import Evaluate from "./commands/eval"; import Help from "./commands/help"; import Kick from "./commands/kick"; import Mute from "./commands/mute"; @@ -27,35 +26,34 @@ import MemberEvents from "./events/MemberEvents"; import MessageEvents from "./events/MessageEvents"; export default class Registry { - public static RegisterCommands(client: CoreClient) { - client.RegisterCommand("about", new About()); - client.RegisterCommand("ban", new Ban()); - client.RegisterCommand("clear", new Clear()); - client.RegisterCommand("eval", new Evaluate()); - client.RegisterCommand("help", new Help()); - client.RegisterCommand("kick", new Kick()); - client.RegisterCommand("mute", new Mute()); - client.RegisterCommand("poll", new Poll()); - client.RegisterCommand("role", new Role()); - client.RegisterCommand("rules", new Rules()); - client.RegisterCommand("unmute", new Unmute()); - client.RegisterCommand("warn", new Warn()); - client.RegisterCommand("setup", new Setup()); - client.RegisterCommand("config", new Config()); - client.RegisterCommand("code", new Code()); - client.RegisterCommand("disable", new Disable()); + public static RegisterCommands() { + CoreClient.RegisterCommand("about", new About()); + CoreClient.RegisterCommand("ban", new Ban()); + CoreClient.RegisterCommand("clear", new Clear()); + CoreClient.RegisterCommand("help", new Help()); + CoreClient.RegisterCommand("kick", new Kick()); + CoreClient.RegisterCommand("mute", new Mute()); + CoreClient.RegisterCommand("poll", new Poll()); + CoreClient.RegisterCommand("role", new Role()); + CoreClient.RegisterCommand("rules", new Rules()); + CoreClient.RegisterCommand("unmute", new Unmute()); + CoreClient.RegisterCommand("warn", new Warn()); + CoreClient.RegisterCommand("setup", new Setup()); + CoreClient.RegisterCommand("config", new Config()); + CoreClient.RegisterCommand("code", new Code()); + CoreClient.RegisterCommand("disable", new Disable()); // Exclusive Commands: MankBot - client.RegisterCommand("lobby", new Lobby(), "501231711271780357"); - client.RegisterCommand("entry", new Entry(), "501231711271780357"); + CoreClient.RegisterCommand("lobby", new Lobby(), "501231711271780357"); + CoreClient.RegisterCommand("entry", new Entry(), "501231711271780357"); // Add Exclusive Commands to Test Server - client.RegisterCommand("lobby", new Lobby(), "442730357897429002"); - client.RegisterCommand("entry", new Entry(), "442730357897429002"); + CoreClient.RegisterCommand("lobby", new Lobby(), "442730357897429002"); + CoreClient.RegisterCommand("entry", new Entry(), "442730357897429002"); } - public static RegisterEvents(client: CoreClient) { - client.RegisterEvent(new MemberEvents()); - client.RegisterEvent(new MessageEvents()); + public static RegisterEvents() { + CoreClient.RegisterEvent(new MemberEvents()); + CoreClient.RegisterEvent(new MessageEvents()); } } \ No newline at end of file diff --git a/src/type/command.ts b/src/type/command.ts index a8cfdd7..1d04686 100644 --- a/src/type/command.ts +++ b/src/type/command.ts @@ -2,12 +2,11 @@ import { CommandResponse } from "../constants/CommandResponse"; import { ICommandContext } from "../contracts/ICommandContext"; export class Command { - public _roles: string[]; - - public _category?: string; + public Roles: string[]; + public Category?: string; constructor() { - this._roles = []; + this.Roles = []; } public precheck(context: ICommandContext): CommandResponse { diff --git a/src/type/event.ts b/src/type/event.ts index 0e747bd..77771de 100644 --- a/src/type/event.ts +++ b/src/type/event.ts @@ -37,7 +37,7 @@ export class Event { } - public message(message: Message) { + public messageCreate(message: Message) { } diff --git a/src/vylbot.ts b/src/vylbot.ts index f4734e0..50f1d87 100644 --- a/src/vylbot.ts +++ b/src/vylbot.ts @@ -27,7 +27,7 @@ const client = new CoreClient([ Intents.FLAGS.GUILD_MEMBERS, ], devmode); -registry.RegisterCommands(client); -registry.RegisterEvents(client); +registry.RegisterCommands(); +registry.RegisterEvents(); client.start(); \ No newline at end of file