2021-02-17 18:12:45 +00:00
|
|
|
// Required Components
|
2020-11-04 19:58:54 +00:00
|
|
|
const { command } = require('vylbot-core');
|
|
|
|
const { MessageEmbed } = require('discord.js');
|
|
|
|
const { existsSync, readFileSync } = require('fs');
|
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Command variables
|
2020-11-04 19:58:54 +00:00
|
|
|
const embedColor = "0x3050ba";
|
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Command class
|
2020-11-04 19:58:54 +00:00
|
|
|
class rules extends command {
|
|
|
|
constructor() {
|
2020-11-07 17:01:03 +00:00
|
|
|
// Set the command's run method, description, and category
|
2020-11-04 19:58:54 +00:00
|
|
|
super("rules");
|
|
|
|
super.description = "Generates the rules embeds from the rules.txt file";
|
2021-02-17 18:12:45 +00:00
|
|
|
super.category = "Admin";
|
2020-11-04 19:58:54 +00:00
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Require in the config the name of the admin role and the rules file name
|
2020-11-04 19:58:54 +00:00
|
|
|
super.requiredConfigs = "adminrole";
|
|
|
|
super.requiredConfigs = "rulesfile";
|
|
|
|
}
|
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Run method
|
2020-11-04 19:58:54 +00:00
|
|
|
rules(context) {
|
2020-11-07 17:01:03 +00:00
|
|
|
// If the user is an Admin (has the admin role)
|
2020-11-04 19:58:54 +00:00
|
|
|
if (context.message.member.roles.cache.find(role => role.name == context.client.config.rules.adminrole)) {
|
2020-11-07 17:01:03 +00:00
|
|
|
// If the rulesfile exists
|
2020-11-04 19:58:54 +00:00
|
|
|
if (existsSync(context.client.config.rules.rulesfile)) {
|
2020-11-07 17:01:03 +00:00
|
|
|
// Get the contents of the rules file, and split it by "> "
|
|
|
|
// Each embed in the rules is set by the "> " syntax
|
2020-11-04 19:58:54 +00:00
|
|
|
let rulesText = readFileSync(context.client.config.rules.rulesfile).toString();
|
|
|
|
rulesText = rulesText.split("> ");
|
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Loop through each embed to be sent
|
2020-11-04 19:58:54 +00:00
|
|
|
for (let i = 0; i < rulesText.length; i++) {
|
2020-11-07 17:01:03 +00:00
|
|
|
// If the first line after "> " has a "#", create and embed with an image of the url specified after
|
2020-11-04 19:58:54 +00:00
|
|
|
if (rulesText[i].charAt(0) == '#') {
|
2021-02-17 18:12:45 +00:00
|
|
|
const embed = new MessageEmbed()
|
2020-11-04 19:58:54 +00:00
|
|
|
.setColor(embedColor)
|
|
|
|
.setImage(rulesText[i].substring(1));
|
|
|
|
|
|
|
|
context.message.channel.send(embed);
|
2020-11-07 17:01:03 +00:00
|
|
|
} else { // If the file doesn't have a "#" at the start
|
|
|
|
// Split the embed into different lines, set the first line as the title, and the rest as the description
|
2021-02-17 18:12:45 +00:00
|
|
|
const rulesLines = rulesText[i].split("\n");
|
|
|
|
const rulesTitle = rulesLines[0];
|
|
|
|
const rulesDescription = rulesLines.slice(1).join("\n");
|
2020-11-04 19:58:54 +00:00
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Create the embed with the specified information above
|
2021-02-17 18:12:45 +00:00
|
|
|
const embed = new MessageEmbed()
|
2020-11-04 19:58:54 +00:00
|
|
|
.setTitle(rulesTitle)
|
|
|
|
.setColor(embedColor)
|
|
|
|
.setDescription(rulesDescription);
|
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
// Send the embed
|
2020-11-04 19:58:54 +00:00
|
|
|
context.message.channel.send(embed);
|
|
|
|
}
|
|
|
|
}
|
2020-11-07 17:01:03 +00:00
|
|
|
} else { // If the rules file doesn't exist
|
2021-02-17 18:12:45 +00:00
|
|
|
const errorEmbed = new MessageEmbed()
|
2020-11-04 19:58:54 +00:00
|
|
|
.setColor(embedColor)
|
|
|
|
.setDescription(`${context.client.config.rules.rulesfile} doesn't exist`);
|
|
|
|
|
|
|
|
context.message.channel.send(errorEmbed);
|
|
|
|
}
|
2020-11-07 17:01:03 +00:00
|
|
|
} else { // If the user doesn't have the Admin role
|
2021-02-17 18:12:45 +00:00
|
|
|
const errorEmbed = new MessageEmbed()
|
2020-11-04 19:58:54 +00:00
|
|
|
.setColor(embedColor)
|
|
|
|
.setDescription("You do not have permission to run this command");
|
|
|
|
|
|
|
|
context.message.channel.send(errorEmbed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 17:01:03 +00:00
|
|
|
module.exports = rules;
|