const ESMCommand = require("../esm_command"); module.exports = class ESMCommand_Discord_Log extends ESMCommand { constructor(bot) { super(bot); this.permissions = { restricted: true }; } async fromServer() { let log_info = this.params.log_info; let type = log_info["type"], template = log_info["template"], embed = { fields: [] }; switch (template) { case "message": embed.title = "Message received"; embed.fields.push({ name: "Message", value: log_info["message"] }); break; case "embed": let data = this.util.tryParseJSON(log_info["embed"]); if (_.isNull(data)) { return this.ESMBot.send(await this.db.getLoggingChannel(this.serverID), `**Uh oh, we ran into an error parsing a message from your server.**\n\n**If this is a custom message**\nPlease fix any errors in your JSON (https://jsonlint.com)\n**If this is an message made by ESM**\nPlease join our Discord and provide the raw message so we can determine how to fix it.\n\nRaw Message:\n\`\`\`\n${log_info["embed"]}\n\`\`\``); } embed = { title: data[0], description: data[1], fields: [] }; for (let field of data[2]) { embed.fields.push({ name: `${field[0]}`, value: _.isArray(field[1]) || _.isPlainObject(field[1]) ? `${this.ESMBot.inspect(field[1])}` : `${field[1]}`, inline: field[2] ? field[2] : false }); } break; default: return; } switch (type) { case "success": embed.color = this.ESMBot.colors.GREEN; break; case "warn": embed.color = this.ESMBot.colors.YELLOW; break; case "error": embed.color = this.ESMBot.colors.RED; break; default: embed.color = this.ESMBot.colors.BLUE; break; } embed.timestamp = new Date(); embed.author = { name: `Server '${this.serverID}'`, icon_url: this.client.user.avatarURL() }; this.ESMBot.send(await this.db.getLoggingChannel(this.serverID), embed); } }