node-ainzfb-new 1.5.4 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1054 -562
- package/package.json +1 -1
    
        package/index.js
    CHANGED
    
    | @@ -1,603 +1,1095 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            'use strict';
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
            var cheerio = require("cheerio");
         | 
| 5 | 
            -
            var log = require("npmlog");
         | 
| 3 | 
            +
            /!-[ Max Cpu Speed ]-!/
         | 
| 6 4 |  | 
| 5 | 
            +
            process.env.UV_THREADPOOL_SIZE = require('os').cpus().length;
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            /!-[ Global Set ]-!/
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            global.isThread = new Array();
         | 
| 10 | 
            +
            global.isUser = new Array();
         | 
| 11 | 
            +
            global.startTime = Date.now();
         | 
| 12 | 
            +
            global.getText =  require('gettext.js')();
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            /!-[ Require All Package Need Use ]-!/
         | 
| 15 | 
            +
            /*globalThis.Fca = new Object({
         | 
| 16 | 
            +
                test: console,log("test"),
         | 
| 17 | 
            +
                Require: new Object({})
         | 
| 18 | 
            +
            });*/
         | 
| 19 | 
            +
            var utils = require("./utils"),
         | 
| 20 | 
            +
                cheerio = require("cheerio"),
         | 
| 21 | 
            +
                log = require("npmlog"),
         | 
| 22 | 
            +
            //{ getAccessToken } = require('./Extra/ExtraAddons'),
         | 
| 23 | 
            +
                logger = require('./logger'),
         | 
| 24 | 
            +
                fs = require('fs-extra'),
         | 
| 25 | 
            +
                getText = require('gettext.js')(),
         | 
| 26 | 
            +
                logger = require('./logger'),
         | 
| 27 | 
            +
                Fetch = require('got'),
         | 
| 28 | 
            +
                fs = require('fs-extra'),
         | 
| 29 | 
            +
                StateCrypt = require('./StateCrypt'),
         | 
| 30 | 
            +
                Client = require("@replit/database"),
         | 
| 31 | 
            +
                languageFile = require('./Language/index.json'),
         | 
| 32 | 
            +
                ObjFastConfig = {
         | 
| 33 | 
            +
                    "Language": "en",
         | 
| 34 | 
            +
                    "MainColor": "#9900FF",
         | 
| 35 | 
            +
                    "BroadCast": true,
         | 
| 36 | 
            +
                    "EncryptFeature": true,
         | 
| 37 | 
            +
                    "PreKey": "",
         | 
| 38 | 
            +
                    "Uptime": false
         | 
| 39 | 
            +
                };
         | 
| 40 | 
            +
             | 
| 41 | 
            +
             | 
| 42 | 
            +
            /!-[ Check File To Run Process ]-!/
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            try {
         | 
| 45 | 
            +
                if (!fs.existsSync('./FastConfigFca.json')) {
         | 
| 46 | 
            +
                    fs.writeFileSync("./FastConfigFca.json", JSON.stringify(ObjFastConfig, null, "\t"));
         | 
| 47 | 
            +
                    process.exit(1);
         | 
| 48 | 
            +
                } else if (fs.existsSync('./FastConfigFca.json')) {
         | 
| 49 | 
            +
                    try {
         | 
| 50 | 
            +
                        var DataLanguageSetting = require("../../FastConfigFca.json");
         | 
| 51 | 
            +
                    } catch (e) {
         | 
| 52 | 
            +
                        logger("Invalid Config Settings, Restoring Default...");
         | 
| 53 | 
            +
                        fs.writeFileSync("./FastConfigFca.json", JSON.stringify(ObjFastConfig, null, "\t"));
         | 
| 54 | 
            +
                        process.exit(1);
         | 
| 55 | 
            +
                    }
         | 
| 56 | 
            +
                    try {
         | 
| 57 | 
            +
                        if (DataLanguageSetting && !DataLanguageSetting.PreKey) {
         | 
| 58 | 
            +
                            DataLanguageSetting.PreKey = "";
         | 
| 59 | 
            +
                            fs.writeFileSync("./FastConfigFca.json", JSON.stringify(DataLanguageSetting, null, "\t"));
         | 
| 60 | 
            +
                        }
         | 
| 61 | 
            +
                    } catch (e) {
         | 
| 62 | 
            +
                        console.log(e);
         | 
| 63 | 
            +
                    }
         | 
| 64 | 
            +
                    if (!languageFile.some(i => i.Language == DataLanguageSetting.Language)) {
         | 
| 65 | 
            +
                        logger("Not Support Language: " + DataLanguageSetting.Language + " Only 'en' and 'vi'", "[ FCA-SUS ]");
         | 
| 66 | 
            +
                        process.exit(0);
         | 
| 67 | 
            +
                    }
         | 
| 68 | 
            +
                    var Language = languageFile.find(i => i.Language == DataLanguageSetting.Language).Folder.Index;
         | 
| 69 | 
            +
                } else process.exit(1);
         | 
| 70 | 
            +
                if (utils.getType(DataLanguageSetting.BroadCast) != "Boolean" && DataLanguageSetting.BroadCast != undefined) {
         | 
| 71 | 
            +
                    log.warn("FastConfig-BroadCast", getText.gettext(Language.IsNotABoolean, DataLanguageSetting.BroadCast));
         | 
| 72 | 
            +
                    process.exit(0)
         | 
| 73 | 
            +
                } else if (DataLanguageSetting.BroadCast == undefined) {
         | 
| 74 | 
            +
                    fs.writeFileSync("./FastConfigFca.json", JSON.stringify(ObjFastConfig, null, "\t"));
         | 
| 75 | 
            +
                    process.exit(1);
         | 
| 76 | 
            +
                }
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                global.FastConfig = DataLanguageSetting;
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            } catch (e) {
         | 
| 81 | 
            +
                console.log(e);
         | 
| 82 | 
            +
                logger.Error();
         | 
| 83 | 
            +
            }
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            /!-[ Set Variable For Process ]-!/
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            log.maxRecordSize = 100;
         | 
| 7 88 | 
             
            var checkVerified = null;
         | 
| 8 89 |  | 
| 9 | 
            -
             | 
| 10 | 
            -
            log.maxRecordSize = defaultLogRecordSize;
         | 
| 90 | 
            +
            /!-[ Function setOptions ]-!/
         | 
| 11 91 |  | 
| 12 92 | 
             
            function setOptions(globalOptions, options) {
         | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 93 | 
            +
                Object.keys(options).map(function(key) {
         | 
| 94 | 
            +
                    switch (key) {
         | 
| 95 | 
            +
                        case 'pauseLog':
         | 
| 96 | 
            +
                            if (options.pauseLog) log.pause();
         | 
| 97 | 
            +
                            break;
         | 
| 98 | 
            +
                        case 'online':
         | 
| 99 | 
            +
                            globalOptions.online = Boolean(options.online);
         | 
| 100 | 
            +
                            break;
         | 
| 101 | 
            +
                        case 'logLevel':
         | 
| 102 | 
            +
                            log.level = options.logLevel;
         | 
| 103 | 
            +
                            globalOptions.logLevel = options.logLevel;
         | 
| 104 | 
            +
                            break;
         | 
| 105 | 
            +
                        case 'logRecordSize':
         | 
| 106 | 
            +
                            log.maxRecordSize = options.logRecordSize;
         | 
| 107 | 
            +
                            globalOptions.logRecordSize = options.logRecordSize;
         | 
| 108 | 
            +
                            break;
         | 
| 109 | 
            +
                        case 'selfListen':
         | 
| 110 | 
            +
                            globalOptions.selfListen = Boolean(options.selfListen);
         | 
| 111 | 
            +
                            break;
         | 
| 112 | 
            +
                        case 'listenEvents':
         | 
| 113 | 
            +
                            globalOptions.listenEvents = Boolean(options.listenEvents);
         | 
| 114 | 
            +
                            break;
         | 
| 115 | 
            +
                        case 'pageID':
         | 
| 116 | 
            +
                            globalOptions.pageID = options.pageID.toString();
         | 
| 117 | 
            +
                            break;
         | 
| 118 | 
            +
                        case 'updatePresence':
         | 
| 119 | 
            +
                            globalOptions.updatePresence = Boolean(options.updatePresence);
         | 
| 120 | 
            +
                            break;
         | 
| 121 | 
            +
                        case 'forceLogin':
         | 
| 122 | 
            +
                            globalOptions.forceLogin = Boolean(options.forceLogin);
         | 
| 123 | 
            +
                            break;
         | 
| 124 | 
            +
                        case 'userAgent':
         | 
| 125 | 
            +
                            globalOptions.userAgent = options.userAgent;
         | 
| 126 | 
            +
                            break;
         | 
| 127 | 
            +
                        case 'autoMarkDelivery':
         | 
| 128 | 
            +
                            globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
         | 
| 129 | 
            +
                            break;
         | 
| 130 | 
            +
                        case 'autoMarkRead':
         | 
| 131 | 
            +
                            globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
         | 
| 132 | 
            +
                            break;
         | 
| 133 | 
            +
                        case 'listenTyping':
         | 
| 134 | 
            +
                            globalOptions.listenTyping = Boolean(options.listenTyping);
         | 
| 135 | 
            +
                            break;
         | 
| 136 | 
            +
                        case 'proxy':
         | 
| 137 | 
            +
                            if (typeof options.proxy != "string") {
         | 
| 138 | 
            +
                                delete globalOptions.proxy;
         | 
| 139 | 
            +
                                utils.setProxy();
         | 
| 140 | 
            +
                            } else {
         | 
| 141 | 
            +
                                globalOptions.proxy = options.proxy;
         | 
| 142 | 
            +
                                utils.setProxy(globalOptions.proxy);
         | 
| 143 | 
            +
                            }
         | 
| 144 | 
            +
                            break;
         | 
| 145 | 
            +
                        case 'autoReconnect':
         | 
| 146 | 
            +
                            globalOptions.autoReconnect = Boolean(options.autoReconnect);
         | 
| 147 | 
            +
                            break;
         | 
| 148 | 
            +
                        case 'emitReady':
         | 
| 149 | 
            +
                            globalOptions.emitReady = Boolean(options.emitReady);
         | 
| 150 | 
            +
                            break;
         | 
| 151 | 
            +
                        default:
         | 
| 152 | 
            +
                            log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
         | 
| 153 | 
            +
                            break;
         | 
| 60 154 | 
             
                    }
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  case 'autoReconnect':
         | 
| 63 | 
            -
                    globalOptions.autoReconnect = Boolean(options.autoReconnect);
         | 
| 64 | 
            -
                    break;
         | 
| 65 | 
            -
                  case 'emitReady':
         | 
| 66 | 
            -
                    globalOptions.emitReady = Boolean(options.emitReady);
         | 
| 67 | 
            -
                    break;
         | 
| 68 | 
            -
                  default:
         | 
| 69 | 
            -
                    log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
         | 
| 70 | 
            -
                    break;
         | 
| 71 | 
            -
                }
         | 
| 72 | 
            -
              });
         | 
| 155 | 
            +
                });
         | 
| 73 156 | 
             
            }
         | 
| 74 157 |  | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
                 | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
                clearInterval(checkVerified);
         | 
| 93 | 
            -
              } catch (_) { }
         | 
| 94 | 
            -
             | 
| 95 | 
            -
              var clientID = (Math.random() * 2147483648 | 0).toString(16);
         | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
              let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
         | 
| 99 | 
            -
              let mqttEndpoint = null;
         | 
| 100 | 
            -
              let region = null;
         | 
| 101 | 
            -
              let irisSeqID = null;
         | 
| 102 | 
            -
              var noMqttData = null;
         | 
| 103 | 
            -
             | 
| 104 | 
            -
              if (oldFBMQTTMatch) {
         | 
| 105 | 
            -
                irisSeqID = oldFBMQTTMatch[1];
         | 
| 106 | 
            -
                mqttEndpoint = oldFBMQTTMatch[2];
         | 
| 107 | 
            -
                region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
         | 
| 108 | 
            -
                log.info("login", `Got this account's message region: ${region}`);
         | 
| 109 | 
            -
              } else {
         | 
| 110 | 
            -
                let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
         | 
| 111 | 
            -
                if (newFBMQTTMatch) {
         | 
| 112 | 
            -
                  irisSeqID = newFBMQTTMatch[2];
         | 
| 113 | 
            -
                  mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
         | 
| 114 | 
            -
                  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
         | 
| 115 | 
            -
                  log.info("login", `Got this account's message region: ${region}`);
         | 
| 116 | 
            -
                } else {
         | 
| 117 | 
            -
                  let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
         | 
| 118 | 
            -
                  if (legacyFBMQTTMatch) {
         | 
| 119 | 
            -
                    mqttEndpoint = legacyFBMQTTMatch[4];
         | 
| 120 | 
            -
                    region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
         | 
| 121 | 
            -
                    log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
         | 
| 122 | 
            -
                    log.info("login", `Got this account's message region: ${region}`);
         | 
| 123 | 
            -
                    log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
         | 
| 124 | 
            -
                  } else {
         | 
| 125 | 
            -
                    log.warn("login", "Cannot get MQTT region & sequence ID.");
         | 
| 126 | 
            -
                    noMqttData = html;
         | 
| 127 | 
            -
                  }
         | 
| 158 | 
            +
            /!-[ Function BuildAPI ]-!/
         | 
| 159 | 
            +
             | 
| 160 | 
            +
            async function buildAPI(globalOptions, html, jar) {
         | 
| 161 | 
            +
                var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) { return val.cookieString().split("=")[0] === "c_user"; });
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                if (maybeCookie.length === 0) throw { error: Language.ErrAppState };
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", Language.CheckPointLevelI);
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                var userID = maybeCookie[0].cookieString().split("=")[1].toString();
         | 
| 168 | 
            +
                logger(getText.gettext(Language.UID, userID), "[ FCA-SUS ]");
         | 
| 169 | 
            +
                process.env['UID'] = userID;
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                try {
         | 
| 172 | 
            +
                    clearInterval(checkVerified);
         | 
| 173 | 
            +
                } catch (e) {
         | 
| 174 | 
            +
                    console.log(e);
         | 
| 128 175 | 
             
                }
         | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
                 | 
| 134 | 
            -
                 | 
| 135 | 
            -
                 | 
| 136 | 
            -
                 | 
| 137 | 
            -
             | 
| 138 | 
            -
                 | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
                 | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 176 | 
            +
             | 
| 177 | 
            +
                var clientID = (Math.random() * 2147483648 | 0).toString(16);
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                let oldFBMQTTMatch = html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/);
         | 
| 180 | 
            +
                let mqttEndpoint = null;
         | 
| 181 | 
            +
                let region = null;
         | 
| 182 | 
            +
                let irisSeqID = null;
         | 
| 183 | 
            +
                var noMqttData = null;
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                if (oldFBMQTTMatch) {
         | 
| 186 | 
            +
                    irisSeqID = oldFBMQTTMatch[1];
         | 
| 187 | 
            +
                    mqttEndpoint = oldFBMQTTMatch[2];
         | 
| 188 | 
            +
                    region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
         | 
| 189 | 
            +
                    logger(getText.gettext(Language.Area, region), "[ FCA-SUS ]");
         | 
| 190 | 
            +
                } else {
         | 
| 191 | 
            +
                    let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
         | 
| 192 | 
            +
                    if (newFBMQTTMatch) {
         | 
| 193 | 
            +
                        irisSeqID = newFBMQTTMatch[2];
         | 
| 194 | 
            +
                        mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
         | 
| 195 | 
            +
                        region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
         | 
| 196 | 
            +
                        logger(getText.gettext(Language.Area, region), "[ FCA-SUS ]");
         | 
| 197 | 
            +
                    } else {
         | 
| 198 | 
            +
                        let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
         | 
| 199 | 
            +
                        if (legacyFBMQTTMatch) {
         | 
| 200 | 
            +
                            mqttEndpoint = legacyFBMQTTMatch[4];
         | 
| 201 | 
            +
                            region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
         | 
| 202 | 
            +
                            log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
         | 
| 203 | 
            +
                            logger(getText.gettext(Language.Area, region), "[ FCA-SUS ]");
         | 
| 204 | 
            +
                            logger("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
         | 
| 205 | 
            +
                        } else {
         | 
| 206 | 
            +
                            log.warn("login", getText.gettext(Language.NoAreaData));
         | 
| 207 | 
            +
                            noMqttData = html;
         | 
| 208 | 
            +
                        }
         | 
| 209 | 
            +
                    }
         | 
| 152 210 | 
             
                }
         | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
                 | 
| 169 | 
            -
             | 
| 170 | 
            -
                 | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
             | 
| 175 | 
            -
                 | 
| 176 | 
            -
             | 
| 177 | 
            -
                 | 
| 178 | 
            -
             | 
| 179 | 
            -
                ' | 
| 180 | 
            -
             | 
| 181 | 
            -
                 | 
| 182 | 
            -
             | 
| 183 | 
            -
                 | 
| 184 | 
            -
                ' | 
| 185 | 
            -
                 | 
| 186 | 
            -
                'logout',
         | 
| 187 | 
            -
                'markAsDelivered',
         | 
| 188 | 
            -
                'markAsRead',
         | 
| 189 | 
            -
                'markAsReadAll',
         | 
| 190 | 
            -
                'markAsSeen',
         | 
| 191 | 
            -
                'muteThread',
         | 
| 192 | 
            -
                'removeUserFromGroup',
         | 
| 193 | 
            -
                'resolvePhotoUrl',
         | 
| 194 | 
            -
                'searchForThread',
         | 
| 195 | 
            -
                'sendMessage',
         | 
| 196 | 
            -
                'sendTypingIndicator',
         | 
| 197 | 
            -
                'setMessageReaction',
         | 
| 198 | 
            -
                'setTitle',
         | 
| 199 | 
            -
                'threadColors',
         | 
| 200 | 
            -
                'unsendMessage',
         | 
| 201 | 
            -
             | 
| 202 | 
            -
                // HTTP
         | 
| 203 | 
            -
                'httpGet',
         | 
| 204 | 
            -
                'httpPost',
         | 
| 205 | 
            -
             | 
| 206 | 
            -
                // Deprecated features
         | 
| 207 | 
            -
                "getThreadListDeprecated",
         | 
| 208 | 
            -
                'getThreadHistoryDeprecated',
         | 
| 209 | 
            -
                'getThreadInfoDeprecated',
         | 
| 210 | 
            -
              ];
         | 
| 211 | 
            -
             | 
| 212 | 
            -
              var defaultFuncs = utils.makeDefaults(html, userID, ctx);
         | 
| 213 | 
            -
             | 
| 214 | 
            -
              // Load all api functions in a loop
         | 
| 215 | 
            -
              apiFuncNames.map(function (v) {
         | 
| 216 | 
            -
                api[v] = require('./src/' + v)(defaultFuncs, api, ctx);
         | 
| 217 | 
            -
              });
         | 
| 218 | 
            -
             | 
| 219 | 
            -
              //Removing original `listen` that uses pull.
         | 
| 220 | 
            -
              //Map it to listenMqtt instead for backward compatibly.
         | 
| 221 | 
            -
              api.listen = api.listenMqtt;
         | 
| 222 | 
            -
             | 
| 223 | 
            -
              return [ctx, defaultFuncs, api];
         | 
| 211 | 
            +
             | 
| 212 | 
            +
                var ctx = {
         | 
| 213 | 
            +
                    userID: userID,
         | 
| 214 | 
            +
                    jar: jar,
         | 
| 215 | 
            +
                    clientID: clientID,
         | 
| 216 | 
            +
                    globalOptions: globalOptions,
         | 
| 217 | 
            +
                    loggedIn: true,
         | 
| 218 | 
            +
                    access_token: 'none',
         | 
| 219 | 
            +
                    clientMutationId: 0,
         | 
| 220 | 
            +
                    mqttClient: undefined,
         | 
| 221 | 
            +
                    lastSeqId: irisSeqID,
         | 
| 222 | 
            +
                    syncToken: undefined,
         | 
| 223 | 
            +
                    mqttEndpoint,
         | 
| 224 | 
            +
                    region,
         | 
| 225 | 
            +
                    firstListen: true
         | 
| 226 | 
            +
                };
         | 
| 227 | 
            +
             | 
| 228 | 
            +
                var api = {
         | 
| 229 | 
            +
                    setOptions: setOptions.bind(null, globalOptions),
         | 
| 230 | 
            +
                    getAppState: function getAppState() {
         | 
| 231 | 
            +
                        return utils.getAppState(jar);
         | 
| 232 | 
            +
                    }
         | 
| 233 | 
            +
                };
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                if (noMqttData) api["htmlData"] = noMqttData;
         | 
| 236 | 
            +
             | 
| 237 | 
            +
                const apiFuncNames = fs.readdirSync(__dirname + "/src").filter((File) => File.endsWith(".js") && !File.includes('Dev'));
         | 
| 238 | 
            +
             | 
| 239 | 
            +
                var defaultFuncs = utils.makeDefaults(html, userID, ctx);
         | 
| 240 | 
            +
             | 
| 241 | 
            +
                // Load all api functions in a loop
         | 
| 242 | 
            +
                apiFuncNames.map(v => api[v.replace(".js", "")] = require('./src/' + v)(defaultFuncs, api, ctx));
         | 
| 243 | 
            +
                return [ctx, defaultFuncs, api];
         | 
| 224 244 | 
             
            }
         | 
| 225 245 |  | 
| 226 246 | 
             
            function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
         | 
| 227 | 
            -
             | 
| 228 | 
            -
             | 
| 229 | 
            -
             | 
| 230 | 
            -
             | 
| 231 | 
            -
             | 
| 232 | 
            -
                // This will be empty, but just to be sure we leave it
         | 
| 233 | 
            -
                $("#login_form input").map(function (i, v) {
         | 
| 234 | 
            -
                  arr.push({ val: $(v).val(), name: $(v).attr("name") });
         | 
| 235 | 
            -
                });
         | 
| 247 | 
            +
                return function(res) {
         | 
| 248 | 
            +
                    var html = res.body;
         | 
| 249 | 
            +
                    var $ = cheerio.load(html);
         | 
| 250 | 
            +
                    var arr = [];
         | 
| 236 251 |  | 
| 237 | 
            -
             | 
| 238 | 
            -
             | 
| 239 | 
            -
                });
         | 
| 252 | 
            +
                    // This will be empty, but just to be sure we leave it
         | 
| 253 | 
            +
                    $("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
         | 
| 240 254 |  | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 244 | 
            -
                form.email = email;
         | 
| 245 | 
            -
                form.pass = password;
         | 
| 246 | 
            -
                form.default_persistent = '0';
         | 
| 247 | 
            -
                form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
         | 
| 248 | 
            -
                form.locale = 'en_US';
         | 
| 249 | 
            -
                form.timezone = '240';
         | 
| 250 | 
            -
                form.lgnjs = ~~(Date.now() / 1000);
         | 
| 251 | 
            -
             | 
| 252 | 
            -
             | 
| 253 | 
            -
                // Getting cookies from the HTML page... (kill me now plz)
         | 
| 254 | 
            -
                // we used to get a bunch of cookies in the headers of the response of the
         | 
| 255 | 
            -
                // request, but FB changed and they now send those cookies inside the JS.
         | 
| 256 | 
            -
                // They run the JS which then injects the cookies in the page.
         | 
| 257 | 
            -
                // The "solution" is to parse through the html and find those cookies
         | 
| 258 | 
            -
                // which happen to be conveniently indicated with a _js_ in front of their
         | 
| 259 | 
            -
                // variable name.
         | 
| 260 | 
            -
                //
         | 
| 261 | 
            -
                // ---------- Very Hacky Part Starts -----------------
         | 
| 262 | 
            -
                var willBeCookies = html.split("\"_js_");
         | 
| 263 | 
            -
                willBeCookies.slice(1).map(function (val) {
         | 
| 264 | 
            -
                  var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
         | 
| 265 | 
            -
                  jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
         | 
| 266 | 
            -
                });
         | 
| 267 | 
            -
                // ---------- Very Hacky Part Ends -----------------
         | 
| 268 | 
            -
             | 
| 269 | 
            -
                log.info("login", "Logging in...");
         | 
| 270 | 
            -
                return utils
         | 
| 271 | 
            -
                  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
         | 
| 272 | 
            -
                  .then(utils.saveCookies(jar))
         | 
| 273 | 
            -
                  .then(function (res) {
         | 
| 274 | 
            -
                    var headers = res.headers;
         | 
| 275 | 
            -
                    if (!headers.location) {
         | 
| 276 | 
            -
                      throw { error: "Wrong username/password." };
         | 
| 277 | 
            -
                    }
         | 
| 255 | 
            +
                    arr = arr.filter(function(v) {
         | 
| 256 | 
            +
                        return v.val && v.val.length;
         | 
| 257 | 
            +
                    });
         | 
| 278 258 |  | 
| 279 | 
            -
                     | 
| 280 | 
            -
                     | 
| 281 | 
            -
             | 
| 282 | 
            -
             | 
| 259 | 
            +
                    var form = utils.arrToForm(arr);
         | 
| 260 | 
            +
                    form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
         | 
| 261 | 
            +
                    form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
         | 
| 262 | 
            +
                    form.email = email;
         | 
| 263 | 
            +
                    form.pass = password;
         | 
| 264 | 
            +
                    form.default_persistent = '0';
         | 
| 265 | 
            +
                    form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
         | 
| 266 | 
            +
                    form.locale = 'en_US';
         | 
| 267 | 
            +
                    form.timezone = '240';
         | 
| 268 | 
            +
                    form.lgnjs = ~~(Date.now() / 1000);
         | 
| 283 269 |  | 
| 284 | 
            -
             | 
| 285 | 
            -
             | 
| 270 | 
            +
             | 
| 271 | 
            +
                    // Getting cookies from the HTML page... (kill me now plz)
         | 
| 272 | 
            +
                    // we used to get a bunch of cookies in the headers of the response of the
         | 
| 273 | 
            +
                    // request, but FB changed and they now send those cookies inside the JS.
         | 
| 274 | 
            +
                    // They run the JS which then injects the cookies in the page.
         | 
| 275 | 
            +
                    // The "solution" is to parse through the html and find those cookies
         | 
| 276 | 
            +
                    // which happen to be conveniently indicated with a _js_ in front of their
         | 
| 277 | 
            +
                    // variable name.
         | 
| 278 | 
            +
                    //
         | 
| 279 | 
            +
                    // ---------- Very Hacky Part Starts -----------------
         | 
| 280 | 
            +
                    var willBeCookies = html.split("\"_js_");
         | 
| 281 | 
            +
                    willBeCookies.slice(1).map(function(val) {
         | 
| 282 | 
            +
                        var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
         | 
| 283 | 
            +
                        jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
         | 
| 284 | 
            +
                    });
         | 
| 285 | 
            +
                    // ---------- Very Hacky Part Ends -----------------
         | 
| 286 | 
            +
             | 
| 287 | 
            +
                    logger(Language.OnLogin, "[ FCA-SUS ]");
         | 
| 288 | 
            +
                    return utils
         | 
| 289 | 
            +
                        .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
         | 
| 286 290 | 
             
                        .then(utils.saveCookies(jar))
         | 
| 287 | 
            -
                        .then(function | 
| 288 | 
            -
             | 
| 289 | 
            -
             | 
| 290 | 
            -
             | 
| 291 | 
            -
             | 
| 292 | 
            -
             | 
| 293 | 
            -
             | 
| 294 | 
            -
             | 
| 295 | 
            -
             | 
| 296 | 
            -
             | 
| 297 | 
            -
             | 
| 298 | 
            -
                          });
         | 
| 299 | 
            -
             | 
| 300 | 
            -
                          var form = utils.arrToForm(arr);
         | 
| 301 | 
            -
                          if (html.indexOf("checkpoint/?next") > -1) {
         | 
| 302 | 
            -
                            setTimeout(() => {
         | 
| 303 | 
            -
                              checkVerified = setInterval((_form) => {
         | 
| 304 | 
            -
                                /* utils
         | 
| 305 | 
            -
                                  .post("https://www.facebook.com/login/approvals/approved_machine_check/", jar, form, loginOptions, null, {
         | 
| 306 | 
            -
                                    "Referer": "https://www.facebook.com/checkpoint/?next"
         | 
| 307 | 
            -
                                  })
         | 
| 308 | 
            -
                                  .then(utils.saveCookies(jar))
         | 
| 309 | 
            -
                                  .then(res => {
         | 
| 310 | 
            -
                                    try {
         | 
| 311 | 
            -
                                      JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
         | 
| 312 | 
            -
                                    } catch (ex) {
         | 
| 313 | 
            -
                                      clearInterval(checkVerified);
         | 
| 314 | 
            -
                                      log.info("login", "Verified from browser. Logging in...");
         | 
| 315 | 
            -
                                      return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
         | 
| 316 | 
            -
                                    }
         | 
| 317 | 
            -
                                  })
         | 
| 318 | 
            -
                                  .catch(ex => {
         | 
| 319 | 
            -
                                    log.error("login", ex);
         | 
| 320 | 
            -
                                  }); */
         | 
| 321 | 
            -
                              }, 5000, {
         | 
| 322 | 
            -
                                fb_dtsg: form.fb_dtsg,
         | 
| 323 | 
            -
                                jazoest: form.jazoest,
         | 
| 324 | 
            -
                                dpr: 1
         | 
| 325 | 
            -
                              });
         | 
| 326 | 
            -
                            }, 2500);
         | 
| 327 | 
            -
                            throw {
         | 
| 328 | 
            -
                              error: 'login-approval',
         | 
| 329 | 
            -
                              continue: function submit2FA(code) {
         | 
| 330 | 
            -
                                form.approvals_code = code;
         | 
| 331 | 
            -
                                form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
         | 
| 332 | 
            -
                                var prResolve = null;
         | 
| 333 | 
            -
                                var prReject = null;
         | 
| 334 | 
            -
                                var rtPromise = new Promise(function (resolve, reject) {
         | 
| 335 | 
            -
                                  prResolve = resolve;
         | 
| 336 | 
            -
                                  prReject = reject;
         | 
| 337 | 
            -
                                });
         | 
| 338 | 
            -
                                if (typeof code == "string") {
         | 
| 339 | 
            -
                                  utils
         | 
| 340 | 
            -
                                    .post(nextURL, jar, form, loginOptions)
         | 
| 341 | 
            -
                                    .then(utils.saveCookies(jar))
         | 
| 342 | 
            -
                                    .then(function (res) {
         | 
| 343 | 
            -
                                      var $ = cheerio.load(res.body);
         | 
| 344 | 
            -
                                      var error = $("#approvals_code").parent().attr("data-xui-error");
         | 
| 345 | 
            -
                                      if (error) {
         | 
| 346 | 
            -
                                        throw {
         | 
| 347 | 
            -
                                          error: 'login-approval',
         | 
| 348 | 
            -
                                          errordesc: "Invalid 2FA code.",
         | 
| 349 | 
            -
                                          lerror: error,
         | 
| 350 | 
            -
                                          continue: submit2FA
         | 
| 351 | 
            -
                                        };
         | 
| 352 | 
            -
                                      }
         | 
| 353 | 
            -
                                    })
         | 
| 354 | 
            -
                                    .then(function () {
         | 
| 355 | 
            -
                                      // Use the same form (safe I hope)
         | 
| 356 | 
            -
                                      delete form.no_fido;
         | 
| 357 | 
            -
                                      delete form.approvals_code;
         | 
| 358 | 
            -
                                      form.name_action_selected = 'dont_save'; //'save_device';
         | 
| 359 | 
            -
             | 
| 360 | 
            -
                                      return utils
         | 
| 361 | 
            -
                                        .post(nextURL, jar, form, loginOptions)
         | 
| 362 | 
            -
                                        .then(utils.saveCookies(jar));
         | 
| 363 | 
            -
                                    })
         | 
| 364 | 
            -
                                    .then(function (res) {
         | 
| 365 | 
            -
                                      var headers = res.headers;
         | 
| 366 | 
            -
                                      if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
         | 
| 367 | 
            -
                                        throw { error: "Something went wrong with login approvals." };
         | 
| 368 | 
            -
                                      }
         | 
| 369 | 
            -
             | 
| 370 | 
            -
                                      var appState = utils.getAppState(jar);
         | 
| 371 | 
            -
             | 
| 372 | 
            -
                                      if (callback === prCallback) {
         | 
| 373 | 
            -
                                        callback = function (err, api) {
         | 
| 374 | 
            -
                                          if (err) {
         | 
| 375 | 
            -
                                            return prReject(err);
         | 
| 376 | 
            -
                                          }
         | 
| 377 | 
            -
                                          return prResolve(api);
         | 
| 378 | 
            -
                                        };
         | 
| 379 | 
            -
                                      }
         | 
| 380 | 
            -
             | 
| 381 | 
            -
                                      // Simply call loginHelper because all it needs is the jar
         | 
| 382 | 
            -
                                      // and will then complete the login process
         | 
| 383 | 
            -
                                      return loginHelper(appState, email, password, loginOptions, callback);
         | 
| 384 | 
            -
                                    })
         | 
| 385 | 
            -
                                    .catch(function (err) {
         | 
| 386 | 
            -
                                      // Check if using Promise instead of callback
         | 
| 387 | 
            -
                                      if (callback === prCallback) {
         | 
| 388 | 
            -
                                        prReject(err);
         | 
| 389 | 
            -
                                      } else {
         | 
| 390 | 
            -
                                        callback(err);
         | 
| 391 | 
            -
                                      }
         | 
| 392 | 
            -
                                    });
         | 
| 393 | 
            -
                                } else {
         | 
| 394 | 
            -
                                  utils
         | 
| 395 | 
            -
                                    .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, {
         | 
| 396 | 
            -
                                      "Referer": "https://www.facebook.com/checkpoint/?next"
         | 
| 397 | 
            -
                                    })
         | 
| 291 | 
            +
                        .then(function(res) {
         | 
| 292 | 
            +
                            var headers = res.headers;
         | 
| 293 | 
            +
                            if (!headers.location) throw { error: Language.InvaildAccount };
         | 
| 294 | 
            +
             | 
| 295 | 
            +
                            // This means the account has login approvals turned on.
         | 
| 296 | 
            +
                            if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
         | 
| 297 | 
            +
                                logger(Language.TwoAuth, "[ FCA-SUS ]");
         | 
| 298 | 
            +
                                var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
         | 
| 299 | 
            +
             | 
| 300 | 
            +
                                return utils
         | 
| 301 | 
            +
                                    .get(headers.location, jar, null, loginOptions)
         | 
| 398 302 | 
             
                                    .then(utils.saveCookies(jar))
         | 
| 399 | 
            -
                                    .then(res  | 
| 400 | 
            -
             | 
| 401 | 
            -
                                         | 
| 402 | 
            -
             | 
| 403 | 
            -
                                         | 
| 404 | 
            -
                                         | 
| 405 | 
            -
             | 
| 406 | 
            -
             | 
| 407 | 
            -
                                             | 
| 408 | 
            -
             | 
| 409 | 
            -
             | 
| 410 | 
            -
             | 
| 411 | 
            -
             | 
| 303 | 
            +
                                    .then(function(res) {
         | 
| 304 | 
            +
                                        var html = res.body;
         | 
| 305 | 
            +
                                        // Make the form in advance which will contain the fb_dtsg and nh
         | 
| 306 | 
            +
                                        var $ = cheerio.load(html);
         | 
| 307 | 
            +
                                        var arr = [];
         | 
| 308 | 
            +
                                        $("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
         | 
| 309 | 
            +
             | 
| 310 | 
            +
                                        arr = arr.filter(function(v) {
         | 
| 311 | 
            +
                                            return v.val && v.val.length;
         | 
| 312 | 
            +
                                        });
         | 
| 313 | 
            +
             | 
| 314 | 
            +
                                        var form = utils.arrToForm(arr);
         | 
| 315 | 
            +
                                        if (html.indexOf("checkpoint/?next") > -1) {
         | 
| 316 | 
            +
                                            setTimeout(() => {
         | 
| 317 | 
            +
                                                checkVerified = setInterval((_form) => {}, 5000, {
         | 
| 318 | 
            +
                                                    fb_dtsg: form.fb_dtsg,
         | 
| 319 | 
            +
                                                    jazoest: form.jazoest,
         | 
| 320 | 
            +
                                                    dpr: 1
         | 
| 321 | 
            +
                                                });
         | 
| 322 | 
            +
                                            }, 2500);
         | 
| 323 | 
            +
                                            throw {
         | 
| 324 | 
            +
                                                error: 'login-approval',
         | 
| 325 | 
            +
                                                continue: function submit2FA(code) {
         | 
| 326 | 
            +
                                                    form.approvals_code = code;
         | 
| 327 | 
            +
                                                    form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
         | 
| 328 | 
            +
                                                    var prResolve = null;
         | 
| 329 | 
            +
                                                    var prReject = null;
         | 
| 330 | 
            +
                                                    var rtPromise = new Promise(function(resolve, reject) {
         | 
| 331 | 
            +
                                                        prResolve = resolve;
         | 
| 332 | 
            +
                                                        prReject = reject;
         | 
| 333 | 
            +
                                                    });
         | 
| 334 | 
            +
                                                    if (typeof code == "string") {
         | 
| 335 | 
            +
                                                        utils
         | 
| 336 | 
            +
                                                            .post(nextURL, jar, form, loginOptions)
         | 
| 337 | 
            +
                                                            .then(utils.saveCookies(jar))
         | 
| 338 | 
            +
                                                            .then(function(res) {
         | 
| 339 | 
            +
                                                                var $ = cheerio.load(res.body);
         | 
| 340 | 
            +
                                                                var error = $("#approvals_code").parent().attr("data-xui-error");
         | 
| 341 | 
            +
                                                                if (error) {
         | 
| 342 | 
            +
                                                                    throw {
         | 
| 343 | 
            +
                                                                        error: 'login-approval',
         | 
| 344 | 
            +
                                                                        errordesc: Language.InvaildTwoAuthCode,
         | 
| 345 | 
            +
                                                                        lerror: error,
         | 
| 346 | 
            +
                                                                        continue: submit2FA
         | 
| 347 | 
            +
                                                                    };
         | 
| 348 | 
            +
                                                                }
         | 
| 349 | 
            +
                                                            })
         | 
| 350 | 
            +
                                                            .then(function() {
         | 
| 351 | 
            +
                                                                // Use the same form (safe I hope)
         | 
| 352 | 
            +
                                                                delete form.no_fido;
         | 
| 353 | 
            +
                                                                delete form.approvals_code;
         | 
| 354 | 
            +
                                                                form.name_action_selected = 'save_device'; //'save_device' || 'dont_save;
         | 
| 355 | 
            +
             | 
| 356 | 
            +
                                                                return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
         | 
| 357 | 
            +
                                                            })
         | 
| 358 | 
            +
                                                            .then(function(res) {
         | 
| 359 | 
            +
                                                                var headers = res.headers;
         | 
| 360 | 
            +
                                                                if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: Language.ApprovalsErr };
         | 
| 361 | 
            +
             | 
| 362 | 
            +
                                                                var appState = utils.getAppState(jar);
         | 
| 363 | 
            +
             | 
| 364 | 
            +
                                                                if (callback === prCallback) {
         | 
| 365 | 
            +
                                                                    callback = function(err, api) {
         | 
| 366 | 
            +
                                                                        if (err) return prReject(err);
         | 
| 367 | 
            +
                                                                        return prResolve(api);
         | 
| 368 | 
            +
                                                                    };
         | 
| 369 | 
            +
                                                                }
         | 
| 370 | 
            +
             | 
| 371 | 
            +
                                                                // Simply call loginHelper because all it needs is the jar
         | 
| 372 | 
            +
                                                                // and will then complete the login process
         | 
| 373 | 
            +
                                                                return loginHelper(appState, email, password, loginOptions, callback);
         | 
| 374 | 
            +
                                                            })
         | 
| 375 | 
            +
                                                            .catch(function(err) {
         | 
| 376 | 
            +
                                                                // Check if using Promise instead of callback
         | 
| 377 | 
            +
                                                                if (callback === prCallback) prReject(err);
         | 
| 378 | 
            +
                                                                else callback(err);
         | 
| 379 | 
            +
                                                            });
         | 
| 380 | 
            +
                                                    } else {
         | 
| 381 | 
            +
                                                        utils
         | 
| 382 | 
            +
                                                            .post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions, null, { "Referer": "https://www.facebook.com/checkpoint/?next" })
         | 
| 383 | 
            +
                                                            .then(utils.saveCookies(jar))
         | 
| 384 | 
            +
                                                            .then(res => {
         | 
| 385 | 
            +
                                                                try {
         | 
| 386 | 
            +
                                                                    JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
         | 
| 387 | 
            +
                                                                } catch (ex) {
         | 
| 388 | 
            +
                                                                    clearInterval(checkVerified);
         | 
| 389 | 
            +
                                                                    logger(Language.VerifiedCheck, "[ FCA-SUS ]");
         | 
| 390 | 
            +
                                                                    if (callback === prCallback) {
         | 
| 391 | 
            +
                                                                        callback = function(err, api) {
         | 
| 392 | 
            +
                                                                            if (err) return prReject(err);
         | 
| 393 | 
            +
                                                                            return prResolve(api);
         | 
| 394 | 
            +
                                                                        };
         | 
| 395 | 
            +
                                                                    }
         | 
| 396 | 
            +
                                                                    return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
         | 
| 397 | 
            +
                                                                }
         | 
| 398 | 
            +
                                                            })
         | 
| 399 | 
            +
                                                            .catch(ex => {
         | 
| 400 | 
            +
                                                                log.error("login", ex);
         | 
| 401 | 
            +
                                                                if (callback === prCallback) prReject(ex);
         | 
| 402 | 
            +
                                                                else callback(ex);
         | 
| 403 | 
            +
                                                            });
         | 
| 404 | 
            +
                                                    }
         | 
| 405 | 
            +
                                                    return rtPromise;
         | 
| 406 | 
            +
                                                }
         | 
| 407 | 
            +
                                            };
         | 
| 408 | 
            +
                                        } else {
         | 
| 409 | 
            +
                                            if (!loginOptions.forceLogin) throw { error: Language.ForceLoginNotEnable };
         | 
| 410 | 
            +
             | 
| 411 | 
            +
                                            if (html.indexOf("Suspicious Login Attempt") > -1) form['submit[This was me]'] = "This was me";
         | 
| 412 | 
            +
                                            else form['submit[This Is Okay]'] = "This Is Okay";
         | 
| 413 | 
            +
             | 
| 414 | 
            +
                                            return utils
         | 
| 415 | 
            +
                                                .post(nextURL, jar, form, loginOptions)
         | 
| 416 | 
            +
                                                .then(utils.saveCookies(jar))
         | 
| 417 | 
            +
                                                .then(function() {
         | 
| 418 | 
            +
                                                    // Use the same form (safe I hope)
         | 
| 419 | 
            +
                                                    form.name_action_selected = 'save_device';
         | 
| 420 | 
            +
             | 
| 421 | 
            +
                                                    return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
         | 
| 422 | 
            +
                                                })
         | 
| 423 | 
            +
                                                .then(function(res) {
         | 
| 424 | 
            +
                                                    var headers = res.headers;
         | 
| 425 | 
            +
             | 
| 426 | 
            +
                                                    if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
         | 
| 427 | 
            +
             | 
| 428 | 
            +
                                                    var appState = utils.getAppState(jar);
         | 
| 429 | 
            +
             | 
| 430 | 
            +
                                                    // Simply call loginHelper because all it needs is the jar
         | 
| 431 | 
            +
                                                    // and will then complete the login process
         | 
| 432 | 
            +
                                                    return loginHelper(appState, email, password, loginOptions, callback);
         | 
| 433 | 
            +
                                                })
         | 
| 434 | 
            +
                                                .catch(e => callback(e));
         | 
| 412 435 | 
             
                                        }
         | 
| 413 | 
            -
                                        return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
         | 
| 414 | 
            -
                                      }
         | 
| 415 | 
            -
                                    })
         | 
| 416 | 
            -
                                    .catch(ex => {
         | 
| 417 | 
            -
                                      log.error("login", ex);
         | 
| 418 | 
            -
                                      if (callback === prCallback) {
         | 
| 419 | 
            -
                                        prReject(ex);
         | 
| 420 | 
            -
                                      } else {
         | 
| 421 | 
            -
                                        callback(ex);
         | 
| 422 | 
            -
                                      }
         | 
| 423 436 | 
             
                                    });
         | 
| 424 | 
            -
                                }
         | 
| 425 | 
            -
                                return rtPromise;
         | 
| 426 | 
            -
                              }
         | 
| 427 | 
            -
                            };
         | 
| 428 | 
            -
                          } else {
         | 
| 429 | 
            -
                            if (!loginOptions.forceLogin) {
         | 
| 430 | 
            -
                              throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
         | 
| 431 | 
            -
                            }
         | 
| 432 | 
            -
                            if (html.indexOf("Suspicious Login Attempt") > -1) {
         | 
| 433 | 
            -
                              form['submit[This was me]'] = "This was me";
         | 
| 434 | 
            -
                            } else {
         | 
| 435 | 
            -
                              form['submit[This Is Okay]'] = "This Is Okay";
         | 
| 436 437 | 
             
                            }
         | 
| 437 438 |  | 
| 438 | 
            -
                            return utils
         | 
| 439 | 
            -
             | 
| 440 | 
            -
             | 
| 441 | 
            -
             | 
| 442 | 
            -
                                // Use the same form (safe I hope)
         | 
| 443 | 
            -
                                form.name_action_selected = 'save_device';
         | 
| 439 | 
            +
                            return utils.get('https://www.facebook.com/', jar, null, loginOptions).then(utils.saveCookies(jar));
         | 
| 440 | 
            +
                        });
         | 
| 441 | 
            +
                };
         | 
| 442 | 
            +
            }
         | 
| 444 443 |  | 
| 445 | 
            -
             | 
| 446 | 
            -
             | 
| 447 | 
            -
             | 
| 448 | 
            -
             | 
| 449 | 
            -
             | 
| 450 | 
            -
             | 
| 451 | 
            -
             | 
| 452 | 
            -
             | 
| 453 | 
            -
             | 
| 444 | 
            +
            function makeid(length) {
         | 
| 445 | 
            +
                var result = '';
         | 
| 446 | 
            +
                var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
         | 
| 447 | 
            +
                var charactersLength = characters.length;
         | 
| 448 | 
            +
                for (var i = 0; i < length; i++) {
         | 
| 449 | 
            +
                    result += characters.charAt(Math.floor(Math.random() * charactersLength));
         | 
| 450 | 
            +
                }
         | 
| 451 | 
            +
                return result;
         | 
| 452 | 
            +
            }
         | 
| 453 | 
            +
             | 
| 454 | 
            +
             | 
| 455 | 
            +
            // Helps the login
         | 
| 456 | 
            +
            async function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
         | 
| 457 | 
            +
                var mainPromise = null;
         | 
| 458 | 
            +
                var jar = utils.getJar();
         | 
| 459 | 
            +
             | 
| 460 | 
            +
                // If we're given an appState we loop through it and save each cookie
         | 
| 461 | 
            +
                // back into the jar.
         | 
| 462 | 
            +
                try {
         | 
| 463 | 
            +
                    if (appState) {
         | 
| 464 | 
            +
                        //const readline = require("readline");
         | 
| 465 | 
            +
                        //const chalk = require("chalk");
         | 
| 466 | 
            +
                        //const figlet = require("figlet");
         | 
| 467 | 
            +
                        //const os = require("os");
         | 
| 468 | 
            +
                        //const { execSync } = require('child_process');
         | 
| 469 | 
            +
                        // let rl = readline.createInterface({
         | 
| 470 | 
            +
                        // input: process.stdin,
         | 
| 471 | 
            +
                        // output: process.stdout,
         | 
| 472 | 
            +
                        // prompt: chalk.hex('#00CCCC').bold('[FCA-SUS] • ')
         | 
| 473 | 
            +
                        // });
         | 
| 474 | 
            +
                        // let type = {
         | 
| 475 | 
            +
                        //     1: {
         | 
| 476 | 
            +
                        //         "name": "Tạo Mật Khẩu Cho Appstate",
         | 
| 477 | 
            +
                        //          onRun: async function() {
         | 
| 478 | 
            +
                        //             try {
         | 
| 479 | 
            +
                        //                 rl.question("Hãy Nhập Mật Khẩu Bạn Muốn Đặt Cho Appstate !", (answer) => {
         | 
| 480 | 
            +
                        //                     console.log("Được Rồi Mật Khẩu Của Bạn Là: " + answer + ", Bạn Hãy Nhớ Kĩ Nhé !");
         | 
| 481 | 
            +
                        //                 process.env["FBKEY"] = answer;
         | 
| 482 | 
            +
                        //                     fs.writeFile('../.env', `FBKEY=${answer}`, function (err) {
         | 
| 483 | 
            +
                        //                         if (err) {
         | 
| 484 | 
            +
                        //                             submiterr(err)
         | 
| 485 | 
            +
                        //                             logger("Tạo File ENV Thất Bại !", "[ FCA-SUS ]")
         | 
| 486 | 
            +
                        //                             rl.pause();
         | 
| 487 | 
            +
                        //                         }
         | 
| 488 | 
            +
                        //                         else logger("Tạo Thành Công File ENV !","[ FCA-SUS ]")
         | 
| 489 | 
            +
                        //                         rl.pause();
         | 
| 490 | 
            +
                        //                     });
         | 
| 491 | 
            +
                        //                 })
         | 
| 492 | 
            +
                        //             }
         | 
| 493 | 
            +
                        //             catch (e) {
         | 
| 494 | 
            +
                        //                 console.log(e);
         | 
| 495 | 
            +
                        //                 logger("Đã Có Lỗi Khi Đang Try Tạo Ra Câu Hỏi =))", "[ FCA-SUS ]");
         | 
| 496 | 
            +
                        //                 rl.pause();
         | 
| 497 | 
            +
                        //             }
         | 
| 498 | 
            +
                        //         }
         | 
| 499 | 
            +
                        //     },
         | 
| 500 | 
            +
                        //     2: {
         | 
| 501 | 
            +
                        //         "name": "Tiếp Tục Chạy Fca Mà Không Cần Mã Hóa AppState",
         | 
| 502 | 
            +
                        //          onRun: async function () {
         | 
| 503 | 
            +
                        //             rl.pause();
         | 
| 504 | 
            +
                        //         }
         | 
| 505 | 
            +
                        //     },
         | 
| 506 | 
            +
                        //     3: {
         | 
| 507 | 
            +
                        //         "name": "Đổi Mật Khẩu AppState (Comming Soon..)",
         | 
| 508 | 
            +
                        //         onRun: async function () {
         | 
| 509 | 
            +
                        //             console.log(chalk.red.bold("Đã bảo là comming soon rồi mà >:v"));
         | 
| 510 | 
            +
                        //         }
         | 
| 511 | 
            +
                        //     }
         | 
| 512 | 
            +
                        // }
         | 
| 513 | 
            +
                        // const localbrand = JSON.parse(readFileSync('./package.json')).name;
         | 
| 514 | 
            +
                        // const localbrand2 = JSON.parse(readFileSync('./node_modules/fca-sus/package.json')).version;
         | 
| 515 | 
            +
                        // var axios = require('axios');
         | 
| 516 | 
            +
                        //     axios.get('https://raw.githubusercontent.com/amogusdevlol/fca-sus/main/package.json').then(async (res) => {
         | 
| 517 | 
            +
                        //         if (localbrand.toUpperCase() == 'HORIZON') {
         | 
| 518 | 
            +
                        //             console.group(chalk.bold.cyan('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'))
         | 
| 519 | 
            +
                        //                 console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Hệ Điều Hành: " + chalk.bold.red(os.type()));
         | 
| 520 | 
            +
                        //                 console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Thông Tin Máy: " + chalk.bold.red(os.version()));
         | 
| 521 | 
            +
                        //                 console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ') + "Phiên Bản Hiện Tại: " + chalk.bold.red(localbrand2));
         | 
| 522 | 
            +
                        //                 console.log(chalk.bold.hex('#00FFCC')("[</>]") + chalk.bold.yellow(' => ')  + "Phiên Bản Mới Nhất: " + chalk.bold.red(res.data.version));
         | 
| 523 | 
            +
                        //             console.groupEnd();
         | 
| 524 | 
            +
                        //         }
         | 
| 525 | 
            +
                        //     else {
         | 
| 526 | 
            +
                        //         console.clear();
         | 
| 527 | 
            +
                        //         console.log(figlet.textSync('TeamHorizon', {font: 'ANSI Shadow',horizontalLayout: 'default',verticalLayout: 'default',width: 0,whitespaceBreak: true }))
         | 
| 528 | 
            +
                        //         console.log(chalk.hex('#9966CC')(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`));
         | 
| 529 | 
            +
                        //     }
         | 
| 530 | 
            +
                        // });
         | 
| 531 | 
            +
             | 
| 532 | 
            +
                        logger(Language.OnProcess, "[ FCA-SUS ]");
         | 
| 533 | 
            +
                        var backup = async(data) => {
         | 
| 534 | 
            +
                            if (fs.existsSync('./appstate.json')) {
         | 
| 535 | 
            +
                                try {
         | 
| 536 | 
            +
                                    fs.writeFileSync('./appstate.json', data);
         | 
| 537 | 
            +
                                } catch (e) {
         | 
| 538 | 
            +
                                    fs.writeFileSync('./appstate.json', JSON.stringify(data, null, "\t"));
         | 
| 539 | 
            +
                                }
         | 
| 540 | 
            +
                                logger(Language.BackupNoti, "[ FCA-SUS ]");
         | 
| 541 | 
            +
                                await new Promise(resolve => setTimeout(resolve, 5 * 1000));
         | 
| 542 | 
            +
                                process.exit(1);
         | 
| 543 | 
            +
                            } else if (fs.existsSync('./Facebook.json')) {
         | 
| 544 | 
            +
                                try {
         | 
| 545 | 
            +
                                    fs.writeFileSync('./Facebook.json', data);
         | 
| 546 | 
            +
                                } catch (e) {
         | 
| 547 | 
            +
                                    fs.writeFileSync('./Facebook.json', JSON.stringify(data, null, "\t"));
         | 
| 548 | 
            +
                                }
         | 
| 549 | 
            +
                                logger(Language.BackupNoti, "[ FCA-SUS ]");
         | 
| 550 | 
            +
                                await new Promise(resolve => setTimeout(resolve, 5 * 1000));
         | 
| 551 | 
            +
                                process.exit(1);
         | 
| 552 | 
            +
                            } else if (fs.existsSync('fbstate.json')) {
         | 
| 553 | 
            +
                                try {
         | 
| 554 | 
            +
                                    fs.writeFileSync('./fbstate.json', data);
         | 
| 555 | 
            +
                                } catch (e) {
         | 
| 556 | 
            +
                                    fs.writeFileSync('./fbstate.json', JSON.stringify(data), null, "\t");
         | 
| 454 557 | 
             
                                }
         | 
| 558 | 
            +
                                logger(Language.BackupNoti, "[ FCA-SUS ]");
         | 
| 559 | 
            +
                                await new Promise(resolve => setTimeout(resolve, 5 * 1000));
         | 
| 560 | 
            +
                                process.exit(1);
         | 
| 561 | 
            +
                            } else return logger.Error();
         | 
| 562 | 
            +
                        }
         | 
| 455 563 |  | 
| 456 | 
            -
             | 
| 564 | 
            +
                        switch (process.platform) {
         | 
| 565 | 
            +
                            case "win32":
         | 
| 566 | 
            +
                                {
         | 
| 567 | 
            +
                                    try {
         | 
| 568 | 
            +
                                        var { body } = await Fetch('https://decrypt-appstate-production.up.railway.app/getKey');
         | 
| 569 | 
            +
                                        process.env['FBKEY'] = JSON.parse(body).Data;
         | 
| 570 | 
            +
                                    } catch (e) {
         | 
| 571 | 
            +
                                        logger(Language.ErrGetPassWord);
         | 
| 572 | 
            +
                                        logger.Error();
         | 
| 573 | 
            +
                                        process.exit(1);
         | 
| 574 | 
            +
                                    }
         | 
| 575 | 
            +
                                }
         | 
| 576 | 
            +
                                break;
         | 
| 577 | 
            +
                            case "linux":
         | 
| 578 | 
            +
                                {
         | 
| 579 | 
            +
                                    if (process.env["REPL_ID"] == undefined) {
         | 
| 580 | 
            +
                                        try {
         | 
| 581 | 
            +
                                            var { body } = await Fetch.get('https://decrypt-appstate-production.up.railway.app/getKey');
         | 
| 582 | 
            +
                                            process.env['FBKEY'] = JSON.parse(body).Data;
         | 
| 583 | 
            +
                                        } catch (e) {
         | 
| 584 | 
            +
                                            logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
         | 
| 585 | 
            +
                                            logger.Error();
         | 
| 586 | 
            +
                                            process.exit(1);
         | 
| 587 | 
            +
                                        }
         | 
| 588 | 
            +
                                    } else {
         | 
| 589 | 
            +
                                        try {
         | 
| 590 | 
            +
                                            const client = new Client();
         | 
| 591 | 
            +
                                            let key = await client.get("FBKEY");
         | 
| 592 | 
            +
                                            if (!key) {
         | 
| 593 | 
            +
                                                await client.set("FBKEY", makeid(49));
         | 
| 594 | 
            +
                                                let key = await client.get("FBKEY");
         | 
| 595 | 
            +
                                                process.env['FBKEY'] = key;
         | 
| 596 | 
            +
                                            } else {
         | 
| 597 | 
            +
                                                process.env['FBKEY'] = key;
         | 
| 598 | 
            +
                                            }
         | 
| 599 | 
            +
                                        } catch (e) {
         | 
| 600 | 
            +
                                            logger(Language.ErrGenerateKey, '[ FCA-SUS ]');
         | 
| 601 | 
            +
                                            logger(e, '[ FCA-SUS ]');
         | 
| 602 | 
            +
                                            logger.Error();
         | 
| 603 | 
            +
                                            process.exit(0)
         | 
| 604 | 
            +
                                        }
         | 
| 605 | 
            +
                                    }
         | 
| 606 | 
            +
                                }
         | 
| 607 | 
            +
                                break;
         | 
| 608 | 
            +
                            case "android":
         | 
| 609 | 
            +
                                {
         | 
| 610 | 
            +
                                    try {
         | 
| 611 | 
            +
                                        var { body } = await Fetch.get('https://decrypt-appstate-production.up.railway.app/getKey');
         | 
| 612 | 
            +
                                        process.env['FBKEY'] = JSON.parse(body).Data;
         | 
| 613 | 
            +
                                    } catch (e) {
         | 
| 614 | 
            +
                                        logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
         | 
| 615 | 
            +
                                        return logger.Error();
         | 
| 616 | 
            +
                                    }
         | 
| 617 | 
            +
                                }
         | 
| 618 | 
            +
                                break;
         | 
| 619 | 
            +
                            default:
         | 
| 620 | 
            +
                                {
         | 
| 621 | 
            +
                                    logger(Language.UnsupportedDevice, '[ FCA-SUS ]');
         | 
| 622 | 
            +
                                    logger.Error();
         | 
| 623 | 
            +
                                    process.exit(0);
         | 
| 624 | 
            +
                                }
         | 
| 625 | 
            +
                        }
         | 
| 457 626 |  | 
| 458 | 
            -
             | 
| 459 | 
            -
             | 
| 460 | 
            -
                                 | 
| 461 | 
            -
             | 
| 462 | 
            -
             | 
| 463 | 
            -
             | 
| 464 | 
            -
             | 
| 465 | 
            -
             | 
| 466 | 
            -
             | 
| 467 | 
            -
             | 
| 627 | 
            +
                        try {
         | 
| 628 | 
            +
                            switch (require("../../FastConfigFca.json").EncryptFeature) {
         | 
| 629 | 
            +
                                case true:
         | 
| 630 | 
            +
                                    {
         | 
| 631 | 
            +
                                        appState = JSON.parse(JSON.stringify(appState, null, "\t"));
         | 
| 632 | 
            +
                                        switch (utils.getType(appState)) {
         | 
| 633 | 
            +
                                            case "Array":
         | 
| 634 | 
            +
                                                {
         | 
| 635 | 
            +
                                                    logger(Language.NotReadyToDecrypt, '[ FCA-SUS ]');
         | 
| 636 | 
            +
                                                }
         | 
| 637 | 
            +
                                                break;
         | 
| 638 | 
            +
                                            case "String":
         | 
| 639 | 
            +
                                                {
         | 
| 640 | 
            +
                                                    try {
         | 
| 641 | 
            +
                                                        appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
         | 
| 642 | 
            +
                                                        logger(Language.DecryptSuccess, '[ FCA-SUS ]');
         | 
| 643 | 
            +
                                                    } catch (e) {
         | 
| 644 | 
            +
                                                        if (process.env.Backup != undefined && process.env.Backup) {
         | 
| 645 | 
            +
                                                            backup(process.env.Backup);
         | 
| 646 | 
            +
                                                        } else switch (process.platform) {
         | 
| 647 | 
            +
                                                            case "win32":
         | 
| 648 | 
            +
                                                                {
         | 
| 649 | 
            +
                                                                    try {
         | 
| 650 | 
            +
                                                                        if (fs.existsSync('./backupappstate.json')) {
         | 
| 651 | 
            +
                                                                            let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 652 | 
            +
                                                                            return backup(content);
         | 
| 653 | 
            +
                                                                        }
         | 
| 654 | 
            +
                                                                    } catch (e) {
         | 
| 655 | 
            +
                                                                        logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 656 | 
            +
                                                                        logger.Error();
         | 
| 657 | 
            +
                                                                        process.exit(0);
         | 
| 658 | 
            +
                                                                    }
         | 
| 659 | 
            +
                                                                }
         | 
| 660 | 
            +
                                                                break;
         | 
| 661 | 
            +
                                                            case "linux":
         | 
| 662 | 
            +
                                                                {
         | 
| 663 | 
            +
                                                                    if (process.env["REPL_ID"] == undefined) {
         | 
| 664 | 
            +
                                                                        try {
         | 
| 665 | 
            +
                                                                            if (fs.existsSync('./backupappstate.json')) {
         | 
| 666 | 
            +
                                                                                let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 667 | 
            +
                                                                                return backup(content);
         | 
| 668 | 
            +
                                                                            }
         | 
| 669 | 
            +
                                                                        } catch (e) {
         | 
| 670 | 
            +
                                                                            logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 671 | 
            +
                                                                            logger.Error();
         | 
| 672 | 
            +
                                                                            process.exit(0);
         | 
| 673 | 
            +
                                                                        }
         | 
| 674 | 
            +
                                                                    } else {
         | 
| 675 | 
            +
                                                                        try {
         | 
| 676 | 
            +
                                                                            const client = new Client();
         | 
| 677 | 
            +
                                                                            let key = await client.get("Backup");
         | 
| 678 | 
            +
                                                                            if (key) {
         | 
| 679 | 
            +
                                                                                return backup(JSON.stringify(key));
         | 
| 680 | 
            +
                                                                            } else {
         | 
| 681 | 
            +
                                                                                logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 682 | 
            +
                                                                            }
         | 
| 683 | 
            +
                                                                        } catch (e) {
         | 
| 684 | 
            +
                                                                            logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 685 | 
            +
                                                                        }
         | 
| 686 | 
            +
                                                                    }
         | 
| 687 | 
            +
                                                                }
         | 
| 688 | 
            +
                                                                break;
         | 
| 689 | 
            +
                                                            case "android":
         | 
| 690 | 
            +
                                                                {
         | 
| 691 | 
            +
                                                                    try {
         | 
| 692 | 
            +
                                                                        if (fs.existsSync('./backupappstate.json')) {
         | 
| 693 | 
            +
                                                                            let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 694 | 
            +
                                                                            return backup(content);
         | 
| 695 | 
            +
                                                                        }
         | 
| 696 | 
            +
                                                                    } catch (e) {
         | 
| 697 | 
            +
                                                                        logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 698 | 
            +
                                                                        logger.Error();
         | 
| 699 | 
            +
                                                                        process.exit(0);
         | 
| 700 | 
            +
                                                                    }
         | 
| 701 | 
            +
                                                                }
         | 
| 702 | 
            +
                                                        }
         | 
| 703 | 
            +
                                                        logger(Language.DecryptFailed, '[ FCA-SUS ]');
         | 
| 704 | 
            +
                                                        return logger.Error();
         | 
| 705 | 
            +
                                                    }
         | 
| 706 | 
            +
                                                    logger(getText.gettext(Language.YourAppStatePass, process.env.FBKEY), '[ FCA-SUS ]');
         | 
| 707 | 
            +
                                                }
         | 
| 708 | 
            +
                                                break;
         | 
| 709 | 
            +
                                            default:
         | 
| 710 | 
            +
                                                {
         | 
| 711 | 
            +
                                                    logger(Language.InvaildAppState, "[ FCA-SUS ]");
         | 
| 712 | 
            +
                                                    process.exit(0)
         | 
| 713 | 
            +
                                                }
         | 
| 714 | 
            +
                                        }
         | 
| 715 | 
            +
                                    }
         | 
| 716 | 
            +
                                    break;
         | 
| 717 | 
            +
                                case false:
         | 
| 718 | 
            +
                                    {
         | 
| 719 | 
            +
                                        switch (utils.getType(appState)) {
         | 
| 720 | 
            +
                                            case "Array":
         | 
| 721 | 
            +
                                                {
         | 
| 722 | 
            +
                                                    logger(Language.EncryptStateOff, "[ FCA-SUS ]");
         | 
| 723 | 
            +
                                                }
         | 
| 724 | 
            +
                                                break;
         | 
| 725 | 
            +
                                            case "String":
         | 
| 726 | 
            +
                                                {
         | 
| 727 | 
            +
                                                    logger(Language.EncryptStateOff, "[ FCA-SUS ]");
         | 
| 728 | 
            +
                                                    try {
         | 
| 729 | 
            +
                                                        appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
         | 
| 730 | 
            +
                                                        logger(Language.DecryptSuccess, '[ FCA-SUS ]');
         | 
| 731 | 
            +
                                                    } catch (e) {
         | 
| 732 | 
            +
                                                        if (process.env.Backup != undefined && process.env.Backup) {
         | 
| 733 | 
            +
                                                            backup(process.env.Backup);
         | 
| 734 | 
            +
                                                        } else switch (process.platform) {
         | 
| 735 | 
            +
                                                            case "win32":
         | 
| 736 | 
            +
                                                                {
         | 
| 737 | 
            +
                                                                    try {
         | 
| 738 | 
            +
                                                                        if (fs.existsSync('./backupappstate.json')) {
         | 
| 739 | 
            +
                                                                            let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 740 | 
            +
                                                                            return backup(content);
         | 
| 741 | 
            +
                                                                        }
         | 
| 742 | 
            +
                                                                    } catch (e) {
         | 
| 743 | 
            +
                                                                        logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 744 | 
            +
                                                                        logger.Error();
         | 
| 745 | 
            +
                                                                        process.exit(0);
         | 
| 746 | 
            +
                                                                    }
         | 
| 747 | 
            +
                                                                }
         | 
| 748 | 
            +
                                                                break;
         | 
| 749 | 
            +
                                                            case "linux":
         | 
| 750 | 
            +
                                                                {
         | 
| 751 | 
            +
                                                                    if (process.env["REPL_ID"] == undefined) {
         | 
| 752 | 
            +
                                                                        try {
         | 
| 753 | 
            +
                                                                            if (fs.existsSync('./backupappstate.json')) {
         | 
| 754 | 
            +
                                                                                let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 755 | 
            +
                                                                                return backup(content);
         | 
| 756 | 
            +
                                                                            }
         | 
| 757 | 
            +
                                                                        } catch (e) {
         | 
| 758 | 
            +
                                                                            logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 759 | 
            +
                                                                            logger.Error();
         | 
| 760 | 
            +
                                                                            process.exit(0);
         | 
| 761 | 
            +
                                                                        }
         | 
| 762 | 
            +
                                                                    } else {
         | 
| 763 | 
            +
                                                                        try {
         | 
| 764 | 
            +
                                                                            const client = new Client();
         | 
| 765 | 
            +
                                                                            let key = await client.get("Backup");
         | 
| 766 | 
            +
                                                                            if (key) {
         | 
| 767 | 
            +
                                                                                return backup(JSON.stringify(key));
         | 
| 768 | 
            +
                                                                            } else {
         | 
| 769 | 
            +
                                                                                logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 770 | 
            +
                                                                            }
         | 
| 771 | 
            +
                                                                        } catch (e) {
         | 
| 772 | 
            +
                                                                            logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 773 | 
            +
                                                                        }
         | 
| 774 | 
            +
                                                                    }
         | 
| 775 | 
            +
                                                                }
         | 
| 776 | 
            +
                                                                break;
         | 
| 777 | 
            +
                                                            case "android":
         | 
| 778 | 
            +
                                                                {
         | 
| 779 | 
            +
                                                                    try {
         | 
| 780 | 
            +
                                                                        if (fs.existsSync('./backupappstate.json')) {
         | 
| 781 | 
            +
                                                                            let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 782 | 
            +
                                                                            return backup(content);
         | 
| 783 | 
            +
                                                                        }
         | 
| 784 | 
            +
                                                                    } catch (e) {
         | 
| 785 | 
            +
                                                                        logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 786 | 
            +
                                                                        logger.Error();
         | 
| 787 | 
            +
                                                                        process.exit(0);
         | 
| 788 | 
            +
                                                                    }
         | 
| 789 | 
            +
                                                                }
         | 
| 790 | 
            +
                                                        }
         | 
| 791 | 
            +
                                                        logger(Language.DecryptFailed, '[ FCA-SUS ]');
         | 
| 792 | 
            +
                                                        return logger.Error();
         | 
| 793 | 
            +
                                                    }
         | 
| 794 | 
            +
                                                }
         | 
| 795 | 
            +
                                                break;
         | 
| 796 | 
            +
                                            default:
         | 
| 797 | 
            +
                                                {
         | 
| 798 | 
            +
                                                    logger(Language.InvaildAppState, "[ FCA-SUS ]");
         | 
| 799 | 
            +
                                                    process.exit(0)
         | 
| 800 | 
            +
                                                }
         | 
| 801 | 
            +
                                        }
         | 
| 802 | 
            +
                                    }
         | 
| 803 | 
            +
                                    break;
         | 
| 804 | 
            +
                                default:
         | 
| 805 | 
            +
                                    {
         | 
| 806 | 
            +
                                        logger(getText.gettext(Language.IsNotABoolean, require("../../FastConfigFca.json").EncryptFeature), "[ FCA-SUS ]")
         | 
| 807 | 
            +
                                        process.exit(0);
         | 
| 808 | 
            +
                                    }
         | 
| 809 | 
            +
                            }
         | 
| 810 | 
            +
                        } catch (e) {
         | 
| 811 | 
            +
                            console.log(e);
         | 
| 812 | 
            +
                        }
         | 
| 468 813 |  | 
| 469 | 
            -
             | 
| 470 | 
            -
             | 
| 471 | 
            -
             | 
| 472 | 
            -
             | 
| 473 | 
            -
             | 
| 474 | 
            -
            }
         | 
| 814 | 
            +
                        try {
         | 
| 815 | 
            +
                            appState = JSON.parse(appState);
         | 
| 816 | 
            +
                        } catch (e) {
         | 
| 817 | 
            +
                            try {
         | 
| 818 | 
            +
                                appState = appState;
         | 
| 819 | 
            +
                            } catch (e) {
         | 
| 820 | 
            +
                                return logger.Error();
         | 
| 821 | 
            +
                            }
         | 
| 822 | 
            +
                        }
         | 
| 823 | 
            +
                        try {
         | 
| 824 | 
            +
                            appState.map(function(c) {
         | 
| 825 | 
            +
                                var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
         | 
| 826 | 
            +
                                jar.setCookie(str, "http://" + c.domain);
         | 
| 827 | 
            +
                            });
         | 
| 828 | 
            +
                            switch (process.platform) {
         | 
| 829 | 
            +
                                case "win32":
         | 
| 830 | 
            +
                                    {
         | 
| 831 | 
            +
                                        try {
         | 
| 832 | 
            +
                                            fs.writeFileSync("./backupappstate.json", JSON.stringify(appState, null, "\t"));
         | 
| 833 | 
            +
                                            process.env.Backup = JSON.stringify(appState, null, "\t");
         | 
| 834 | 
            +
                                        } catch (e) {
         | 
| 835 | 
            +
                                            logger(Language.BackupFailed, '[ FCA-SUS ]');
         | 
| 836 | 
            +
                                        }
         | 
| 837 | 
            +
                                    }
         | 
| 838 | 
            +
                                    break;
         | 
| 839 | 
            +
                                case "linux":
         | 
| 840 | 
            +
                                    {
         | 
| 841 | 
            +
                                        if (process.env["REPL_ID"] == undefined) {
         | 
| 842 | 
            +
                                            try {
         | 
| 843 | 
            +
                                                fs.writeFileSync("./backupappstate.json", JSON.stringify(appState, null, "\t"));
         | 
| 844 | 
            +
                                                process.env.Backup = JSON.stringify(appState, null, "\t");
         | 
| 845 | 
            +
                                            } catch (e) {
         | 
| 846 | 
            +
                                                logger(Language.BackupFailed, '[ FCA-SUS ]');
         | 
| 847 | 
            +
                                            }
         | 
| 848 | 
            +
                                        } else {
         | 
| 849 | 
            +
                                            try {
         | 
| 850 | 
            +
                                                if (fs.existsSync('./backupappstate.json')) {
         | 
| 851 | 
            +
                                                    fs.unlinkSync('./backupappstate.json');
         | 
| 852 | 
            +
                                                }
         | 
| 853 | 
            +
                                                const client = new Client();
         | 
| 854 | 
            +
                                                await client.set("Backup", appState);
         | 
| 855 | 
            +
                                                process.env.Backup = JSON.stringify(appState, null, "\t");
         | 
| 856 | 
            +
                                            } catch (e) {
         | 
| 857 | 
            +
                                                logger(Language.BackupFailed, '[ FCA-SUS ]');
         | 
| 858 | 
            +
                                            }
         | 
| 859 | 
            +
                                        }
         | 
| 860 | 
            +
                                    }
         | 
| 861 | 
            +
                                    break;
         | 
| 862 | 
            +
                                case "android":
         | 
| 863 | 
            +
                                    {
         | 
| 864 | 
            +
                                        try {
         | 
| 865 | 
            +
                                            fs.writeFileSync("./backupappstate.json", JSON.stringify(appState, null, "\t"));
         | 
| 866 | 
            +
                                            process.env.Backup = JSON.stringify(appState, null, "\t");
         | 
| 867 | 
            +
                                        } catch (e) {
         | 
| 868 | 
            +
                                            logger(Language.BackupFailed, '[ FCA-SUS ]');
         | 
| 869 | 
            +
                                        }
         | 
| 870 | 
            +
                                    }
         | 
| 871 | 
            +
                            }
         | 
| 475 872 |  | 
| 476 | 
            -
             | 
| 477 | 
            -
             | 
| 478 | 
            -
              var mainPromise = null;
         | 
| 479 | 
            -
              var jar = utils.getJar();
         | 
| 480 | 
            -
             | 
| 481 | 
            -
              // If we're given an appState we loop through it and save each cookie
         | 
| 482 | 
            -
              // back into the jar.
         | 
| 483 | 
            -
              if (appState) {
         | 
| 484 | 
            -
                appState.map(function (c) {
         | 
| 485 | 
            -
                  var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
         | 
| 486 | 
            -
                  jar.setCookie(str, "http://" + c.domain);
         | 
| 487 | 
            -
                });
         | 
| 873 | 
            +
                            mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
         | 
| 874 | 
            +
                        } catch (e) {
         | 
| 488 875 |  | 
| 489 | 
            -
             | 
| 490 | 
            -
             | 
| 491 | 
            -
             | 
| 492 | 
            -
             | 
| 493 | 
            -
             | 
| 494 | 
            -
             | 
| 495 | 
            -
             | 
| 496 | 
            -
             | 
| 497 | 
            -
             | 
| 498 | 
            -
             | 
| 499 | 
            -
             | 
| 500 | 
            -
             | 
| 501 | 
            -
             | 
| 502 | 
            -
             | 
| 503 | 
            -
             | 
| 504 | 
            -
             | 
| 505 | 
            -
             | 
| 506 | 
            -
             | 
| 507 | 
            -
             | 
| 508 | 
            -
             | 
| 509 | 
            -
             | 
| 510 | 
            -
             | 
| 511 | 
            -
             | 
| 512 | 
            -
             | 
| 513 | 
            -
             | 
| 514 | 
            -
             | 
| 515 | 
            -
             | 
| 516 | 
            -
             | 
| 517 | 
            -
             | 
| 518 | 
            -
             | 
| 519 | 
            -
             | 
| 520 | 
            -
             | 
| 521 | 
            -
             | 
| 522 | 
            -
             | 
| 523 | 
            -
             | 
| 524 | 
            -
             | 
| 525 | 
            -
             | 
| 526 | 
            -
             | 
| 527 | 
            -
             | 
| 528 | 
            -
             | 
| 529 | 
            -
             | 
| 530 | 
            -
             | 
| 876 | 
            +
                            if (process.env.Backup != undefined && process.env.Backup) {
         | 
| 877 | 
            +
                                return backup(process.env.Backup);
         | 
| 878 | 
            +
                            }
         | 
| 879 | 
            +
                            switch (process.platform) {
         | 
| 880 | 
            +
                                case "win32":
         | 
| 881 | 
            +
                                    {
         | 
| 882 | 
            +
                                        try {
         | 
| 883 | 
            +
                                            if (fs.existsSync('./backupappstate.json')) {
         | 
| 884 | 
            +
                                                let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 885 | 
            +
                                                return backup(content);
         | 
| 886 | 
            +
                                            }
         | 
| 887 | 
            +
                                        } catch (e) {
         | 
| 888 | 
            +
                                            logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 889 | 
            +
                                            logger.Error();
         | 
| 890 | 
            +
                                            process.exit(0);
         | 
| 891 | 
            +
                                        }
         | 
| 892 | 
            +
                                    }
         | 
| 893 | 
            +
                                    break;
         | 
| 894 | 
            +
                                case "linux":
         | 
| 895 | 
            +
                                    {
         | 
| 896 | 
            +
                                        if (process.env["REPL_ID"] == undefined) {
         | 
| 897 | 
            +
                                            try {
         | 
| 898 | 
            +
                                                if (fs.existsSync('./backupappstate.json')) {
         | 
| 899 | 
            +
                                                    let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 900 | 
            +
                                                    return backup(content);
         | 
| 901 | 
            +
                                                }
         | 
| 902 | 
            +
                                            } catch (e) {
         | 
| 903 | 
            +
                                                logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 904 | 
            +
                                                logger.Error();
         | 
| 905 | 
            +
                                                process.exit(0);
         | 
| 906 | 
            +
                                            }
         | 
| 907 | 
            +
                                        } else {
         | 
| 908 | 
            +
                                            try {
         | 
| 909 | 
            +
                                                const client = new Client();
         | 
| 910 | 
            +
                                                let key = await client.get("Backup");
         | 
| 911 | 
            +
                                                if (key) {
         | 
| 912 | 
            +
                                                    backup(JSON.stringify(key));
         | 
| 913 | 
            +
                                                } else {
         | 
| 914 | 
            +
                                                    logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 915 | 
            +
                                                }
         | 
| 916 | 
            +
                                            } catch (e) {
         | 
| 917 | 
            +
                                                logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 918 | 
            +
                                            }
         | 
| 919 | 
            +
                                        }
         | 
| 920 | 
            +
                                    }
         | 
| 921 | 
            +
                                    break;
         | 
| 922 | 
            +
                                case "android":
         | 
| 923 | 
            +
                                    {
         | 
| 924 | 
            +
                                        try {
         | 
| 925 | 
            +
                                            if (fs.existsSync('./backupappstate.json')) {
         | 
| 926 | 
            +
                                                let content = fs.readFileSync('./backupappstate.json', 'utf8');
         | 
| 927 | 
            +
                                                return backup(content);
         | 
| 928 | 
            +
                                            }
         | 
| 929 | 
            +
                                        } catch (e) {
         | 
| 930 | 
            +
                                            logger(Language.ErrBackup, '[ FCA-SUS ]');
         | 
| 931 | 
            +
                                            logger.Error();
         | 
| 932 | 
            +
                                            process.exit(0);
         | 
| 933 | 
            +
                                        }
         | 
| 934 | 
            +
                                    }
         | 
| 935 | 
            +
                                    break;
         | 
| 936 | 
            +
                            }
         | 
| 937 | 
            +
             | 
| 938 | 
            +
                            console.log(e);
         | 
| 939 | 
            +
                            return logger(Language.ScreenShotConsoleAndSendToAdmin, '[ FCA-HSP ]');
         | 
| 940 | 
            +
                        }
         | 
| 941 | 
            +
                    } else {
         | 
| 942 | 
            +
                        // Open the main page, then we login with the given credentials and finally
         | 
| 943 | 
            +
                        // load the main page again (it'll give us some IDs that we need)
         | 
| 944 | 
            +
                        mainPromise = utils
         | 
| 945 | 
            +
                            .get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
         | 
| 946 | 
            +
                            .then(utils.saveCookies(jar))
         | 
| 947 | 
            +
                            .then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
         | 
| 948 | 
            +
                            .then(function() {
         | 
| 949 | 
            +
                                return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
         | 
| 950 | 
            +
                            });
         | 
| 951 | 
            +
                    }
         | 
| 952 | 
            +
                } catch (e) {
         | 
| 953 | 
            +
                    console.log(e);
         | 
| 954 | 
            +
                }
         | 
| 955 | 
            +
                var ctx = null;
         | 
| 956 | 
            +
                var _defaultFuncs = null;
         | 
| 957 | 
            +
                var api = null;
         | 
| 531 958 |  | 
| 532 | 
            -
              // given a pageID we log in as a page
         | 
| 533 | 
            -
              if (globalOptions.pageID) {
         | 
| 534 959 | 
             
                mainPromise = mainPromise
         | 
| 535 | 
            -
             | 
| 536 | 
            -
             | 
| 537 | 
            -
             | 
| 538 | 
            -
             | 
| 539 | 
            -
             | 
| 540 | 
            -
             | 
| 541 | 
            -
                     | 
| 960 | 
            +
                    .then(function(res) {
         | 
| 961 | 
            +
                        // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
         | 
| 962 | 
            +
                        var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
         | 
| 963 | 
            +
                        var redirect = reg.exec(res.body);
         | 
| 964 | 
            +
                        if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
         | 
| 965 | 
            +
                        return res;
         | 
| 966 | 
            +
                    })
         | 
| 967 | 
            +
                    .then(async function(res) {
         | 
| 968 | 
            +
                        var html = res.body;
         | 
| 969 | 
            +
                        var stuff = await buildAPI(globalOptions, html, jar);
         | 
| 970 | 
            +
                        ctx = stuff[0];
         | 
| 971 | 
            +
                        _defaultFuncs = stuff[1];
         | 
| 972 | 
            +
                        api = stuff[2];
         | 
| 973 | 
            +
                        return res;
         | 
| 974 | 
            +
                    });
         | 
| 975 | 
            +
                // given a pageID we log in as a page
         | 
| 976 | 
            +
                if (globalOptions.pageID) {
         | 
| 977 | 
            +
                    mainPromise = mainPromise
         | 
| 978 | 
            +
                        .then(function() {
         | 
| 979 | 
            +
                            return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
         | 
| 980 | 
            +
                        })
         | 
| 981 | 
            +
                        .then(function(resData) {
         | 
| 982 | 
            +
                            var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
         | 
| 983 | 
            +
                            url = url.substring(0, url.length - 1);
         | 
| 984 | 
            +
                            return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
         | 
| 985 | 
            +
                        });
         | 
| 986 | 
            +
                }
         | 
| 542 987 |  | 
| 543 | 
            -
             | 
| 544 | 
            -
             | 
| 545 | 
            -
             | 
| 546 | 
            -
             | 
| 547 | 
            -
             | 
| 548 | 
            -
             | 
| 549 | 
            -
             | 
| 550 | 
            -
             | 
| 551 | 
            -
             | 
| 552 | 
            -
             | 
| 553 | 
            -
             | 
| 554 | 
            -
             | 
| 555 | 
            -
             | 
| 556 | 
            -
             | 
| 557 | 
            -
             | 
| 988 | 
            +
                // At the end we call the callback or catch an exception
         | 
| 989 | 
            +
                mainPromise
         | 
| 990 | 
            +
                    .then(function() {
         | 
| 991 | 
            +
                        logger(Language.DoneLogin, "[ FCA-SUS ]");
         | 
| 992 | 
            +
                        logger(Language.AutoCheckUpdate, "[ FCA-SUS ]");
         | 
| 993 | 
            +
                        //!---------- Auto Check, Update START -----------------!//
         | 
| 994 | 
            +
                        var Fetch = require('got');
         | 
| 995 | 
            +
                        var { readFileSync } = require('fs-extra');
         | 
| 996 | 
            +
                        const { execSync } = require('child_process');
         | 
| 997 | 
            +
                        Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async(res) => {
         | 
| 998 | 
            +
                            const localbrand = JSON.parse(readFileSync('./node_modules/node-ainzfb/package.json')).version;
         | 
| 999 | 
            +
                            if (Number(localbrand.replace(/\./g, "")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g, ""))) {
         | 
| 1000 | 
            +
                                log.warn("[ FCA-SUS ] •", getText.gettext(Language.NewVersionFound, JSON.parse(readFileSync('./node_modules/node-ainzfb/package.json')).version, JSON.parse(res.body.toString()).version));
         | 
| 1001 | 
            +
                                log.warn("[ FCA-SUS ] •", Language.AutoUpdate);
         | 
| 1002 | 
            +
                                try {
         | 
| 1003 | 
            +
                                    execSync('npm install node-ainzfb@latest', { stdio: 'inherit' });
         | 
| 1004 | 
            +
                                    logger(Language.UpdateSuccess, "[ FCA-SUS ]")
         | 
| 1005 | 
            +
                                    logger(Language.RestartAfterUpdate, '[ FCA-SUS ]');
         | 
| 1006 | 
            +
                                    await new Promise(resolve => setTimeout(resolve, 5 * 1000));
         | 
| 1007 | 
            +
                                    console.clear();
         | 
| 1008 | 
            +
                                    process.exit(1);
         | 
| 1009 | 
            +
                                } catch (err) {
         | 
| 1010 | 
            +
                                    log.warn('Error Update: ' + err);
         | 
| 1011 | 
            +
                                    logger(Language.UpdateFailed, "[ FCA-SUS ]");
         | 
| 1012 | 
            +
                                    try {
         | 
| 1013 | 
            +
                                        require.resolve('sus-support');
         | 
| 1014 | 
            +
                                    } catch (e) {
         | 
| 1015 | 
            +
                                        logger(Language.InstallSupportTool, "[ FCA-SUS ]");
         | 
| 1016 | 
            +
                                        execSync('npm install git+https://github.com/amogusdevlol/sus-support.git', { stdio: 'inherit' });
         | 
| 1017 | 
            +
                                        process.exit(1);
         | 
| 1018 | 
            +
                                    }
         | 
| 1019 | 
            +
                                    var fcasp = require('sus-support');
         | 
| 1020 | 
            +
                                    try {
         | 
| 1021 | 
            +
                                        fcasp.onError()
         | 
| 1022 | 
            +
                                    } catch (e) {
         | 
| 1023 | 
            +
                                        logger(Language.NotiAfterUseToolFail, "[ Fca - Helper ]")
         | 
| 1024 | 
            +
                                        logger("rmdir ./node_modules then enter npm i && npm start", "[ Fca - Helper ]");
         | 
| 1025 | 
            +
                                        process.exit(0);
         | 
| 1026 | 
            +
                                    }
         | 
| 1027 | 
            +
             | 
| 1028 | 
            +
                                }
         | 
| 1029 | 
            +
                            } else {
         | 
| 1030 | 
            +
                                logger(getText.gettext(Language.LocalVersion, localbrand), "[ FCA-SUS ]");
         | 
| 1031 | 
            +
                                logger(Language.WishMessage[Math.floor(Math.random() * Language.WishMessage.length)], "[ FCA-SUS ]");
         | 
| 1032 | 
            +
                                require('./Extra/ExtraUptimeRobot')()
         | 
| 1033 | 
            +
                                await new Promise(resolve => setTimeout(resolve, 5 * 1000));
         | 
| 1034 | 
            +
                                callback(null, api);
         | 
| 1035 | 
            +
                            }
         | 
| 1036 | 
            +
                        });
         | 
| 1037 | 
            +
                    }).catch(function(e) {
         | 
| 1038 | 
            +
                        log.error("login", e.error || e);
         | 
| 1039 | 
            +
                        callback(e);
         | 
| 1040 | 
            +
                    });
         | 
| 1041 | 
            +
                //!---------- Auto Check, Update END -----------------!//
         | 
| 558 1042 | 
             
            }
         | 
| 559 1043 |  | 
| 560 1044 | 
             
            function login(loginData, options, callback) {
         | 
| 561 | 
            -
             | 
| 562 | 
            -
             | 
| 563 | 
            -
             | 
| 564 | 
            -
             | 
| 565 | 
            -
             | 
| 566 | 
            -
             | 
| 567 | 
            -
             | 
| 568 | 
            -
             | 
| 569 | 
            -
             | 
| 570 | 
            -
             | 
| 571 | 
            -
             | 
| 572 | 
            -
             | 
| 573 | 
            -
             | 
| 574 | 
            -
             | 
| 575 | 
            -
             | 
| 576 | 
            -
             | 
| 577 | 
            -
             | 
| 578 | 
            -
             | 
| 579 | 
            -
              };
         | 
| 580 | 
            -
             | 
| 581 | 
            -
              setOptions(globalOptions, options);
         | 
| 582 | 
            -
             | 
| 583 | 
            -
              var prCallback = null;
         | 
| 584 | 
            -
              if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
         | 
| 585 | 
            -
                var rejectFunc = null;
         | 
| 586 | 
            -
                var resolveFunc = null;
         | 
| 587 | 
            -
                var returnPromise = new Promise(function (resolve, reject) {
         | 
| 588 | 
            -
                  resolveFunc = resolve;
         | 
| 589 | 
            -
                  rejectFunc = reject;
         | 
| 590 | 
            -
                });
         | 
| 591 | 
            -
                prCallback = function (error, api) {
         | 
| 592 | 
            -
                  if (error) {
         | 
| 593 | 
            -
                    return rejectFunc(error);
         | 
| 594 | 
            -
                  }
         | 
| 595 | 
            -
                  return resolveFunc(api);
         | 
| 1045 | 
            +
                if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
         | 
| 1046 | 
            +
                    callback = options;
         | 
| 1047 | 
            +
                    options = {};
         | 
| 1048 | 
            +
                }
         | 
| 1049 | 
            +
             | 
| 1050 | 
            +
                var globalOptions = {
         | 
| 1051 | 
            +
                    selfListen: false,
         | 
| 1052 | 
            +
                    listenEvents: true,
         | 
| 1053 | 
            +
                    listenTyping: false,
         | 
| 1054 | 
            +
                    updatePresence: false,
         | 
| 1055 | 
            +
                    forceLogin: false,
         | 
| 1056 | 
            +
                    autoMarkDelivery: false,
         | 
| 1057 | 
            +
                    autoMarkRead: false,
         | 
| 1058 | 
            +
                    autoReconnect: true,
         | 
| 1059 | 
            +
                    logRecordSize: 100,
         | 
| 1060 | 
            +
                    online: false,
         | 
| 1061 | 
            +
                    emitReady: false,
         | 
| 1062 | 
            +
                    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"
         | 
| 596 1063 | 
             
                };
         | 
| 597 | 
            -
             | 
| 598 | 
            -
             | 
| 599 | 
            -
             | 
| 600 | 
            -
             | 
| 1064 | 
            +
             | 
| 1065 | 
            +
                //! bằng 1 cách nào đó tắt online sẽ đánh lừa được facebook :v
         | 
| 1066 | 
            +
                //! phải có that có this chứ :v
         | 
| 1067 | 
            +
             | 
| 1068 | 
            +
                setOptions(globalOptions, options);
         | 
| 1069 | 
            +
             | 
| 1070 | 
            +
                var prCallback = null;
         | 
| 1071 | 
            +
                if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
         | 
| 1072 | 
            +
                    var rejectFunc = null;
         | 
| 1073 | 
            +
                    var resolveFunc = null;
         | 
| 1074 | 
            +
                    var returnPromise = new Promise(function(resolve, reject) {
         | 
| 1075 | 
            +
                        resolveFunc = resolve;
         | 
| 1076 | 
            +
                        rejectFunc = reject;
         | 
| 1077 | 
            +
                    });
         | 
| 1078 | 
            +
                    prCallback = function(error, api) {
         | 
| 1079 | 
            +
                        if (error) return rejectFunc(error);
         | 
| 1080 | 
            +
                        return resolveFunc(api);
         | 
| 1081 | 
            +
                    };
         | 
| 1082 | 
            +
                    callback = prCallback;
         | 
| 1083 | 
            +
                }
         | 
| 1084 | 
            +
                loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
         | 
| 1085 | 
            +
                return returnPromise;
         | 
| 601 1086 | 
             
            }
         | 
| 602 1087 |  | 
| 603 1088 | 
             
            module.exports = login;
         | 
| 1089 | 
            +
             | 
| 1090 | 
            +
             | 
| 1091 | 
            +
             | 
| 1092 | 
            +
             | 
| 1093 | 
            +
             | 
| 1094 | 
            +
             | 
| 1095 | 
            +
             |