v3.0 #145
5 changed files with 50 additions and 85 deletions
|
@ -23,6 +23,8 @@ COMMANDS_DISABLED_MESSAGE=This command is disabled.
|
|||
|
||||
COMMANDS_ROLE_ROLES=Notify,VotePings,ProjectUpdates
|
||||
|
||||
COMMANDS_RULES_FILE=data/rules/rules.json
|
||||
|
||||
EMBED_COLOUR=0x3050ba
|
||||
EMBED_COLOUR_ERROR=0xD52803
|
||||
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
// Required Components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { existsSync, readFileSync } = require('fs');
|
||||
|
||||
// Command variables
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command class
|
||||
class rules extends command {
|
||||
constructor() {
|
||||
// Set the command's run method, description, and category
|
||||
super("rules");
|
||||
super.description = "Generates the rules embeds from the rules.txt file";
|
||||
super.category = "Admin";
|
||||
|
||||
// Require in the config the name of the admin role and the rules file name
|
||||
super.requiredConfigs = "adminrole";
|
||||
super.requiredConfigs = "rulesfile";
|
||||
}
|
||||
|
||||
// Run method
|
||||
rules(context) {
|
||||
// If the user is an Admin (has the admin role)
|
||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.rules.adminrole)) {
|
||||
// If the rulesfile exists
|
||||
if (existsSync(context.client.config.rules.rulesfile)) {
|
||||
const rulesJson = readFileSync(context.client.config.rules.rulesfile);
|
||||
const rules = JSON.parse(rulesJson);
|
||||
|
||||
for (let i = 0; i < rules.length; i++) {
|
||||
const rule = rules[i];
|
||||
const embed = new MessageEmbed();
|
||||
|
||||
embed.setColor(embedColor);
|
||||
|
||||
if (rule.image) embed.setImage(rule.image);
|
||||
if (rule.title) embed.setTitle(rule.title);
|
||||
if (rule.footer) embed.setFooter(rule.footer);
|
||||
if (rule.description) {
|
||||
let description = "";
|
||||
|
||||
for (let j = 0; j < rule.description.length; j++) {
|
||||
const line = rule.description[j];
|
||||
description += `${line}\n`;
|
||||
}
|
||||
|
||||
embed.setDescription(description);
|
||||
}
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
} else { // If the rules file doesn't exist
|
||||
const errorEmbed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${context.client.config.rules.rulesfile} doesn't exist`);
|
||||
|
||||
context.message.channel.send(errorEmbed);
|
||||
}
|
||||
} else { // If the user doesn't have the Admin role
|
||||
const errorEmbed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription("You do not have permission to run this command");
|
||||
|
||||
context.message.channel.send(errorEmbed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = rules;
|
|
@ -1,14 +0,0 @@
|
|||
[
|
||||
{
|
||||
"name": "Cuzethstan",
|
||||
"description": "Cuzeth Server. Yes.",
|
||||
"invite": "http://discord.gg/uhEFNw7",
|
||||
"icon": "https://cdn.discordapp.com/icons/720177983016665251/a_e4250e57b26559c6609dfe562774ee27.gif"
|
||||
},
|
||||
{
|
||||
"name": "Boblin",
|
||||
"description": "Official server of the... Boblin?\n- Multiple Topics\n- Lots of Very Active Members",
|
||||
"invite": "https://discord.gg/Td4uzVu",
|
||||
"icon": "https://cdn.discordapp.com/attachments/464708407010787328/487824441846267907/image0.png"
|
||||
}
|
||||
]
|
46
src/commands/rules.ts
Normal file
46
src/commands/rules.ts
Normal 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());
|
||||
}
|
||||
}
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in a new issue