Feature/48 database #114

Merged
Vylpes merged 12 commits from feature/48-database into develop 2022-03-29 18:19:54 +01:00
8 changed files with 113 additions and 12 deletions
Showing only changes of commit d5b3daaec5 - Show all commits

View file

@ -7,11 +7,7 @@
# any secret values.
BOT_TOKEN=
BOT_PREFIX=v!
BOT_VER=3.0
BOT_AUTHOR=Vylpes
BOT_DATE=28 Nov 2021
BOT_OWNERID=147392775707426816
FOLDERS_COMMANDS=src/commands
FOLDERS_EVENTS=src/events

View file

@ -3,8 +3,7 @@ USAGE: <key> <set|reset> [value]
===[ KEYS ]===
bot.prefix: The bot prefix for the server (Default: "v!")
commands.disabled: Disabled commands (Default: "")
commands.disabled.message: The message to show when a disabled command is ran (Default: "This command is disabled.")
commands.disabled: Disabled commands, separated by commas (Default: "")
role.assignable: List of roles assignable to user (Default: [])
role.moderator: The moderator role name (Default: "Moderator")

View file

@ -6,7 +6,7 @@
"typings": "./dist",
"scripts": {
"build": "tsc",
"start": "node ./dist/vylbot",
"start": "tsc && node ./dist/vylbot",
"test": "jest"
},
"repository": {

View file

@ -37,9 +37,6 @@ export class CoreClient extends Client {
public async start() {
if (!process.env.BOT_TOKEN) throw "BOT_TOKEN is not defined in .env";
if (!process.env.BOT_PREFIX) throw "BOT_PREFIX is not defined in .env";
if (!process.env.FOLDERS_COMMANDS) throw "FOLDERS_COMMANDS is not defined in .env";
if (!process.env.FOLDERS_EVENTS) throw "FOLDERS_EVENTS is not defined in .env";
await createConnection().catch(e => {
throw e;

View file

@ -28,7 +28,13 @@ export class Util {
message: "Member is not part of message",
};
const disabledCommands = process.env.COMMANDS_DISABLED?.split(',');
if (!message.guild) return {
valid: false,
message: "Message is not part of a guild",
};
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.");

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

@ -0,0 +1,96 @@
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 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();
}
}

View file

@ -4,6 +4,7 @@ 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 Evaluate from "./commands/eval";
import Help from "./commands/help";
import Kick from "./commands/kick";
@ -34,6 +35,7 @@ export default class Registry {
client.RegisterCommand("setup", new Setup());
client.RegisterCommand("config", new Config());
client.RegisterCommand("code", new Code());
client.RegisterCommand("disable", new Disable())
}
public static RegisterEvents(client: CoreClient) {

View file

@ -5,6 +5,11 @@ import registry from "./registry";
dotenv.config();
const requiredConfigs: string[] = [
"BOT_TOKEN",
"BOT_VER",
"BOT_AUTHOR",
"BOT_DATE",
"BOT_OWNERID",
];
requiredConfigs.forEach(config => {