UNPKG

superchats

Version:

SuperChats is a premium library with unique features that control Whatsapp functions. With Superchats you can build service bots, multiservice chats or any system that uses whatsapp

266 lines (265 loc) 12.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.decrypt = exports.decryptSave = exports.create = exports.BRAND = void 0; const mode_1 = require("./Connection/mode"); const path = __importStar(require("path")); const axios_1 = __importDefault(require("axios")); const fs_1 = __importDefault(require("fs")); const ip = require('ip'); const atob = require('atob'); const initializer_1 = require("./initializer"); require("dotenv").config({ path: path.resolve(__dirname, "../.env") }); const chalk_1 = __importDefault(require("chalk")); const yoo_hoo_1 = require("yoo-hoo"); const WhiteList_1 = require("./WhiteList"); const { notify } = require('boxen-notify'); const latestVersion = require('get-latest-version'); //@ts-ignore const package_json_1 = __importDefault(require("../package.json")); const Settings_1 = require("./Settings"); const Storage_1 = require("./Storage"); const file_type_1 = require("file-type"); exports.BRAND = (_a = process.env) === null || _a === void 0 ? void 0 : _a.NAME; __exportStar(require("./Models/Functions"), exports); const defaultOptions = { driveStorage: 'local', welcomeScreen: true, license: '', retries: 5, decryptUrl: '', logQr: true, autoRead: true, alwaysOn: true, nodata: false, nodataFull: false }; async function create(sessionOrOption, options) { let session = 'session'; if (typeof sessionOrOption === 'string' && sessionOrOption.replace(/\s/g, '').length) { session = sessionOrOption.replace(/\s/g, ''); } else if (typeof sessionOrOption === 'object') { session = sessionOrOption.session || session; options = sessionOrOption; } const { logger } = mode_1.DEFAULT_CONNECTION_CONFIG; mode_1.optionsDefault.sessionName = session; let dirName = (options === null || options === void 0 ? void 0 : options.folderPath) !== undefined ? options.folderPath : ''; if (!fs_1.default.existsSync(dirName) && (options === null || options === void 0 ? void 0 : options.folderPath) !== undefined) { fs_1.default.mkdirSync(options === null || options === void 0 ? void 0 : options.folderPath); } if (!fs_1.default.existsSync(dirName + 'tmp')) { fs_1.default.mkdirSync(dirName + 'tmp'); } if (!fs_1.default.existsSync(dirName + 'tokens')) { fs_1.default.mkdirSync(dirName + 'tokens'); } if ((options && options.welcomeScreen === true) || (options === null || options === void 0 ? void 0 : options.welcomeScreen) === undefined) { console.log("\n\n"); (0, yoo_hoo_1.yo)(options && options.welcomeText ? options.welcomeText : exports.BRAND, { color: "rainbow" }); console.log("\n\n"); } (async function () { let version_latest = await latestVersion(package_json_1.default.name, { auth: false }); if (version_latest !== package_json_1.default.version) { notify({ message: `new version available: ${version_latest} \n` + chalk_1.default.green(`npm i ${package_json_1.default.name}@latest`) }); } logger.info(`version: ${package_json_1.default.version}`); })(); if (options && (options === null || options === void 0 ? void 0 : options.decryptUrl) !== "") { mode_1.DEFAULT_CONNECTION_CONFIG.decryptUrl = options.decryptUrl; } if (options) { mode_1.DEFAULT_CONNECTION_CONFIG.printQRInTerminal = options.logQr === true || options.logQr === undefined ? true : false; mode_1.DEFAULT_CONNECTION_CONFIG.license = options.license ? options.license : ''; mode_1.DEFAULT_CONNECTION_CONFIG.welcomeScreen = options.welcomeScreen ? options.welcomeScreen : mode_1.DEFAULT_CONNECTION_CONFIG.welcomeScreen; } async function client() { let hash = 'UGFyYWxlbGVwaXBpZG9OYXJ6ZW5pbGRvT3JhdG9yb2V1YXJvdXBhZG9yZWlkZXJvbWExIQ=='; const response = await axios_1.default.post(atob('aHR0cHM6Ly9saWNlbnNlLnNlbmRhY3RpdmUuY29tLmJyLi9hcGkvbGljZW5zZS92ZXJpZnk='), { key: options === null || options === void 0 ? void 0 : options.license }).catch(error => { console.log(error); }); //@ts-ignore let data = response.data; if (data.tk1 && data.tk2 && data.tk3 && data.tk4) { let tk1 = [742, 1239, 87, 21, 7, 1234, 865, 48, 2637, 13]; let tk2 = [33, 3456, 654, 1, 752, 5321, 412, 65, 3, 964]; let tk3 = [1242, 39, 15, 2344, 5755, 9877, 1345, 346, 90, 191]; let tk4 = [21, 2331, 655, 453, 0, 9766, 1304, 789, 5332, 6]; if (tk1.indexOf(data.tk1) >= 0 && tk2.indexOf(data.tk2) >= 0 && tk3.indexOf(data.tk3) >= 0 && tk4.indexOf(data.tk4) >= 0) { let _tk1 = tk1[Math.floor(Math.random() * 10)]; let _tk2 = tk2[Math.floor(Math.random() * 10)]; let _tk3 = tk3[Math.floor(Math.random() * 10)]; let _tk4 = tk4[Math.floor(Math.random() * 10)]; const etp2 = await axios_1.default.post(atob('aHR0cHM6Ly9saWNlbnNlLnNlbmRhY3RpdmUuY29tLmJyL2FwaS9saWNlbnNlL3ZlcmlmeS9ldHAy'), { ctrl: data.ctrl, tk1: _tk1, tk2: _tk2, tk3: _tk3, tk4: _tk4, key: options === null || options === void 0 ? void 0 : options.license, xxx_i: ip.address() }).catch(error => { logger.fail(atob('TGljZW5jYSBJbnZhbGlkYSE=')); process.exit(); }); //@ts-ignore if (etp2.data && etp2.data.secret) { if (etp2.data.secret == hash) { let autt = 'QUZYMjAwOVZHVDIwMzM='; let resp_autt = await axios_1.default.post(atob('aHR0cHM6Ly9saWNlbnNlLnNlbmRhY3RpdmUuY29tLmJyL2FwaS9saWNlbnNlL3ZlcmlmeS9ldHAz'), { key: options === null || options === void 0 ? void 0 : options.license, autt: autt }); if (resp_autt.data.autt == autt) { logger.info(atob('TGljZW5jYSBWYWxpZGEh')); logger.info(atob('U3RhdHVzIExpY2VuY2E6') + resp_autt.data.status); logger.info(atob('TGljZW5jYSBFeHBpcmEgZW06') + resp_autt.data.expired); //@ts-ignore await (0, initializer_1.init)(session, options); } else { logger.fail(atob(resp_autt.data.code).split('_')[0] + ' ' + atob(resp_autt.data.code).split('_')[1]); process.exit(); } } else { logger.fail(atob('U2VtIFBlcm1pc3NhbyBkZSBVc28sIENvbnRyYXRlIHVtYSBMaWNlbmNh')); process.exit(); } } else { logger.fail(atob(etp2.data.code).split('_')[0] + ' ' + atob(etp2.data.code).split('_')[1]); process.exit(); } } else { logger.fail(atob('VG9rZW5zIFNpbmNyb25pemFkb3MgY29tIG8gU2Vydmlkb3IgSW52YWxpZG9z')); process.exit(); } } else { logger.fail(atob('TGljZW5jYSBpbnZhbGlkYSE=')); process.exit(); } } await client(); // await init(session, options) let ssData = (0, initializer_1.getUser)(session); return await (0, WhiteList_1.whiteList)(session, ssData); } exports.create = create; const decrypt = async (options) => { let buffer; let obj = {}; try { if (options.content) { let Json = typeof options.content === 'object' ? options.content : JSON.parse(options.content); let template = `{ "message": ${JSON.stringify(Json.content)} }`; buffer = await (0, Settings_1.downloadMediaMessage)(JSON.parse(template), 'buffer', {}); } else if (options.msgId) { const store = (0, Storage_1.getCache)(mode_1.optionsDefault.sessionName); let msg = await store.searchData("messages", el => el.key.id === (options === null || options === void 0 ? void 0 : options.msgId)); buffer = await (0, Settings_1.downloadMediaMessage)(msg[0], 'buffer', {}); } let mime = await (0, file_type_1.fromBuffer)(buffer); obj = { session: mode_1.optionsDefault.sessionName, status: 200, type: "decrypt", mime: mime === null || mime === void 0 ? void 0 : mime.mime, ext: mime === null || mime === void 0 ? void 0 : mime.ext, buffer: buffer, }; } catch (error) { obj = { session: mode_1.optionsDefault.sessionName, status: 404, type: "decrypt", message: "The message not is media", }; } return obj; }; exports.decrypt = decrypt; const decryptSave = async (options) => { let buffer; let obj = {}; let mime; try { if (options.content) { let Json = typeof options.content === 'object' ? options.content : JSON.parse(options.content); let template = `{ "message": ${JSON.stringify(Json.content)} }`; buffer = await (0, Settings_1.downloadMediaMessage)(JSON.parse(template), 'buffer', {}); mime = await (0, file_type_1.fromBuffer)(buffer); } else if (options.msgId) { const store = (0, Storage_1.getCache)(mode_1.optionsDefault.sessionName); let msg = await store.searchData("messages", el => el.key.id === (options === null || options === void 0 ? void 0 : options.msgId)); buffer = await (0, Settings_1.downloadMediaMessage)(msg[0], 'buffer', {}); mime = await (0, file_type_1.fromBuffer)(buffer); } await fs_1.default.writeFileSync(options.filename + "." + (mime === null || mime === void 0 ? void 0 : mime.ext), buffer); obj = { session: mode_1.optionsDefault.sessionName, status: 200, type: "decrypt-save", mime: mime === null || mime === void 0 ? void 0 : mime.mime, ext: mime === null || mime === void 0 ? void 0 : mime.ext, file: options.filename + "." + (mime === null || mime === void 0 ? void 0 : mime.ext) }; } catch (error) { obj = { session: mode_1.optionsDefault.sessionName, status: 404, type: "decrypt-save", message: "The message not is media", }; } return obj; }; exports.decryptSave = decryptSave;