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
package/index.js ADDED
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+
3
+ var utils = require("./utils");
4
+ var cheerio = require("cheerio");
5
+ var log = require("npmlog");
6
+
7
+ var defaultLogRecordSize = 100;
8
+ log.maxRecordSize = defaultLogRecordSize;
9
+
10
+ function setOptions(globalOptions, options) {
11
+ Object.keys(options).map(function(key) {
12
+ switch (key) {
13
+ case 'logLevel':
14
+ log.level = options.logLevel;
15
+ globalOptions.logLevel = options.logLevel;
16
+ break;
17
+ case 'logRecordSize':
18
+ log.maxRecordSize = options.logRecordSize;
19
+ globalOptions.logRecordSize = options.logRecordSize;
20
+ break;
21
+ case 'selfListen':
22
+ globalOptions.selfListen = options.selfListen;
23
+ break;
24
+ case 'listenEvents':
25
+ globalOptions.listenEvents = options.listenEvents;
26
+ break;
27
+ case 'pageID':
28
+ globalOptions.pageID = options.pageID.toString();
29
+ break;
30
+ case 'updatePresence':
31
+ globalOptions.updatePresence = options.updatePresence;
32
+ break;
33
+ case 'forceLogin':
34
+ globalOptions.forceLogin = options.forceLogin;
35
+ break;
36
+ case 'userAgent':
37
+ globalOptions.userAgent = options.userAgent;
38
+ break;
39
+ case 'autoMarkDelivery':
40
+ globalOptions.autoMarkDelivery = options.autoMarkDelivery;
41
+ break;
42
+ case 'autoMarkRead':
43
+ globalOptions.autoMarkRead = options.autoMarkRead;
44
+ break;
45
+ default:
46
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
47
+ break;
48
+ }
49
+ });
50
+ }
51
+
52
+ function buildAPI(globalOptions, html, jar) {
53
+ var maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
54
+ return val.cookieString().split("=")[0] === "c_user";
55
+ });
56
+
57
+ if(maybeCookie.length === 0) {
58
+ throw {error: "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify."};
59
+ }
60
+
61
+ var userID = maybeCookie[0].cookieString().split("=")[1].toString();
62
+ log.info("login", "Logged in");
63
+
64
+ var clientID = (Math.random() * 2147483648 | 0).toString(16);
65
+
66
+ // All data available to api functions
67
+ var ctx = {
68
+ userID: userID,
69
+ jar: jar,
70
+ clientID: clientID,
71
+ globalOptions: globalOptions,
72
+ loggedIn: true,
73
+ access_token: 'NONE',
74
+ clientMutationId: 0,
75
+ mqttClient: undefined,
76
+ lastSeqId: 0,
77
+ syncToken: undefined
78
+ };
79
+
80
+ var bot = {
81
+ setOptions: setOptions.bind(null, globalOptions),
82
+ getAppState: function getAppState() {
83
+ return utils.getAppState(jar);
84
+ },
85
+ };
86
+
87
+ const apiFuncNames = [
88
+ "add",
89
+ "admin",
90
+ "archive",
91
+ "block",
92
+ "chat",
93
+ "color",
94
+ "deletegc",
95
+ "deletemsg",
96
+ "delivered",
97
+ "emoji",
98
+ "emojiurl",
99
+ "forward",
100
+ "friend",
101
+ "gchistorydeprecated",
102
+ "gcimage",
103
+ "gcimg",
104
+ "gcinfo",
105
+ "gcinfodeprecated",
106
+ "gclist",
107
+ "gclistdeprecated",
108
+ "gcolor",
109
+ "gcsearch",
110
+ "history",
111
+ "id",
112
+ "kick",
113
+ "listen",
114
+ "listenMqtt",
115
+ "logout",
116
+ "magrequest",
117
+ "mute",
118
+ "nickname",
119
+ "poll",
120
+ "react",
121
+ "read",
122
+ "resolveimgurl",
123
+ "seen",
124
+ "title",
125
+ "typeindicator",
126
+ "unsend",
127
+ "userid",
128
+ "userinfo"
129
+ ];
130
+
131
+ var defaultFuncs = utils.makeDefaults(html, userID, ctx);
132
+
133
+ // Load all api functions in a loop
134
+ apiFuncNames.map(function(v) {
135
+ bot[v] = require('./alice/' + v)(defaultFuncs, bot, ctx);
136
+ });
137
+
138
+ return [ctx, defaultFuncs, bot];
139
+ }
140
+
141
+ function makeLogin(jar, email, password, loginOptions, callback) {
142
+ return function(res) {
143
+ var html = res.body;
144
+ var $ = cheerio.load(html);
145
+ var arr = [];
146
+
147
+ // This will be empty, but just to be sure we leave it
148
+ $("#login_form input").map(function(i, v){
149
+ arr.push({val: $(v).val(), name: $(v).attr("name")});
150
+ });
151
+
152
+ arr = arr.filter(function(v) {
153
+ return v.val && v.val.length;
154
+ });
155
+
156
+ var form = utils.arrToForm(arr);
157
+ form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
158
+ form.lgndim = Buffer.from("{\"w\":1440,\"h\":900,\"aw\":1440,\"ah\":834,\"c\":24}").toString('base64');
159
+ form.email = email;
160
+ form.pass = password;
161
+ form.default_persistent = '0';
162
+ form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
163
+ form.locale = 'fil_PH';
164
+ form.timezone = '240';
165
+ form.lgnjs = ~~(Date.now() / 1000);
166
+
167
+
168
+ // Getting cookies from the HTML page... (kill me now plz)
169
+ // we used to get a bunch of cookies in the headers of the response of the
170
+ // request, but FB changed and they now send those cookies inside the JS.
171
+ // They run the JS which then injects the cookies in the page.
172
+ // The "solution" is to parse through the html and find those cookies
173
+ // which happen to be conveniently indicated with a _js_ in front of their
174
+ // variable name.
175
+ //
176
+ // ---------- Very Hacky Part Starts -----------------
177
+ var willBeCookies = html.split("\"_js_");
178
+ willBeCookies.slice(1).map(function(val) {
179
+ var cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
180
+ jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
181
+ });
182
+ // ---------- Very Hacky Part Ends -----------------
183
+
184
+ log.info("login", "Logging in...");
185
+ return utils
186
+ .post("https://www.facebook.com/login.php?login_attempt=1&lwv=110", jar, form, loginOptions)
187
+ .then(utils.saveCookies(jar))
188
+ .then(function(res) {
189
+ var headers = res.headers;
190
+ if (!headers.location) {
191
+ throw {error: "Wrong username/password."};
192
+ }
193
+
194
+ // This means the account has login approvals turned on.
195
+ if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
196
+ log.info("login", "You have login approvals turned on.");
197
+ var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
198
+
199
+ return utils
200
+ .get(headers.location, jar, null, loginOptions)
201
+ .then(utils.saveCookies(jar))
202
+ .then(function(res) {
203
+ var html = res.body;
204
+ // Make the form in advance which will contain the fb_dtsg and nh
205
+ var $ = cheerio.load(html);
206
+ var arr = [];
207
+ $("form input").map(function(i, v){
208
+ arr.push({val: $(v).val(), name: $(v).attr("name")});
209
+ });
210
+
211
+ arr = arr.filter(function(v) {
212
+ return v.val && v.val.length;
213
+ });
214
+
215
+ var form = utils.arrToForm(arr);
216
+ if (html.indexOf("checkpoint/?next") > -1) {
217
+ throw {
218
+ error: 'login-approval',
219
+ continue: function(code) {
220
+ form.approvals_code = code;
221
+ form['submit[Continue]'] = 'Continue';
222
+ return utils
223
+ .post(nextURL, jar, form, loginOptions)
224
+ .then(utils.saveCookies(jar))
225
+ .then(function() {
226
+ // Use the same form (safe I hope)
227
+ form.name_action_selected = 'save_device';
228
+
229
+ return utils
230
+ .post(nextURL, jar, form, loginOptions)
231
+ .then(utils.saveCookies(jar));
232
+ })
233
+ .then(function(res) {
234
+ var headers = res.headers;
235
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
236
+ throw {error: "Something went wrong with login approvals."};
237
+ }
238
+
239
+ var appState = utils.getAppState(jar);
240
+
241
+ // Simply call loginHelper because all it needs is the jar
242
+ // and will then complete the login process
243
+ return loginHelper(appState, email, password, loginOptions, callback);
244
+ })
245
+ .catch(function(err) {
246
+ callback(err);
247
+ });
248
+ }
249
+ };
250
+ } else {
251
+ if (!loginOptions.forceLogin) {
252
+ throw {error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again."};
253
+ }
254
+ if (html.indexOf("Suspicious Login Attempt") > -1) {
255
+ form['submit[This was me]'] = "This was me";
256
+ } else {
257
+ form['submit[This Is Okay]'] = "This Is Okay";
258
+ }
259
+
260
+ return utils
261
+ .post(nextURL, jar, form, loginOptions)
262
+ .then(utils.saveCookies(jar))
263
+ .then(function() {
264
+ // Use the same form (safe I hope)
265
+ form.name_action_selected = 'save_device';
266
+
267
+ return utils
268
+ .post(nextURL, jar, form, loginOptions)
269
+ .then(utils.saveCookies(jar));
270
+ })
271
+ .then(function(res) {
272
+ var headers = res.headers;
273
+
274
+ if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
275
+ throw {error: "Something went wrong with review recent login."};
276
+ }
277
+
278
+ var appState = utils.getAppState(jar);
279
+
280
+ // Simply call loginHelper because all it needs is the jar
281
+ // and will then complete the login process
282
+ return loginHelper(appState, email, password, loginOptions, callback);
283
+ })
284
+ .catch(function(e) {
285
+ callback(e);
286
+ });
287
+ }
288
+ });
289
+ }
290
+
291
+ return utils
292
+ .get('https://www.facebook.com/', jar, null, loginOptions)
293
+ .then(utils.saveCookies(jar));
294
+ });
295
+ };
296
+ }
297
+
298
+ // Helps the login
299
+ function loginHelper(appState, email, password, globalOptions, callback) {
300
+ var mainPromise = null;
301
+ var jar = utils.getJar();
302
+
303
+ // If we're given an appState we loop through it and save each cookie
304
+ // back into the jar.
305
+ if(appState) {
306
+ appState.map(function(c) {
307
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
308
+ jar.setCookie(str, "http://" + c.domain);
309
+ });
310
+
311
+ // Load the main page.
312
+ mainPromise = utils
313
+ .get('https://www.facebook.com/', jar, null, globalOptions)
314
+ .then(utils.saveCookies(jar));
315
+ } else {
316
+ // Open the main page, then we login with the given credentials and finally
317
+ // load the main page again (it'll give us some IDs that we need)
318
+ mainPromise = utils
319
+ .get("https://www.facebook.com/", null, null, globalOptions)
320
+ .then(utils.saveCookies(jar))
321
+ .then(makeLogin(jar, email, password, globalOptions, callback))
322
+ .then(function() {
323
+ return utils
324
+ .get('https://www.facebook.com/', jar, null, globalOptions)
325
+ .then(utils.saveCookies(jar));
326
+ });
327
+ }
328
+
329
+ var ctx = null;
330
+ var defaultFuncs = null;
331
+ var bot = null;
332
+
333
+ mainPromise = mainPromise
334
+ .then(function(res) {
335
+ // Hacky check for the redirection that happens on some ISPs, which doesn't return statusCode 3xx
336
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
337
+ var redirect = reg.exec(res.body);
338
+ if (redirect && redirect[1]) {
339
+ return utils
340
+ .get(redirect[1], jar, null, globalOptions)
341
+ .then(utils.saveCookies(jar));
342
+ }
343
+ return res;
344
+ })
345
+ .then(function(res) {
346
+ var html = res.body;
347
+ var stuff = buildAPI(globalOptions, html, jar);
348
+ ctx = stuff[0];
349
+ defaultFuncs = stuff[1];
350
+ api = stuff[2];
351
+ return res;
352
+ })
353
+ .then(function() {
354
+ var form = {
355
+ reason: 6
356
+ };
357
+ log.info("login", 'Request to reconnect');
358
+ return defaultFuncs
359
+ .get("https://www.facebook.com/ajax/presence/reconnect.php", ctx.jar, form)
360
+ .then(utils.saveCookies(ctx.jar));
361
+ })
362
+ .then(function() {
363
+ var presence = utils.generatePresence(ctx.userID);
364
+ ctx.jar.setCookie("presence=" + presence + "; path=/; domain=.facebook.com; secure", "https://www.facebook.com");
365
+ ctx.jar.setCookie("presence=" + presence + "; path=/; domain=.messenger.com; secure", "https://www.messenger.com");
366
+ ctx.jar.setCookie("locale=fil_PH; path=/; domain=.facebook.com; secure", "https://www.facebook.com");
367
+ ctx.jar.setCookie("locale=fil_PH; path=/; domain=.messenger.com; secure", "https://www.messenger.com");
368
+ ctx.jar.setCookie("a11y=" + utils.generateAccessiblityCookie() + "; path=/; domain=.facebook.com; secure", "https://www.facebook.com");
369
+ return true;
370
+ });
371
+
372
+ // given a pageID we log in as a page
373
+ if (globalOptions.pageID) {
374
+ mainPromise = mainPromise
375
+ .then(function() {
376
+ return utils
377
+ .get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
378
+ })
379
+ .then(function(resData) {
380
+ var url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
381
+ url = url.substring(0, url.length - 1);
382
+
383
+ return utils
384
+ .get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
385
+ });
386
+ }
387
+
388
+ // At the end we call the callback or catch an exception
389
+ mainPromise
390
+ .then(function() {
391
+ log.info("login", 'Done logging in.');
392
+ return callback(null, api);
393
+ })
394
+ .catch(function(e) {
395
+ log.error("login", e.error || e);
396
+ callback(e);
397
+ });
398
+ }
399
+
400
+ function login(loginData, options, callback) {
401
+ if(utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
402
+ callback = options;
403
+ options = {};
404
+ }
405
+
406
+ var globalOptions = {
407
+ selfListen: false,
408
+ listenEvents: false,
409
+ updatePresence: false,
410
+ forceLogin: false,
411
+ autoMarkDelivery: true,
412
+ autoMarkRead: false,
413
+ logRecordSize: defaultLogRecordSize,
414
+ 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"
415
+ };
416
+
417
+ setOptions(globalOptions, options);
418
+
419
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback);
420
+ }
421
+
422
+ module.exports = login;
423
+
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "alicezetion",
3
+ "version": "1.0.0",
4
+ "description": "make your messenger account as a bot",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "lint": "./node_modules/.bin/eslint **.js",
9
+ "prettier": "prettier utils.js src/* --write"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/LeiamNashRebirth"
14
+ },
15
+ "keywords": [
16
+ "bot",
17
+ "messenger",
18
+ "alice",
19
+ "leiamnash",
20
+ "alicezetion"
21
+ ],
22
+ "author": "LeiamNash",
23
+ "license": "ISC",
24
+ "bugs": {
25
+ "url": "https://github.com/LeiamNashRebirth"
26
+ },
27
+ "homepage": "https://web.leiamnash.repl.co/npm",
28
+ "dependencies": {
29
+ "bluebird": "^3.0.0",
30
+ "cheerio": "^0.22.0",
31
+ "mqtt": "^3.0.0",
32
+ "npmlog": "^1.2.0",
33
+ "request": "^2.53.0",
34
+ "websocket-stream": "^5.5.0"
35
+ },
36
+ "engines": {
37
+ "node": ">=4.x"
38
+ },
39
+ "devDependencies": {
40
+ "eslint": "^4.19.1",
41
+ "mocha": "^7.0.1",
42
+ "prettier": "^1.11.1"
43
+ },
44
+ "eslintConfig": {
45
+ "env": {
46
+ "es6": true,
47
+ "node": true
48
+ },
49
+ "extends": "eslint:recommended",
50
+ "parserOptions": {
51
+ "sourceType": "module"
52
+ },
53
+ "rules": {
54
+ "linebreak-style": [
55
+ "error",
56
+ "unix"
57
+ ],
58
+ "semi": [
59
+ "error",
60
+ "always"
61
+ ],
62
+ "no-unused-vars": [
63
+ 1,
64
+ {
65
+ "argsIgnorePattern": "^_"
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ }