const ESMCommand = require("../esm_command"); module.exports = class ESMCommand_Exec extends ESMCommand { constructor(bot) { super(bot); this.permissions = { disabled_in_player_mode: true, requires_registration: true, requires_server: true, text_only: true }; this.commandParams = { serverID: { regex: this.util.regex.serverID.base }, target: { regex: this.util.regex.target.base, nullable: true }, code: { regex: /[\s\S]+/, preserve_case: true } }; this.information = { category: "server", params: "<server_id> <@user or steam_uid> <code>", help: "Executes code on the Arma server" }; this.configuration = { permissions: { modifiable: true, default: {} }, allowedInTextChannels: { modifiable: false, default: true }, cooldown: { modifiable: true, default: [5, "seconds"] }, enabled: { modifiable: true, default: true } }; } async fromDiscord() { let target = "server"; // todo: Look into improving this, why am I just exiting when the target is null? if (!this.util.isNull(this.params.target)) { if (this.util.regex.discordTag.base.test(this.params.target)) { let discordUser = await this.ESMBot.getUser(this.params.target); if (discordUser == null) { return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "USER_NOT_FOUND")); } let isRegistered = await this.db.isRegistered(discordUser.id); if (!isRegistered) { return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "USER_NOT_REGISTERED")); } target = await this.db.getSteamUIDFromID(discordUser.id); if (target == null) return; } else { target = this.params.target; } } this.send({ command: "exec", parameters: { function_name: "exec", target: target, code: this.util.minifyCode(this.params.code) } }); } async fromServer() { if (this.util.isEmpty(this.params)) return; this.ESMBot.send(this.info.channel, this.params.message); } }