const ESMCommand = require("../esm_command"); module.exports = class ESMCommand_Servers extends ESMCommand { constructor(bot) { super(bot); this.commandParams = { communityID: { regex: this.util.regex.communityID.base } }; this.information = { category: "system", params: "<community_id>", help: "Displays all servers linked with the specified community" }; this.configuration = { allowedInTextChannels: { modifiable: true, default: true }, cooldown: { modifiable: true, default: [2, "seconds"] } }; } async fromDiscord() { let communityID = this.util.getCommunityID(this.params.communityID); if (!(await this.db.isValidCommunity(communityID))) { return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "FAILED_TO_FIND_COMMUNITY")); } let servers = await this.db.getServers(communityID); if (this.util.isEmpty(servers)) { return this.ESMBot.send(this.message.channel, "I didn't find any servers under that community. If you are the owner, make sure to add your servers via the web portal"); } for (let server of servers) { let serverStatus = this.ESMBot.wss.isServerOnline(server.id); let embed = { title: server.name, timestamp: new Date(), color: serverStatus ? this.ESMBot.colors.GREEN : this.ESMBot.colors.RED, fields: [{ name: "Server ID", value: server.id, inline: true }, { name: "IP and port", value: `${server.ip}:${server.port}`, inline: true } ] }; if (serverStatus) { let serverUptime = await this.db.getServerUptime(server.id); embed.fields.push({ name: "Uptime", value: serverUptime, inline: true }); } else { embed.fields.push({ name: "Status", value: "Offline", inline: true }); } this.ESMBot.send(this.message.channel, embed); } } }