"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const discord_js_1 = require("discord.js"); const node_path_1 = __importDefault(require("node:path")); const node_util_1 = __importDefault(require("node:util")); const execFile = node_util_1.default.promisify(require('child_process').execFile); const exec = node_util_1.default.promisify(require('child_process').exec); const Event = { name: discord_js_1.Events.MessageCreate, once: false, execute(core, message) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const [commandName, ...args] = message.content.slice(1).trim().split(' '); if (((_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions.has(discord_js_1.PermissionFlagsBits.Administrator)) && commandName.startsWith('change_server')) { args[0] = args[0].replace(/[<>]/g, ''); if (!message.author.bot && (!args[0] || !args[0].startsWith('soldat://'))) { return yield message.reply('You need to provide a valid server address with ` soldat:// ` protocol.'); } if (message.author.bot) { if (!core.avaliable) { return yield message.reply(`Currently, a match with ID **${core.matchId}** is being presented, and the bot needs to wait for this match to end in order to change it.`); } core.avaliable = false; core.matchId = args[1]; } try { yield exec(`echo ${args[0]} | clip`); yield execFile(node_path_1.default.join(__dirname, '../utils/open_soldat.exe')); yield execFile(node_path_1.default.join(__dirname, '../utils/return_menu.exe')); yield execFile(node_path_1.default.join(__dirname, '../utils/connect_to_server.exe')); core.interval = setInterval(() => __awaiter(this, void 0, void 0, function* () { yield execFile(node_path_1.default.join(__dirname, '../utils/change_player.exe')); }), 30000); yield message.react('✅'); } catch (err) { return console.error(err); } } if (((_b = message.member) === null || _b === void 0 ? void 0 : _b.permissions.has(discord_js_1.PermissionFlagsBits.Administrator)) && commandName.startsWith('return_menu')) { if (message.author.bot && core.matchId != args[0]) { return yield message.reply({ content: `No match with ID ${args[0]} that is currently being broadcast was found.`, }); } try { yield execFile(node_path_1.default.join(__dirname, '../utils/open_soldat.exe')); yield execFile(node_path_1.default.join(__dirname, '../utils/return_menu.exe')); clearInterval(core.interval); core.avaliable = true; yield message.react('✅'); } catch (err) { return console.error(err); } } }); }, }; exports.default = Event;