* Change rules.txt to rules.json (#31)

* Migrate to yarn

* Add role configs to config template

* Install packges and setup typescript

* Migrate entry point

* Migrate about command

* Migrate ban command

* Migrate clear command

* Migrate kick command

* Migrate mute command

* Migrate poll command

* Migrate bunny command

* Update required roles checker

* Migrate role command

* Migrate unmute command

* Migrate warn command

* Migrate eval command

* Migrate help command

* Migrate rules command

* Migrate events to typescript

* Update about command to use the PublicEmbed class

* Update ErrorMessage to ChannelNotFound

* Update messageDelete event to ignore bots

* Feature/74 merge vylbot core (#80)

* Merge VylBot-Core

* Update commands to new system

* Fix issue where events would not load

* Feature/12 create tests (#102)

* Fix tests

* Update coverage

* Remove unrequired mock files

* Add about command test

* Update about tests

* Ban command tests

* eval command tests

* Start help command tests

* Add help command tests

* Add kick command tests

* Mute command tests

* Poll command tests

* Add role command tests

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add rules command tests

* Add unmute command tests

* Add warn command tests

* Add MemberEvents tests

* Add GuildMemberUpdate tests

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add MessageEvents tests

* Add StringTools test

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add embed tests

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add GitHub Actions

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Move to tslint

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Remove tslint

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Remove linting script

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Update rules with blog website and event spoilers rule" (#106)

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Containerise bot (#107)

* Add moderator names to audit reason (#108)

* Feature/48 database (#114)

* Add database and default values

* Add ability to save a setting to the database

* Get commands and events to use database

* Setup and config command

* Update commands to check roles per server

* Different rules per server

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Different prefix per server

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Add verification system

Signed-off-by: Ethan Lane <ethan@vylpes.com>

* Disabled commands per server

* Add devmode for default prefix

* Update embeds

* Fix broken tests

* Feature/66 add different commands per server (#122)

* Add ability for server exclusive commands

* Add MankBot server-exclusive commands

* Add lobby entity to database

* Add documentation

* Add setup command for lobby (#123)

* Update bot to discord.js v13 (#125)

* Update bot to discord.js v13

* Remove debug code

* 110 commandshelp about command errors which causes command to not run (#126)

* Change onMessage to onMessageCreate

* Fix help command

* Add override for bot owner and server owner (#135)

* Change help command so exclusive commands can only be seen for the server they're assigned to (#136)

* Change parsing to not crash if invalid (#142)

* 137 role command cannot read properties of undefined (#141)

* Fix issue with bot crashing

* Fix server prefix not showing

* Add easy way to configure role command

* Move help text to its own directory

* Make role config command to use role id

* Get lobby command to use IDs instead of names (#144)

Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
This commit is contained in:
Vylpes 2022-04-24 14:46:37 +01:00 committed by GitHub
parent 1168898e57
commit 04a4a6204c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
118 changed files with 13966 additions and 4027 deletions

79
src/client/client.ts Normal file
View file

@ -0,0 +1,79 @@
import { Client } from "discord.js";
import * as dotenv from "dotenv";
import { createConnection } from "typeorm";
import DefaultValues from "../constants/DefaultValues";
import ICommandItem from "../contracts/ICommandItem";
import IEventItem from "../contracts/IEventItem";
import { Command } from "../type/command";
import { Event } from "../type/event";
import { Events } from "./events";
import { Util } from "./util";
export class CoreClient extends Client {
private static _commandItems: ICommandItem[];
private static _eventItems: IEventItem[];
private _events: Events;
private _util: Util;
public static get commandItems(): ICommandItem[] {
return this._commandItems;
}
public static get eventItems(): IEventItem[] {
return this._eventItems;
}
constructor(intents: number[], devmode: boolean = false) {
super({ intents: intents });
dotenv.config();
DefaultValues.useDevPrefix = devmode;
CoreClient._commandItems = [];
CoreClient._eventItems = [];
this._events = new Events();
this._util = new Util();
}
public async start() {
if (!process.env.BOT_TOKEN) {
console.error("BOT_TOKEN is not defined in .env");
return;
}
await createConnection().catch(e => {
console.error(e);
return;
});
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, CoreClient._eventItems);
}
public static RegisterCommand(name: string, command: Command, serverId?: string) {
const item: ICommandItem = {
Name: name,
Command: command,
ServerId: serverId,
};
CoreClient._commandItems.push(item);
}
public static RegisterEvent(event: Event) {
const item: IEventItem = {
Event: event,
};
CoreClient._eventItems.push(item);
}
}

37
src/client/events.ts Normal file
View file

@ -0,0 +1,37 @@
import { Message } from "discord.js";
import ICommandItem from "../contracts/ICommandItem";
import SettingsHelper from "../helpers/SettingsHelper";
import { Util } from "./util";
export class Events {
private _util: Util;
constructor() {
this._util = new Util();
}
// Emit when a message is sent
// Used to check for commands
public async onMessageCreate(message: Message, commands: ICommandItem[]) {
if (!message.guild) return;
if (message.author.bot) return;
const prefix = await SettingsHelper.GetSetting("bot.prefix", message.guild.id);
if (!prefix) return;
if (message.content.substring(0, prefix.length).toLowerCase() == prefix.toLowerCase()) {
const args = message.content.substring(prefix.length).split(" ");
const name = args.shift();
if (!name) return;
await this._util.loadCommand(name, args, message, commands);
}
}
// Emit when bot is logged in and ready to use
public onReady() {
console.log("Ready");
}
}

101
src/client/util.ts Normal file
View file

@ -0,0 +1,101 @@
// Required Components
import { Client, Message } from "discord.js";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandItem from "../contracts/ICommandItem";
import IEventItem from "../contracts/IEventItem";
import SettingsHelper from "../helpers/SettingsHelper";
import StringTools from "../helpers/StringTools";
import { CommandResponse } from "../constants/CommandResponse";
import ErrorMessages from "../constants/ErrorMessages";
// Util Class
export class Util {
public async loadCommand(name: string, args: string[], message: Message, commands: ICommandItem[]) {
if (!message.member) return;
if (!message.guild) return;
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", message.guild?.id);
const disabledCommands = disabledCommandsString?.split(",");
if (disabledCommands?.find(x => x == name)) {
message.reply(process.env.COMMANDS_DISABLED_MESSAGE || "This command is disabled.");
return;
}
const item = commands.find(x => x.Name == name && !x.ServerId);
const itemForServer = commands.find(x => x.Name == name && x.ServerId == message.guild?.id);
let itemToUse: ICommandItem;
if (!itemForServer) {
if (!item) {
message.reply('Command not found');
return;
}
itemToUse = item;
} else {
itemToUse = itemForServer;
}
const requiredRoles = itemToUse.Command.Roles;
if (message.author.id != process.env.BOT_OWNERID && message.author.id != message.guild.ownerId) {
for (const i in requiredRoles) {
if (message.guild) {
const setting = await SettingsHelper.GetSetting(`role.${requiredRoles[i]}`, message.guild?.id);
if (!setting) {
message.reply("Unable to verify if you have this role, please contact your bot administrator");
return;
}
if (!message.member.roles.cache.find(role => role.name == setting)) {
message.reply(`You require the \`${StringTools.Capitalise(setting)}\` role to run this command`);
return;
}
}
}
}
const context: ICommandContext = {
name: name,
args: args,
message: message
};
const precheckResponse = itemToUse.Command.precheck(context);
const precheckAsyncResponse = await itemToUse.Command.precheckAsync(context);
if (precheckResponse != CommandResponse.Ok) {
message.reply(ErrorMessages.GetErrorMessage(precheckResponse));
return;
}
if (precheckAsyncResponse != CommandResponse.Ok) {
message.reply(ErrorMessages.GetErrorMessage(precheckAsyncResponse));
return;
}
itemToUse.Command.execute(context);
}
// Load the events
loadEvents(client: Client, events: IEventItem[]) {
events.forEach((e) => {
client.on('channelCreate', e.Event.channelCreate);
client.on('channelDelete', e.Event.channelDelete);
client.on('channelUpdate', e.Event.channelUpdate);
client.on('guildBanAdd', e.Event.guildBanAdd);
client.on('guildBanRemove', e.Event.guildBanRemove);
client.on('guildCreate', e.Event.guildCreate);
client.on('guildMemberAdd', e.Event.guildMemberAdd);
client.on('guildMemberRemove', e.Event.guildMemberRemove);
client.on('guildMemberUpdate', e.Event.guildMemberUpdate);
client.on('messageCreate', e.Event.messageCreate);
client.on('messageDelete', e.Event.messageDelete);
client.on('messageUpdate', e.Event.messageUpdate);
client.on('ready', e.Event.ready);
});
}
}

View file

@ -0,0 +1,25 @@
import { ICommandContext } from "../../contracts/ICommandContext";
import PublicEmbed from "../../helpers/embeds/PublicEmbed";
import SettingsHelper from "../../helpers/SettingsHelper";
import { Command } from "../../type/command";
export default class Entry extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext) {
if (!context.message.guild) return;
const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", context.message.guild.id) || "rules";
const embedInfo = new PublicEmbed(context, "", `Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`);
embedInfo.SendToCurrentChannel();
}
}

View file

@ -0,0 +1,143 @@
import { TextChannel } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
import { Command } from "../../type/command";
import { default as eLobby } from "../../entity/501231711271780357/Lobby";
import SettingsHelper from "../../helpers/SettingsHelper";
import PublicEmbed from "../../helpers/embeds/PublicEmbed";
import { readFileSync } from "fs";
import ErrorEmbed from "../../helpers/embeds/ErrorEmbed";
import BaseEntity from "../../contracts/BaseEntity";
export default class Lobby extends Command {
constructor() {
super();
super.Category = "General";
}
public override async execute(context: ICommandContext) {
if (!context.message.guild) return;
switch (context.args[0]) {
case "config":
await this.UseConfig(context);
break;
default:
await this.UseDefault(context);
}
}
// =======
// Default
// =======
private async UseDefault(context: ICommandContext) {
const channel = context.message.channel as TextChannel;
const channelId = channel.id;
const lobby = await eLobby.FetchOneByChannelId(channelId);
if (!lobby) {
this.SendDisabled(context);
return;
}
const timeNow = Date.now();
const timeLength = lobby.Cooldown * 60 * 1000; // x minutes in ms
const timeAgo = timeNow - timeLength;
// If it was less than x minutes ago
if (lobby.LastUsed.getTime() > timeAgo) {
this.SendOnCooldown(context, timeLength, new Date(timeNow), lobby.LastUsed);
return;
}
await this.RequestLobby(context, lobby);
}
private async RequestLobby(context: ICommandContext, lobby: eLobby) {
lobby.MarkAsUsed();
await lobby.Save(eLobby, lobby);
context.message.channel.send(`${context.message.author} would like to organise a lobby of **${lobby.Name}**! <@&${lobby.RoleId}>`);
}
private SendOnCooldown(context: ICommandContext, timeLength: number, timeNow: Date, timeUsed: Date) {
const timeLeft = Math.ceil((timeLength - (timeNow.getTime() - timeUsed.getTime())) / 1000 / 60);
context.message.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`);
}
private SendDisabled(context: ICommandContext) {
context.message.reply("This channel hasn't been setup for lobbies.");
}
// ======
// Config
// ======
private async UseConfig(context: ICommandContext) {
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", context.message.guild!.id);
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
errorEmbed.SendToCurrentChannel();
return;
}
switch (context.args[1]) {
case "add":
await this.AddLobbyConfig(context);
break;
case "remove":
await this.RemoveLobbyConfig(context);
break;
case "help":
default:
this.SendConfigHelp(context);
}
}
private SendConfigHelp(context: ICommandContext) {
const helpText = readFileSync(`${process.cwd()}/data/usage/lobby.txt`).toString();
const embed = new PublicEmbed(context, "Configure Lobby Command", helpText);
embed.SendToCurrentChannel();
}
private async AddLobbyConfig(context: ICommandContext) {
const channel = context.message.guild!.channels.cache.find(x => x.id == context.args[2]);
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[3]);
const cooldown = Number(context.args[4]) || 30;
const gameName = context.args.splice(5).join(" ");
if (!channel || !role) {
this.SendConfigHelp(context);
return;
}
const entity = new eLobby(channel.id, role.id, cooldown, gameName);
await entity.Save(eLobby, entity);
const embed = new PublicEmbed(context, "", `Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown} minutes\` and will ping \`${role.name}\` on use`);
embed.SendToCurrentChannel();
}
private async RemoveLobbyConfig(context: ICommandContext) {
const channel = context.message.guild!.channels.cache.find(x => x.id == context.args[2]);
if (!channel) {
this.SendConfigHelp(context);
return;
}
const entity = await eLobby.FetchOneByChannelId(channel.id);
if (entity) {
await BaseEntity.Remove<eLobby>(eLobby, entity);
}
const embed = new PublicEmbed(context, "", `Removed \`${channel.name}\` from the list of lobby channels`);
embed.SendToCurrentChannel();
}
}

25
src/commands/about.ts Normal file
View file

@ -0,0 +1,25 @@
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class About extends Command {
constructor() {
super();
super.Category = "General";
}
public override execute(context: ICommandContext): ICommandReturnContext {
const embed = new PublicEmbed(context, "About", "")
.addField("Version", process.env.BOT_VER!)
.addField("Author", process.env.BOT_AUTHOR!)
.addField("Date", process.env.BOT_DATE!);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
}

80
src/commands/ban.ts Normal file
View file

@ -0,0 +1,80 @@
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import ErrorMessages from "../constants/ErrorMessages";
import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
export default class Ban extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed],
};
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed],
};
}
const reasonArgs = context.args;
reasonArgs.splice(0, 1)
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: [],
};
}
if (!targetMember.bannable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed],
};
}
const logEmbed = new LogEmbed(context, "Member Banned");
logEmbed.AddUser("User", targetUser, true);
logEmbed.AddUser("Moderator", context.message.author);
logEmbed.AddReason(reason);
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been banned`);
await targetMember.ban({ reason: `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}` });
await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [logEmbed, publicEmbed],
};
}
}

50
src/commands/clear.ts Normal file
View file

@ -0,0 +1,50 @@
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import { TextChannel } from "discord.js";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
export default class Clear extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
if (context.args.length == 0) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const totalToClear = Number.parseInt(context.args[0]);
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
}

94
src/commands/code.ts Normal file
View file

@ -0,0 +1,94 @@
import { CommandResponse } from "../constants/CommandResponse";
import { ICommandContext } from "../contracts/ICommandContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import SettingsHelper from "../helpers/SettingsHelper";
import StringTools from "../helpers/StringTools";
import { Command } from "../type/command";
export default class Code extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
if (!context.message.guild){
return CommandResponse.NotInServer;
}
const isEnabled = await SettingsHelper.GetSetting("verification.enabled", context.message.guild?.id);
if (!isEnabled) {
return CommandResponse.FeatureDisabled;
}
if (isEnabled.toLocaleLowerCase() != 'true') {
return CommandResponse.FeatureDisabled;
}
return CommandResponse.Ok;
}
public override async execute(context: ICommandContext) {
const action = context.args[0];
switch (action) {
case "randomise":
await this.Randomise(context);
break;
case "embed":
await this.SendEmbed(context);
break;
default:
await this.SendUsage(context);
}
}
private async SendUsage(context: ICommandContext) {
const description = [
"USAGE: <randomise|embed>",
"",
"randomise: Sets the server's entry code to a random code",
"embed: Sends an embed with the server's entry code"
].join("\n");
const embed = new PublicEmbed(context, "", description);
embed.SendToCurrentChannel();
}
private async Randomise(context: ICommandContext) {
if (!context.message.guild) {
return;
}
const randomCode = StringTools.RandomString(5);
await SettingsHelper.SetSetting("verification.code", context.message.guild.id, randomCode);
const embed = new PublicEmbed(context, "Code", `Entry code has been set to \`${randomCode}\``);
embed.SendToCurrentChannel();
}
private async SendEmbed(context: ICommandContext) {
if (!context.message.guild) {
return;
}
const code = await SettingsHelper.GetSetting("verification.code", context.message.guild.id);
if (!code || code == "") {
const errorEmbed = new ErrorEmbed(context, "There is no code for this server setup.");
errorEmbed.SendToCurrentChannel();
return;
}
const embed = new PublicEmbed(context, "Entry Code", code!);
embed.SendToCurrentChannel();
}
}

136
src/commands/config.ts Normal file
View file

@ -0,0 +1,136 @@
import { Guild } from "discord.js";
import { readFileSync } from "fs";
import { CommandResponse } from "../constants/CommandResponse";
import DefaultValues from "../constants/DefaultValues";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import Server from "../entity/Server";
import Setting from "../entity/Setting";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Config extends Command {
constructor() {
super();
super.Category = "Administration";
super.Roles = [
"administrator"
]
}
public override async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
if (!context.message.guild) {
return CommandResponse.ServerNotSetup;
}
const server = await Server.FetchOneById<Server>(Server, context.message.guild?.id, [
"Settings",
]);
if (!server) {
return CommandResponse.ServerNotSetup;
}
return CommandResponse.Ok;
}
public override async execute(context: ICommandContext) {
if (!context.message.guild) {
return;
}
const server = await Server.FetchOneById<Server>(Server, context.message.guild?.id, [
"Settings",
]);
if (!server) {
return;
}
const key = context.args[0];
const action = context.args[1];
const value = context.args.splice(2).join(" ");
if (!key) {
this.SendHelpText(context);
} else if (!action) {
this.GetValue(context, server, key);
} else {
switch(action) {
case 'reset':
this.ResetValue(context, server, key);
break;
case 'set':
if (!value) {
const errorEmbed = new ErrorEmbed(context, "Value is required when setting");
errorEmbed.SendToCurrentChannel();
return;
}
this.SetValue(context, server, key, value);
break;
default:
const errorEmbed = new ErrorEmbed(context, "Action must be either set or reset");
errorEmbed.SendToCurrentChannel();
return;
}
}
}
private async SendHelpText(context: ICommandContext) {
const description = readFileSync(`${process.cwd()}/data/usage/config.txt`).toString();
const embed = new PublicEmbed(context, "Config", description);
embed.SendToCurrentChannel();
}
private async GetValue(context: ICommandContext, server: Server, key: string) {
const setting = server.Settings.filter(x => x.Key == key)[0];
if (setting) {
const embed = new PublicEmbed(context, "", `${key}: ${setting.Value}`);
embed.SendToCurrentChannel();
} else {
const embed = new PublicEmbed(context, "", `${key}: ${DefaultValues.GetValue(key)} <DEFAULT>`);
embed.SendToCurrentChannel();
}
}
private async ResetValue(context: ICommandContext, server: Server, key: string) {
const setting = server.Settings.filter(x => x.Key == key)[0];
if (!setting) {
const embed = new PublicEmbed(context, "", "Setting has been reset");
embed.SendToCurrentChannel();
return;
}
await Setting.Remove(Setting, setting);
const embed = new PublicEmbed(context, "", "Setting has been reset");
embed.SendToCurrentChannel();
}
private async SetValue(context: ICommandContext, server: Server, key: string, value: string) {
const setting = server.Settings.filter(x => x.Key == key)[0];
if (setting) {
setting.UpdateBasicDetails(key, value);
await setting.Save(Setting, setting);
} else {
const newSetting = new Setting(key, value);
await newSetting.Save(Setting, newSetting);
server.AddSettingToServer(newSetting);
await server.Save(Server, server);
}
const embed = new PublicEmbed(context, "", "Setting has been set");
embed.SendToCurrentChannel();
}
}

93
src/commands/disable.ts Normal file
View file

@ -0,0 +1,93 @@
import { ICommandContext } from "../contracts/ICommandContext";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command";
export default class Disable extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext) {
const action = context.args[0];
switch (action) {
case "add":
await this.Add(context);
break;
case "remove":
await this.Remove(context);
break;
default:
await this.SendUsage(context);
}
}
private async SendUsage(context: ICommandContext) {
const description = [
"USAGE: <add|remove> <name>",
"",
"add: Adds the command name to the server's disabled command string",
"remove: Removes the command name from the server's disabled command string",
"name: The name of the command to enable/disable"
].join("\n");
const embed = new PublicEmbed(context, "", description);
embed.SendToCurrentChannel();
}
private async Add(context: ICommandContext) {
if (!context.message.guild) {
return;
}
const commandName = context.args[1];
if (!commandName) {
this.SendUsage(context);
return;
}
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", context.message.guild.id);
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
disabledCommands?.push(commandName);
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
const embed = new PublicEmbed(context, "", `Disabled command: ${commandName}`);
embed.SendToCurrentChannel();
}
private async Remove(context: ICommandContext) {
if (!context.message.guild) {
return;
}
const commandName = context.args[1];
if (!commandName) {
this.SendUsage(context);
return;
}
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", context.message.guild.id);
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName);
if (disabledCommandsInstance! > -1) {
disabledCommands?.splice(disabledCommandsInstance!, 1);
}
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
const embed = new PublicEmbed(context, "", `Enabled command: ${commandName}`);
embed.SendToCurrentChannel();
}
}

70
src/commands/help.ts Normal file
View file

@ -0,0 +1,70 @@
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 { Command } from "../type/command";
export interface ICommandData {
Exists: boolean;
Name?: string;
Category?: string;
Roles?: string[];
}
export default class Help extends Command {
constructor() {
super();
super.Category = "General";
}
public override execute(context: ICommandContext) {
if (context.args.length == 0) {
this.SendAll(context);
} else {
this.SendSingle(context);
}
}
public SendAll(context: ICommandContext) {
const allCommands = CoreClient.commandItems
.filter(x => !x.ServerId || x.ServerId == context.message.guild?.id);
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.Command.Category == category);
embed.addField(StringTools.Capitalise(category || "Uncategorised"), StringTools.CapitaliseArray(filtered.flatMap(x => x.Name)).join(", "));
});
embed.SendToCurrentChannel();
}
public SendSingle(context: ICommandContext) {
const command = CoreClient.commandItems.find(x => x.Name == context.args[0] && !x.ServerId);
const exclusiveCommand = CoreClient.commandItems.find(x => x.Name == context.args[0] && x.ServerId == context.message.guild?.id);
if (exclusiveCommand) {
const embed = new PublicEmbed(context, StringTools.Capitalise(exclusiveCommand.Name), "");
embed.addField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised"));
embed.addField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
embed.SendToCurrentChannel();
} else if (command) {
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();
} else {
const errorEmbed = new ErrorEmbed(context, "Command does not exist");
errorEmbed.SendToCurrentChannel();
return;
}
}
}

83
src/commands/kick.ts Normal file
View file

@ -0,0 +1,83 @@
import ErrorMessages from "../constants/ErrorMessages";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Kick extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const reasonArgs = context.args;
reasonArgs.splice(0, 1)
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!targetMember.kickable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const logEmbed = new LogEmbed(context, "Member Kicked");
logEmbed.AddUser("User", targetUser, true);
logEmbed.AddUser("Moderator", context.message.author);
logEmbed.AddReason(reason);
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been kicked`);
await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

96
src/commands/mute.ts Normal file
View file

@ -0,0 +1,96 @@
import ErrorMessages from "../constants/ErrorMessages";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Mute extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const reasonArgs = context.args;
reasonArgs.splice(0, 1);
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!targetMember.manageable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const logEmbed = new LogEmbed(context, "Member Muted");
logEmbed.AddUser("User", targetUser, true)
logEmbed.AddUser("Moderator", context.message.author);
logEmbed.AddReason(reason);
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been muted`);
publicEmbed.AddReason(reason);
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
if (!mutedRole) {
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
await targetMember.roles.add(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

67
src/commands/poll.ts Normal file
View file

@ -0,0 +1,67 @@
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 Poll extends Command {
constructor() {
super();
super.Category = "General";
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
const argsJoined = context.args.join(" ");
const argsSplit = argsJoined.split(";");
if (argsSplit.length < 3 || argsSplit.length > 10) {
const errorEmbed = new ErrorEmbed(context, "Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const title = argsSplit[0];
const arrayOfNumbers = [
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:'
];
const reactionEmojis = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"];
const description = arrayOfNumbers.splice(0, argsSplit.length - 1);
description.forEach((value, index) => {
description[index] = `${value} ${argsSplit[index + 1]}`;
});
const embed = new PublicEmbed(context, title, description.join("\n"));
const message = await context.message.channel.send({ embeds: [ embed ]});
description.forEach(async (value, index) => {
await message.react(reactionEmojis[index]);
});
if (context.message.deletable) {
await context.message.delete();
}
return {
commandContext: context,
embeds: [embed]
};
}
}

209
src/commands/role.ts Normal file
View file

@ -0,0 +1,209 @@
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Role as DiscordRole } from "discord.js";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import SettingsHelper from "../helpers/SettingsHelper";
import { readFileSync } from "fs";
export default class Role extends Command {
constructor() {
super();
super.Category = "General";
}
public override async execute(context: ICommandContext) {
if (!context.message.guild) return;
switch (context.args[0]) {
case "config":
await this.UseConfig(context);
break;
default:
await this.UseDefault(context);
}
}
// =======
// Default
// =======
private async UseDefault(context: ICommandContext) {
const roles = await SettingsHelper.GetSetting("role.assignable", context.message.guild!.id);
if (!roles) {
const errorEmbed = new ErrorEmbed(context, "Unable to find any assignable roles");
errorEmbed.SendToCurrentChannel();
return;
}
const rolesArray = roles.split(",");
if (context.args.length == 0) {
await this.SendRolesList(context, rolesArray, context.message.guild!.id);
} else {
await this.ToggleRole(context, rolesArray);
}
}
public async SendRolesList(context: ICommandContext, roles: String[], serverId: string): Promise<ICommandReturnContext> {
const botPrefix = await SettingsHelper.GetServerPrefix(serverId);
const description = `Do ${botPrefix}role <role> to get the role!\n${roles.join('\n')}`;
const embed = new PublicEmbed(context, "Roles", description);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
public async ToggleRole(context: ICommandContext, roles: String[]): Promise<ICommandReturnContext> {
const requestedRole = context.args.join(" ");
if (!roles.includes(requestedRole)) {
const errorEmbed = new ErrorEmbed(context, "This role isn't marked as assignable, to see a list of assignable roles, run this command without any parameters");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const assignRole = context.message.guild?.roles.cache.find(x => x.name == requestedRole);
if (!assignRole) {
const errorEmbed = new ErrorEmbed(context, "The current server doesn't have this role. Please contact the server's moderators");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const role = context.message.member?.roles.cache.find(x => x.name == requestedRole)
if (!role) {
await this.AddRole(context, assignRole);
} else {
await this.RemoveRole(context, assignRole);
}
return {
commandContext: context,
embeds: []
};
}
public async AddRole(context: ICommandContext, role: DiscordRole): Promise<ICommandReturnContext> {
await context.message.member?.roles.add(role, "Toggled with role command");
const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
public async RemoveRole(context: ICommandContext, role: DiscordRole): Promise<ICommandReturnContext> {
await context.message.member?.roles.remove(role, "Toggled with role command");
const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
// ======
// Config
// ======
private async UseConfig(context: ICommandContext) {
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", context.message.guild!.id);
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
errorEmbed.SendToCurrentChannel();
return;
}
switch (context.args[1]) {
case "add":
await this.AddRoleConfig(context);
break;
case "remove":
await this.RemoveRoleConfig(context);
break;
default:
this.SendConfigHelp(context);
}
}
private SendConfigHelp(context: ICommandContext) {
const helpText = readFileSync(`${process.cwd()}/data/usage/role.txt`).toString();
const embed = new PublicEmbed(context, "Configure Role Command", helpText);
embed.SendToCurrentChannel();
}
private async AddRoleConfig(context: ICommandContext) {
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[2]);
if (!role) {
this.SendConfigHelp(context);
return;
}
let setting = await SettingsHelper.GetSetting("role.assignable", context.message.guild!.id) || "";
const settingArray = setting.split(",");
settingArray.push(role.name);
setting = settingArray.join(",");
await SettingsHelper.SetSetting("role.assignable", context.message.guild!.id, setting);
const embed = new PublicEmbed(context, "", `Added \`${role.name}\` as a new assignable role`);
embed.SendToCurrentChannel();
}
private async RemoveRoleConfig(context: ICommandContext) {
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[2]);
if (!role) {
this.SendConfigHelp(context);
return;
}
let setting = await SettingsHelper.GetSetting("role.assignable", context.message.guild!.id);
if (!setting) return;
const settingArray = setting.split(",");
const index = settingArray.findIndex(x => x == role.name);
if (index == -1) return;
settingArray.splice(index, 1);
setting = settingArray.join(",");
await SettingsHelper.SetSetting("role.assignable", context.message.guild!.id, setting);
const embed = new PublicEmbed(context, "", `Removed \`${role.name}\` from the list of assignable roles`);
embed.SendToCurrentChannel();
}
}

57
src/commands/rules.ts Normal file
View file

@ -0,0 +1,57 @@
import { existsSync, readFileSync } from "fs";
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";
interface IRules {
title?: string;
description?: string[];
image?: string;
footer?: string;
}
export default class Rules extends Command {
constructor() {
super();
super.Category = "Admin";
super.Roles = [
"administrator"
];
}
public override execute(context: ICommandContext): ICommandReturnContext {
if (!existsSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`)) {
const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`).toString();
const rules = JSON.parse(rulesFile) as IRules[];
const embeds: PublicEmbed[] = [];
rules.forEach(rule => {
const embed = new PublicEmbed(context, rule.title || "", rule.description?.join("\n") || "");
embed.setImage(rule.image || "");
embed.setFooter(rule.footer || "");
embeds.push(embed);
});
embeds.forEach(x => x.SendToCurrentChannel());
return {
commandContext: context,
embeds: embeds
};
}
}

36
src/commands/setup.ts Normal file
View file

@ -0,0 +1,36 @@
import { ICommandContext } from "../contracts/ICommandContext";
import Server from "../entity/Server";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Setup extends Command {
constructor() {
super();
super.Category = "Administration";
super.Roles = [
"moderator"
]
}
public override async execute(context: ICommandContext) {
if (!context.message.guild) {
return;
}
const server = await Server.FetchOneById(Server, context.message.guild?.id);
if (server) {
const embed = new ErrorEmbed(context, "This server has already been setup, please configure using the config command");
embed.SendToCurrentChannel();
return;
}
const newServer = new Server(context.message.guild?.id);
await newServer.Save(Server, newServer);
const embed = new PublicEmbed(context, "Success", "Please configure using the config command");
embed.SendToCurrentChannel();
}
}

96
src/commands/unmute.ts Normal file
View file

@ -0,0 +1,96 @@
import ErrorMessages from "../constants/ErrorMessages";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Unmute extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const reasonArgs = context.args;
reasonArgs.splice(0, 1);
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!targetMember.manageable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
const logEmbed = new LogEmbed(context, "Member Unmuted");
logEmbed.AddUser("User", targetUser, true)
logEmbed.AddUser("Moderator", context.message.author);
logEmbed.AddReason(reason);
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been unmuted`);
publicEmbed.AddReason(reason);
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
if (!mutedRole) {
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
await targetMember.roles.remove(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

71
src/commands/warn.ts Normal file
View file

@ -0,0 +1,71 @@
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
export default class Warn extends Command {
constructor() {
super();
super.Category = "Moderation";
super.Roles = [
"moderator"
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
const user = context.message.mentions.users.first();
if (!user) {
const errorEmbed = new ErrorEmbed(context, "User does not exist");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const member = context.message.guild?.members.cache.find(x => x.user.id == user.id);
if (!member) {
const errorEmbed = new ErrorEmbed(context, "User is not in this server");
errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
}
const reasonArgs = context.args;
reasonArgs.splice(0, 1);
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
const logEmbed = new LogEmbed(context, "Member Warned");
logEmbed.AddUser("User", user, true);
logEmbed.AddUser("Moderator", context.message.author);
logEmbed.AddReason(reason);
const publicEmbed = new PublicEmbed(context, "", `${user} has been warned`);
publicEmbed.AddReason(reason);
await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

View file

@ -0,0 +1,7 @@
export enum CommandResponse {
Ok,
Unauthorised,
ServerNotSetup,
NotInServer,
FeatureDisabled,
}

View file

@ -0,0 +1,56 @@
export default class DefaultValues {
public static values: ISettingValue[] = [];
public static useDevPrefix: boolean = false;
public static GetValue(key: string): string | undefined {
this.SetValues();
const res = this.values.find(x => x.Key == key);
if (!res) {
return undefined;
}
return res.Value;
}
private static SetValues() {
if (this.values.length == 0) {
// Bot
if (this.useDevPrefix) {
this.values.push({ Key: "bot.prefix", Value: "d!" });
} else {
this.values.push({ Key: "bot.prefix", Value: "v!" });
}
// Commands
this.values.push({ Key: "commands.disabled", Value: "" });
this.values.push({ Key: "commands.disabled.message", Value: "This command is disabled." });
// Role (Command)
this.values.push({ Key: "role.assignable", Value: "" });
this.values.push({ Key: "role.moderator", Value: "Moderator" });
this.values.push({ Key: "role.administrator", Value: "Administrator"});
this.values.push({ Key: "role.muted", Value: "Muted" });
// Rules (Command)
this.values.push({ Key: "rules.file", Value: "data/rules/rules" });
// Channels
this.values.push({ Key: "channels.logs.message", Value: "message-logs" });
this.values.push({ Key: "channels.logs.member", Value: "member-logs" });
this.values.push({ Key: "channels.logs.mod", Value: "mod-logs" });
// Verification
this.values.push({ Key: "verification.enabled", Value: "false" });
this.values.push({ Key: "verification.channel", Value: "entry" });
this.values.push({ Key: "verification.role", Value: "Entry" });
this.values.push({ Key: "verification.code", Value: "" });
}
}
}
export interface ISettingValue {
Key: string,
Value: string,
};

View file

@ -0,0 +1,27 @@
import { CommandResponse } from "./CommandResponse";
export default class ErrorMessages {
public static readonly InsufficientBotPermissions = "Unable to do this action, am I missing permissions?";
public static readonly ChannelNotFound = "Unable to find channel";
public static readonly RoleNotFound = "Unable to find role";
public static readonly UserUnauthorised = "You are not authorised to use this command";
public static readonly ServerNotSetup = "This server hasn't been setup yet, please run the setup command";
public static readonly NotInServer = "This command requires to be ran inside of a server";
public static readonly FeatureDisabled = "This feature is currently disabled by a server moderator";
public static GetErrorMessage(response: CommandResponse): string {
switch (response) {
case CommandResponse.Unauthorised:
return this.UserUnauthorised;
case CommandResponse.ServerNotSetup:
return this.ServerNotSetup;
case CommandResponse.NotInServer:
return this.NotInServer;
case CommandResponse.FeatureDisabled:
return this.FeatureDisabled;
default:
return "";
}
}
}

View file

@ -0,0 +1,68 @@
import { Column, DeepPartial, EntityTarget, getConnection, PrimaryColumn } from "typeorm";
import { v4 } from "uuid";
export default class BaseEntity {
constructor() {
this.Id = v4();
this.WhenCreated = new Date();
this.WhenUpdated = new Date();
}
@PrimaryColumn()
Id: string;
@Column()
WhenCreated: Date;
@Column()
WhenUpdated: Date;
public async Save<T>(target: EntityTarget<T>, entity: DeepPartial<T>): Promise<void> {
this.WhenUpdated = new Date();
const connection = getConnection();
const repository = connection.getRepository<T>(target);
await repository.save(entity);
}
public static async Remove<T>(target: EntityTarget<T>, entity: T): Promise<void> {
const connection = getConnection();
const repository = connection.getRepository<T>(target);
await repository.remove(entity);
}
public static async FetchAll<T>(target: EntityTarget<T>, relations?: string[]): Promise<T[]> {
const connection = getConnection();
const repository = connection.getRepository<T>(target);
const all = await repository.find({ relations: relations || [] });
return all;
}
public static async FetchOneById<T>(target: EntityTarget<T>, id: string, relations?: string[]): Promise<T | undefined> {
const connection = getConnection();
const repository = connection.getRepository<T>(target);
const single = await repository.findOne(id, { relations: relations || [] });
return single;
}
public static async Any<T>(target: EntityTarget<T>): Promise<boolean> {
const connection = getConnection();
const repository = connection.getRepository<T>(target);
const any = await repository.find();
return any.length > 0;
}
}

View file

@ -0,0 +1,4 @@
export interface IBaseResponse {
valid: boolean;
message?: string;
}

View file

@ -0,0 +1,7 @@
import { Message } from "discord.js";
export interface ICommandContext {
name: string;
args: string[];
message: Message;
}

View file

@ -0,0 +1,7 @@
import { Command } from "../type/command";
export default interface ICommandItem {
Name: string,
Command: Command,
ServerId?: string,
}

View file

@ -0,0 +1,7 @@
import { MessageEmbed } from "discord.js";
import { ICommandContext } from "./ICommandContext";
export default interface ICommandReturnContext {
commandContext: ICommandContext,
embeds: MessageEmbed[]
}

View file

@ -0,0 +1,6 @@
import { Event } from "../type/event";
export default interface IEventItem {
Event: Event,
}

View file

@ -0,0 +1,6 @@
import { MessageEmbed } from "discord.js";
import { ICommandContext } from "./ICommandContext";
export default interface ICommandReturnContext {
embeds: MessageEmbed[]
}

View file

@ -0,0 +1,45 @@
import { Column, Entity, getConnection } from "typeorm";
import BaseEntity from "../../contracts/BaseEntity";
@Entity()
export default class Lobby extends BaseEntity {
constructor(channelId: string, roleId: string, cooldown: number, name: string) {
super();
this.ChannelId = channelId;
this.RoleId = roleId;
this.Cooldown = cooldown;
this.Name = name;
this.LastUsed = new Date(0);
}
@Column()
public ChannelId: string;
@Column()
public RoleId: string;
@Column()
public Cooldown: number;
@Column()
public LastUsed: Date;
@Column()
public Name: string;
public MarkAsUsed() {
this.LastUsed = new Date();
}
public static async FetchOneByChannelId(channelId: string, relations?: string[]): Promise<Lobby | undefined> {
const connection = getConnection();
const repository = connection.getRepository(Lobby);
const single = await repository.findOne({ ChannelId: channelId }, { relations: relations || [] });
return single;
}
}

19
src/entity/Server.ts Normal file
View file

@ -0,0 +1,19 @@
import { Column, Entity, getConnection, OneToMany } from "typeorm";
import BaseEntity from "../contracts/BaseEntity";
import Setting from "./Setting";
@Entity()
export default class Server extends BaseEntity {
constructor(serverId: string) {
super();
this.Id = serverId;
}
@OneToMany(() => Setting, x => x.Server)
Settings: Setting[];
public AddSettingToServer(setting: Setting) {
this.Settings.push(setting);
}
}

37
src/entity/Setting.ts Normal file
View file

@ -0,0 +1,37 @@
import { Column, Entity, getConnection, ManyToOne } from "typeorm";
import BaseEntity from "../contracts/BaseEntity";
import Server from "./Server";
@Entity()
export default class Setting extends BaseEntity {
constructor(key: string, value: string) {
super();
this.Key = key;
this.Value = value;
}
@Column()
Key: string;
@Column()
Value: string;
@ManyToOne(() => Server, x => x.Settings)
Server: Server;
public UpdateBasicDetails(key: string, value: string) {
this.Key = key;
this.Value = value;
}
public static async FetchOneByKey(key: string, relations?: string[]): Promise<Setting | undefined> {
const connection = getConnection();
const repository = connection.getRepository(Setting);
const single = await repository.findOne({ Key: key }, { relations: relations || [] });
return single;
}
}

View file

@ -0,0 +1,49 @@
import { Event } from "../type/event";
import { GuildMember } from "discord.js";
import EventEmbed from "../helpers/embeds/EventEmbed";
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
import IEventReturnContext from "../contracts/IEventReturnContext";
export default class MemberEvents extends Event {
constructor() {
super();
}
public override async guildMemberAdd(member: GuildMember): Promise<IEventReturnContext> {
const embed = new EventEmbed(member.guild, "Member Joined");
embed.AddUser("User", member.user, true);
embed.addField("Created", member.user.createdAt.toISOString());
embed.setFooter({ text: `Id: ${member.user.id}` });
await embed.SendToMemberLogsChannel();
return {
embeds: [embed]
};
}
public override async guildMemberRemove(member: GuildMember): Promise<IEventReturnContext> {
const embed = new EventEmbed(member.guild, "Member Left");
embed.AddUser("User", member.user, true);
embed.addField("Joined", member.joinedAt?.toISOString() || "n/a");
embed.setFooter({ text: `Id: ${member.user.id}` });
await embed.SendToMemberLogsChannel();
return {
embeds: [embed]
};
}
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember): Promise<IEventReturnContext> {
const handler = new GuildMemberUpdate(oldMember, newMember);
if (oldMember.nickname != newMember.nickname) { // Nickname change
await handler.NicknameChanged();
}
return {
embeds: []
};
}
}

View file

@ -0,0 +1,30 @@
import { GuildMember } from "discord.js";
import IEventReturnContext from "../../contracts/IEventReturnContext";
import EventEmbed from "../../helpers/embeds/EventEmbed";
export default class GuildMemberUpdate {
public oldMember: GuildMember;
public newMember: GuildMember;
constructor(oldMember: GuildMember, newMember: GuildMember) {
this.oldMember = oldMember;
this.newMember = newMember;
}
public async NicknameChanged(): Promise<IEventReturnContext> {
const oldNickname = this.oldMember.nickname || "*none*";
const newNickname = this.newMember.nickname || "*none*";
const embed = new EventEmbed(this.newMember.guild, "Nickname Changed");
embed.AddUser("User", this.newMember.user, true);
embed.addField("Before", oldNickname, true);
embed.addField("After", newNickname, true);
embed.setFooter({ text: `Id: ${this.newMember.user.id}` });
await embed.SendToMemberLogsChannel();
return {
embeds: [embed]
};
}
}

View file

@ -0,0 +1,84 @@
import { Event } from "../type/event";
import { Message } from "discord.js";
import EventEmbed from "../helpers/embeds/EventEmbed";
import IEventReturnContext from "../contracts/IEventReturnContext";
import SettingsHelper from "../helpers/SettingsHelper";
import OnMessage from "./MessageEvents/OnMessage";
export default class MessageEvents extends Event {
constructor() {
super();
}
public override async messageDelete(message: Message): Promise<IEventReturnContext> {
if (!message.guild) {
return {
embeds: []
};
}
if (message.author.bot) {
return {
embeds: []
};
}
const embed = new EventEmbed(message.guild, "Message Deleted");
embed.AddUser("User", message.author, true);
embed.addField("Channel", message.channel.toString(), true);
embed.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``);
if (message.attachments.size > 0) {
embed.addField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``);
}
await embed.SendToMessageLogsChannel();
return {
embeds: [embed]
};
}
public override async messageUpdate(oldMessage: Message, newMessage: Message): Promise<IEventReturnContext> {
if (!newMessage.guild){
return {
embeds: []
};
}
if (newMessage.author.bot) {
return {
embeds: []
};
}
if (oldMessage.content == newMessage.content) {
return {
embeds: []
};
}
const embed = new EventEmbed(newMessage.guild, "Message Edited");
embed.AddUser("User", newMessage.author, true);
embed.addField("Channel", newMessage.channel.toString(), true);
embed.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
embed.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
await embed.SendToMessageLogsChannel();
return {
embeds: [embed]
};
}
public override async messageCreate(message: Message) {
if (!message.guild) return;
if (message.author.bot) return;
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
await OnMessage.VerificationCheck(message);
}
}
}

View file

@ -0,0 +1,59 @@
import { Message as Message } from "discord.js";
import SettingsHelper from "../../helpers/SettingsHelper";
export default class OnMessage {
public static async VerificationCheck(message: Message) {
if (!message.guild) return;
const verificationChannel = await SettingsHelper.GetSetting("verification.channel", message.guild.id);
if (!verificationChannel) {
return;
}
const channel = message.guild.channels.cache.find(x => x.name == verificationChannel);
if (!channel) {
return;
}
const currentChannel = message.guild.channels.cache.find(x => x == message.channel);
if (!currentChannel || currentChannel.name != verificationChannel) {
return;
}
const verificationCode = await SettingsHelper.GetSetting("verification.code", message.guild.id);
if (!verificationCode || verificationCode == "") {
await message.reply("`verification.code` is not set inside of the server's config. Please contact the server's mod team.");
await message.delete();
return;
}
const verificationRoleName = await SettingsHelper.GetSetting("verification.role", message.guild.id);
if (!verificationRoleName) {
await message.reply("`verification.role` is not set inside of the server's config. Please contact the server's mod team.");
await message.delete();
return;
}
const role = message.guild.roles.cache.find(x => x.name == verificationRoleName);
if (!role) {
await message.reply("The entry role configured for this server does not exist. Please contact the server's mod team.");
await message.delete();
return;
}
if (message.content.toLocaleLowerCase() != verificationCode.toLocaleLowerCase()) {
await message.delete();
return;
}
await message.member?.roles.add(role);
await message.delete();
}
}

View file

@ -0,0 +1,59 @@
import DefaultValues from "../constants/DefaultValues";
import Server from "../entity/Server";
import Setting from "../entity/Setting";
export default class SettingsHelper {
public static async GetSetting(key: string, serverId: string): Promise<string | undefined> {
const server = await Server.FetchOneById(Server, serverId, [
"Settings"
]);
if (!server) {
return DefaultValues.GetValue(key);
}
const setting = server.Settings.filter(x => x.Key == key)[0];
if (!setting) {
return DefaultValues.GetValue(key);
}
return setting.Value;
}
public static async SetSetting(key: string, serverId: string, value: string): Promise<void> {
const server = await Server.FetchOneById(Server, serverId, [
"Settings"
]);
if (!server) {
return;
}
const setting = server.Settings.filter(x => x.Key == key)[0];
if (setting) {
setting.UpdateBasicDetails(key, value);
await setting.Save(Setting, setting);
} else {
const newSetting = new Setting(key, value);
await newSetting.Save(Setting, newSetting);
server.AddSettingToServer(newSetting);
await server.Save(Server, server);
}
}
public static async GetServerPrefix(serverId: string): Promise<string> {
const setting = await this.GetSetting("bot.prefix", serverId);
if (!setting) {
return "v!";
}
return setting;
}
}

View file

@ -0,0 +1,38 @@
export default class StringTools {
public static Capitalise(str: string): string {
const words = str.split(" ");
let result: string[] = [];
words.forEach(word => {
const firstLetter = word.substring(0, 1).toUpperCase();
const rest = word.substring(1);
result.push(firstLetter + rest);
});
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 = "";
const characters = 'abcdefghkmnpqrstuvwxyz23456789';
const charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
}

View file

@ -0,0 +1,19 @@
import { MessageEmbed } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
export default class ErrorEmbed extends MessageEmbed {
public context: ICommandContext;
constructor(context: ICommandContext, message: string) {
super();
super.setColor(0xd52803);
super.setDescription(message);
this.context = context;
}
public SendToCurrentChannel() {
this.context.message.channel.send({ embeds: [ this ]});
}
}

View file

@ -0,0 +1,72 @@
import { MessageEmbed, TextChannel, User, Guild } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
import SettingsHelper from "../SettingsHelper";
export default class EventEmbed extends MessageEmbed {
public guild: Guild;
constructor(guild: Guild, title: string) {
super();
super.setColor(0x3050ba);
super.setTitle(title);
this.guild = guild;
}
// Detail methods
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
this.addField(title, `${user} \`${user.tag}\``, true);
if (setThumbnail) {
this.setThumbnail(user.displayAvatarURL());
}
}
public AddReason(message: string) {
this.addField("Reason", message || "*none*");
}
// Send methods
public SendToChannel(name: string) {
const channel = this.guild.channels.cache
.find(channel => channel.name == name) as TextChannel;
if (!channel) {
console.error(`Unable to find channel ${name}`);
return;
}
channel.send({embeds: [ this ]});
}
public async SendToMessageLogsChannel() {
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.guild.id);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
}
public async SendToMemberLogsChannel() {
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.guild.id);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
}
public async SendToModLogsChannel() {
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.guild.id);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
}
}

View file

@ -0,0 +1,79 @@
import { MessageEmbed, TextChannel, User } from "discord.js";
import ErrorMessages from "../../constants/ErrorMessages";
import { ICommandContext } from "../../contracts/ICommandContext";
import SettingsHelper from "../SettingsHelper";
import ErrorEmbed from "./ErrorEmbed";
export default class LogEmbed extends MessageEmbed {
public context: ICommandContext;
constructor(context: ICommandContext, title: string) {
super();
super.setColor(0x3050ba);
super.setTitle(title);
this.context = context;
}
// Detail methods
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
this.addField(title, `${user} \`${user.tag}\``, true);
if (setThumbnail) {
this.setThumbnail(user.displayAvatarURL());
}
}
public AddReason(message: string) {
this.addField("Reason", message || "*none*");
}
// Send methods
public SendToCurrentChannel() {
this.context.message.channel.send({ embeds: [ this ]});
}
public SendToChannel(name: string) {
const channel = this.context.message.guild?.channels.cache
.find(channel => channel.name == name) as TextChannel;
if (!channel) {
const errorEmbed = new ErrorEmbed(this.context, ErrorMessages.ChannelNotFound);
errorEmbed.SendToCurrentChannel();
return;
}
channel.send({ embeds: [ this ]});
}
public async SendToMessageLogsChannel() {
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.context.message.guild?.id!);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
}
public async SendToMemberLogsChannel() {
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.context.message.guild?.id!);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
}
public async SendToModLogsChannel() {
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.context.message.guild?.id!);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
}
}

View file

@ -0,0 +1,26 @@
import { MessageEmbed } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
export default class PublicEmbed extends MessageEmbed {
public context: ICommandContext;
constructor(context: ICommandContext, title: string, description: string) {
super();
super.setColor(0x3050ba);
super.setTitle(title);
super.setDescription(description);
this.context = context;
}
// Detail methods
public AddReason(message: string) {
this.addField("Reason", message || "*none*");
}
// Send methods
public SendToCurrentChannel() {
this.context.message.channel.send({ embeds: [ this ]});
}
}

59
src/registry.ts Normal file
View file

@ -0,0 +1,59 @@
import { CoreClient } from "./client/client";
// Command Imports
import About from "./commands/about";
import Ban from "./commands/ban";
import Clear from "./commands/clear";
import Code from "./commands/code";
import Config from "./commands/config";
import Disable from "./commands/disable";
import Help from "./commands/help";
import Kick from "./commands/kick";
import Mute from "./commands/mute";
import Poll from "./commands/poll";
import Role from "./commands/role";
import Rules from "./commands/rules";
import Setup from "./commands/setup";
import Unmute from "./commands/unmute";
import Warn from "./commands/warn";
// Command Imports: MankBot
import Entry from "./commands/501231711271780357/entry";
import Lobby from "./commands/501231711271780357/lobby";
// Event Imports
import MemberEvents from "./events/MemberEvents";
import MessageEvents from "./events/MessageEvents";
export default class Registry {
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
CoreClient.RegisterCommand("lobby", new Lobby(), "501231711271780357");
CoreClient.RegisterCommand("entry", new Entry(), "501231711271780357");
// Add Exclusive Commands to Test Server
CoreClient.RegisterCommand("lobby", new Lobby(), "442730357897429002");
CoreClient.RegisterCommand("entry", new Entry(), "442730357897429002");
}
public static RegisterEvents() {
CoreClient.RegisterEvent(new MemberEvents());
CoreClient.RegisterEvent(new MessageEvents());
}
}

23
src/type/command.ts Normal file
View file

@ -0,0 +1,23 @@
import { CommandResponse } from "../constants/CommandResponse";
import { ICommandContext } from "../contracts/ICommandContext";
export class Command {
public Roles: string[];
public Category?: string;
constructor() {
this.Roles = [];
}
public precheck(context: ICommandContext): CommandResponse {
return CommandResponse.Ok;
}
public async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
return CommandResponse.Ok;
}
public execute(context: ICommandContext) {
}
}

55
src/type/event.ts Normal file
View file

@ -0,0 +1,55 @@
import { Channel, Guild, GuildMember, Message, PartialDMChannel, PartialGuildMember, PartialMessage, GuildBan } from "discord.js";
export class Event {
public channelCreate(channel: Channel) {
}
public channelDelete(channel: Channel | PartialDMChannel) {
}
public channelUpdate(oldChannel: Channel, newChannel: Channel) {
}
public guildBanAdd(ban: GuildBan) {
}
public guildBanRemove(ban: GuildBan) {
}
public guildCreate(guild: Guild) {
}
public guildMemberAdd(member: GuildMember) {
}
public guildMemberRemove(member: GuildMember | PartialGuildMember) {
}
public guildMemberUpdate(oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) {
}
public messageCreate(message: Message) {
}
public messageDelete(message: Message | PartialMessage) {
}
public messageUpdate(oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) {
}
public ready() {
}
}

33
src/vylbot.ts Normal file
View file

@ -0,0 +1,33 @@
import { CoreClient } from "./client/client";
import * as dotenv from "dotenv";
import registry from "./registry";
import { Intents } from "discord.js";
dotenv.config();
const requiredConfigs: string[] = [
"BOT_TOKEN",
"BOT_VER",
"BOT_AUTHOR",
"BOT_DATE",
"BOT_OWNERID",
];
requiredConfigs.forEach(config => {
if (!process.env[config]) {
throw `${config} is required in .env`;
}
});
const devmode = process.argv.find(x => x.toLowerCase() == "--dev") != null;
const client = new CoreClient([
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
], devmode);
registry.RegisterCommands();
registry.RegisterEvents();
client.start();