node-ainzfb-new 1.7.9-uOw19mf → 1.7.10-13
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +83 -41
- package/package.json +2 -2
- package/src/changeAvt.js +73 -73
- package/src/editMessage.js +29 -26
- package/src/getAccessToken.js +21 -21
- package/src/getThreadInfo.js +3423 -18
- package/src/getUserInfoV2.js +19 -22
- package/src/pinMessage.js +61 -0
- package/src/shareContact.js +56 -0
- package/src/shareLink.js +57 -0
- package/utils.js +13 -6
package/index.js
CHANGED
@@ -9,7 +9,7 @@ process.env.UV_THREADPOOL_SIZE = require('os').cpus().length;
|
|
9
9
|
global.isThread = new Array();
|
10
10
|
global.isUser = new Array();
|
11
11
|
global.startTime = Date.now();
|
12
|
-
global.getText =
|
12
|
+
global.getText = require('gettext.js')();
|
13
13
|
|
14
14
|
/!-[ Require All Package Need Use ]-!/
|
15
15
|
/*globalThis.Fca = new Object({
|
@@ -19,7 +19,7 @@ global.getText = require('gettext.js')();
|
|
19
19
|
var utils = require("./utils"),
|
20
20
|
cheerio = require("cheerio"),
|
21
21
|
log = require("npmlog"),
|
22
|
-
//{ getAccessToken } = require('./Extra/ExtraAddons'),
|
22
|
+
//{ getAccessToken } = require('./Extra/ExtraAddons'),
|
23
23
|
logger = require('./logger'),
|
24
24
|
fs = require('fs-extra'),
|
25
25
|
getText = require('gettext.js')(),
|
@@ -90,7 +90,7 @@ var checkVerified = null;
|
|
90
90
|
/!-[ Function setOptions ]-!/
|
91
91
|
|
92
92
|
function setOptions(globalOptions, options) {
|
93
|
-
Object.keys(options).map(function(key) {
|
93
|
+
Object.keys(options).map(function (key) {
|
94
94
|
switch (key) {
|
95
95
|
case 'pauseLog':
|
96
96
|
if (options.pauseLog) log.pause();
|
@@ -158,7 +158,7 @@ function setOptions(globalOptions, options) {
|
|
158
158
|
/!-[ Function BuildAPI ]-!/
|
159
159
|
|
160
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"; });
|
161
|
+
var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function (val) { return val.cookieString().split("=")[0] === "c_user"; });
|
162
162
|
|
163
163
|
if (maybeCookie.length === 0) throw { error: Language.ErrAppState };
|
164
164
|
|
@@ -222,7 +222,9 @@ async function buildAPI(globalOptions, html, jar) {
|
|
222
222
|
syncToken: undefined,
|
223
223
|
mqttEndpoint,
|
224
224
|
region,
|
225
|
-
firstListen: true
|
225
|
+
firstListen: true,
|
226
|
+
wsReqNumber: 0,
|
227
|
+
wsTaskNumber: 0
|
226
228
|
};
|
227
229
|
|
228
230
|
var api = {
|
@@ -244,7 +246,7 @@ async function buildAPI(globalOptions, html, jar) {
|
|
244
246
|
}
|
245
247
|
|
246
248
|
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
247
|
-
return function(res) {
|
249
|
+
return function (res) {
|
248
250
|
var html = res.body;
|
249
251
|
var $ = cheerio.load(html);
|
250
252
|
var arr = [];
|
@@ -252,7 +254,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
252
254
|
// This will be empty, but just to be sure we leave it
|
253
255
|
$("#login_form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
254
256
|
|
255
|
-
arr = arr.filter(function(v) {
|
257
|
+
arr = arr.filter(function (v) {
|
256
258
|
return v.val && v.val.length;
|
257
259
|
});
|
258
260
|
|
@@ -278,7 +280,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
278
280
|
//
|
279
281
|
// ---------- Very Hacky Part Starts -----------------
|
280
282
|
var willBeCookies = html.split("\"_js_");
|
281
|
-
willBeCookies.slice(1).map(function(val) {
|
283
|
+
willBeCookies.slice(1).map(function (val) {
|
282
284
|
var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
283
285
|
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
284
286
|
});
|
@@ -288,7 +290,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
288
290
|
return utils
|
289
291
|
.post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
|
290
292
|
.then(utils.saveCookies(jar))
|
291
|
-
.then(function(res) {
|
293
|
+
.then(function (res) {
|
292
294
|
var headers = res.headers;
|
293
295
|
if (!headers.location) throw { error: Language.InvaildAccount };
|
294
296
|
|
@@ -300,21 +302,21 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
300
302
|
return utils
|
301
303
|
.get(headers.location, jar, null, loginOptions)
|
302
304
|
.then(utils.saveCookies(jar))
|
303
|
-
.then(function(res) {
|
305
|
+
.then(function (res) {
|
304
306
|
var html = res.body;
|
305
307
|
// Make the form in advance which will contain the fb_dtsg and nh
|
306
308
|
var $ = cheerio.load(html);
|
307
309
|
var arr = [];
|
308
310
|
$("form input").map((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
309
311
|
|
310
|
-
arr = arr.filter(function(v) {
|
312
|
+
arr = arr.filter(function (v) {
|
311
313
|
return v.val && v.val.length;
|
312
314
|
});
|
313
315
|
|
314
316
|
var form = utils.arrToForm(arr);
|
315
317
|
if (html.indexOf("checkpoint/?next") > -1) {
|
316
318
|
setTimeout(() => {
|
317
|
-
checkVerified = setInterval((_form) => {}, 5000, {
|
319
|
+
checkVerified = setInterval((_form) => { }, 5000, {
|
318
320
|
fb_dtsg: form.fb_dtsg,
|
319
321
|
jazoest: form.jazoest,
|
320
322
|
dpr: 1
|
@@ -327,7 +329,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
327
329
|
form['submit[Continue]'] = $("#checkpointSubmitButton").html(); //'Continue';
|
328
330
|
var prResolve = null;
|
329
331
|
var prReject = null;
|
330
|
-
var rtPromise = new Promise(function(resolve, reject) {
|
332
|
+
var rtPromise = new Promise(function (resolve, reject) {
|
331
333
|
prResolve = resolve;
|
332
334
|
prReject = reject;
|
333
335
|
});
|
@@ -335,7 +337,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
335
337
|
utils
|
336
338
|
.post(nextURL, jar, form, loginOptions)
|
337
339
|
.then(utils.saveCookies(jar))
|
338
|
-
.then(function(res) {
|
340
|
+
.then(function (res) {
|
339
341
|
var $ = cheerio.load(res.body);
|
340
342
|
var error = $("#approvals_code").parent().attr("data-xui-error");
|
341
343
|
if (error) {
|
@@ -347,7 +349,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
347
349
|
};
|
348
350
|
}
|
349
351
|
})
|
350
|
-
.then(function() {
|
352
|
+
.then(function () {
|
351
353
|
// Use the same form (safe I hope)
|
352
354
|
delete form.no_fido;
|
353
355
|
delete form.approvals_code;
|
@@ -355,14 +357,14 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
355
357
|
|
356
358
|
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
357
359
|
})
|
358
|
-
.then(function(res) {
|
360
|
+
.then(function (res) {
|
359
361
|
var headers = res.headers;
|
360
362
|
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: Language.ApprovalsErr };
|
361
363
|
|
362
364
|
var appState = utils.getAppState(jar);
|
363
365
|
|
364
366
|
if (callback === prCallback) {
|
365
|
-
callback = function(err, api) {
|
367
|
+
callback = function (err, api) {
|
366
368
|
if (err) return prReject(err);
|
367
369
|
return prResolve(api);
|
368
370
|
};
|
@@ -372,7 +374,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
372
374
|
// and will then complete the login process
|
373
375
|
return loginHelper(appState, email, password, loginOptions, callback);
|
374
376
|
})
|
375
|
-
.catch(function(err) {
|
377
|
+
.catch(function (err) {
|
376
378
|
// Check if using Promise instead of callback
|
377
379
|
if (callback === prCallback) prReject(err);
|
378
380
|
else callback(err);
|
@@ -388,7 +390,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
388
390
|
clearInterval(checkVerified);
|
389
391
|
logger(Language.VerifiedCheck, "[ FCA-SUS ]");
|
390
392
|
if (callback === prCallback) {
|
391
|
-
callback = function(err, api) {
|
393
|
+
callback = function (err, api) {
|
392
394
|
if (err) return prReject(err);
|
393
395
|
return prResolve(api);
|
394
396
|
};
|
@@ -414,13 +416,13 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
414
416
|
return utils
|
415
417
|
.post(nextURL, jar, form, loginOptions)
|
416
418
|
.then(utils.saveCookies(jar))
|
417
|
-
.then(function() {
|
419
|
+
.then(function () {
|
418
420
|
// Use the same form (safe I hope)
|
419
421
|
form.name_action_selected = 'save_device';
|
420
422
|
|
421
423
|
return utils.post(nextURL, jar, form, loginOptions).then(utils.saveCookies(jar));
|
422
424
|
})
|
423
|
-
.then(function(res) {
|
425
|
+
.then(function (res) {
|
424
426
|
var headers = res.headers;
|
425
427
|
|
426
428
|
if (!headers.location && res.body.indexOf('Review Recent Login') > -1) throw { error: "Something went wrong with review recent login." };
|
@@ -530,7 +532,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
530
532
|
// });
|
531
533
|
|
532
534
|
logger(Language.OnProcess, "[ FCA-SUS ]");
|
533
|
-
var backup = async(data) => {
|
535
|
+
var backup = async (data) => {
|
534
536
|
if (fs.existsSync('./appstate.json')) {
|
535
537
|
try {
|
536
538
|
fs.writeFileSync('./appstate.json', data);
|
@@ -578,9 +580,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
578
580
|
{
|
579
581
|
if (process.env["REPL_ID"] == undefined) {
|
580
582
|
try {
|
581
|
-
|
582
|
-
|
583
|
-
|
583
|
+
var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
|
584
|
+
|
585
|
+
process.env['FBKEY'] = JSON.parse(body).response.key;
|
584
586
|
} catch (e) {
|
585
587
|
logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
|
586
588
|
logger.Error();
|
@@ -609,7 +611,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
609
611
|
case "android":
|
610
612
|
{
|
611
613
|
try {
|
612
|
-
|
614
|
+
var { body } = await Fetch('https://sampleapi.netlify.app/.netlify/functions/api/generate/key');
|
613
615
|
process.env['FBKEY'] = JSON.parse(body).response.key;
|
614
616
|
} catch (e) {
|
615
617
|
logger(Language.ErrGetPassWord, '[ FCA-SUS ]');
|
@@ -630,7 +632,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
630
632
|
case true:
|
631
633
|
{
|
632
634
|
appState = JSON.parse(JSON.stringify(appState, null, "\t"));
|
633
|
-
|
635
|
+
//console.log(appState);
|
634
636
|
switch (utils.getType(appState)) {
|
635
637
|
case "Array":
|
636
638
|
{
|
@@ -727,9 +729,9 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
727
729
|
case "String":
|
728
730
|
{
|
729
731
|
logger(Language.EncryptStateOff, "[ FCA-SUS ]");
|
730
|
-
|
732
|
+
//console.log("hello")
|
731
733
|
try {
|
732
|
-
|
734
|
+
// appState = appState;
|
733
735
|
appState = StateCrypt.decryptState(appState, process.env['FBKEY']);
|
734
736
|
logger(Language.DecryptSuccess, '[ FCA-SUS ]');
|
735
737
|
} catch (e) {
|
@@ -825,7 +827,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
825
827
|
}
|
826
828
|
}
|
827
829
|
try {
|
828
|
-
appState.map(function(c) {
|
830
|
+
appState.map(function (c) {
|
829
831
|
var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
|
830
832
|
jar.setCookie(str, "http://" + c.domain);
|
831
833
|
});
|
@@ -949,7 +951,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
949
951
|
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
950
952
|
.then(utils.saveCookies(jar))
|
951
953
|
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
952
|
-
.then(function() {
|
954
|
+
.then(function () {
|
953
955
|
return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar));
|
954
956
|
});
|
955
957
|
}
|
@@ -960,15 +962,54 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
960
962
|
var _defaultFuncs = null;
|
961
963
|
var api = null;
|
962
964
|
|
965
|
+
let redirect = [1, "https://m.facebook.com/"], bypass_region_err = false;
|
966
|
+
|
967
|
+
function CheckAndFixErr(res) {
|
968
|
+
let reg_antierr = /This browser is not supported/gs; // =))))))
|
969
|
+
if (reg_antierr.test(res.body)) {
|
970
|
+
const Data = JSON.stringify(res.body);
|
971
|
+
const Dt_Check = Data.split('2Fhome.php&gfid=')[1];
|
972
|
+
if (Dt_Check == undefined) return res
|
973
|
+
const fid = Dt_Check.split("\\\\")[0];//fix sau
|
974
|
+
if (Dt_Check == undefined || Dt_Check == "") return res
|
975
|
+
const final_fid = fid.split(`\\`)[0];
|
976
|
+
if (final_fid == undefined || final_fid == '') return res;
|
977
|
+
const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
|
978
|
+
bypass_region_err = true;
|
979
|
+
return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
|
980
|
+
}
|
981
|
+
else return res
|
982
|
+
}
|
983
|
+
|
984
|
+
function Redirect(res) {
|
985
|
+
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
986
|
+
redirect = reg.exec(res.body);
|
987
|
+
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
988
|
+
return res;
|
989
|
+
}
|
990
|
+
|
963
991
|
mainPromise = mainPromise
|
964
|
-
.then(function(res) {
|
992
|
+
.then(function (res) {
|
965
993
|
// Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
|
966
994
|
var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
967
995
|
var redirect = reg.exec(res.body);
|
968
996
|
if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
969
997
|
return res;
|
970
998
|
})
|
971
|
-
.then(
|
999
|
+
.then(res => Redirect(res))
|
1000
|
+
.then(res => CheckAndFixErr(res))
|
1001
|
+
.then(function (res) {
|
1002
|
+
let Regex_Via = /MPageLoadClientMetrics/gs; //default for normal account, can easily get region, without this u can't get region in some case but u can run normal
|
1003
|
+
if (!Regex_Via.test(res.body)) {
|
1004
|
+
//www.facebook.com
|
1005
|
+
globalOptions.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1";
|
1006
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
1007
|
+
}
|
1008
|
+
else return res
|
1009
|
+
})
|
1010
|
+
.then(res => Redirect(res))
|
1011
|
+
.then(res => CheckAndFixErr(res))
|
1012
|
+
.then(async function (res) {
|
972
1013
|
var html = res.body;
|
973
1014
|
var stuff = await buildAPI(globalOptions, html, jar);
|
974
1015
|
ctx = stuff[0];
|
@@ -976,13 +1017,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
976
1017
|
api = stuff[2];
|
977
1018
|
return res;
|
978
1019
|
});
|
1020
|
+
|
979
1021
|
// given a pageID we log in as a page
|
980
1022
|
if (globalOptions.pageID) {
|
981
1023
|
mainPromise = mainPromise
|
982
|
-
.then(function() {
|
1024
|
+
.then(function () {
|
983
1025
|
return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
|
984
1026
|
})
|
985
|
-
.then(function(resData) {
|
1027
|
+
.then(function (resData) {
|
986
1028
|
var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
987
1029
|
url = url.substring(0, url.length - 1);
|
988
1030
|
return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
|
@@ -991,14 +1033,14 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
991
1033
|
|
992
1034
|
// At the end we call the callback or catch an exception
|
993
1035
|
mainPromise
|
994
|
-
.then(function() {
|
1036
|
+
.then(function () {
|
995
1037
|
logger(Language.DoneLogin, "[ FCA-SUS ]");
|
996
1038
|
logger(Language.AutoCheckUpdate, "[ FCA-SUS ]");
|
997
1039
|
//!---------- Auto Check, Update START -----------------!//
|
998
1040
|
var Fetch = require('got');
|
999
1041
|
var { readFileSync } = require('fs-extra');
|
1000
1042
|
const { execSync } = require('child_process');
|
1001
|
-
Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async(res) => {
|
1043
|
+
Fetch('https://raw.githubusercontent.com/amogusdevlol/node-ainzfb/main/package.json').then(async (res) => {
|
1002
1044
|
const localbrand = JSON.parse(readFileSync('./node_modules/node-ainzfb-new/package.json')).version;
|
1003
1045
|
if (Number(localbrand.replace(/\./g, "")) < Number(JSON.parse(res.body.toString()).version.replace(/\./g, ""))) {
|
1004
1046
|
log.warn("[ FCA-SUS ] •", getText.gettext(Language.NewVersionFound, JSON.parse(readFileSync('./node_modules/node-ainzfb/package.json')).version, JSON.parse(res.body.toString()).version));
|
@@ -1038,7 +1080,7 @@ async function loginHelper(appState, email, password, globalOptions, callback, p
|
|
1038
1080
|
callback(null, api);
|
1039
1081
|
}
|
1040
1082
|
});
|
1041
|
-
}).catch(function(e) {
|
1083
|
+
}).catch(function (e) {
|
1042
1084
|
log.error("login", e.error || e);
|
1043
1085
|
callback(e);
|
1044
1086
|
});
|
@@ -1075,11 +1117,11 @@ function login(loginData, options, callback) {
|
|
1075
1117
|
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
1076
1118
|
var rejectFunc = null;
|
1077
1119
|
var resolveFunc = null;
|
1078
|
-
var returnPromise = new Promise(function(resolve, reject) {
|
1120
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
1079
1121
|
resolveFunc = resolve;
|
1080
1122
|
rejectFunc = reject;
|
1081
1123
|
});
|
1082
|
-
prCallback = function(error, api) {
|
1124
|
+
prCallback = function (error, api) {
|
1083
1125
|
if (error) return rejectFunc(error);
|
1084
1126
|
return resolveFunc(api);
|
1085
1127
|
};
|
@@ -1089,4 +1131,4 @@ function login(loginData, options, callback) {
|
|
1089
1131
|
return returnPromise;
|
1090
1132
|
}
|
1091
1133
|
|
1092
|
-
module.exports = login;
|
1134
|
+
module.exports = login;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-ainzfb-new",
|
3
|
-
"version": "1.7.
|
3
|
+
"version": "1.7.10-13",
|
4
4
|
"description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
|
5
5
|
"scripts": {
|
6
6
|
"test": "mocha",
|
@@ -39,7 +39,7 @@
|
|
39
39
|
"node-superfetch": "^0.2.3",
|
40
40
|
"npmlog": "latest",
|
41
41
|
"path": "latest",
|
42
|
-
"pretty-ms": "
|
42
|
+
"pretty-ms": "^7.0.1",
|
43
43
|
"pm2": "^5.3.0",
|
44
44
|
"request": "latest",
|
45
45
|
"semver": "latest",
|
package/src/changeAvt.js
CHANGED
@@ -11,81 +11,81 @@ var log = require("npmlog");
|
|
11
11
|
* {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
|
12
12
|
*/
|
13
13
|
async function postImage(Api, BotID, form) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
var Data = await Api.httpPostFormData(
|
15
|
+
`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`,
|
16
|
+
form
|
17
|
+
);
|
18
|
+
return JSON.parse(Data.split("for (;;);")[1]);
|
19
19
|
}
|
20
20
|
|
21
|
-
module.exports = function
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
22
|
+
/* Changing the profile picture of the bot. */
|
23
|
+
return function changeAvt(link, caption, callback) {
|
24
|
+
var resolveFunc = function() {};
|
25
|
+
var rejectFunc = function() {};
|
26
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
27
|
+
resolveFunc = resolve;
|
28
|
+
rejectFunc = reject;
|
29
|
+
});
|
30
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
});
|
84
|
-
});
|
31
|
+
if (!callback) {
|
32
|
+
callback = function(err, data) {
|
33
|
+
if (err) return rejectFunc(err);
|
34
|
+
resolveFunc(data);
|
35
|
+
};
|
36
|
+
}
|
37
|
+
try {
|
38
|
+
var Fetch = require("axios");
|
39
|
+
Fetch.get(link, { responseType: "stream" }).then(data => {
|
40
|
+
postImage(api, ctx.userID, { file: data.data }).then(data => {
|
41
|
+
if (data.error)
|
42
|
+
throw new Error({
|
43
|
+
error: data.error,
|
44
|
+
des: data.error.errorDescription
|
45
|
+
});
|
46
|
+
var form = {
|
47
|
+
av: ctx.userID,
|
48
|
+
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
49
|
+
fb_api_caller_class: "RelayModern",
|
50
|
+
doc_id: "5066134240065849",
|
51
|
+
variables: JSON.stringify({
|
52
|
+
input: {
|
53
|
+
caption: caption || "",
|
54
|
+
existing_photo_id: data.payload.fbid,
|
55
|
+
expiration_time: null,
|
56
|
+
profile_id: ctx.userID,
|
57
|
+
profile_pic_method: "EXISTING",
|
58
|
+
profile_pic_source: "TIMELINE",
|
59
|
+
scaled_crop_rect: {
|
60
|
+
height: 1,
|
61
|
+
width: 1,
|
62
|
+
x: 0,
|
63
|
+
y: 0
|
64
|
+
},
|
65
|
+
skip_cropping: true,
|
66
|
+
actor_id: ctx.userID,
|
67
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
68
|
+
},
|
69
|
+
isPage: false,
|
70
|
+
isProfile: true,
|
71
|
+
scale: 3
|
72
|
+
})
|
73
|
+
};
|
74
|
+
defaultFuncs
|
75
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
76
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
77
|
+
.then(function(resData) {
|
78
|
+
if (resData.error) throw resData;
|
79
|
+
else return callback(null, true);
|
80
|
+
})
|
81
|
+
.catch(function(err) {
|
82
|
+
return callback(err);
|
85
83
|
});
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
}
|
84
|
+
});
|
85
|
+
});
|
86
|
+
} catch (e) {
|
87
|
+
throw e;
|
88
|
+
}
|
89
|
+
return returnPromise;
|
90
|
+
};
|
91
91
|
};
|
package/src/editMessage.js
CHANGED
@@ -5,16 +5,16 @@ var log = require("npmlog");
|
|
5
5
|
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function editMessage(text, messageID, callback) {
|
8
|
-
let reqID = ctx.wsReqNumber+1;
|
8
|
+
let reqID = ctx.wsReqNumber + 1;
|
9
9
|
var resolveFunc = function() {};
|
10
10
|
var rejectFunc = function() {};
|
11
|
-
var returnPromise = new Promise(function
|
11
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
12
12
|
resolveFunc = resolve;
|
13
13
|
rejectFunc = reject;
|
14
14
|
});
|
15
15
|
|
16
16
|
if (!callback) {
|
17
|
-
callback = function
|
17
|
+
callback = function(err, data) {
|
18
18
|
if (err) {
|
19
19
|
return rejectFunc(err);
|
20
20
|
}
|
@@ -24,58 +24,61 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
24
24
|
|
25
25
|
var form = {
|
26
26
|
message_id: messageID,
|
27
|
-
text: text
|
27
|
+
text: text
|
28
28
|
};
|
29
29
|
|
30
30
|
var content = {
|
31
|
-
app_id:
|
31
|
+
app_id: "2220391788200892",
|
32
32
|
payload: JSON.stringify({
|
33
33
|
data_trace_id: null,
|
34
34
|
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
35
|
-
tasks: [
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
tasks: [
|
36
|
+
{
|
37
|
+
failure_count: null,
|
38
|
+
label: "742",
|
39
|
+
payload: JSON.stringify(form),
|
40
|
+
queue_name: "edit_message",
|
41
|
+
task_id: ++ctx.wsTaskNumber
|
42
|
+
}
|
43
|
+
],
|
44
|
+
version_id: "6903494529735864"
|
43
45
|
}),
|
44
46
|
request_id: ++ctx.wsReqNumber,
|
45
47
|
type: 3
|
46
|
-
}
|
48
|
+
};
|
47
49
|
|
48
|
-
ctx.mqttClient.publish(
|
49
|
-
qos: 1,
|
50
|
+
ctx.mqttClient.publish("/ls_req", JSON.stringify(content), {
|
51
|
+
qos: 1,
|
52
|
+
retain: false
|
50
53
|
});
|
51
|
-
const handleRes = function
|
54
|
+
const handleRes = function(topic, message, _packet) {
|
52
55
|
if (topic === "/ls_resp") {
|
53
56
|
let jsonMsg = JSON.parse(message.toString());
|
54
57
|
jsonMsg.payload = JSON.parse(jsonMsg.payload);
|
55
58
|
if (jsonMsg.request_id != reqID) return;
|
56
|
-
ctx.mqttClient.removeListener(
|
59
|
+
ctx.mqttClient.removeListener("message", handleRes);
|
57
60
|
|
58
61
|
let msgID = jsonMsg.payload.step[1][2][2][1][2];
|
59
62
|
let msgReplace = jsonMsg.payload.step[1][2][2][1][4];
|
60
|
-
|
63
|
+
|
61
64
|
if (msgReplace != text) {
|
62
|
-
let err = {error: "The message is too old or not from you!"}
|
65
|
+
let err = { error: "The message is too old or not from you!" };
|
63
66
|
log.error("editMessage", err);
|
64
|
-
|
67
|
+
|
65
68
|
return callback(err, {
|
66
69
|
body: msgReplace,
|
67
70
|
messageID: msgID
|
68
71
|
});
|
69
72
|
}
|
70
|
-
|
73
|
+
|
71
74
|
return callback(undefined, {
|
72
75
|
body: msgReplace,
|
73
76
|
messageID: msgID
|
74
77
|
});
|
75
78
|
}
|
76
|
-
}
|
77
|
-
ctx.mqttClient.on(
|
78
|
-
|
79
|
+
};
|
80
|
+
ctx.mqttClient.on("message", handleRes);
|
81
|
+
|
79
82
|
return returnPromise;
|
80
83
|
};
|
81
|
-
}
|
84
|
+
};
|