/* Adapted and rewritten to Node based on ading2210/poe-api ading2210/poe-api: a reverse engineered Python API wrapper for Quora's Poe Copyright (C) 2023 ading2210 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ const WebSocket = require('ws'); const axios = require('axios'); const fs = require('fs'); const path = require('path'); const http = require('http'); const https = require('https'); const _ = require('lodash'); const directory = __dirname; function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } const getSavedDeviceId = (userId) => { const device_id_path = 'poe_device.json'; let device_ids = {}; if (fs.existsSync(device_id_path)) { device_ids = JSON.parse(fs.readFileSync(device_id_path, 'utf8')); } if (device_ids.hasOwnProperty(userId)) { return device_ids[userId]; } const device_id = uuidv4(); device_ids[userId] = device_id; fs.writeFileSync(device_id_path, JSON.stringify(device_ids, null, 2)); return device_id; }; const parent_path = path.resolve(directory); const queries_path = path.join(parent_path, "poe_graphql"); let queries = {}; const cached_bots = {}; const logger = console; const delay = ms => new Promise(res => setTimeout(res, ms)); const user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"; function extractFormKey(html) { const scriptRegex = /