alicezetion 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -0
  2. package/.cache/replit/modules.stamp +0 -0
  3. package/.cache/replit/nix/env.json +1 -0
  4. package/.travis.yml +6 -0
  5. package/README.md +40 -0
  6. package/alice/add.js +99 -0
  7. package/alice/admin.js +65 -0
  8. package/alice/archive.js +41 -0
  9. package/alice/block.js +72 -0
  10. package/alice/chat.js +415 -0
  11. package/alice/color.js +53 -0
  12. package/alice/deletegc.js +43 -0
  13. package/alice/deletemsg.js +43 -0
  14. package/alice/delivered.js +41 -0
  15. package/alice/emoji.js +41 -0
  16. package/alice/emojiurl.js +29 -0
  17. package/alice/forward.js +47 -0
  18. package/alice/friend.js +70 -0
  19. package/alice/gchistorydeprecated.js +76 -0
  20. package/alice/gcimage.js +115 -0
  21. package/alice/gcimg.js +66 -0
  22. package/alice/gcinfo.js +170 -0
  23. package/alice/gcinfodeprecated.js +65 -0
  24. package/alice/gclist.js +220 -0
  25. package/alice/gclistdeprecated.js +75 -0
  26. package/alice/gcolor.js +22 -0
  27. package/alice/gcsearch.js +39 -0
  28. package/alice/history.js +632 -0
  29. package/alice/id.js +7 -0
  30. package/alice/kick.js +65 -0
  31. package/alice/listen.js +553 -0
  32. package/alice/listenMqtt.js +560 -0
  33. package/alice/logout.js +59 -0
  34. package/alice/msgrequest.js +51 -0
  35. package/alice/mute.js +38 -0
  36. package/alice/nickname.js +44 -0
  37. package/alice/poll.js +55 -0
  38. package/alice/react.js +82 -0
  39. package/alice/read.js +52 -0
  40. package/alice/resolveimgurl.js +31 -0
  41. package/alice/seen.js +36 -0
  42. package/alice/title.js +73 -0
  43. package/alice/typeindicator.js +77 -0
  44. package/alice/unsend.js +35 -0
  45. package/alice/userid.js +52 -0
  46. package/alice/userinfo.js +57 -0
  47. package/index.js +423 -0
  48. package/package.json +70 -0
  49. package/utils.js +1283 -0
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function changeNickname(nickname, threadID, participantID, callback) {
8
+ callback = callback || function() {};
9
+
10
+ var form = {
11
+ nickname: nickname,
12
+ participant_id: participantID,
13
+ thread_or_other_fbid: threadID
14
+ };
15
+
16
+ defaultFuncs
17
+ .post(
18
+ "https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
19
+ ctx.jar,
20
+ form
21
+ )
22
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
23
+ .then(function(resData) {
24
+ if (resData.error === 1545014) {
25
+ throw { error: "Trying to change nickname of user isn't in thread" };
26
+ }
27
+ if (resData.error === 1357031) {
28
+ throw {
29
+ error:
30
+ "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."
31
+ };
32
+ }
33
+ if (resData.error) {
34
+ throw resData;
35
+ }
36
+
37
+ return callback();
38
+ })
39
+ .catch(function(err) {
40
+ log.error("changeNickname", err);
41
+ return callback(err);
42
+ });
43
+ };
44
+ };
package/alice/poll.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function createPoll(title, threadID, options, callback) {
8
+ if (!callback) {
9
+ if (utils.getType(options) == "Function") {
10
+ callback = options;
11
+ } else {
12
+ callback = function() {};
13
+ }
14
+ }
15
+ if (!options) {
16
+ options = {}; // Initial poll options are optional
17
+ }
18
+
19
+ var form = {
20
+ target_id: threadID,
21
+ question_text: title
22
+ };
23
+
24
+ // Set fields for options (and whether they are selected initially by the posting user)
25
+ var ind = 0;
26
+ for (var opt in options) {
27
+ if (options.hasOwnProperty(opt)) {
28
+ form["option_text_array[" + ind + "]"] = opt;
29
+ form["option_is_selected_array[" + ind + "]"] = options[opt]
30
+ ? "1"
31
+ : "0";
32
+ ind++;
33
+ }
34
+ }
35
+
36
+ defaultFuncs
37
+ .post(
38
+ "https://www.facebook.com/messaging/group_polling/create_poll/?dpr=1",
39
+ ctx.jar,
40
+ form
41
+ )
42
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
43
+ .then(function(resData) {
44
+ if (resData.payload.status != "success") {
45
+ throw resData;
46
+ }
47
+
48
+ return callback();
49
+ })
50
+ .catch(function(err) {
51
+ log.error("createPoll", err);
52
+ return callback(err);
53
+ });
54
+ };
55
+ };
package/alice/react.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function setMessageReaction(reaction, messageID, callback) {
8
+ if (!callback) {
9
+ callback = function() {};
10
+ }
11
+
12
+ switch (reaction) {
13
+ case ":heart_eyes:":
14
+ case ":love:":
15
+ reaction = "\uD83D\uDE0D";
16
+ break;
17
+ case ":laughing:":
18
+ case ":haha:":
19
+ reaction = "\uD83D\uDE06";
20
+ break;
21
+ case ":open_mouth:":
22
+ case ":wow:":
23
+ reaction = "\uD83D\uDE2E";
24
+ break;
25
+ case ":cry:":
26
+ case ":sad:":
27
+ reaction = "\uD83D\uDE22";
28
+ break;
29
+ case ":angry:":
30
+ reaction = "\uD83D\uDE20";
31
+ break;
32
+ case ":thumbsup:":
33
+ case ":like:":
34
+ reaction = "\uD83D\uDC4D";
35
+ break;
36
+ case ":thumbsdown:":
37
+ case ":dislike:":
38
+ reaction = "\uD83D\uDC4E";
39
+ break;
40
+ default:
41
+ break;
42
+ }
43
+
44
+ var variables = {
45
+ data: {
46
+ client_mutation_id: ctx.clientMutationId++,
47
+ actor_id: ctx.userID,
48
+ action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
49
+ message_id: messageID,
50
+ reaction: reaction
51
+ }
52
+ };
53
+
54
+ var qs = {
55
+ doc_id: "1491398900900362",
56
+ variables: JSON.stringify(variables),
57
+ dpr: 1
58
+ };
59
+
60
+ defaultFuncs
61
+ .postFormData(
62
+ "https://www.facebook.com/webgraphql/mutation/",
63
+ ctx.jar,
64
+ {},
65
+ qs
66
+ )
67
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
68
+ .then(function(resData) {
69
+ if (!resData) {
70
+ throw { error: "setReaction returned empty object." };
71
+ }
72
+ if (resData.error) {
73
+ throw resData;
74
+ }
75
+ callback(null);
76
+ })
77
+ .catch(function(err) {
78
+ log.error("setReaction", err);
79
+ return callback(err);
80
+ });
81
+ };
82
+ };
package/alice/read.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function markAsRead(threadID, read, callback) {
8
+ if (utils.getType(read) === 'Function' || utils.getType(read) === 'AsyncFunction') {
9
+ callback = read;
10
+ read = true;
11
+ }
12
+ if (read == undefined) {
13
+ read = true;
14
+ }
15
+ if (!callback) {
16
+ callback = function() {};
17
+ }
18
+
19
+ var form = {};
20
+
21
+ if (typeof ctx.globalOptions.pageID !== 'undefined') {
22
+ form["source"] = "PagesManagerMessagesInterface";
23
+ form["request_user_id"] = ctx.globalOptions.pageID;
24
+ }
25
+
26
+ form["ids[" + threadID + "]"] = read;
27
+ form["watermarkTimestamp"] = new Date().getTime();
28
+ form["shouldSendReadReceipt"] = true;
29
+ form["commerce_last_message_type"] = "non_ad";
30
+ form["titanOriginatedThreadId"] = utils.generateThreadingID(ctx.clientID);
31
+
32
+ defaultFuncs
33
+ .post(
34
+ "https://www.facebook.com/ajax/mercury/change_read_status.php",
35
+ ctx.jar,
36
+ form
37
+ )
38
+ .then(utils.saveCookies(ctx.jar))
39
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
40
+ .then(function(resData) {
41
+ if (resData.error) {
42
+ throw resData;
43
+ }
44
+
45
+ return callback();
46
+ })
47
+ .catch(function(err) {
48
+ log.error("markAsRead", err);
49
+ return callback(err);
50
+ });
51
+ };
52
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function resolvePhotoUrl(photoID, callback) {
8
+ if (!callback) {
9
+ throw { error: "resolvePhotoUrl: need callback" };
10
+ }
11
+
12
+ defaultFuncs
13
+ .get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
14
+ photo_id: photoID
15
+ })
16
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
17
+ .then(resData => {
18
+ if (resData.error) {
19
+ throw resData;
20
+ }
21
+
22
+ var photoUrl = resData.jsmods.require[0][3][0];
23
+
24
+ return callback(null, photoUrl);
25
+ })
26
+ .catch(err => {
27
+ log.error("resolvePhotoUrl", err);
28
+ return callback(err);
29
+ });
30
+ };
31
+ };
package/alice/seen.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function markAsReadAll(callback) {
8
+ if (!callback) {
9
+ callback = function() {};
10
+ }
11
+
12
+ var form = {
13
+ folder: 'inbox'
14
+ };
15
+
16
+ defaultFuncs
17
+ .post(
18
+ "https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
19
+ ctx.jar,
20
+ form
21
+ )
22
+ .then(utils.saveCookies(ctx.jar))
23
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
+ .then(function(resData) {
25
+ if (resData.error) {
26
+ throw resData;
27
+ }
28
+
29
+ return callback();
30
+ })
31
+ .catch(function(err) {
32
+ log.error("markAsReadAll", err);
33
+ return callback(err);
34
+ });
35
+ };
36
+ };
package/alice/title.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function setTitle(newTitle, threadID, callback) {
8
+ if (
9
+ !callback &&
10
+ (utils.getType(threadID) === "Function" ||
11
+ utils.getType(threadID) === "AsyncFunction")
12
+ ) {
13
+ throw { error: "please pass a threadID as a second argument." };
14
+ }
15
+
16
+ if (!callback) {
17
+ callback = function() {};
18
+ }
19
+
20
+ var messageAndOTID = utils.generateOfflineThreadingID();
21
+ var form = {
22
+ client: "mercury",
23
+ action_type: "ma-type:log-message",
24
+ author: "fbid:" + ctx.userID,
25
+ thread_id: "",
26
+ author_email: "",
27
+ coordinates: "",
28
+ timestamp: Date.now(),
29
+ timestamp_absolute: "Today",
30
+ timestamp_relative: utils.generateTimestampRelative(),
31
+ timestamp_time_passed: "0",
32
+ is_unread: false,
33
+ is_cleared: false,
34
+ is_forward: false,
35
+ is_filtered_content: false,
36
+ is_spoof_warning: false,
37
+ source: "source:chat:web",
38
+ "source_tags[0]": "source:chat",
39
+ status: "0",
40
+ offline_threading_id: messageAndOTID,
41
+ message_id: messageAndOTID,
42
+ threading_id: utils.generateThreadingID(ctx.clientID),
43
+ manual_retry_cnt: "0",
44
+ thread_fbid: threadID,
45
+ thread_name: newTitle,
46
+ thread_id: threadID,
47
+ log_message_type: "log:thread-name"
48
+ };
49
+
50
+ defaultFuncs
51
+ .post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
52
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
53
+ .then(function(resData) {
54
+ if (resData.error && resData.error === 1545012) {
55
+ throw { error: "Cannot change chat title: Not member of chat." };
56
+ }
57
+
58
+ if (resData.error && resData.error === 1545003) {
59
+ throw { error: "Cannot set title of single-user chat." };
60
+ }
61
+
62
+ if (resData.error) {
63
+ throw resData;
64
+ }
65
+
66
+ return callback();
67
+ })
68
+ .catch(function(err) {
69
+ log.error("setTitle", err);
70
+ return callback(err);
71
+ });
72
+ };
73
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ function makeTypingIndicator(typ, threadID, callback) {
8
+ var form = {
9
+ typ: +typ,
10
+ to: "",
11
+ source: "mercury-chat",
12
+ thread: threadID
13
+ };
14
+
15
+ // Check if thread is a single person chat or a group chat
16
+ // More info on this is in api.sendMessage
17
+ api.getUserInfo(threadID, function(err, res) {
18
+ if (err) {
19
+ return callback(err);
20
+ }
21
+
22
+ // If id is single person chat
23
+ if (Object.keys(res).length > 0) {
24
+ form.to = threadID;
25
+ }
26
+
27
+ defaultFuncs
28
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
29
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
+ .then(function(resData) {
31
+ if (resData.error) {
32
+ throw resData;
33
+ }
34
+
35
+ return callback();
36
+ })
37
+ .catch(function(err) {
38
+ log.error("sendTypingIndicator", err);
39
+ return callback(err);
40
+ });
41
+ });
42
+ }
43
+
44
+ return function sendTypingIndicator(threadID, callback) {
45
+ if (
46
+ utils.getType(callback) !== "Function" &&
47
+ utils.getType(callback) !== "AsyncFunction"
48
+ ) {
49
+ if (callback) {
50
+ log.warn(
51
+ "sendTypingIndicator",
52
+ "callback is not a function - ignoring."
53
+ );
54
+ }
55
+ callback = () => {};
56
+ }
57
+
58
+ makeTypingIndicator(true, threadID, callback);
59
+
60
+ return function end(cb) {
61
+ if (
62
+ utils.getType(cb) !== "Function" &&
63
+ utils.getType(cb) !== "AsyncFunction"
64
+ ) {
65
+ if (cb) {
66
+ log.warn(
67
+ "sendTypingIndicator",
68
+ "callback is not a function - ignoring."
69
+ );
70
+ }
71
+ cb = () => {};
72
+ }
73
+
74
+ makeTypingIndicator(false, threadID, cb);
75
+ };
76
+ };
77
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, bot, ctx) {
7
+ return function unsendMessage(messageID, callback) {
8
+ if (!callback) {
9
+ callback = function() {};
10
+ }
11
+
12
+ var form = {
13
+ message_id: messageID
14
+ };
15
+
16
+ defaultFuncs
17
+ .post(
18
+ "https://www.facebook.com/messaging/unsend_message/",
19
+ ctx.jar,
20
+ form
21
+ )
22
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
23
+ .then(function(resData) {
24
+ if (resData.error) {
25
+ throw resData;
26
+ }
27
+
28
+ return callback();
29
+ })
30
+ .catch(function(err) {
31
+ log.error("unsendMessage", err);
32
+ return callback(err);
33
+ });
34
+ };
35
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ function formatData(data) {
7
+ return {
8
+ userID: utils.formatID(data.uid.toString()),
9
+ photoUrl: data.photo,
10
+ indexRank: data.index_rank,
11
+ name: data.text,
12
+ isVerified: data.is_verified,
13
+ profileUrl: data.path,
14
+ category: data.category,
15
+ score: data.score,
16
+ type: data.type
17
+ };
18
+ }
19
+
20
+ module.exports = function(defaultFuncs, bot, ctx) {
21
+ return function getUserID(name, callback) {
22
+ if (!callback) {
23
+ throw { error: "getUserID: need callback" };
24
+ }
25
+
26
+ var form = {
27
+ value: name.toLowerCase(),
28
+ viewer: ctx.userID,
29
+ rsp: "search",
30
+ context: "search",
31
+ path: "/home.php",
32
+ request_id: utils.getGUID()
33
+ };
34
+
35
+ defaultFuncs
36
+ .get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
37
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
38
+ .then(function(resData) {
39
+ if (resData.error) {
40
+ throw resData;
41
+ }
42
+
43
+ var data = resData.payload.entries;
44
+
45
+ callback(null, data.map(formatData));
46
+ })
47
+ .catch(function(err) {
48
+ log.error("getUserID", err);
49
+ return callback(err);
50
+ });
51
+ };
52
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ function formatData(data) {
7
+ var retObj = {};
8
+
9
+ for (var prop in data) {
10
+ if (data.hasOwnProperty(prop)) {
11
+ var innerObj = data[prop];
12
+ retObj[prop] = {
13
+ name: innerObj.name,
14
+ firstName: innerObj.firstName,
15
+ vanity: innerObj.vanity,
16
+ thumbSrc: innerObj.thumbSrc,
17
+ profileUrl: innerObj.uri,
18
+ gender: innerObj.gender,
19
+ type: innerObj.type,
20
+ isFriend: innerObj.is_friend,
21
+ isBirthday: !!innerObj.is_birthday
22
+ };
23
+ }
24
+ }
25
+
26
+ return retObj;
27
+ }
28
+
29
+ module.exports = function(defaultFuncs, bot, ctx) {
30
+ return function getUserInfo(id, callback) {
31
+ if (!callback) {
32
+ throw { error: "getUserInfo: need callback" };
33
+ }
34
+
35
+ if (utils.getType(id) !== "Array") {
36
+ id = [id];
37
+ }
38
+
39
+ var form = {};
40
+ id.map(function(v, i) {
41
+ form["ids[" + i + "]"] = v;
42
+ });
43
+ defaultFuncs
44
+ .post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
45
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
46
+ .then(function(resData) {
47
+ if (resData.error) {
48
+ throw resData;
49
+ }
50
+ return callback(null, formatData(resData.payload.profiles));
51
+ })
52
+ .catch(function(err) {
53
+ log.error("getUserInfo", err);
54
+ return callback(err);
55
+ });
56
+ };
57
+ };