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

This commit is contained in:
Vylpes 2021-04-25 16:50:27 +01:00 committed by GitHub
parent 25c4f8c8fd
commit 9854f3c60f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 71 deletions

View file

@ -25,35 +25,30 @@ class rules extends command {
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)) {
// Get the contents of the rules file, and split it by "> "
// Each embed in the rules is set by the "> " syntax
let rulesText = readFileSync(context.client.config.rules.rulesfile).toString();
rulesText = rulesText.split("> ");
const rulesJson = readFileSync(context.client.config.rules.rulesfile);
const rules = JSON.parse(rulesJson);
// Loop through each embed to be sent
for (let i = 0; i < rulesText.length; i++) {
// If the first line after "> " has a "#", create and embed with an image of the url specified after
if (rulesText[i].charAt(0) == '#') {
const embed = new MessageEmbed()
.setColor(embedColor)
.setImage(rulesText[i].substring(1));
for (let i = 0; i < rules.length; i++) {
const rule = rules[i];
const embed = new MessageEmbed();
context.message.channel.send(embed);
} 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
const rulesLines = rulesText[i].split("\n");
const rulesTitle = rulesLines[0];
const rulesDescription = rulesLines.slice(1).join("\n");
embed.setColor(embedColor);
// Create the embed with the specified information above
const embed = new MessageEmbed()
.setTitle(rulesTitle)
.setColor(embedColor)
.setDescription(rulesDescription);
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 = "";
// Send the embed
context.message.channel.send(embed);
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()