@irfanshadikrishad/anilist 1.0.0-forbidden.2 → 1.0.0-forbidden.3
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.
- package/LICENSE +373 -0
- package/LICENSE.md +382 -382
- package/README.md +255 -243
- package/bin/helpers/auth.d.ts +14 -4
- package/bin/helpers/auth.js +307 -209
- package/bin/helpers/lists.js +143 -123
- package/bin/helpers/queries.d.ts +4 -3
- package/bin/helpers/queries.js +10 -6
- package/bin/helpers/types.d.ts +110 -82
- package/bin/helpers/validation.d.ts +29 -0
- package/bin/helpers/validation.js +117 -0
- package/bin/helpers/workers.d.ts +14 -6
- package/bin/helpers/workers.js +80 -34
- package/bin/index.js +25 -1
- package/package.json +84 -81
package/bin/helpers/auth.js
CHANGED
|
@@ -13,13 +13,16 @@ import fetch from "node-fetch";
|
|
|
13
13
|
import open from "open";
|
|
14
14
|
import os from "os";
|
|
15
15
|
import path from "path";
|
|
16
|
+
import { exit } from "process";
|
|
17
|
+
import Spinner from "tiny-spinner";
|
|
16
18
|
import { fetcher } from "./fetcher.js";
|
|
17
19
|
import { AniDB, AniList, MyAnimeList } from "./lists.js";
|
|
18
20
|
import { deleteActivityMutation, likeActivityMutation, saveTextActivityMutation, } from "./mutations.js";
|
|
19
|
-
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.js";
|
|
21
|
+
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, toggleFollowMutation, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.js";
|
|
20
22
|
import { activityBy, aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
|
|
21
23
|
const home_dir = os.homedir();
|
|
22
24
|
const save_path = path.join(home_dir, ".anilist_token");
|
|
25
|
+
const spinner = new Spinner();
|
|
23
26
|
class Auth {
|
|
24
27
|
/**
|
|
25
28
|
* Get access-token from user
|
|
@@ -34,20 +37,29 @@ class Auth {
|
|
|
34
37
|
message: "Please enter your AniList access token:",
|
|
35
38
|
},
|
|
36
39
|
]);
|
|
40
|
+
if (!token) {
|
|
41
|
+
console.warn("\nNo token entered. Please try again.");
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
37
44
|
return token;
|
|
38
45
|
}
|
|
39
46
|
catch (error) {
|
|
40
|
-
console.error(`\
|
|
47
|
+
console.error(`\nAn error occurred while getting the access token: ${error.message}`);
|
|
48
|
+
return null;
|
|
41
49
|
}
|
|
42
50
|
});
|
|
43
51
|
}
|
|
44
52
|
static StoreAccessToken(token) {
|
|
45
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
54
|
try {
|
|
55
|
+
if (!token) {
|
|
56
|
+
console.warn("\nNo token provided. Nothing to store.");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
47
59
|
fs.writeFileSync(save_path, token, { encoding: "utf8" });
|
|
48
60
|
}
|
|
49
61
|
catch (error) {
|
|
50
|
-
console.error(`\nError storing
|
|
62
|
+
console.error(`\nError storing access token: ${error.message}`);
|
|
51
63
|
}
|
|
52
64
|
});
|
|
53
65
|
}
|
|
@@ -63,6 +75,7 @@ class Auth {
|
|
|
63
75
|
}
|
|
64
76
|
catch (error) {
|
|
65
77
|
console.error(`\nError retriving acess-token. ${error.message}`);
|
|
78
|
+
return null;
|
|
66
79
|
}
|
|
67
80
|
});
|
|
68
81
|
}
|
|
@@ -193,15 +206,12 @@ Statistics (Manga):
|
|
|
193
206
|
static isLoggedIn() {
|
|
194
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
208
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
209
|
+
const token = yield Auth.RetriveAccessToken();
|
|
210
|
+
return token !== null;
|
|
202
211
|
}
|
|
203
212
|
catch (error) {
|
|
204
|
-
console.error(
|
|
213
|
+
console.error(`Error checking login status: ${error.message}`);
|
|
214
|
+
return false;
|
|
205
215
|
}
|
|
206
216
|
});
|
|
207
217
|
}
|
|
@@ -215,15 +225,15 @@ Statistics (Manga):
|
|
|
215
225
|
console.log(`\nLogout successful. See you soon, ${username}.`);
|
|
216
226
|
}
|
|
217
227
|
catch (error) {
|
|
218
|
-
console.error("\
|
|
228
|
+
console.error("\nFailed to remove the save file during logout:", error.message);
|
|
219
229
|
}
|
|
220
230
|
}
|
|
221
231
|
else {
|
|
222
|
-
console.
|
|
232
|
+
console.warn("\nNo active session found. You may already be logged out.");
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
235
|
catch (error) {
|
|
226
|
-
console.error(`\
|
|
236
|
+
console.error(`\nAn error occurred during logout: ${error.message}`);
|
|
227
237
|
}
|
|
228
238
|
});
|
|
229
239
|
}
|
|
@@ -234,20 +244,7 @@ Statistics (Manga):
|
|
|
234
244
|
console.warn(`\nUser not logged in.`);
|
|
235
245
|
return null;
|
|
236
246
|
}
|
|
237
|
-
const
|
|
238
|
-
const request = yield fetch(aniListEndpoint, {
|
|
239
|
-
method: "POST",
|
|
240
|
-
headers: {
|
|
241
|
-
"Content-Type": "application/json",
|
|
242
|
-
"Authorization": `Bearer ${token}`,
|
|
243
|
-
},
|
|
244
|
-
body: JSON.stringify({ query: currentUserQuery }),
|
|
245
|
-
});
|
|
246
|
-
if (!(request.status === 200)) {
|
|
247
|
-
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
const { data } = yield request.json();
|
|
247
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
251
248
|
return (_b = (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
|
|
252
249
|
});
|
|
253
250
|
}
|
|
@@ -258,20 +255,7 @@ Statistics (Manga):
|
|
|
258
255
|
console.log(`\nUser not logged in.`);
|
|
259
256
|
return null;
|
|
260
257
|
}
|
|
261
|
-
const
|
|
262
|
-
const request = yield fetch(aniListEndpoint, {
|
|
263
|
-
method: "POST",
|
|
264
|
-
headers: {
|
|
265
|
-
"Content-Type": "application/json",
|
|
266
|
-
"Authorization": `Bearer ${token}`,
|
|
267
|
-
},
|
|
268
|
-
body: JSON.stringify({ query: currentUserQuery }),
|
|
269
|
-
});
|
|
270
|
-
if (!request.ok) {
|
|
271
|
-
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
const { data } = yield request.json();
|
|
258
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
275
259
|
return (_b = (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : null;
|
|
276
260
|
});
|
|
277
261
|
}
|
|
@@ -279,72 +263,70 @@ Statistics (Manga):
|
|
|
279
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
280
264
|
var _a, _b, _c, _d, _e, _f;
|
|
281
265
|
try {
|
|
282
|
-
if (yield Auth.isLoggedIn()) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
// Ensure ID is present to avoid unintended errors
|
|
325
|
-
if (act === null || act === void 0 ? void 0 : act.id) {
|
|
326
|
-
const deleteResponse = yield fetcher(deleteActivityMutation, {
|
|
327
|
-
id: act === null || act === void 0 ? void 0 : act.id,
|
|
328
|
-
});
|
|
329
|
-
const isDeleted = (_f = (_e = deleteResponse === null || deleteResponse === void 0 ? void 0 : deleteResponse.data) === null || _e === void 0 ? void 0 : _e.DeleteActivity) === null || _f === void 0 ? void 0 : _f.deleted;
|
|
330
|
-
count++;
|
|
331
|
-
totalCount++;
|
|
332
|
-
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
333
|
-
// Avoiding rate-limit
|
|
334
|
-
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
266
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
267
|
+
console.error(`\nPlease log in to delete your activities.`);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const { activityType } = yield inquirer.prompt([
|
|
271
|
+
{
|
|
272
|
+
type: "list",
|
|
273
|
+
name: "activityType",
|
|
274
|
+
message: "What type of activity you want to delete?",
|
|
275
|
+
choices: [
|
|
276
|
+
{ name: "All Activity", value: 0 },
|
|
277
|
+
{ name: "Text Activity", value: 1 },
|
|
278
|
+
{ name: "Media List Activity", value: 2 },
|
|
279
|
+
{ name: "Anime List Activity", value: 3 },
|
|
280
|
+
{ name: "Manga List Activity", value: 4 },
|
|
281
|
+
{ name: "Message Activity", value: 5 },
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
]);
|
|
285
|
+
const queryMap = {
|
|
286
|
+
0: activityAllQuery,
|
|
287
|
+
1: activityTextQuery,
|
|
288
|
+
2: activityMediaList,
|
|
289
|
+
3: activityAnimeListQuery,
|
|
290
|
+
4: activityMangaListQuery,
|
|
291
|
+
5: activityMessageQuery,
|
|
292
|
+
};
|
|
293
|
+
const query = queryMap[activityType];
|
|
294
|
+
let hasMoreActivities = true;
|
|
295
|
+
let totalCount = 0;
|
|
296
|
+
while (hasMoreActivities) {
|
|
297
|
+
const response = yield fetcher(query, {
|
|
298
|
+
page: 1,
|
|
299
|
+
perPage: 50,
|
|
300
|
+
userId: yield Auth.MyUserId(),
|
|
301
|
+
});
|
|
302
|
+
if ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities) {
|
|
303
|
+
let count = 0;
|
|
304
|
+
const activities = (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
|
|
305
|
+
if (!activities || activities.length === 0) {
|
|
306
|
+
console.log(`\nNo more activities available.`);
|
|
307
|
+
hasMoreActivities = false;
|
|
338
308
|
}
|
|
339
309
|
else {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
310
|
+
for (const act of activities) {
|
|
311
|
+
if (act === null || act === void 0 ? void 0 : act.id) {
|
|
312
|
+
const deleteResponse = yield fetcher(deleteActivityMutation, {
|
|
313
|
+
id: act === null || act === void 0 ? void 0 : act.id,
|
|
314
|
+
});
|
|
315
|
+
const isDeleted = (_f = (_e = deleteResponse === null || deleteResponse === void 0 ? void 0 : deleteResponse.data) === null || _e === void 0 ? void 0 : _e.DeleteActivity) === null || _f === void 0 ? void 0 : _f.deleted;
|
|
316
|
+
count++;
|
|
317
|
+
totalCount++;
|
|
318
|
+
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
319
|
+
// Avoiding rate-limit
|
|
320
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
343
323
|
}
|
|
344
324
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
325
|
+
else {
|
|
326
|
+
// In case of an unexpected null response, exit the loop
|
|
327
|
+
console.log(`\nProbably deleted all the activities of this type.`);
|
|
328
|
+
hasMoreActivities = false;
|
|
329
|
+
}
|
|
348
330
|
}
|
|
349
331
|
}
|
|
350
332
|
catch (error) {
|
|
@@ -355,54 +337,51 @@ Statistics (Manga):
|
|
|
355
337
|
static DeleteMyAnimeList() {
|
|
356
338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
339
|
var _a, _b, _c, _d;
|
|
358
|
-
if (yield Auth.isLoggedIn()) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
340
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
341
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (!(yield Auth.MyUserId())) {
|
|
345
|
+
console.log(`\nFailed getting current user Id.`);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const response = yield fetcher(currentUserAnimeList, { id: yield Auth.MyUserId() });
|
|
349
|
+
if (response !== null) {
|
|
350
|
+
const lists = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.MediaListCollection) === null || _b === void 0 ? void 0 : _b.lists;
|
|
351
|
+
if (lists.length > 0) {
|
|
352
|
+
const { selectedList } = yield inquirer.prompt([
|
|
353
|
+
{
|
|
354
|
+
type: "list",
|
|
355
|
+
name: "selectedList",
|
|
356
|
+
message: "Select an anime list:",
|
|
357
|
+
choices: lists.map((list) => list.name),
|
|
358
|
+
pageSize: 10,
|
|
359
|
+
},
|
|
360
|
+
]);
|
|
361
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
362
|
+
if (selectedEntries) {
|
|
363
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
364
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
365
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
366
|
+
yield Auth.DeleteAnimeById(entry === null || entry === void 0 ? void 0 : entry.id, (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title);
|
|
367
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
387
368
|
}
|
|
388
369
|
else {
|
|
389
|
-
console.log(
|
|
370
|
+
console.log(`No id in entry.`);
|
|
371
|
+
console.log(entry);
|
|
390
372
|
}
|
|
391
373
|
}
|
|
392
|
-
else {
|
|
393
|
-
console.log(`\nNo anime(s) found in any list.`);
|
|
394
|
-
}
|
|
395
374
|
}
|
|
396
375
|
else {
|
|
397
|
-
console.log(
|
|
376
|
+
console.log("No entries found.");
|
|
398
377
|
}
|
|
399
378
|
}
|
|
400
379
|
else {
|
|
401
|
-
console.log(`\
|
|
380
|
+
console.log(`\nNo anime(s) found in any list.`);
|
|
402
381
|
}
|
|
403
382
|
}
|
|
404
383
|
else {
|
|
405
|
-
console.
|
|
384
|
+
console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
406
385
|
}
|
|
407
386
|
});
|
|
408
387
|
}
|
|
@@ -429,54 +408,50 @@ Statistics (Manga):
|
|
|
429
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
430
409
|
var _a, _b, _c, _d;
|
|
431
410
|
try {
|
|
432
|
-
if (yield Auth.isLoggedIn()) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
console.error("\nNo entries found.");
|
|
464
|
-
}
|
|
411
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
412
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (!(yield Auth.MyUserId())) {
|
|
416
|
+
console.error(`\nFailed getting current user Id.`);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const response = yield fetcher(currentUserMangaList, { id: yield Auth.MyUserId() });
|
|
420
|
+
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
421
|
+
console.error(`\nSomething went wrong. ${(_a = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const lists = (_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.MediaListCollection) === null || _c === void 0 ? void 0 : _c.lists;
|
|
425
|
+
if (lists.length > 0) {
|
|
426
|
+
const { selectedList } = yield inquirer.prompt([
|
|
427
|
+
{
|
|
428
|
+
type: "list",
|
|
429
|
+
name: "selectedList",
|
|
430
|
+
message: "Select a manga list:",
|
|
431
|
+
choices: lists.map((list) => list.name),
|
|
432
|
+
pageSize: 10,
|
|
433
|
+
},
|
|
434
|
+
]);
|
|
435
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
436
|
+
if (selectedEntries) {
|
|
437
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
438
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
439
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
440
|
+
yield Auth.DeleteMangaById(entry === null || entry === void 0 ? void 0 : entry.id, (_d = entry === null || entry === void 0 ? void 0 : entry.media) === null || _d === void 0 ? void 0 : _d.title);
|
|
441
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
465
442
|
}
|
|
466
443
|
else {
|
|
467
|
-
console.
|
|
444
|
+
console.log(`No id in entry.`);
|
|
445
|
+
console.log(entry);
|
|
468
446
|
}
|
|
469
447
|
}
|
|
470
|
-
else {
|
|
471
|
-
console.error(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
472
|
-
}
|
|
473
448
|
}
|
|
474
449
|
else {
|
|
475
|
-
console.error(
|
|
450
|
+
console.error("\nNo entries found.");
|
|
476
451
|
}
|
|
477
452
|
}
|
|
478
453
|
else {
|
|
479
|
-
console.error(`\
|
|
454
|
+
console.error(`\nNo manga(s) found in any list.`);
|
|
480
455
|
}
|
|
481
456
|
}
|
|
482
457
|
catch (error) {
|
|
@@ -505,22 +480,20 @@ Statistics (Manga):
|
|
|
505
480
|
}
|
|
506
481
|
static Write(status) {
|
|
507
482
|
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
-
var _a;
|
|
509
483
|
try {
|
|
510
484
|
if (!(yield Auth.isLoggedIn())) {
|
|
511
485
|
console.error(`\nPlease login to use this feature.`);
|
|
512
486
|
return;
|
|
513
487
|
}
|
|
514
|
-
const data = yield fetcher(saveTextActivityMutation, {
|
|
488
|
+
const { data } = yield fetcher(saveTextActivityMutation, {
|
|
515
489
|
status: status,
|
|
516
490
|
});
|
|
517
491
|
if (!data) {
|
|
518
492
|
console.error(`\nSomething went wrong. ${data}.`);
|
|
519
493
|
return;
|
|
520
494
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
console.log(`\n[${savedActivity.id}] status saved successfully!`);
|
|
495
|
+
if (data.SaveTextActivity.id) {
|
|
496
|
+
console.log(`\n[${data.SaveTextActivity.id}] status saved successfully!`);
|
|
524
497
|
}
|
|
525
498
|
}
|
|
526
499
|
catch (error) {
|
|
@@ -598,7 +571,7 @@ Statistics (Manga):
|
|
|
598
571
|
}
|
|
599
572
|
static LikeFollowing() {
|
|
600
573
|
return __awaiter(this, void 0, void 0, function* () {
|
|
601
|
-
var _a, _b, _c, _d;
|
|
574
|
+
var _a, _b, _c, _d, _e, _f;
|
|
602
575
|
try {
|
|
603
576
|
let page = 1;
|
|
604
577
|
let hasMoreActivities = true;
|
|
@@ -610,8 +583,9 @@ Statistics (Manga):
|
|
|
610
583
|
perPage: 50,
|
|
611
584
|
});
|
|
612
585
|
if (activities && ((_b = (_a = activities === null || activities === void 0 ? void 0 : activities.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities.length) > 0) {
|
|
586
|
+
spinner.success(`Got ${(_d = (_c = activities === null || activities === void 0 ? void 0 : activities.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities.length} activities..`);
|
|
613
587
|
retryCount = 0; // Reset retry count on successful fetch
|
|
614
|
-
const activiti = (
|
|
588
|
+
const activiti = (_f = (_e = activities === null || activities === void 0 ? void 0 : activities.data) === null || _e === void 0 ? void 0 : _e.Page) === null || _f === void 0 ? void 0 : _f.activities;
|
|
615
589
|
for (let activ of activiti) {
|
|
616
590
|
if (!activ.isLiked && activ.id) {
|
|
617
591
|
try {
|
|
@@ -636,13 +610,13 @@ Statistics (Manga):
|
|
|
636
610
|
}
|
|
637
611
|
else {
|
|
638
612
|
if (retryCount < maxRetries) {
|
|
613
|
+
spinner.start("Getting activities...");
|
|
639
614
|
retryCount++;
|
|
640
|
-
|
|
641
|
-
yield new Promise((resolve) => setTimeout(resolve,
|
|
615
|
+
spinner.update(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
|
|
616
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
642
617
|
}
|
|
643
618
|
else {
|
|
644
|
-
|
|
645
|
-
console.info(activities);
|
|
619
|
+
spinner.error(`Probably the end of activities after ${maxRetries} retries.`);
|
|
646
620
|
hasMoreActivities = false;
|
|
647
621
|
}
|
|
648
622
|
}
|
|
@@ -653,24 +627,22 @@ Statistics (Manga):
|
|
|
653
627
|
}
|
|
654
628
|
});
|
|
655
629
|
}
|
|
656
|
-
static
|
|
630
|
+
static LikeGlobal() {
|
|
657
631
|
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
-
var _a, _b, _c, _d;
|
|
632
|
+
var _a, _b, _c, _d, _e, _f;
|
|
659
633
|
try {
|
|
660
634
|
let page = 1;
|
|
661
635
|
let hasMoreActivities = true;
|
|
662
|
-
let
|
|
663
|
-
|
|
664
|
-
: type === 1
|
|
665
|
-
? globalActivitiesQuery
|
|
666
|
-
: followingActivitiesQuery;
|
|
636
|
+
let likedCount = 0;
|
|
637
|
+
spinner.start(`Getting global activities...`);
|
|
667
638
|
while (hasMoreActivities) {
|
|
668
|
-
const activities = yield fetcher(
|
|
639
|
+
const activities = yield fetcher(globalActivitiesQuery, {
|
|
669
640
|
page,
|
|
670
641
|
perPage: 50,
|
|
671
642
|
});
|
|
672
643
|
if (activities && ((_b = (_a = activities === null || activities === void 0 ? void 0 : activities.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities.length) > 0) {
|
|
673
644
|
const activiti = (_d = (_c = activities === null || activities === void 0 ? void 0 : activities.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
|
|
645
|
+
spinner.success(`Got ${activiti.length} activities...`);
|
|
674
646
|
for (let activ of activiti) {
|
|
675
647
|
if (!activ.isLiked && activ.id) {
|
|
676
648
|
try {
|
|
@@ -678,7 +650,8 @@ Statistics (Manga):
|
|
|
678
650
|
activityId: activ.id,
|
|
679
651
|
});
|
|
680
652
|
// const ToggleLike = like?.data?.ToggleLike
|
|
681
|
-
|
|
653
|
+
likedCount++;
|
|
654
|
+
console.info(`${activityBy(activ, likedCount)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
682
655
|
}
|
|
683
656
|
catch (error) {
|
|
684
657
|
console.error(`Activity possibly deleted. ${error.message}`);
|
|
@@ -696,8 +669,7 @@ Statistics (Manga):
|
|
|
696
669
|
}
|
|
697
670
|
else {
|
|
698
671
|
// No more activities to like
|
|
699
|
-
|
|
700
|
-
console.info(activities);
|
|
672
|
+
spinner.error(`Probably the end of activities. ${(_f = (_e = activities === null || activities === void 0 ? void 0 : activities.data) === null || _e === void 0 ? void 0 : _e.Page) === null || _f === void 0 ? void 0 : _f.activities}`);
|
|
701
673
|
hasMoreActivities = false;
|
|
702
674
|
}
|
|
703
675
|
}
|
|
@@ -709,7 +681,7 @@ Statistics (Manga):
|
|
|
709
681
|
}
|
|
710
682
|
static LikeSpecificUser() {
|
|
711
683
|
return __awaiter(this, void 0, void 0, function* () {
|
|
712
|
-
var _a, _b, _c, _d;
|
|
684
|
+
var _a, _b, _c, _d, _e, _f;
|
|
713
685
|
try {
|
|
714
686
|
const { username } = yield inquirer.prompt([
|
|
715
687
|
{
|
|
@@ -719,10 +691,12 @@ Statistics (Manga):
|
|
|
719
691
|
},
|
|
720
692
|
]);
|
|
721
693
|
const userDetails = yield fetcher(userQuery, { username: username });
|
|
722
|
-
|
|
694
|
+
spinner.start(`Getting activities by ${username}`);
|
|
695
|
+
if ((_b = (_a = userDetails === null || userDetails === void 0 ? void 0 : userDetails.data) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.id) {
|
|
723
696
|
let page = 1;
|
|
724
697
|
const perPage = 50;
|
|
725
|
-
const userId = (
|
|
698
|
+
const userId = (_d = (_c = userDetails === null || userDetails === void 0 ? void 0 : userDetails.data) === null || _c === void 0 ? void 0 : _c.User) === null || _d === void 0 ? void 0 : _d.id;
|
|
699
|
+
let likedCount = 0;
|
|
726
700
|
if (userId) {
|
|
727
701
|
while (true) {
|
|
728
702
|
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
@@ -730,19 +704,21 @@ Statistics (Manga):
|
|
|
730
704
|
perPage,
|
|
731
705
|
userId,
|
|
732
706
|
});
|
|
733
|
-
const activiti = (
|
|
707
|
+
const activiti = (_f = (_e = activities === null || activities === void 0 ? void 0 : activities.data) === null || _e === void 0 ? void 0 : _e.Page) === null || _f === void 0 ? void 0 : _f.activities;
|
|
734
708
|
// Break the loop if no more activities are found
|
|
735
709
|
if (!activiti || activiti.length === 0) {
|
|
736
|
-
|
|
710
|
+
spinner.error("No more activities found.");
|
|
737
711
|
break;
|
|
738
712
|
}
|
|
713
|
+
spinner.success(`Got ${activiti.length} activities...`);
|
|
739
714
|
for (let activ of activiti) {
|
|
740
715
|
if (!activ.isLiked && activ.id) {
|
|
741
716
|
try {
|
|
742
717
|
const like = yield fetcher(likeActivityMutation, {
|
|
743
718
|
activityId: activ.id,
|
|
744
719
|
});
|
|
745
|
-
|
|
720
|
+
likedCount++;
|
|
721
|
+
console.info(`${activityBy(activ, likedCount)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
746
722
|
}
|
|
747
723
|
catch (error) {
|
|
748
724
|
console.error(`Activity possibly deleted. ${error.message}`);
|
|
@@ -761,6 +737,10 @@ Statistics (Manga):
|
|
|
761
737
|
}
|
|
762
738
|
}
|
|
763
739
|
}
|
|
740
|
+
else {
|
|
741
|
+
spinner.error(`User ${username} does not exist.`);
|
|
742
|
+
exit(1);
|
|
743
|
+
}
|
|
764
744
|
}
|
|
765
745
|
catch (error) {
|
|
766
746
|
console.error(`\nError from LikeSpecificUser. ${error.message}`);
|
|
@@ -778,8 +758,11 @@ Statistics (Manga):
|
|
|
778
758
|
const allFollowingUsers = [];
|
|
779
759
|
let hasNextPage = true;
|
|
780
760
|
let page = 1;
|
|
761
|
+
let liked = 0;
|
|
781
762
|
// Fetch all following users
|
|
763
|
+
spinner.start(`Gathering following information...`);
|
|
782
764
|
while (hasNextPage) {
|
|
765
|
+
spinner.update(`Fetched page ${page}...`);
|
|
783
766
|
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
784
767
|
userId: yield Auth.MyUserId(),
|
|
785
768
|
page,
|
|
@@ -792,6 +775,7 @@ Statistics (Manga):
|
|
|
792
775
|
hasNextPage = followingUsers.data.Page.pageInfo.hasNextPage;
|
|
793
776
|
page++;
|
|
794
777
|
}
|
|
778
|
+
spinner.stop(`Got ${allFollowingUsers.length} following user.`);
|
|
795
779
|
// Extract the IDs of all following users
|
|
796
780
|
const followingUserIds = allFollowingUsers.map((user) => user.id);
|
|
797
781
|
console.log(`\nTotal Following: ${followingUserIds.length}\nApproximately ${followingUserIds.length * perPage} activities to like.\nWill take around ${((followingUserIds.length * perPage * 1200) /
|
|
@@ -821,6 +805,9 @@ Statistics (Manga):
|
|
|
821
805
|
activityId: activ.id,
|
|
822
806
|
});
|
|
823
807
|
console.info(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
808
|
+
if (like === null || like === void 0 ? void 0 : like.data) {
|
|
809
|
+
liked++;
|
|
810
|
+
}
|
|
824
811
|
}
|
|
825
812
|
catch (error) {
|
|
826
813
|
console.error(`[${userNumber}/${i + 1}/${activiti.length}] Activity possibly deleted. ${error.message}`);
|
|
@@ -833,7 +820,7 @@ Statistics (Manga):
|
|
|
833
820
|
yield new Promise((resolve) => setTimeout(resolve, 1200));
|
|
834
821
|
}
|
|
835
822
|
}
|
|
836
|
-
console.log(`\n✅ All activities liked successfully.`);
|
|
823
|
+
console.log(`\n✅ All ${liked} activities liked successfully.`);
|
|
837
824
|
}
|
|
838
825
|
catch (error) {
|
|
839
826
|
console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
|
|
@@ -865,7 +852,7 @@ Statistics (Manga):
|
|
|
865
852
|
yield this.LikeFollowing();
|
|
866
853
|
break;
|
|
867
854
|
case 2:
|
|
868
|
-
yield this.
|
|
855
|
+
yield this.LikeGlobal();
|
|
869
856
|
break;
|
|
870
857
|
case 3:
|
|
871
858
|
yield this.LikeSpecificUser();
|
|
@@ -880,4 +867,115 @@ Statistics (Manga):
|
|
|
880
867
|
});
|
|
881
868
|
}
|
|
882
869
|
}
|
|
883
|
-
|
|
870
|
+
class Social {
|
|
871
|
+
/**
|
|
872
|
+
* Follow the users that follows you
|
|
873
|
+
*/
|
|
874
|
+
static follow() {
|
|
875
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
876
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
877
|
+
try {
|
|
878
|
+
let pager = 1;
|
|
879
|
+
let hasNextPage = true;
|
|
880
|
+
let allFollowerUsers = [];
|
|
881
|
+
spinner.start("Fetching all the followers...");
|
|
882
|
+
while (hasNextPage) {
|
|
883
|
+
const followerUsers = yield fetcher(userFollowersQuery, {
|
|
884
|
+
userId: yield Auth.MyUserId(),
|
|
885
|
+
page: pager,
|
|
886
|
+
});
|
|
887
|
+
spinner.update(`Fetched page ${pager} of ${(_c = (_b = (_a = followerUsers === null || followerUsers === void 0 ? void 0 : followerUsers.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.lastPage}...`);
|
|
888
|
+
if (!((_f = (_e = (_d = followerUsers === null || followerUsers === void 0 ? void 0 : followerUsers.data) === null || _d === void 0 ? void 0 : _d.Page) === null || _e === void 0 ? void 0 : _e.pageInfo) === null || _f === void 0 ? void 0 : _f.hasNextPage)) {
|
|
889
|
+
hasNextPage = false;
|
|
890
|
+
}
|
|
891
|
+
allFollowerUsers.push(...(((_h = (_g = followerUsers === null || followerUsers === void 0 ? void 0 : followerUsers.data) === null || _g === void 0 ? void 0 : _g.Page) === null || _h === void 0 ? void 0 : _h.followers) || []));
|
|
892
|
+
pager++;
|
|
893
|
+
}
|
|
894
|
+
spinner.stop("Fetched all the followers. Starting follow back.");
|
|
895
|
+
// Filter users that do no follow me
|
|
896
|
+
const notFollowing = allFollowerUsers
|
|
897
|
+
.filter(({ isFollowing }) => !isFollowing)
|
|
898
|
+
.map(({ id, name }) => ({ id: id, name: name }));
|
|
899
|
+
console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
|
|
900
|
+
if (notFollowing.length <= 0) {
|
|
901
|
+
console.log(`Probably followed back all the users.`);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
// Traverse and follow back
|
|
905
|
+
const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
|
|
906
|
+
const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
|
|
907
|
+
for (let nf of notFollowing) {
|
|
908
|
+
try {
|
|
909
|
+
const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
|
|
910
|
+
console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
|
|
911
|
+
`\t${String(`[${(_k = (_j = follow === null || follow === void 0 ? void 0 : follow.data) === null || _j === void 0 ? void 0 : _j.ToggleFollow) === null || _k === void 0 ? void 0 : _k.name}]`).padEnd(maxNameLength)}` +
|
|
912
|
+
`\t${((_m = (_l = follow === null || follow === void 0 ? void 0 : follow.data) === null || _l === void 0 ? void 0 : _l.ToggleFollow) === null || _m === void 0 ? void 0 : _m.id) ? "✅" : "🈵"}`);
|
|
913
|
+
}
|
|
914
|
+
catch (error) {
|
|
915
|
+
console.log(`automate_follow_toggle_follow: ${error.message}`);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
console.log(`\n✅ Followed back ${notFollowing.length} users.`);
|
|
919
|
+
}
|
|
920
|
+
catch (error) {
|
|
921
|
+
console.log(`\nautomate_follow ${error.message}`);
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Unfollow the users thats not following you
|
|
927
|
+
*/
|
|
928
|
+
static unfollow() {
|
|
929
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
930
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
931
|
+
try {
|
|
932
|
+
let pager = 1;
|
|
933
|
+
let hasNextPage = true;
|
|
934
|
+
let allFollowingUsers = [];
|
|
935
|
+
spinner.start("Fetching all following users...");
|
|
936
|
+
while (hasNextPage) {
|
|
937
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
938
|
+
userId: yield Auth.MyUserId(),
|
|
939
|
+
page: pager,
|
|
940
|
+
});
|
|
941
|
+
spinner.update(`Fetched page ${pager} of ${(_c = (_b = (_a = followingUsers === null || followingUsers === void 0 ? void 0 : followingUsers.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.lastPage} ...`);
|
|
942
|
+
if (!((_f = (_e = (_d = followingUsers === null || followingUsers === void 0 ? void 0 : followingUsers.data) === null || _d === void 0 ? void 0 : _d.Page) === null || _e === void 0 ? void 0 : _e.pageInfo) === null || _f === void 0 ? void 0 : _f.hasNextPage)) {
|
|
943
|
+
hasNextPage = false;
|
|
944
|
+
}
|
|
945
|
+
allFollowingUsers.push(...(((_h = (_g = followingUsers === null || followingUsers === void 0 ? void 0 : followingUsers.data) === null || _g === void 0 ? void 0 : _g.Page) === null || _h === void 0 ? void 0 : _h.following) || []));
|
|
946
|
+
pager++;
|
|
947
|
+
}
|
|
948
|
+
spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
|
|
949
|
+
// Filter users that do no follow me
|
|
950
|
+
const notFollowingMe = allFollowingUsers
|
|
951
|
+
.filter((user) => !user.isFollower)
|
|
952
|
+
.map((u3r) => ({ id: u3r.id, name: u3r.name }));
|
|
953
|
+
if (notFollowingMe.length <= 0) {
|
|
954
|
+
console.warn(`\nNot following list is empty!`);
|
|
955
|
+
spinner.stop(`No users to unfollow. Aborting process...`);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
|
|
959
|
+
let nfmCount = 0;
|
|
960
|
+
console.log(`\n`);
|
|
961
|
+
for (let nfm of notFollowingMe) {
|
|
962
|
+
nfmCount++;
|
|
963
|
+
try {
|
|
964
|
+
const unfollow = yield fetcher(toggleFollowMutation, {
|
|
965
|
+
userId: nfm.id,
|
|
966
|
+
});
|
|
967
|
+
console.log(`[${nfm.id}]\t[${(_k = (_j = unfollow === null || unfollow === void 0 ? void 0 : unfollow.data) === null || _j === void 0 ? void 0 : _j.ToggleFollow) === null || _k === void 0 ? void 0 : _k.name}]\t${((_m = (_l = unfollow === null || unfollow === void 0 ? void 0 : unfollow.data) === null || _l === void 0 ? void 0 : _l.ToggleFollow) === null || _m === void 0 ? void 0 : _m.id) ? "✅" : "🈵"}`);
|
|
968
|
+
}
|
|
969
|
+
catch (error) {
|
|
970
|
+
console.log(`unfollow_toggle_follow. ${error.message}`);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
console.log(`\nTotal Unfollowed: ${nfmCount}`);
|
|
974
|
+
}
|
|
975
|
+
catch (error) {
|
|
976
|
+
console.error(`\nautomate_unfollow: ${error.message}`);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
export { Auth, Social };
|