alicezetion 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/index.js +5 -2
  4. package/leiamnash/addExternalModule.js +6 -10
  5. package/leiamnash/addUserToGroup.js +16 -52
  6. package/leiamnash/changeAdminStatus.js +37 -69
  7. package/leiamnash/changeArchivedStatus.js +12 -26
  8. package/leiamnash/changeBio.js +6 -19
  9. package/leiamnash/changeBlockedStatus.js +3 -14
  10. package/leiamnash/changeGroupImage.js +16 -40
  11. package/leiamnash/changeNickname.js +11 -27
  12. package/leiamnash/changeThreadColor.js +10 -20
  13. package/leiamnash/changeThreadEmoji.js +10 -24
  14. package/leiamnash/chat.js +279 -414
  15. package/leiamnash/createNewGroup.js +12 -28
  16. package/leiamnash/createPoll.js +13 -25
  17. package/leiamnash/deleteMessage.js +12 -24
  18. package/leiamnash/deleteThread.js +11 -25
  19. package/leiamnash/forwardAttachment.js +13 -26
  20. package/leiamnash/forwardMessage.js +0 -0
  21. package/leiamnash/getCurrentUserID.js +1 -1
  22. package/leiamnash/getEmojiUrl.js +2 -4
  23. package/leiamnash/getFriendsList.js +10 -21
  24. package/leiamnash/getThreadHistory.js +58 -166
  25. package/leiamnash/getThreadHistoryDeprecated.js +20 -42
  26. package/leiamnash/getThreadInfo.js +25 -60
  27. package/leiamnash/getThreadInfoDeprecated.js +18 -42
  28. package/leiamnash/getThreadList.js +41 -66
  29. package/leiamnash/getThreadListDeprecated.js +14 -43
  30. package/leiamnash/getThreadPictures.js +17 -37
  31. package/leiamnash/getUserID.js +9 -14
  32. package/leiamnash/getUserInfo.js +12 -18
  33. package/leiamnash/handleFriendRequest.js +37 -52
  34. package/leiamnash/handleMessageRequest.js +14 -32
  35. package/leiamnash/httpGet.js +12 -17
  36. package/leiamnash/httpPost.js +12 -17
  37. package/leiamnash/listen.js +553 -0
  38. package/leiamnash/listenMqtt-Test.js +687 -0
  39. package/leiamnash/listenMqtt.js +1 -2
  40. package/leiamnash/logout.js +13 -20
  41. package/leiamnash/markAsDelivered.js +11 -22
  42. package/leiamnash/markAsRead.js +11 -21
  43. package/leiamnash/markAsReadAll.js +10 -20
  44. package/leiamnash/markAsSeen.js +7 -18
  45. package/leiamnash/muteThread.js +11 -18
  46. package/leiamnash/removeUserFromGroup.js +14 -48
  47. package/leiamnash/resolvePhotoUrl.js +8 -17
  48. package/leiamnash/searchForThread.js +10 -21
  49. package/leiamnash/sendTypingIndicator.js +14 -47
  50. package/leiamnash/setMessageReaction.js +12 -26
  51. package/leiamnash/setPostReaction.js +13 -26
  52. package/leiamnash/setTitle.js +13 -29
  53. package/leiamnash/threadColors.js +28 -44
  54. package/leiamnash/unfriend.js +9 -19
  55. package/leiamnash/unsendMessage.js +9 -19
  56. package/package.json +1 -1
  57. package/replit.nix +1 -3
  58. package/utils.js +0 -0
@@ -1 +1 @@
1
- {"nonce":6928808597510966173,"last_updated":{"seconds":1693007708,"nanos":164183000}}
1
+ {"nonce":4667484136687373514,"last_updated":{"seconds":1693008336,"nanos":139018000}}
@@ -1 +1 @@
1
- {"entries":{"replit.nix":{"env":{"AR":"ar","AS":"as","CC":"gcc","CONFIG_SHELL":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","CXX":"g++","HOST_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/q7hl931ry0vb2i3hn583qfdsd1zvjkmh-unzip-6.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","LD":"ld","LOCALE_ARCHIVE":"/usr/lib/locale/locale-archive","NIX_BINTOOLS":"/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1","NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_BUILD_CORES":"8","NIX_BUILD_TOP":"/tmp","NIX_CC":"/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0","NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_CFLAGS_COMPILE":" -frandom-seed=j90wwfwz47 -isystem /nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/include -isystem /nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/include","NIX_ENFORCE_NO_NATIVE":"1","NIX_HARDENING_ENABLE":"fortify stackprotector pic strictoverflow format relro bindnow","NIX_INDENT_MAKE":"1","NIX_LDFLAGS":"-rpath /nix/store/j90wwfwz4704lgl07g0gpahamm48dqqn-nix-shell/lib64 -rpath /nix/store/j90wwfwz4704lgl07g0gpahamm48dqqn-nix-shell/lib ","NIX_STORE":"/nix/store","NM":"nm","NODE_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/lib/node_modules","OBJCOPY":"objcopy","OBJDUMP":"objdump","PATH":"/nix/store/w07a7k61dw5gnsyxj3kgcq3shr76jax8-bash-interactive-4.4-p23/bin:/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin:/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0/bin:/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/bin:/nix/store/6z35qvn00xrjvaznv9kfy8xddbbdz4gl-glibc-2.33-47-bin/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1/bin:/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin:/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/q7hl931ry0vb2i3hn583qfdsd1zvjkmh-unzip-6.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","RANLIB":"ranlib","READELF":"readelf","SIZE":"size","SOURCE_DATE_EPOCH":"315532800","STRINGS":"strings","STRIP":"strip","XDG_DATA_DIRS":"/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/share","_":"/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin/env","__ETC_PROFILE_SOURCED":"1","buildInputs":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0 /nix/store/q7hl931ry0vb2i3hn583qfdsd1zvjkmh-unzip-6.0","builder":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","configureFlags":"","depsBuildBuild":"","depsBuildBuildPropagated":"","depsBuildTarget":"","depsBuildTargetPropagated":"","depsHostHost":"","depsHostHostPropagated":"","depsTargetTarget":"","depsTargetTargetPropagated":"","doCheck":"","doInstallCheck":"","name":"nix-shell","nativeBuildInputs":"","nobuildPhase":"echo\necho \"This derivation is not meant to be built, aborting\";\necho\nexit 1\n","out":"/nix/store/j90wwfwz4704lgl07g0gpahamm48dqqn-nix-shell","outputs":"out","patches":"","phases":"nobuildPhase","propagatedBuildInputs":"","propagatedNativeBuildInputs":"","shell":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","shellHook":"","stdenv":"/nix/store/r4bl79l2bdjawmr2rhhqvci56qh0fkvv-stdenv-linux","strictDeps":"","system":"x86_64-linux"},"dependencies":[{"path":"replit.nix","mod_time":"2023-08-25T22:29:07.968769314Z"}],"channel":"","channel_nix_path":""}}}
1
+ {"entries":{"replit.nix":{"env":{"AR":"ar","AS":"as","CC":"gcc","CONFIG_SHELL":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","CXX":"g++","HOST_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","LD":"ld","LOCALE_ARCHIVE":"/usr/lib/locale/locale-archive","NIX_BINTOOLS":"/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1","NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_BUILD_CORES":"8","NIX_BUILD_TOP":"/tmp","NIX_CC":"/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0","NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_CFLAGS_COMPILE":" -frandom-seed=wn4q3px71j -isystem /nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/include -isystem /nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/include","NIX_ENFORCE_NO_NATIVE":"1","NIX_HARDENING_ENABLE":"fortify stackprotector pic strictoverflow format relro bindnow","NIX_INDENT_MAKE":"1","NIX_LDFLAGS":"-rpath /nix/store/wn4q3px71j98mf9lcy14i6xlgmfhk75m-nix-shell/lib64 -rpath /nix/store/wn4q3px71j98mf9lcy14i6xlgmfhk75m-nix-shell/lib ","NIX_STORE":"/nix/store","NM":"nm","NODE_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/lib/node_modules","OBJCOPY":"objcopy","OBJDUMP":"objdump","PATH":"/nix/store/w07a7k61dw5gnsyxj3kgcq3shr76jax8-bash-interactive-4.4-p23/bin:/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin:/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0/bin:/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/bin:/nix/store/6z35qvn00xrjvaznv9kfy8xddbbdz4gl-glibc-2.33-47-bin/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1/bin:/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin:/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","RANLIB":"ranlib","READELF":"readelf","SIZE":"size","SOURCE_DATE_EPOCH":"315532800","STRINGS":"strings","STRIP":"strip","XDG_DATA_DIRS":"/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/share","_":"/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin/env","__ETC_PROFILE_SOURCED":"1","buildInputs":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0","builder":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","configureFlags":"","depsBuildBuild":"","depsBuildBuildPropagated":"","depsBuildTarget":"","depsBuildTargetPropagated":"","depsHostHost":"","depsHostHostPropagated":"","depsTargetTarget":"","depsTargetTargetPropagated":"","doCheck":"","doInstallCheck":"","name":"nix-shell","nativeBuildInputs":"","nobuildPhase":"echo\necho \"This derivation is not meant to be built, aborting\";\necho\nexit 1\n","out":"/nix/store/wn4q3px71j98mf9lcy14i6xlgmfhk75m-nix-shell","outputs":"out","patches":"","phases":"nobuildPhase","propagatedBuildInputs":"","propagatedNativeBuildInputs":"","shell":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","shellHook":"","stdenv":"/nix/store/r4bl79l2bdjawmr2rhhqvci56qh0fkvv-stdenv-linux","strictDeps":"","system":"x86_64-linux"},"dependencies":[{"path":"replit.nix","mod_time":"2023-08-26T00:05:17.951815802Z"}],"channel":"","channel_nix_path":""}}}
package/index.js CHANGED
@@ -94,6 +94,8 @@ function buildAPI(globalOptions, html, jar) {
94
94
  if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
95
95
 
96
96
  var userID = maybeCookie[0].cookieString().split("=")[1].toString();
97
+ //log.info("login", `Logged in as ${userID}`);
98
+
97
99
  try {
98
100
  clearInterval(checkVerified);
99
101
  } catch (_) {}
@@ -110,6 +112,7 @@ function buildAPI(globalOptions, html, jar) {
110
112
  irisSeqID = oldFBMQTTMatch[1];
111
113
  mqttEndpoint = oldFBMQTTMatch[2];
112
114
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
115
+ //log.info("login", `Got this account's message region: ${region}`);
113
116
  } else {
114
117
  let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
115
118
  if (newFBMQTTMatch) {
@@ -122,7 +125,6 @@ function buildAPI(globalOptions, html, jar) {
122
125
  mqttEndpoint = legacyFBMQTTMatch[4];
123
126
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
124
127
  log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
125
- log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
126
128
  } else {
127
129
  log.warn("login", "» Cannot get MQTT region & sequence ID.");
128
130
  log.error("login", "» Please try closing and reopening your browser window or get new fbstate.");
@@ -262,6 +264,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
262
264
  });
263
265
  // ---------- Very Hacky Part Ends -----------------
264
266
 
267
+ log.info("login", "Logging in...");
265
268
  return utils
266
269
  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
267
270
  .then(utils.saveCookies(jar))
@@ -363,7 +366,6 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
363
366
  JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
364
367
  } catch (ex) {
365
368
  clearInterval(checkVerified);
366
- log.info("login", "Verified from browser. Logging in...");
367
369
  if (callback === prCallback) {
368
370
  callback = function(err, api) {
369
371
  if (err) return prReject(err);
@@ -482,6 +484,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
482
484
  // At the end we call the callback or catch an exception
483
485
  mainPromise
484
486
  .then(function() {
487
+ //log.info("login", 'Done logging in.');
485
488
  return callback(null, api);
486
489
  })
487
490
  .catch(function(e) {
@@ -2,18 +2,14 @@
2
2
 
3
3
  const utils = require("../utils");
4
4
 
5
- module.exports = function(defaultFuncs, api, ctx) {
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
6
  return function addExternalModule(moduleObj) {
7
7
  if (utils.getType(moduleObj) == "Object") {
8
- for (let apiName in moduleObj) {
9
- if (utils.getType(moduleObj[apiName]) == "Function") {
10
- api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
11
- } else {
12
- throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
13
- }
14
- }
15
- } else {
16
- throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
8
+ for (let apiName in moduleObj) {
9
+ if (utils.getType(moduleObj[apiName]) == "Function") api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
10
+ else throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
11
+ }
17
12
  }
13
+ else throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
18
14
  };
19
15
  };
@@ -3,47 +3,27 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function addUserToGroup(userID, threadID, callback) {
8
- var resolveFunc = function(){};
9
- var rejectFunc = function(){};
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
10
  var returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
- if (
16
- !callback &&
17
- (utils.getType(threadID) === "Function" ||
18
- utils.getType(threadID) === "AsyncFunction")
19
- ) {
20
- throw { error: "please pass a threadID as a second argument." };
21
- }
15
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
22
16
 
23
17
  if (!callback) {
24
- callback = function(err) {
25
- if (err) {
26
- return rejectFunc(err);
27
- }
18
+ callback = function (err) {
19
+ if (err) return rejectFunc(err);
28
20
  resolveFunc();
29
21
  };
30
22
  }
31
23
 
32
- if (
33
- utils.getType(threadID) !== "Number" &&
34
- utils.getType(threadID) !== "String"
35
- ) {
36
- throw {
37
- error:
38
- "ThreadID should be of type Number or String and not " +
39
- utils.getType(threadID) +
40
- "."
41
- };
42
- }
24
+ if (utils.getType(threadID) !== "Number" && utils.getType(threadID) !== "String") throw { error: "ThreadID should be of type Number or String and not " + utils.getType(threadID) + "." };
43
25
 
44
- if (utils.getType(userID) !== "Array") {
45
- userID = [userID];
46
- }
26
+ if (utils.getType(userID) !== "Array") userID = [userID];
47
27
 
48
28
  var messageAndOTID = utils.generateOfflineThreadingID();
49
29
  var form = {
@@ -74,40 +54,24 @@ module.exports = function(defaultFuncs, api, ctx) {
74
54
  };
75
55
 
76
56
  for (var i = 0; i < userID.length; i++) {
77
- if (
78
- utils.getType(userID[i]) !== "Number" &&
79
- utils.getType(userID[i]) !== "String"
80
- ) {
81
- throw {
82
- error:
83
- "Elements of userID should be of type Number or String and not " +
84
- utils.getType(userID[i]) +
85
- "."
86
- };
87
- }
88
-
89
- form["log_message_data[added_participants][" + i + "]"] =
90
- "fbid:" + userID[i];
57
+ if (utils.getType(userID[i]) !== "Number" && utils.getType(userID[i]) !== "String") throw { error: "Elements of userID should be of type Number or String and not " + utils.getType(userID[i]) + "." };
58
+ form["log_message_data[added_participants][" + i + "]"] = "fbid:" + userID[i];
91
59
  }
92
60
 
93
61
  defaultFuncs
94
62
  .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
95
63
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
- .then(function(resData) {
97
- if (!resData) {
98
- throw { error: "Add to group failed." };
99
- }
100
- if (resData.error) {
101
- throw resData;
102
- }
64
+ .then(function (resData) {
65
+ if (!resData) throw { error: "Add to group failed." };
66
+ if (resData.error) throw resData;
103
67
 
104
68
  return callback();
105
69
  })
106
- .catch(function(err) {
107
- log.error("addUserToGroup", err);
70
+ .catch(function (err) {
71
+ log.error("addUserToGroup", "» Cannot add user to the voice chat. Please try again after");
108
72
  return callback(err);
109
73
  });
110
-
74
+
111
75
  return returnPromise;
112
76
  };
113
77
  };
@@ -1,79 +1,47 @@
1
1
  "use strict";
2
2
 
3
3
  const utils = require("../utils");
4
- const log = require("npmlog");
5
4
 
6
- module.exports = function(defaultFuncs, api, ctx) {
7
- return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
8
- if (utils.getType(threadID) !== "String") {
9
- throw {error: "changeAdminStatus: threadID must be a string"};
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function changeAdminStatus(threadID, adminID, adminStatus) {
7
+ if (utils.getType(threadID) !== "String") throw { error: "changeAdminStatus: threadID must be a string" };
8
+ if (utils.getType(adminID) !== "String" && utils.getType(adminID) !== "Array") throw { error: "changeAdminStatus: adminID must be a string or an array" };
9
+ if (utils.getType(adminStatus) !== "Boolean") throw { error: "changeAdminStatus: adminStatus must be true or false" };
10
+
11
+ let wsContent = {
12
+ request_id: 1,
13
+ type: 3,
14
+ payload: {
15
+ version_id: '3816854585040595',
16
+ tasks: [],
17
+ epoch_id: 6763184801413415579,
18
+ data_trace_id: null
19
+ },
20
+ app_id: '772021112871879'
10
21
  }
11
22
 
12
- if (utils.getType(adminIDs) === "String") {
13
- adminIDs = [adminIDs];
23
+ if (utils.getType(adminID) === "Array") {
24
+ for (let i = 0; i < adminID.length; i++) {
25
+ wsContent.payload.tasks.push({
26
+ label: '25',
27
+ payload: JSON.stringify({ thread_key: threadID, contact_id: adminID[i], is_admin: adminStatus }),
28
+ queue_name: 'admin_status',
29
+ task_id: i + 1,
30
+ failure_count: null
31
+ });
32
+ }
14
33
  }
15
-
16
- if (utils.getType(adminIDs) !== "Array") {
17
- throw {error: "changeAdminStatus: adminIDs must be an array or string"};
18
- }
19
-
20
- if (utils.getType(adminStatus) !== "Boolean") {
21
- throw {error: "changeAdminStatus: adminStatus must be a string"};
22
- }
23
-
24
- var resolveFunc = function(){};
25
- var rejectFunc = function(){};
26
- var returnPromise = new Promise(function (resolve, reject) {
27
- resolveFunc = resolve;
28
- rejectFunc = reject;
29
- });
30
-
31
- if (!callback) {
32
- callback = function (err) {
33
- if (err) {
34
- return rejectFunc(err);
35
- }
36
- resolveFunc();
37
- };
38
- }
39
-
40
- if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
41
- throw {error: "changeAdminStatus: callback is not a function"};
42
- }
43
-
44
- let form = {
45
- "thread_fbid": threadID,
46
- };
47
-
48
- let i = 0;
49
- for (let u of adminIDs) {
50
- form[`admin_ids[${i++}]`] = u;
34
+ else {
35
+ wsContent.payload.tasks.push({
36
+ label: '25',
37
+ payload: JSON.stringify({ thread_key: threadID, contact_id: adminID, is_admin: adminStatus }),
38
+ queue_name: 'admin_status',
39
+ task_id: 1,
40
+ failure_count: null
41
+ });
51
42
  }
52
- form["add"] = adminStatus;
53
43
 
54
- defaultFuncs
55
- .post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
56
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
- .then(function(resData) {
58
- if (resData.error) {
59
- switch (resData.error) {
60
- case 1976004:
61
- throw { error: "Cannot alter admin status: you are not an admin.", rawResponse: resData };
62
- case 1357031:
63
- throw { error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData };
64
- default:
65
- throw { error: "Cannot alter admin status: unknown error.", rawResponse: resData };
66
- }
67
- }
68
-
69
- callback();
70
- })
71
- .catch(function(err) {
72
- log.error("changeAdminStatus", err);
73
- return callback(err);
74
- });
75
-
76
- return returnPromise;
44
+ wsContent.payload = JSON.stringify(wsContent.payload);
45
+ return new Promise((resolve, reject) => ctx.mqttClient && ctx.mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => err ? reject(err) : resolve()));
77
46
  };
78
- };
79
-
47
+ };
@@ -3,53 +3,39 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeArchivedStatus(threadOrThreads, archive, callback) {
8
- var resolveFunc = function(){};
9
- var rejectFunc = function(){};
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
10
  var returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- callback = function(err) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
16
+ callback = function (err) {
17
+ if (err) return rejectFunc(err);
20
18
  resolveFunc();
21
19
  };
22
20
  }
23
21
 
24
22
  var form = {};
25
23
 
26
- if (utils.getType(threadOrThreads) === "Array") {
27
- for (var i = 0; i < threadOrThreads.length; i++) {
28
- form["ids[" + threadOrThreads[i] + "]"] = archive;
29
- }
30
- } else {
31
- form["ids[" + threadOrThreads + "]"] = archive;
32
- }
24
+ if (utils.getType(threadOrThreads) === "Array") for (var i = 0; i < threadOrThreads.length; i++) form["ids[" + threadOrThreads[i] + "]"] = archive;
25
+ else form["ids[" + threadOrThreads + "]"] = archive;
33
26
 
34
27
  defaultFuncs
35
- .post(
36
- "https://www.facebook.com/ajax/mercury/change_archived_status.php",
37
- ctx.jar,
38
- form
39
- )
28
+ .post("https://www.facebook.com/ajax/mercury/change_archived_status.php", ctx.jar, form)
40
29
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
41
- .then(function(resData) {
42
- if (resData.error) {
43
- throw resData;
44
- }
45
-
30
+ .then(function (resData) {
31
+ if (resData.error) throw resData;
46
32
  return callback();
47
33
  })
48
- .catch(function(err) {
34
+ .catch(function (err) {
49
35
  log.error("changeArchivedStatus", err);
50
36
  return callback(err);
51
37
  });
52
-
38
+
53
39
  return returnPromise;
54
40
  };
55
41
  };
@@ -13,22 +13,16 @@ module.exports = function (defaultFuncs, api, ctx) {
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") {
17
- callback = publish;
18
- } else {
16
+ if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") callback = publish;
17
+ else {
19
18
  callback = function (err) {
20
- if (err) {
21
- return rejectFunc(err);
22
- }
19
+ if (err) return rejectFunc(err);
23
20
  resolveFunc();
24
21
  };
25
22
  }
26
23
  }
27
24
 
28
- if (utils.getType(publish) != "Boolean") {
29
- publish = false;
30
- }
31
-
25
+ if (utils.getType(publish) != "Boolean") publish = false;
32
26
  if (utils.getType(bio) != "String") {
33
27
  bio = "";
34
28
  publish = false;
@@ -54,17 +48,10 @@ module.exports = function (defaultFuncs, api, ctx) {
54
48
  };
55
49
 
56
50
  defaultFuncs
57
- .post(
58
- "https://www.facebook.com/api/graphql/",
59
- ctx.jar,
60
- form
61
- )
51
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
62
52
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
63
53
  .then(function (resData) {
64
- if (resData.errors) {
65
- throw resData;
66
- }
67
-
54
+ if (resData.errors) throw resData;
68
55
  return callback();
69
56
  })
70
57
  .catch(function (err) {
@@ -14,28 +14,17 @@ module.exports = function (defaultFuncs, api, ctx) {
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
17
+ if (err) return rejectFunc(err);
20
18
  resolveFunc();
21
19
  };
22
20
  }
23
21
 
24
22
  defaultFuncs
25
- .post(
26
- `https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`,
27
- ctx.jar,
28
- {
29
- fbid: userID
30
- }
31
- )
23
+ .post(`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`, ctx.jar, { fbid: userID })
32
24
  .then(utils.saveCookies(ctx.jar))
33
25
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
26
  .then(function (resData) {
35
- if (resData.error) {
36
- throw resData;
37
- }
38
-
27
+ if (resData.error) throw resData;
39
28
  return callback();
40
29
  })
41
30
  .catch(function (err) {
@@ -4,7 +4,7 @@ var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
  var bluebird = require("bluebird");
6
6
 
7
- module.exports = function(defaultFuncs, api, ctx) {
7
+ module.exports = function (defaultFuncs, api, ctx) {
8
8
  function handleUpload(image, callback) {
9
9
  var uploads = [];
10
10
 
@@ -15,18 +15,10 @@ module.exports = function(defaultFuncs, api, ctx) {
15
15
 
16
16
  uploads.push(
17
17
  defaultFuncs
18
- .postFormData(
19
- "https://upload.facebook.com/ajax/mercury/upload.php",
20
- ctx.jar,
21
- form,
22
- {}
23
- )
18
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
24
19
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
25
- .then(function(resData) {
26
- if (resData.error) {
27
- throw resData;
28
- }
29
-
20
+ .then(function (resData) {
21
+ if (resData.error) throw resData;
30
22
  return resData.payload.metadata[0];
31
23
  })
32
24
  );
@@ -34,36 +26,26 @@ module.exports = function(defaultFuncs, api, ctx) {
34
26
  // resolve all promises
35
27
  bluebird
36
28
  .all(uploads)
37
- .then(function(resData) {
38
- callback(null, resData);
39
- })
40
- .catch(function(err) {
29
+ .then(resData => callback(null, resData))
30
+ .catch(function (err) {
41
31
  log.error("handleUpload", err);
42
32
  return callback(err);
43
33
  });
44
34
  }
45
35
 
46
36
  return function changeGroupImage(image, threadID, callback) {
47
- if (
48
- !callback &&
49
- (utils.getType(threadID) === "Function" ||
50
- utils.getType(threadID) === "AsyncFunction")
51
- ) {
52
- throw { error: "please pass a threadID as a second argument." };
53
- }
37
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
54
38
 
55
- var resolveFunc = function(){};
56
- var rejectFunc = function(){};
39
+ var resolveFunc = function () { };
40
+ var rejectFunc = function () { };
57
41
  var returnPromise = new Promise(function (resolve, reject) {
58
42
  resolveFunc = resolve;
59
43
  rejectFunc = reject;
60
44
  });
61
45
 
62
46
  if (!callback) {
63
- callback = function(err) {
64
- if (err) {
65
- return rejectFunc(err);
66
- }
47
+ callback = function (err) {
48
+ if (err) return rejectFunc(err);
67
49
  resolveFunc();
68
50
  };
69
51
  }
@@ -98,10 +80,8 @@ module.exports = function(defaultFuncs, api, ctx) {
98
80
  timestamp_time_passed: "0"
99
81
  };
100
82
 
101
- handleUpload(image, function(err, payload) {
102
- if (err) {
103
- return callback(err);
104
- }
83
+ handleUpload(image, function (err, payload) {
84
+ if (err) return callback(err);
105
85
 
106
86
  form["thread_image_id"] = payload[0]["image_id"];
107
87
  form["thread_id"] = threadID;
@@ -109,16 +89,12 @@ module.exports = function(defaultFuncs, api, ctx) {
109
89
  defaultFuncs
110
90
  .post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
111
91
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
112
- .then(function(resData) {
92
+ .then(function (resData) {
113
93
  // check for errors here
114
-
115
- if (resData.error) {
116
- throw resData;
117
- }
118
-
94
+ if (resData.error) throw resData;
119
95
  return callback();
120
96
  })
121
- .catch(function(err) {
97
+ .catch(function (err) {
122
98
  log.error("changeGroupImage", err);
123
99
  return callback(err);
124
100
  });
@@ -3,19 +3,17 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeNickname(nickname, threadID, participantID, callback) {
8
- var resolveFunc = function(){};
9
- var rejectFunc = function(){};
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
10
  var returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
  if (!callback) {
15
15
  callback = function (err) {
16
- if (err) {
17
- return rejectFunc(err);
18
- }
16
+ if (err) return rejectFunc(err);
19
17
  resolveFunc();
20
18
  };
21
19
  }
@@ -27,30 +25,16 @@ module.exports = function(defaultFuncs, api, ctx) {
27
25
  };
28
26
 
29
27
  defaultFuncs
30
- .post(
31
- "https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
32
- ctx.jar,
33
- form
34
- )
28
+ .post("https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1", ctx.jar, form)
35
29
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
- .then(function(resData) {
37
- if (resData.error === 1545014) {
38
- throw { error: "Trying to change nickname of user isn't in thread" };
39
- }
40
- if (resData.error === 1357031) {
41
- throw {
42
- error:
43
- "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname."
44
- };
45
- }
46
- if (resData.error) {
47
- throw resData;
48
- }
49
-
30
+ .then(function (resData) {
31
+ if (resData.error === 1545014) throw { error: "Trying to change nickname of user isn't in thread" };
32
+ if (resData.error === 1357031) throw { error: "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname." };
33
+ if (resData.error) throw resData;
50
34
  return callback();
51
35
  })
52
- .catch(function(err) {
53
- log.error("changeNickname", err);
36
+ .catch(function (err) {
37
+ log.error("changeNickname", "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname.");
54
38
  return callback(err);
55
39
  });
56
40