Migrate rules command

This commit is contained in:
Ethan Lane 2021-12-02 14:36:24 +00:00
parent 6c90307754
commit 24818bcb44
Signed by: Vylpes
GPG key ID: EED233CC06D12504
5 changed files with 50 additions and 85 deletions

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

@ -0,0 +1,46 @@
import { existsSync, readFileSync } from "fs";
import { Command, ICommandContext } from "vylbot-core";
import ErrorEmbed from "../helpers/ErrorEmbed";
import PublicEmbed from "../helpers/PublicEmbed";
interface IRules {
title?: string;
description?: string[];
image?: string;
footer?: string;
}
export default class Rules extends Command {
constructor() {
super();
super._category = "Admin";
super._roles = [
process.env.ROLES_MODERATOR!
];
}
public override execute(context: ICommandContext) {
if (!existsSync(process.env.COMMANDS_RULES_FILE!)) {
const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist");
errorEmbed.SendToCurrentChannel();
return;
}
const rulesFile = readFileSync(`${process.cwd()}/${process.env.COMMANDS_RULES_FILE}`).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());
}
}

View file

@ -11,7 +11,8 @@ const requiredConfigs = [
"CHANNELS_LOGS_MESSAGE",
"CHANNELS_LOGS_MEMBER",
"CHANNELS_LOGS_MOD",
"COMMANDS_ROLE_ROLES"
"COMMANDS_ROLE_ROLES",
"COMMANDS_RULES_FILE"
];
requiredConfigs.forEach(config => {