const ESMCommand = require("../esm_command"); module.exports = class ESMCommand_Ping extends ESMCommand { constructor(bot) { super(bot); this.permissions = { disabled_in_player_mode: true, requires_registration: true, requires_server: true }; this.commandParams = { serverID: { regex: this.util.regex.serverID.base } }; this.information = { category: "server", params: "<server_id>", help: "Checkes connectivity between ESM, the server, and Arma" }; this.configuration = { permissions: { modifiable: true, default: {} }, cooldown: { modifiable: false, default: [5, "seconds"] } }; } async fromDiscord() { this.send({ command: "ping", parameters: { function_name: "ping", discord_start: Date.now() } }); } async fromServer() { // Reply from DLL the first time if (this.params.dll_start) { this.info.parameters.dll_start = this.params.dll_start; this.info.parameters.discord_end = Date.now(); let message = await this.ESMBot.send(this.info.channel, "Collecting results, please wait..."); this.info.parameters.message_id = message.id; this.db.updateCommand(this.info.id, this.info); } else { let discordStart = this.info.parameters.discord_start; let discordEnd = this.info.parameters.discord_end; let dllStart = this.info.parameters.dll_start; let dllEnd = this.params.dll_end; if (this.util.isEmpty(discordStart) || this.util.isEmpty(discordEnd) || this.util.isEmpty(dllStart) || this.util.isEmpty(dllEnd)) { return this.ESMBot.send(this.info.channel, `Well, this is awkward. The response times took too long and things got garbled up. Please try again in a few moments`); } let embed = new this.ESMBot.discord.MessageEmbed() .setTitle(`Ping Results for ${this.serverID}`) .setColor(this.ESMBot.colors.BLUE) .addField("ESM to DLL", `Round Trip: \`${discordEnd - discordStart}\`ms`) .addField("DLL to Arma", `Round Trip: \`${dllEnd - dllStart}\`ms`) .addField("ESM to Arma", `Round Trip: \`${dllEnd - discordStart}\`ms`); await this.ESMBot.send(this.info.channel, embed); let channel = await this.ESMBot.getChannel(this.info.channel); let message = await channel.messages.fetch(this.info.parameters.message_id); if (!this.util.isEmpty(message)) { message.delete(); } } } }