const ESMCommand = require("../esm_command"); const Path = require("path"); const Fs = require("fs"); module.exports = class ESMCommand_Update extends ESMCommand { constructor(bot) { super(bot); this.permissions = { dev_only: true }; this.commandParams = { version: { regex: /\d+\.\d+\.\d+/ } }; this.information = { category: "development", params: "", help: "A development command. Posts a changelog for the current release" }; } async fromDiscord() { this.message.delete(); let path = Path.resolve(`./changelogs/${this.params.version}.json`); if (!Fs.existsSync(path)) { return this.ESMBot.send(this.message.channel, `Version \`${this.params.version}\` changelog doesn't exist!`); } let updateInfo = Fs.readFileSync(path, "utf8"); updateInfo = JSON.parse(updateInfo); let embed = new this.ESMBot.discord.MessageEmbed(); embed.setTitle(`Changelog for Exile Server Manager (${this.params.version})`); embed.setDescription(this.util.isEmpty(updateInfo.notes) ? "" : updateInfo.notes); embed.setColor(this.ESMBot.colors.GREEN); embed.setAuthor(this.client.user.username, this.client.user.avatarURL()); embed.setTimestamp(this.ESMBot.moment.utc()); embed.addField( updateInfo.update_required ? "❗ Mod update is required" : "👌 No mod update needed", updateInfo.update_required ? `- Mod version is now: \`${updateInfo.mod_version}\`\n- You can download the update [here](http://www.esmbot.com/downloads)` : `- Current mod version: \`${updateInfo.mod_version}\`` ); if (!this.util.isEmpty(updateInfo.highlights)) { embed.addField("\u200B", `__${this.params.version} Highlights:__`, false); for (let highlight in updateInfo.highlights) { embed.addField(highlight, updateInfo.highlights[highlight]); } } embed.addField("\u200B", `__${this.params.version} Full Changelog:__`, false); for (let type in updateInfo.changes) { let entries = updateInfo.changes[type]; if (this.util.isEmpty(entries)) continue; let value = ""; for (let [state, entry] of entries) { value += `**[${state}]** ${entry}\n`; } embed.addField(type.toUpperCase(), value); } this.ESMBot.send(this.message.channel, embed); } }