@irfanshadikrishad/anilist 2.0.0-forbidden → 2.0.0-forbidden.1
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/.husky/pre-commit +3 -0
- package/README.md +35 -21
- package/bin/helpers/auth.d.ts +22 -2
- package/bin/helpers/auth.js +238 -236
- package/bin/helpers/lists.d.ts +40 -0
- package/bin/helpers/lists.js +339 -705
- package/bin/helpers/validation.d.ts +10 -1
- package/bin/helpers/validation.js +24 -36
- package/bin/helpers/workers.d.ts +2 -1
- package/bin/helpers/workers.js +5 -2
- package/bin/index.js +57 -67
- package/package.json +4 -2
package/bin/helpers/auth.js
CHANGED
|
@@ -22,7 +22,7 @@ import { AniDB, AniList, MyAnimeList } from './lists.js';
|
|
|
22
22
|
import { deleteActivityMutation, deleteMangaEntryMutation, deleteMediaEntryMutation, likeActivityMutation, saveTextActivityMutation, toggleFollowMutation, } from './mutations.js';
|
|
23
23
|
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from './queries.js';
|
|
24
24
|
import { responsiveOutput } from './truncate.js';
|
|
25
|
-
import { activityBy, aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from './workers.js';
|
|
25
|
+
import { activityBy, aniListEndpoint, getTitle, redirectUri, sleep, timestampToTimeAgo, } from './workers.js';
|
|
26
26
|
const home_dir = os.homedir();
|
|
27
27
|
const save_path = path.join(home_dir, '.anilist_token');
|
|
28
28
|
const spinner = new Spinner();
|
|
@@ -321,7 +321,7 @@ Statistics (Manga):
|
|
|
321
321
|
totalCount++;
|
|
322
322
|
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? colorize.Green('✔') : colorize.Red('✘')}`);
|
|
323
323
|
// Avoiding rate-limit
|
|
324
|
-
yield
|
|
324
|
+
yield sleep(1100);
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
}
|
|
@@ -338,79 +338,37 @@ Statistics (Manga):
|
|
|
338
338
|
}
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
|
-
static
|
|
341
|
+
static DeleteMediaEntryById(mutation, id, title) {
|
|
342
342
|
return __awaiter(this, void 0, void 0, function* () {
|
|
343
343
|
var _a, _b, _c, _d;
|
|
344
|
-
if (!(yield Auth.isLoggedIn())) {
|
|
345
|
-
console.error(`\nPlease log in first to delete your lists.`);
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
if (!(yield Auth.MyUserId())) {
|
|
349
|
-
console.log(`\nFailed getting current user Id.`);
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const response = yield fetcher(currentUserAnimeList, { id: yield Auth.MyUserId() });
|
|
353
|
-
if (response !== null) {
|
|
354
|
-
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;
|
|
355
|
-
if (lists.length > 0) {
|
|
356
|
-
const { selectedList } = yield inquirer.prompt([
|
|
357
|
-
{
|
|
358
|
-
type: 'list',
|
|
359
|
-
name: 'selectedList',
|
|
360
|
-
message: 'Select an anime list:',
|
|
361
|
-
choices: lists.map((list) => list.name),
|
|
362
|
-
pageSize: 10,
|
|
363
|
-
},
|
|
364
|
-
]);
|
|
365
|
-
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
366
|
-
if (selectedEntries) {
|
|
367
|
-
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
368
|
-
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
369
|
-
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
370
|
-
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);
|
|
371
|
-
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
console.log(`No id in entry.`);
|
|
375
|
-
console.log(entry);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
console.log('No entries found.');
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
console.log(`\nNo anime(s) found in any list.`);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
static DeleteAnimeById(id, title) {
|
|
393
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
394
|
-
var _a, _b, _c;
|
|
395
344
|
try {
|
|
396
|
-
const response = yield fetcher(
|
|
345
|
+
const response = yield fetcher(mutation, { id });
|
|
397
346
|
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
398
347
|
const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
|
|
399
348
|
console.log(`del ${title ? getTitle(title) : ''} ${deleted ? colorize.Green('✔') : colorize.Red('✘')}`);
|
|
400
349
|
}
|
|
401
350
|
else {
|
|
402
|
-
console.
|
|
403
|
-
console.log(response);
|
|
351
|
+
console.error(`\nError deleting entry. ${(_d = (_c = response === null || response === void 0 ? void 0 : response.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
404
352
|
}
|
|
405
353
|
}
|
|
406
354
|
catch (error) {
|
|
407
|
-
console.
|
|
355
|
+
console.error(`\nError deleting entry. ${id} ${error.message}`);
|
|
408
356
|
}
|
|
409
357
|
});
|
|
410
358
|
}
|
|
411
|
-
static
|
|
359
|
+
static DeleteAnimeById(id, title) {
|
|
412
360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
413
|
-
|
|
361
|
+
return Auth.DeleteMediaEntryById(deleteMediaEntryMutation, id, title);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
static DeleteMangaById(id, title) {
|
|
365
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
+
return Auth.DeleteMediaEntryById(deleteMangaEntryMutation, id, title);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
static DeleteMyMediaList(listQuery, deleteByIdFn, mediaLabel) {
|
|
370
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
371
|
+
var _a, _b, _c, _d, _e;
|
|
414
372
|
try {
|
|
415
373
|
if (!(yield Auth.isLoggedIn())) {
|
|
416
374
|
console.error(`\nPlease log in first to delete your lists.`);
|
|
@@ -420,66 +378,57 @@ Statistics (Manga):
|
|
|
420
378
|
console.error(`\nFailed getting current user Id.`);
|
|
421
379
|
return;
|
|
422
380
|
}
|
|
423
|
-
const response = yield fetcher(
|
|
381
|
+
const response = yield fetcher(listQuery, {
|
|
382
|
+
id: yield Auth.MyUserId(),
|
|
383
|
+
});
|
|
424
384
|
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
425
|
-
console.error(`\nSomething went wrong. ${(_a = response === null || response === void 0 ? void 0 : response.errors[0]) === null ||
|
|
385
|
+
console.error(`\nSomething went wrong. ${(_b = (_a = response === null || response === void 0 ? void 0 : response.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
426
386
|
return;
|
|
427
387
|
}
|
|
428
|
-
const lists = (
|
|
429
|
-
if (lists.length
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
388
|
+
const lists = (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.MediaListCollection) === null || _d === void 0 ? void 0 : _d.lists;
|
|
389
|
+
if (!lists || lists.length === 0) {
|
|
390
|
+
console.error(`\nNo ${mediaLabel}(s) found in any list.`);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const { selectedList } = yield inquirer.prompt([
|
|
394
|
+
{
|
|
395
|
+
type: 'list',
|
|
396
|
+
name: 'selectedList',
|
|
397
|
+
message: `Select a${mediaLabel === 'anime' ? 'n' : ''} ${mediaLabel} list:`,
|
|
398
|
+
choices: lists.map((list) => list.name),
|
|
399
|
+
pageSize: 10,
|
|
400
|
+
},
|
|
401
|
+
]);
|
|
402
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
403
|
+
if (!selectedEntries) {
|
|
404
|
+
console.error('\nNo entries found.');
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
408
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
409
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
410
|
+
yield deleteByIdFn(entry === null || entry === void 0 ? void 0 : entry.id, (_e = entry === null || entry === void 0 ? void 0 : entry.media) === null || _e === void 0 ? void 0 : _e.title);
|
|
411
|
+
yield sleep(1100);
|
|
452
412
|
}
|
|
453
413
|
else {
|
|
454
|
-
console.
|
|
414
|
+
console.log(`No id in entry.`);
|
|
415
|
+
console.log(entry);
|
|
455
416
|
}
|
|
456
417
|
}
|
|
457
|
-
else {
|
|
458
|
-
console.error(`\nNo manga(s) found in any list.`);
|
|
459
|
-
}
|
|
460
418
|
}
|
|
461
419
|
catch (error) {
|
|
462
|
-
console.error(`\nError deleting
|
|
420
|
+
console.error(`\nError deleting ${mediaLabel}. ${error.message}`);
|
|
463
421
|
}
|
|
464
422
|
});
|
|
465
423
|
}
|
|
466
|
-
static
|
|
424
|
+
static DeleteMyAnimeList() {
|
|
467
425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
console.log(`del ${statusMessage} ${deleted ? colorize.Green('✔') : colorize.Red('✘')}`);
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
console.error(`Error deleting manga. ${(_d = (_c = response === null || response === void 0 ? void 0 : response.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
console.error(`Error deleting manga. ${id} ${error instanceof Error ? error.message : error}`);
|
|
482
|
-
}
|
|
426
|
+
return Auth.DeleteMyMediaList(currentUserAnimeList, Auth.DeleteAnimeById, 'anime');
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
static DeleteMyMangaList() {
|
|
430
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
431
|
+
return Auth.DeleteMyMediaList(currentUserMangaList, Auth.DeleteMangaById, 'manga');
|
|
483
432
|
});
|
|
484
433
|
}
|
|
485
434
|
static Write(status) {
|
|
@@ -573,6 +522,27 @@ Statistics (Manga):
|
|
|
573
522
|
}
|
|
574
523
|
});
|
|
575
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* Attempt to like a single activity, respecting activities that are already liked.
|
|
527
|
+
* Printing/counting is left to the caller since labeling conventions differ per flow.
|
|
528
|
+
*/
|
|
529
|
+
static attemptLikeActivity(activ) {
|
|
530
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
531
|
+
if (activ.isLiked || !activ.id) {
|
|
532
|
+
return 'skipped';
|
|
533
|
+
}
|
|
534
|
+
try {
|
|
535
|
+
const like = yield fetcher(likeActivityMutation, {
|
|
536
|
+
activityId: activ.id,
|
|
537
|
+
});
|
|
538
|
+
return (like === null || like === void 0 ? void 0 : like.data) ? 'liked' : 'failed';
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
542
|
+
return 'error';
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
576
546
|
static LikeFollowing() {
|
|
577
547
|
return __awaiter(this, void 0, void 0, function* () {
|
|
578
548
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -592,27 +562,18 @@ Statistics (Manga):
|
|
|
592
562
|
retryCount = 0; // Reset retry count on successful fetch
|
|
593
563
|
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;
|
|
594
564
|
for (let activ of activiti) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
likedCount++;
|
|
602
|
-
}
|
|
603
|
-
responsiveOutput(`${(like === null || like === void 0 ? void 0 : like.data) ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
|
|
604
|
-
}
|
|
605
|
-
catch (error) {
|
|
606
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
607
|
-
}
|
|
565
|
+
const result = yield Auth.attemptLikeActivity(activ);
|
|
566
|
+
if (result === 'liked') {
|
|
567
|
+
likedCount++;
|
|
568
|
+
}
|
|
569
|
+
if (result === 'liked' || result === 'failed') {
|
|
570
|
+
responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
|
|
608
571
|
}
|
|
609
|
-
else {
|
|
572
|
+
else if (result === 'skipped') {
|
|
610
573
|
responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, likedCount)}`);
|
|
611
574
|
}
|
|
612
575
|
// avoiding rate-limit
|
|
613
|
-
yield
|
|
614
|
-
setTimeout(resolve, 2000);
|
|
615
|
-
});
|
|
576
|
+
yield sleep(2000);
|
|
616
577
|
}
|
|
617
578
|
page++;
|
|
618
579
|
}
|
|
@@ -621,7 +582,7 @@ Statistics (Manga):
|
|
|
621
582
|
spinner.start('Getting activities...');
|
|
622
583
|
retryCount++;
|
|
623
584
|
spinner.update(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
|
|
624
|
-
yield
|
|
585
|
+
yield sleep(2000);
|
|
625
586
|
}
|
|
626
587
|
else {
|
|
627
588
|
spinner.error(`Probably the end of activities after ${maxRetries} retries.`);
|
|
@@ -652,26 +613,16 @@ Statistics (Manga):
|
|
|
652
613
|
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;
|
|
653
614
|
spinner.success(`Got ${activiti.length} activities...`);
|
|
654
615
|
for (let activ of activiti) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
});
|
|
660
|
-
// const ToggleLike = like?.data?.ToggleLike
|
|
661
|
-
likedCount++;
|
|
662
|
-
responsiveOutput(`${(like === null || like === void 0 ? void 0 : like.data) ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
|
|
663
|
-
}
|
|
664
|
-
catch (error) {
|
|
665
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
666
|
-
}
|
|
616
|
+
const result = yield Auth.attemptLikeActivity(activ);
|
|
617
|
+
if (result === 'liked' || result === 'failed') {
|
|
618
|
+
likedCount++;
|
|
619
|
+
responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
|
|
667
620
|
}
|
|
668
|
-
else {
|
|
621
|
+
else if (result === 'skipped') {
|
|
669
622
|
responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, likedCount)}`);
|
|
670
623
|
}
|
|
671
624
|
// avoiding rate-limit
|
|
672
|
-
yield
|
|
673
|
-
setTimeout(resolve, 1500);
|
|
674
|
-
});
|
|
625
|
+
yield sleep(1500);
|
|
675
626
|
}
|
|
676
627
|
page++;
|
|
677
628
|
}
|
|
@@ -725,23 +676,16 @@ Statistics (Manga):
|
|
|
725
676
|
}
|
|
726
677
|
spinner.success(`Got ${activiti.length} activities...`);
|
|
727
678
|
for (let activ of activiti) {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
likedCount
|
|
734
|
-
|
|
735
|
-
if (likedCount >= toLikeAmount) {
|
|
736
|
-
spinner.success(`Finished liking ${likedCount} activities of ${username}.`);
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
catch (error) {
|
|
741
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
679
|
+
const result = yield Auth.attemptLikeActivity(activ);
|
|
680
|
+
if (result === 'liked' || result === 'failed') {
|
|
681
|
+
likedCount++;
|
|
682
|
+
responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
|
|
683
|
+
if (likedCount >= toLikeAmount) {
|
|
684
|
+
spinner.success(`Finished liking ${likedCount} activities of ${username}.`);
|
|
685
|
+
return;
|
|
742
686
|
}
|
|
743
687
|
}
|
|
744
|
-
else {
|
|
688
|
+
else if (result === 'skipped') {
|
|
745
689
|
responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, likedCount)}`);
|
|
746
690
|
}
|
|
747
691
|
}
|
|
@@ -830,25 +774,18 @@ Statistics (Manga):
|
|
|
830
774
|
const activiti = activities.data.Page.activities;
|
|
831
775
|
for (let i = 0; i < activiti.length; i++) {
|
|
832
776
|
const activ = activiti[i];
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
responsiveOutput(`${(like === null || like === void 0 ? void 0 : like.data) ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, i + 1)}`);
|
|
839
|
-
if (like === null || like === void 0 ? void 0 : like.data) {
|
|
840
|
-
liked++;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
catch (error) {
|
|
844
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
777
|
+
const result = yield Auth.attemptLikeActivity(activ);
|
|
778
|
+
if (result === 'liked' || result === 'failed') {
|
|
779
|
+
responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, i + 1)}`);
|
|
780
|
+
if (result === 'liked') {
|
|
781
|
+
liked++;
|
|
845
782
|
}
|
|
846
783
|
}
|
|
847
|
-
else {
|
|
784
|
+
else if (result === 'skipped') {
|
|
848
785
|
responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, i + 1)}`);
|
|
849
786
|
}
|
|
850
787
|
// Avoid rate-limiting
|
|
851
|
-
yield
|
|
788
|
+
yield sleep(1200);
|
|
852
789
|
}
|
|
853
790
|
}
|
|
854
791
|
console.log(`\n${colorize.Green('✔')} All ${liked} activities liked successfully.`);
|
|
@@ -911,55 +848,79 @@ Statistics (Manga):
|
|
|
911
848
|
}
|
|
912
849
|
}
|
|
913
850
|
class Social {
|
|
851
|
+
/**
|
|
852
|
+
* Fetch every page of a followers/following listing for the current user.
|
|
853
|
+
*/
|
|
854
|
+
static fetchAllUsers(query, extractPage) {
|
|
855
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
856
|
+
let pager = 1;
|
|
857
|
+
let hasNextPage = true;
|
|
858
|
+
const allUsers = [];
|
|
859
|
+
const userId = yield Auth.MyUserId();
|
|
860
|
+
while (hasNextPage) {
|
|
861
|
+
const response = yield fetcher(query, {
|
|
862
|
+
userId,
|
|
863
|
+
page: pager,
|
|
864
|
+
});
|
|
865
|
+
const page = extractPage(response);
|
|
866
|
+
spinner.update(`Fetched page ${pager} of ${page.lastPage}...`);
|
|
867
|
+
allUsers.push(...page.list);
|
|
868
|
+
hasNextPage = page.hasNextPage;
|
|
869
|
+
pager++;
|
|
870
|
+
}
|
|
871
|
+
return allUsers;
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Toggle-follow a batch of users, logging the outcome of each.
|
|
876
|
+
*/
|
|
877
|
+
static toggleFollowBatch(users) {
|
|
878
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
879
|
+
var _a, _b, _c, _d, _e, _f;
|
|
880
|
+
let toggled = 0;
|
|
881
|
+
const maxIdLength = Math.max(...users.map(({ id }) => String(id).length));
|
|
882
|
+
const maxNameLength = Math.max(...users.map(({ name }) => name.length));
|
|
883
|
+
for (const user of users) {
|
|
884
|
+
try {
|
|
885
|
+
const response = yield fetcher(toggleFollowMutation, { userId: user.id });
|
|
886
|
+
console.log(`${String(`[${user.id}]`).padEnd(maxIdLength)}\t${String(`[${(_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.ToggleFollow) === null || _b === void 0 ? void 0 : _b.name}]`).padEnd(maxNameLength)}\t${((_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.ToggleFollow) === null || _d === void 0 ? void 0 : _d.id) ? colorize.Green('✔') : colorize.Red('✘')}`);
|
|
887
|
+
if ((_f = (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.ToggleFollow) === null || _f === void 0 ? void 0 : _f.id) {
|
|
888
|
+
toggled++;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
catch (error) {
|
|
892
|
+
console.log(`toggle_follow: ${error.message}`);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return toggled;
|
|
896
|
+
});
|
|
897
|
+
}
|
|
914
898
|
/**
|
|
915
899
|
* Follow the users that follows you
|
|
916
900
|
*/
|
|
917
901
|
static follow() {
|
|
918
902
|
return __awaiter(this, void 0, void 0, function* () {
|
|
919
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
920
903
|
try {
|
|
921
|
-
let pager = 1;
|
|
922
|
-
let hasNextPage = true;
|
|
923
|
-
let allFollowerUsers = [];
|
|
924
|
-
let followedBack = 0;
|
|
925
904
|
spinner.start('Fetching all the followers...');
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
905
|
+
const allFollowerUsers = yield Social.fetchAllUsers(userFollowersQuery, (response) => {
|
|
906
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
907
|
+
return ({
|
|
908
|
+
list: ((_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.followers) || [],
|
|
909
|
+
hasNextPage: (_f = (_e = (_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.pageInfo) === null || _e === void 0 ? void 0 : _e.hasNextPage) !== null && _f !== void 0 ? _f : false,
|
|
910
|
+
lastPage: (_j = (_h = (_g = response === null || response === void 0 ? void 0 : response.data) === null || _g === void 0 ? void 0 : _g.Page) === null || _h === void 0 ? void 0 : _h.pageInfo) === null || _j === void 0 ? void 0 : _j.lastPage,
|
|
930
911
|
});
|
|
931
|
-
|
|
932
|
-
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)) {
|
|
933
|
-
hasNextPage = false;
|
|
934
|
-
}
|
|
935
|
-
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) || []));
|
|
936
|
-
pager++;
|
|
937
|
-
}
|
|
912
|
+
});
|
|
938
913
|
spinner.stop('Fetched all the followers. Starting follow back.');
|
|
939
914
|
// Filter users that do no follow me
|
|
940
915
|
const notFollowing = allFollowerUsers
|
|
941
916
|
.filter(({ isFollowing }) => !isFollowing)
|
|
942
|
-
.map(({ id, name }) => ({ id
|
|
917
|
+
.map(({ id, name }) => ({ id, name }));
|
|
943
918
|
console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
|
|
944
919
|
if (notFollowing.length <= 0) {
|
|
945
920
|
console.log(`Probably followed back all the users.`);
|
|
946
921
|
return;
|
|
947
922
|
}
|
|
948
|
-
|
|
949
|
-
const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
|
|
950
|
-
const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
|
|
951
|
-
for (let nf of notFollowing) {
|
|
952
|
-
try {
|
|
953
|
-
const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
|
|
954
|
-
console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}\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)}\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) ? colorize.Green('✔') : colorize.Red('✘')}`); // Count the followed back users
|
|
955
|
-
if ((_p = (_o = follow === null || follow === void 0 ? void 0 : follow.data) === null || _o === void 0 ? void 0 : _o.ToggleFollow) === null || _p === void 0 ? void 0 : _p.id) {
|
|
956
|
-
followedBack++;
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
catch (error) {
|
|
960
|
-
console.log(`automate_follow_toggle_follow: ${error.message}`);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
923
|
+
const followedBack = yield Social.toggleFollowBatch(notFollowing);
|
|
963
924
|
console.log(`\n${colorize.Green('✔')} Followed back ${followedBack} users.`);
|
|
964
925
|
}
|
|
965
926
|
catch (error) {
|
|
@@ -972,57 +933,98 @@ class Social {
|
|
|
972
933
|
*/
|
|
973
934
|
static unfollow() {
|
|
974
935
|
return __awaiter(this, void 0, void 0, function* () {
|
|
975
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
976
936
|
try {
|
|
977
|
-
let pager = 1;
|
|
978
|
-
let hasNextPage = true;
|
|
979
|
-
let allFollowingUsers = [];
|
|
980
|
-
let unfollowedUsers = 0;
|
|
981
937
|
spinner.start('Fetching all following users...');
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
938
|
+
const allFollowingUsers = yield Social.fetchAllUsers(userFollowingQuery, (response) => {
|
|
939
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
940
|
+
return ({
|
|
941
|
+
list: ((_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.following) || [],
|
|
942
|
+
hasNextPage: (_f = (_e = (_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.pageInfo) === null || _e === void 0 ? void 0 : _e.hasNextPage) !== null && _f !== void 0 ? _f : false,
|
|
943
|
+
lastPage: (_j = (_h = (_g = response === null || response === void 0 ? void 0 : response.data) === null || _g === void 0 ? void 0 : _g.Page) === null || _h === void 0 ? void 0 : _h.pageInfo) === null || _j === void 0 ? void 0 : _j.lastPage,
|
|
986
944
|
});
|
|
987
|
-
|
|
988
|
-
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)) {
|
|
989
|
-
hasNextPage = false;
|
|
990
|
-
}
|
|
991
|
-
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) || []));
|
|
992
|
-
pager++;
|
|
993
|
-
}
|
|
945
|
+
});
|
|
994
946
|
spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
|
|
995
947
|
// Filter users that do no follow me
|
|
996
948
|
const notFollowingMe = allFollowingUsers
|
|
997
949
|
.filter((user) => !user.isFollower)
|
|
998
|
-
.map((
|
|
950
|
+
.map(({ id, name }) => ({ id, name }));
|
|
999
951
|
if (notFollowingMe.length <= 0) {
|
|
1000
952
|
spinner.stop(`No users to unfollow. Exiting operation...`);
|
|
1001
953
|
return;
|
|
1002
954
|
}
|
|
1003
955
|
spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
|
|
1004
|
-
let nfmCount = 0;
|
|
1005
956
|
console.log(`\n`);
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
957
|
+
const unfollowedUsers = yield Social.toggleFollowBatch(notFollowingMe);
|
|
958
|
+
console.log(`\n${colorize.Green('✔')} Total Unfollowed: ${unfollowedUsers} of ${notFollowingMe.length} users.`);
|
|
959
|
+
}
|
|
960
|
+
catch (error) {
|
|
961
|
+
console.error(`\nautomate_unfollow: ${error.message}`);
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Unfollow the users you follow who haven't posted any activity in the
|
|
967
|
+
* given number of months, to help clear out stale/inactive accounts.
|
|
968
|
+
*/
|
|
969
|
+
static unfollowInactive(months) {
|
|
970
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
971
|
+
var _a, _b, _c, _d;
|
|
972
|
+
try {
|
|
973
|
+
if (!Number.isFinite(months) || months <= 0) {
|
|
974
|
+
console.error(`\nMust provide a positive number of months.`);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
spinner.start('Fetching all following users...');
|
|
978
|
+
const allFollowingUsers = yield Social.fetchAllUsers(userFollowingQuery, (response) => {
|
|
979
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
980
|
+
return ({
|
|
981
|
+
list: ((_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.following) || [],
|
|
982
|
+
hasNextPage: (_f = (_e = (_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.pageInfo) === null || _e === void 0 ? void 0 : _e.hasNextPage) !== null && _f !== void 0 ? _f : false,
|
|
983
|
+
lastPage: (_j = (_h = (_g = response === null || response === void 0 ? void 0 : response.data) === null || _g === void 0 ? void 0 : _g.Page) === null || _h === void 0 ? void 0 : _h.pageInfo) === null || _j === void 0 ? void 0 : _j.lastPage,
|
|
984
|
+
});
|
|
985
|
+
});
|
|
986
|
+
spinner.stop(`Fetched ${allFollowingUsers.length} following user(s). Checking their last activity...`);
|
|
987
|
+
const inactivityWindow = months * 30 * 24 * 60 * 60;
|
|
988
|
+
const cutoff = Math.floor(Date.now() / 1000) - inactivityWindow;
|
|
989
|
+
// Users active within this many seconds *after* the cutoff are "almost"
|
|
990
|
+
// stale (within 20% of the inactivity window) and get a soft warning.
|
|
991
|
+
const nearCutoff = cutoff + inactivityWindow * 0.2;
|
|
992
|
+
const staleUsers = [];
|
|
993
|
+
// Fixed-width columns so rows line up regardless of name/index length
|
|
994
|
+
const maxIndexLength = `[${allFollowingUsers.length}/${allFollowingUsers.length}]`.length;
|
|
995
|
+
const maxNameLength = Math.max(...allFollowingUsers.map(({ name }) => name.length));
|
|
996
|
+
let checked = 0;
|
|
997
|
+
for (const user of allFollowingUsers) {
|
|
998
|
+
checked++;
|
|
999
|
+
const activityResponse = yield fetcher(specificUserActivitiesQuery, { userId: user.id, page: 1, perPage: 1 });
|
|
1000
|
+
const lastActiveAt = (_d = (_c = (_b = (_a = activityResponse === null || activityResponse === void 0 ? void 0 : activityResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.createdAt;
|
|
1001
|
+
const isStale = !lastActiveAt || lastActiveAt < cutoff;
|
|
1002
|
+
const isNearStale = !isStale && lastActiveAt < nearCutoff;
|
|
1003
|
+
const activityLabel = lastActiveAt
|
|
1004
|
+
? timestampToTimeAgo(lastActiveAt)
|
|
1005
|
+
: 'no activity found';
|
|
1006
|
+
const coloredActivityLabel = isStale
|
|
1007
|
+
? colorize.Red(activityLabel)
|
|
1008
|
+
: isNearStale
|
|
1009
|
+
? colorize.Yellow(activityLabel)
|
|
1010
|
+
: activityLabel;
|
|
1011
|
+
responsiveOutput(`${`[${checked}/${allFollowingUsers.length}]`.padEnd(maxIndexLength)}\t${user.name.padEnd(maxNameLength)}\t${coloredActivityLabel}`);
|
|
1012
|
+
if (isStale) {
|
|
1013
|
+
staleUsers.push({ id: user.id, name: user.name });
|
|
1020
1014
|
}
|
|
1015
|
+
// avoiding rate-limit
|
|
1016
|
+
yield sleep(1100);
|
|
1017
|
+
}
|
|
1018
|
+
console.log(`\nFound ${staleUsers.length} user(s) inactive for ${months}+ month(s).`);
|
|
1019
|
+
if (staleUsers.length <= 0) {
|
|
1020
|
+
console.log(`No stale accounts to unfollow.`);
|
|
1021
|
+
return;
|
|
1021
1022
|
}
|
|
1022
|
-
|
|
1023
|
+
const unfollowedUsers = yield Social.toggleFollowBatch(staleUsers);
|
|
1024
|
+
console.log(`\n${colorize.Green('✔')} Unfollowed ${unfollowedUsers} of ${staleUsers.length} inactive user(s).`);
|
|
1023
1025
|
}
|
|
1024
1026
|
catch (error) {
|
|
1025
|
-
console.error(`\
|
|
1027
|
+
console.error(`\nautomate_unfollow_inactive: ${error.message}`);
|
|
1026
1028
|
}
|
|
1027
1029
|
});
|
|
1028
1030
|
}
|