v3.0 #145
27 changed files with 102 additions and 202 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,8 +7,8 @@ export default class Entry extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export default class Lobby extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "General";
|
||||
super.Category = "General";
|
||||
}
|
||||
|
||||
public override async execute(context: ICommandContext) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -10,8 +10,8 @@ export default class Ban extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ export default class Clear extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ export default class Code extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ export default class Disable extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ export default class Kick extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ export default class Mute extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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<ICommandReturnContext> {
|
||||
|
|
|
@ -9,7 +9,7 @@ export default class Role extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "General";
|
||||
super.Category = "General";
|
||||
}
|
||||
|
||||
public override async execute(context: ICommandContext) {
|
||||
|
|
|
@ -16,8 +16,8 @@ export default class Rules extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Admin";
|
||||
super._roles = [
|
||||
super.Category = "Admin";
|
||||
super.Roles = [
|
||||
"administrator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ export default class Unmute extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ export default class Warn extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
super.Category = "Moderation";
|
||||
super.Roles = [
|
||||
"moderator"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 = "";
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -37,7 +37,7 @@ export class Event {
|
|||
|
||||
}
|
||||
|
||||
public message(message: Message) {
|
||||
public messageCreate(message: Message) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
Loading…
Reference in a new issue