alicezetion 1.3.0 → 1.3.1

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 +1 -8
  4. package/leiamnash/addExternalModule.js +10 -6
  5. package/leiamnash/addUserToGroup.js +52 -16
  6. package/leiamnash/changeAdminStatus.js +69 -37
  7. package/leiamnash/changeArchivedStatus.js +26 -12
  8. package/leiamnash/changeBio.js +19 -6
  9. package/leiamnash/changeBlockedStatus.js +14 -3
  10. package/leiamnash/changeGroupImage.js +40 -16
  11. package/leiamnash/changeNickname.js +27 -11
  12. package/leiamnash/changeThreadColor.js +20 -10
  13. package/leiamnash/changeThreadEmoji.js +24 -10
  14. package/leiamnash/chat.js +414 -279
  15. package/leiamnash/createNewGroup.js +28 -12
  16. package/leiamnash/createPoll.js +25 -13
  17. package/leiamnash/deleteMessage.js +24 -12
  18. package/leiamnash/deleteThread.js +25 -11
  19. package/leiamnash/forwardAttachment.js +26 -13
  20. package/leiamnash/getCurrentUserID.js +1 -1
  21. package/leiamnash/getEmojiUrl.js +4 -2
  22. package/leiamnash/getFriendsList.js +21 -10
  23. package/leiamnash/getThreadHistory.js +166 -58
  24. package/leiamnash/getThreadHistoryDeprecated.js +42 -20
  25. package/leiamnash/getThreadInfo.js +60 -25
  26. package/leiamnash/getThreadInfoDeprecated.js +42 -18
  27. package/leiamnash/getThreadList.js +66 -41
  28. package/leiamnash/getThreadListDeprecated.js +43 -14
  29. package/leiamnash/getThreadPictures.js +37 -17
  30. package/leiamnash/getUserID.js +14 -9
  31. package/leiamnash/getUserInfo.js +18 -12
  32. package/leiamnash/handleFriendRequest.js +52 -37
  33. package/leiamnash/handleMessageRequest.js +32 -14
  34. package/leiamnash/httpGet.js +17 -12
  35. package/leiamnash/httpPost.js +17 -12
  36. package/leiamnash/listenMqtt.js +2 -1
  37. package/leiamnash/logout.js +20 -13
  38. package/leiamnash/markAsDelivered.js +22 -11
  39. package/leiamnash/markAsRead.js +21 -11
  40. package/leiamnash/markAsReadAll.js +20 -10
  41. package/leiamnash/markAsSeen.js +18 -7
  42. package/leiamnash/muteThread.js +18 -11
  43. package/leiamnash/removeUserFromGroup.js +48 -14
  44. package/leiamnash/resolvePhotoUrl.js +17 -8
  45. package/leiamnash/searchForThread.js +21 -10
  46. package/leiamnash/sendTypingIndicator.js +47 -14
  47. package/leiamnash/setMessageReaction.js +26 -12
  48. package/leiamnash/setPostReaction.js +26 -13
  49. package/leiamnash/setTitle.js +29 -13
  50. package/leiamnash/threadColors.js +44 -28
  51. package/leiamnash/unfriend.js +19 -9
  52. package/leiamnash/unsendMessage.js +19 -9
  53. package/package.json +1 -1
  54. package/replit.nix +3 -1
  55. package/utils.js +0 -0
  56. package/leiamnash/forwardMessage.js +0 -0
  57. package/leiamnash/listen.js +0 -553
  58. package/leiamnash/listenMqtt-Test.js +0 -687
@@ -1 +1 @@
1
- {"nonce":4049996291380312265,"last_updated":{"seconds":1693028251,"nanos":279943000}}
1
+ {"nonce":5049488879386018004,"last_updated":{"seconds":1693539698,"nanos":351700000}}
@@ -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/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":""}}}
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":""}}}
package/index.js CHANGED
@@ -94,8 +94,6 @@ 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
-
99
97
  try {
100
98
  clearInterval(checkVerified);
101
99
  } catch (_) {}
@@ -112,21 +110,18 @@ function buildAPI(globalOptions, html, jar) {
112
110
  irisSeqID = oldFBMQTTMatch[1];
113
111
  mqttEndpoint = oldFBMQTTMatch[2];
114
112
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
115
- //log.info("login", `Got this account's message region: ${region}`);
116
113
  } else {
117
114
  let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
118
115
  if (newFBMQTTMatch) {
119
116
  irisSeqID = newFBMQTTMatch[2];
120
117
  mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
121
118
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
122
- log.info("login", `Got this account's message region: ${region}`);
123
119
  } else {
124
120
  let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
125
121
  if (legacyFBMQTTMatch) {
126
122
  mqttEndpoint = legacyFBMQTTMatch[4];
127
123
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
128
124
  log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
129
- log.info("login", `Got this account's message region: ${region}`);
130
125
  log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
131
126
  } else {
132
127
  log.warn("login", "» Cannot get MQTT region & sequence ID.");
@@ -267,7 +262,6 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
267
262
  });
268
263
  // ---------- Very Hacky Part Ends -----------------
269
264
 
270
- log.info("login", "Logging in...");
271
265
  return utils
272
266
  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
273
267
  .then(utils.saveCookies(jar))
@@ -488,7 +482,6 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
488
482
  // At the end we call the callback or catch an exception
489
483
  mainPromise
490
484
  .then(function() {
491
- //log.info("login", 'Done logging in.');
492
485
  return callback(null, api);
493
486
  })
494
487
  .catch(function(e) {
@@ -515,7 +508,7 @@ function login(loginData, options, callback) {
515
508
  logRecordSize: defaultLogRecordSize,
516
509
  online: false,
517
510
  emitReady: false,
518
- userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
511
+ 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 [FBAN/FBIOS;FBAV/68.0.0.49.70;FBBV/41924288;FBRV/0;FBDV/iPhone9,4;FBMD/iPhone;FBSN/iOS;FBSV/9.3.5;FBSS/2;FBCR/carrier;FBID/phone;FBLC/en_US;FBOP/5]"
519
512
  };
520
513
 
521
514
  setOptions(globalOptions, options);
@@ -2,14 +2,18 @@
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") 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
- }
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)}!`);
12
17
  }
13
- else throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
14
18
  };
15
19
  };
@@ -3,27 +3,47 @@
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 (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
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
+ }
16
22
 
17
23
  if (!callback) {
18
- callback = function (err) {
19
- if (err) return rejectFunc(err);
24
+ callback = function(err) {
25
+ if (err) {
26
+ return rejectFunc(err);
27
+ }
20
28
  resolveFunc();
21
29
  };
22
30
  }
23
31
 
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) + "." };
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
+ }
25
43
 
26
- if (utils.getType(userID) !== "Array") userID = [userID];
44
+ if (utils.getType(userID) !== "Array") {
45
+ userID = [userID];
46
+ }
27
47
 
28
48
  var messageAndOTID = utils.generateOfflineThreadingID();
29
49
  var form = {
@@ -54,24 +74,40 @@ module.exports = function (defaultFuncs, api, ctx) {
54
74
  };
55
75
 
56
76
  for (var i = 0; i < userID.length; 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];
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];
59
91
  }
60
92
 
61
93
  defaultFuncs
62
94
  .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
63
95
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
64
- .then(function (resData) {
65
- if (!resData) throw { error: "Add to group failed." };
66
- if (resData.error) throw resData;
96
+ .then(function(resData) {
97
+ if (!resData) {
98
+ throw { error: "Add to group failed." };
99
+ }
100
+ if (resData.error) {
101
+ throw resData;
102
+ }
67
103
 
68
104
  return callback();
69
105
  })
70
- .catch(function (err) {
71
- log.error("addUserToGroup", "» Cannot add user to the voice chat. Please try again after");
106
+ .catch(function(err) {
107
+ log.error("addUserToGroup", err);
72
108
  return callback(err);
73
109
  });
74
-
110
+
75
111
  return returnPromise;
76
112
  };
77
113
  };
@@ -1,47 +1,79 @@
1
1
  "use strict";
2
2
 
3
3
  const utils = require("../utils");
4
+ const log = require("npmlog");
4
5
 
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'
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"};
21
10
  }
22
11
 
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
- }
12
+ if (utils.getType(adminIDs) === "String") {
13
+ adminIDs = [adminIDs];
33
14
  }
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
- });
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"};
42
22
  }
43
23
 
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()));
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;
51
+ }
52
+ form["add"] = adminStatus;
53
+
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;
46
77
  };
47
- };
78
+ };
79
+
@@ -3,39 +3,53 @@
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) return rejectFunc(err);
16
+ callback = function(err) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
18
20
  resolveFunc();
19
21
  };
20
22
  }
21
23
 
22
24
  var form = {};
23
25
 
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;
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
+ }
26
33
 
27
34
  defaultFuncs
28
- .post("https://www.facebook.com/ajax/mercury/change_archived_status.php", ctx.jar, form)
35
+ .post(
36
+ "https://www.facebook.com/ajax/mercury/change_archived_status.php",
37
+ ctx.jar,
38
+ form
39
+ )
29
40
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
- .then(function (resData) {
31
- if (resData.error) throw resData;
41
+ .then(function(resData) {
42
+ if (resData.error) {
43
+ throw resData;
44
+ }
45
+
32
46
  return callback();
33
47
  })
34
- .catch(function (err) {
48
+ .catch(function(err) {
35
49
  log.error("changeArchivedStatus", err);
36
50
  return callback(err);
37
51
  });
38
-
52
+
39
53
  return returnPromise;
40
54
  };
41
55
  };
@@ -13,16 +13,22 @@ module.exports = function (defaultFuncs, api, ctx) {
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") callback = publish;
17
- else {
16
+ if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") {
17
+ callback = publish;
18
+ } else {
18
19
  callback = function (err) {
19
- if (err) return rejectFunc(err);
20
+ if (err) {
21
+ return rejectFunc(err);
22
+ }
20
23
  resolveFunc();
21
24
  };
22
25
  }
23
26
  }
24
27
 
25
- if (utils.getType(publish) != "Boolean") publish = false;
28
+ if (utils.getType(publish) != "Boolean") {
29
+ publish = false;
30
+ }
31
+
26
32
  if (utils.getType(bio) != "String") {
27
33
  bio = "";
28
34
  publish = false;
@@ -48,10 +54,17 @@ module.exports = function (defaultFuncs, api, ctx) {
48
54
  };
49
55
 
50
56
  defaultFuncs
51
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
57
+ .post(
58
+ "https://www.facebook.com/api/graphql/",
59
+ ctx.jar,
60
+ form
61
+ )
52
62
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
53
63
  .then(function (resData) {
54
- if (resData.errors) throw resData;
64
+ if (resData.errors) {
65
+ throw resData;
66
+ }
67
+
55
68
  return callback();
56
69
  })
57
70
  .catch(function (err) {
@@ -14,17 +14,28 @@ module.exports = function (defaultFuncs, api, ctx) {
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) return rejectFunc(err);
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
18
20
  resolveFunc();
19
21
  };
20
22
  }
21
23
 
22
24
  defaultFuncs
23
- .post(`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`, ctx.jar, { fbid: userID })
25
+ .post(
26
+ `https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`,
27
+ ctx.jar,
28
+ {
29
+ fbid: userID
30
+ }
31
+ )
24
32
  .then(utils.saveCookies(ctx.jar))
25
33
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
26
34
  .then(function (resData) {
27
- if (resData.error) throw resData;
35
+ if (resData.error) {
36
+ throw resData;
37
+ }
38
+
28
39
  return callback();
29
40
  })
30
41
  .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,10 +15,18 @@ module.exports = function (defaultFuncs, api, ctx) {
15
15
 
16
16
  uploads.push(
17
17
  defaultFuncs
18
- .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
18
+ .postFormData(
19
+ "https://upload.facebook.com/ajax/mercury/upload.php",
20
+ ctx.jar,
21
+ form,
22
+ {}
23
+ )
19
24
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
20
- .then(function (resData) {
21
- if (resData.error) throw resData;
25
+ .then(function(resData) {
26
+ if (resData.error) {
27
+ throw resData;
28
+ }
29
+
22
30
  return resData.payload.metadata[0];
23
31
  })
24
32
  );
@@ -26,26 +34,36 @@ module.exports = function (defaultFuncs, api, ctx) {
26
34
  // resolve all promises
27
35
  bluebird
28
36
  .all(uploads)
29
- .then(resData => callback(null, resData))
30
- .catch(function (err) {
37
+ .then(function(resData) {
38
+ callback(null, resData);
39
+ })
40
+ .catch(function(err) {
31
41
  log.error("handleUpload", err);
32
42
  return callback(err);
33
43
  });
34
44
  }
35
45
 
36
46
  return function changeGroupImage(image, threadID, callback) {
37
- if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
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
+ }
38
54
 
39
- var resolveFunc = function () { };
40
- var rejectFunc = function () { };
55
+ var resolveFunc = function(){};
56
+ var rejectFunc = function(){};
41
57
  var returnPromise = new Promise(function (resolve, reject) {
42
58
  resolveFunc = resolve;
43
59
  rejectFunc = reject;
44
60
  });
45
61
 
46
62
  if (!callback) {
47
- callback = function (err) {
48
- if (err) return rejectFunc(err);
63
+ callback = function(err) {
64
+ if (err) {
65
+ return rejectFunc(err);
66
+ }
49
67
  resolveFunc();
50
68
  };
51
69
  }
@@ -80,8 +98,10 @@ module.exports = function (defaultFuncs, api, ctx) {
80
98
  timestamp_time_passed: "0"
81
99
  };
82
100
 
83
- handleUpload(image, function (err, payload) {
84
- if (err) return callback(err);
101
+ handleUpload(image, function(err, payload) {
102
+ if (err) {
103
+ return callback(err);
104
+ }
85
105
 
86
106
  form["thread_image_id"] = payload[0]["image_id"];
87
107
  form["thread_id"] = threadID;
@@ -89,12 +109,16 @@ module.exports = function (defaultFuncs, api, ctx) {
89
109
  defaultFuncs
90
110
  .post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
91
111
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
92
- .then(function (resData) {
112
+ .then(function(resData) {
93
113
  // check for errors here
94
- if (resData.error) throw resData;
114
+
115
+ if (resData.error) {
116
+ throw resData;
117
+ }
118
+
95
119
  return callback();
96
120
  })
97
- .catch(function (err) {
121
+ .catch(function(err) {
98
122
  log.error("changeGroupImage", err);
99
123
  return callback(err);
100
124
  });
@@ -3,17 +3,19 @@
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) return rejectFunc(err);
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
17
19
  resolveFunc();
18
20
  };
19
21
  }
@@ -25,16 +27,30 @@ module.exports = function (defaultFuncs, api, ctx) {
25
27
  };
26
28
 
27
29
  defaultFuncs
28
- .post("https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1", ctx.jar, form)
30
+ .post(
31
+ "https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
32
+ ctx.jar,
33
+ form
34
+ )
29
35
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
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;
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
+
34
50
  return callback();
35
51
  })
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.");
52
+ .catch(function(err) {
53
+ log.error("changeNickname", err);
38
54
  return callback(err);
39
55
  });
40
56