const ESMCommand = require("../esm_command"); const Path = require("path"); const Fs = require("fs"); module.exports = class ESMCommand_Changelog extends ESMCommand { constructor(bot) { super(bot); this.commandParams = { version: { regex: /[\d.]+/, nullable: true } }; this.information = { category: "system", params: "<version>", help: "Shows the highlights for the current version or any previous versions of ESM" }; this.configuration = { allowedInTextChannels: { modifiable: true, default: true } }; } async fromDiscord() { let updateInfo = {}, version = this.ESMBot.config.VERSION; if (this.util.isNull(this.params.version)) { let path = Path.resolve(`./changelogs/${version}.json`); if (!Fs.existsSync(path)) { return this.ESMBot.send(this.message.channel, `${this.message.author.toString()}, well shoot, I messed up and forgot to include the changelog for this version`); } updateInfo = JSON.parse(Fs.readFileSync(path, "utf8")); } else { let path = Path.resolve(`./changelogs/${this.params.version}.json`); if (!Fs.existsSync(path)) { return this.ESMBot.send(this.message.channel, `${this.message.author.toString()}, \`${this.params.version}\` is not a valid version.`); } updateInfo = JSON.parse(Fs.readFileSync(path, "utf8")); version = this.params.version; } let embed = new this.ESMBot.discord.MessageEmbed(); embed.setColor(this.ESMBot.colors.GREEN); embed.setAuthor(this.client.user.username, this.client.user.avatarURL()); embed.setTimestamp(this.ESMBot.moment.utc()); embed.setDescription(`__${version} Highlights:__`); if (!this.util.isEmpty(updateInfo.highlights)) { for (let highlight in updateInfo.highlights) { embed.addField(highlight, updateInfo.highlights[highlight]); } } else { return this.ESMBot.send(this.message.channel, `${this.message.author.toString()}, it looks like there aren't any highlights for \`${version}\`.`); } this.ESMBot.send(this.message.channel, embed); } }