@irfanshadikrishad/anilist 1.0.0-forbidden.0 → 1.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.
@@ -16,7 +16,7 @@ import path from "path";
16
16
  import { fetcher } from "./fetcher.js";
17
17
  import { AniList, MyAnimeList } from "./lists.js";
18
18
  import { deleteActivityMutation, likeActivityMutation, saveTextActivityMutation, } from "./mutations.js";
19
- import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, userActivityQuery, } from "./queries.js";
19
+ import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, userActivityQuery, userQuery, } from "./queries.js";
20
20
  import { aniListEndpoint, getTitle, redirectUri } from "./workers.js";
21
21
  const home_dir = os.homedir();
22
22
  const save_path = path.join(home_dir, ".anilist_token");
@@ -130,28 +130,28 @@ class Auth {
130
130
  perPage: 10,
131
131
  });
132
132
  const activities = (_b = (_a = activiResponse === null || activiResponse === void 0 ? void 0 : activiResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
133
- console.log(`
134
- ID: ${user === null || user === void 0 ? void 0 : user.id}
135
- Name: ${user === null || user === void 0 ? void 0 : user.name}
136
- siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
137
- profileColor: ${(_c = user === null || user === void 0 ? void 0 : user.options) === null || _c === void 0 ? void 0 : _c.profileColor}
138
- timeZone: ${(_d = user === null || user === void 0 ? void 0 : user.options) === null || _d === void 0 ? void 0 : _d.timezone}
139
- activityMergeTime: ${(_e = user === null || user === void 0 ? void 0 : user.options) === null || _e === void 0 ? void 0 : _e.activityMergeTime}
140
- donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
141
- donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
142
- unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
143
- Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
144
- Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
145
-
146
- Statistics (Anime):
147
- Count: ${(_g = (_f = user === null || user === void 0 ? void 0 : user.statistics) === null || _f === void 0 ? void 0 : _f.anime) === null || _g === void 0 ? void 0 : _g.count}
148
- Mean Score: ${(_j = (_h = user === null || user === void 0 ? void 0 : user.statistics) === null || _h === void 0 ? void 0 : _h.anime) === null || _j === void 0 ? void 0 : _j.meanScore}
149
- Minutes Watched: ${(_l = (_k = user === null || user === void 0 ? void 0 : user.statistics) === null || _k === void 0 ? void 0 : _k.anime) === null || _l === void 0 ? void 0 : _l.minutesWatched}
150
-
151
- Statistics (Manga):
152
- Count: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.manga) === null || _o === void 0 ? void 0 : _o.count}
153
- Chapters Read: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.manga) === null || _q === void 0 ? void 0 : _q.chaptersRead}
154
- Volumes Read: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.manga) === null || _s === void 0 ? void 0 : _s.volumesRead}
133
+ console.log(`
134
+ ID: ${user === null || user === void 0 ? void 0 : user.id}
135
+ Name: ${user === null || user === void 0 ? void 0 : user.name}
136
+ siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
137
+ profileColor: ${(_c = user === null || user === void 0 ? void 0 : user.options) === null || _c === void 0 ? void 0 : _c.profileColor}
138
+ timeZone: ${(_d = user === null || user === void 0 ? void 0 : user.options) === null || _d === void 0 ? void 0 : _d.timezone}
139
+ activityMergeTime: ${(_e = user === null || user === void 0 ? void 0 : user.options) === null || _e === void 0 ? void 0 : _e.activityMergeTime}
140
+ donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
141
+ donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
142
+ unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
143
+ Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
144
+ Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
145
+
146
+ Statistics (Anime):
147
+ Count: ${(_g = (_f = user === null || user === void 0 ? void 0 : user.statistics) === null || _f === void 0 ? void 0 : _f.anime) === null || _g === void 0 ? void 0 : _g.count}
148
+ Mean Score: ${(_j = (_h = user === null || user === void 0 ? void 0 : user.statistics) === null || _h === void 0 ? void 0 : _h.anime) === null || _j === void 0 ? void 0 : _j.meanScore}
149
+ Minutes Watched: ${(_l = (_k = user === null || user === void 0 ? void 0 : user.statistics) === null || _k === void 0 ? void 0 : _k.anime) === null || _l === void 0 ? void 0 : _l.minutesWatched}
150
+
151
+ Statistics (Manga):
152
+ Count: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.manga) === null || _o === void 0 ? void 0 : _o.count}
153
+ Chapters Read: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.manga) === null || _q === void 0 ? void 0 : _q.chaptersRead}
154
+ Volumes Read: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.manga) === null || _s === void 0 ? void 0 : _s.volumesRead}
155
155
  `);
156
156
  console.log(`\nRecent Activities:`);
157
157
  if (activities.length > 0) {
@@ -625,26 +625,93 @@ Statistics (Manga):
625
625
  }
626
626
  });
627
627
  }
628
- static likeFollowing() {
628
+ static LikeFollowing() {
629
629
  return __awaiter(this, void 0, void 0, function* () {
630
- var _a, _b, _c, _d, _e;
630
+ var _a, _b, _c, _d;
631
631
  try {
632
632
  let page = 1;
633
633
  let hasMoreActivities = true;
634
+ let retryCount = 0;
635
+ const maxRetries = 5;
634
636
  while (hasMoreActivities) {
635
637
  const activities = yield fetcher(followingActivitiesQuery, {
636
638
  page,
637
639
  perPage: 50,
638
640
  });
639
641
  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) {
642
+ retryCount = 0; // Reset retry count on successful fetch
640
643
  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;
641
644
  for (let activ of activiti) {
642
645
  if (!activ.isLiked && activ.id) {
643
- const like = yield fetcher(likeActivityMutation, {
644
- activityId: activ.id,
645
- });
646
- const ToggleLike = (_e = like === null || like === void 0 ? void 0 : like.data) === null || _e === void 0 ? void 0 : _e.ToggleLike;
647
- console.info(`[${activ.id}] liked ${activ.user.name}`);
646
+ try {
647
+ const like = yield fetcher(likeActivityMutation, {
648
+ activityId: activ.id,
649
+ });
650
+ console.info(`[${activ.id}] liked ${activ.user.name}`);
651
+ }
652
+ catch (error) {
653
+ console.error(`Activity possibly deleted.`);
654
+ }
655
+ }
656
+ else {
657
+ console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}] ${activ.user.name} already-liked`);
658
+ }
659
+ // avoiding rate-limit
660
+ yield new Promise((resolve) => {
661
+ setTimeout(resolve, 2000);
662
+ });
663
+ }
664
+ page++;
665
+ }
666
+ else {
667
+ if (retryCount < maxRetries) {
668
+ retryCount++;
669
+ console.warn(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
670
+ yield new Promise((resolve) => setTimeout(resolve, 3000));
671
+ }
672
+ else {
673
+ console.log(`\nProbably the end of activities after ${maxRetries} retries.`);
674
+ console.info(activities);
675
+ hasMoreActivities = false;
676
+ }
677
+ }
678
+ }
679
+ }
680
+ catch (error) {
681
+ console.error(`\nError from likeFollowing. ${error.message}`);
682
+ }
683
+ });
684
+ }
685
+ static Like(type) {
686
+ return __awaiter(this, void 0, void 0, function* () {
687
+ var _a, _b, _c, _d;
688
+ try {
689
+ let page = 1;
690
+ let hasMoreActivities = true;
691
+ let activity = type === 0
692
+ ? followingActivitiesQuery
693
+ : type === 1
694
+ ? globalActivitiesQuery
695
+ : followingActivitiesQuery;
696
+ while (hasMoreActivities) {
697
+ const activities = yield fetcher(activity, {
698
+ page,
699
+ perPage: 50,
700
+ });
701
+ 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) {
702
+ 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;
703
+ for (let activ of activiti) {
704
+ if (!activ.isLiked && activ.id) {
705
+ try {
706
+ const like = yield fetcher(likeActivityMutation, {
707
+ activityId: activ.id,
708
+ });
709
+ // const ToggleLike = like?.data?.ToggleLike
710
+ console.info(`[${activ.id}] liked ${activ.user.name}`);
711
+ }
712
+ catch (error) {
713
+ console.error(`Activity possibly deleted.`);
714
+ }
648
715
  }
649
716
  else {
650
717
  console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}] ${activ.user.name} already-liked`);
@@ -669,6 +736,66 @@ Statistics (Manga):
669
736
  }
670
737
  });
671
738
  }
739
+ static LikeSpecificUser() {
740
+ return __awaiter(this, void 0, void 0, function* () {
741
+ var _a, _b, _c, _d, _e, _f;
742
+ try {
743
+ const { username } = yield inquirer.prompt([
744
+ {
745
+ type: "input",
746
+ name: "username",
747
+ message: "Username of the user:",
748
+ },
749
+ ]);
750
+ const userDetails = yield fetcher(userQuery, { username: username });
751
+ if (userDetails) {
752
+ let page = 1;
753
+ const perPage = 50;
754
+ const userId = (_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;
755
+ if (userId) {
756
+ while (true) {
757
+ const activities = yield fetcher(specificUserActivitiesQuery, {
758
+ page,
759
+ perPage,
760
+ userId,
761
+ });
762
+ 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;
763
+ // Break the loop if no more activities are found
764
+ if (!activiti || activiti.length === 0) {
765
+ console.log("No more activities found.");
766
+ break;
767
+ }
768
+ for (let activ of activiti) {
769
+ if (!activ.isLiked && activ.id) {
770
+ try {
771
+ const like = yield fetcher(likeActivityMutation, {
772
+ activityId: activ.id,
773
+ });
774
+ console.info(`[${activ.id}] liked ${(_e = activ.user) === null || _e === void 0 ? void 0 : _e.name}`);
775
+ }
776
+ catch (error) {
777
+ console.error(`Activity possibly deleted.`);
778
+ }
779
+ }
780
+ else {
781
+ console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}] ${(_f = activ.user) === null || _f === void 0 ? void 0 : _f.name} already liked`);
782
+ }
783
+ // Avoiding rate limit
784
+ yield new Promise((resolve) => {
785
+ setTimeout(resolve, 2000);
786
+ });
787
+ }
788
+ // Go to the next page
789
+ page += 1;
790
+ }
791
+ }
792
+ }
793
+ }
794
+ catch (error) {
795
+ console.error(`\nError from LikeSpecificUser. ${error.message}`);
796
+ }
797
+ });
798
+ }
672
799
  static AutoLike() {
673
800
  return __awaiter(this, void 0, void 0, function* () {
674
801
  try {
@@ -684,16 +811,20 @@ Statistics (Manga):
684
811
  choices: [
685
812
  { name: "Following", value: 1 },
686
813
  { name: "Global", value: 2 },
814
+ { name: "Specific User", value: 3 },
687
815
  ],
688
816
  pageSize: 10,
689
817
  },
690
818
  ]);
691
819
  switch (activityType) {
692
820
  case 1:
693
- yield this.likeFollowing();
821
+ yield this.LikeFollowing();
694
822
  break;
695
823
  case 2:
696
- console.warn(`\nNot yet implemented!`);
824
+ yield this.Like(1);
825
+ break;
826
+ case 3:
827
+ yield this.LikeSpecificUser();
697
828
  break;
698
829
  default:
699
830
  console.error(`\nInvalid choice. (${activityType})`);
@@ -1,43 +1,43 @@
1
- const addAnimeToListMutation = `
2
- mutation($mediaId: Int, $status: MediaListStatus) {
3
- SaveMediaListEntry(mediaId: $mediaId, status: $status) { id status }
4
- }
1
+ const addAnimeToListMutation = `
2
+ mutation($mediaId: Int, $status: MediaListStatus) {
3
+ SaveMediaListEntry(mediaId: $mediaId, status: $status) { id status }
4
+ }
5
5
  `;
6
- const addMangaToListMutation = `
7
- mutation($mediaId: Int, $status: MediaListStatus) {
8
- SaveMediaListEntry(mediaId: $mediaId, status: $status) {
9
- id
10
- status
11
- media { id title { romaji english } }
12
- }
13
- }
6
+ const addMangaToListMutation = `
7
+ mutation($mediaId: Int, $status: MediaListStatus) {
8
+ SaveMediaListEntry(mediaId: $mediaId, status: $status) {
9
+ id
10
+ status
11
+ media { id title { romaji english } }
12
+ }
13
+ }
14
14
  `;
15
- const deleteActivityMutation = `
16
- mutation($id: Int!) {
17
- DeleteActivity(id: $id) { deleted }
18
- }
15
+ const deleteActivityMutation = `
16
+ mutation($id: Int!) {
17
+ DeleteActivity(id: $id) { deleted }
18
+ }
19
19
  `;
20
- const saveTextActivityMutation = `
21
- mutation SaveTextActivity($status: String!) {
22
- SaveTextActivity(text: $status) { id text userId createdAt }
23
- }
20
+ const saveTextActivityMutation = `
21
+ mutation SaveTextActivity($status: String!) {
22
+ SaveTextActivity(text: $status) { id text userId createdAt }
23
+ }
24
24
  `;
25
- const saveAnimeWithProgressMutation = `
26
- mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean) {
27
- SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists) {
28
- id progress hiddenFromStatusLists
29
- }
30
- }
25
+ const saveAnimeWithProgressMutation = `
26
+ mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean) {
27
+ SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists) {
28
+ id progress hiddenFromStatusLists
29
+ }
30
+ }
31
31
  `;
32
- const saveMangaWithProgressMutation = `
33
- mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean, $private: Boolean) {
34
- SaveMediaListEntry( mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists, private: $private
35
- ) { id progress hiddenFromStatusLists private }
36
- }
32
+ const saveMangaWithProgressMutation = `
33
+ mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean, $private: Boolean) {
34
+ SaveMediaListEntry( mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists, private: $private
35
+ ) { id progress hiddenFromStatusLists private }
36
+ }
37
37
  `;
38
- const likeActivityMutation = `
39
- mutation($activityId: Int!) {
40
- ToggleLike(id: $activityId, type: ACTIVITY) { id }
41
- }
38
+ const likeActivityMutation = `
39
+ mutation($activityId: Int!) {
40
+ ToggleLike(id: $activityId, type: ACTIVITY) { id }
41
+ }
42
42
  `;
43
43
  export { addAnimeToListMutation, addMangaToListMutation, deleteActivityMutation, likeActivityMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, saveTextActivityMutation, };
@@ -17,7 +17,9 @@ declare const activityMangaListQuery = "query ($userId: Int, $page: Int, $perPag
17
17
  declare const activityMessageQuery = "query ($userId: Int, $page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(userId: $userId, type: MESSAGE, sort: ID_DESC) {\n ... on MessageActivity { id type message recipient { id name } createdAt }\n }\n }\n}";
18
18
  declare const activityAllQuery = "query ($userId: Int, $page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(userId: $userId, sort: ID_DESC) {\n ... on TextActivity { id type text createdAt user { id name } }\n ... on ListActivity { id type status progress createdAt media { id title { romaji english native } } }\n ... on MessageActivity { id type message recipient { id name } createdAt }\n }\n }\n}";
19
19
  declare const activityMediaList = "query ($userId: Int, $page: Int, $perPage: Int, $type: ActivityType) {\n Page(page: $page, perPage: $perPage) {\n pageInfo { total currentPage lastPage hasNextPage perPage }\n activities(userId: $userId, type: $type, sort: ID_DESC) {\n ... on ListActivity { id type status progress media { id title { romaji english native } format } createdAt }\n }\n }\n}";
20
- declare const malIdToAnilistAnimeId = "query ($malId: Int) {\n Media(idMal: $malId, type: ANIME) {\n id title { romaji english } } \n}\n";
21
- declare const malIdToAnilistMangaId = "query ($malId: Int) {\n Media(idMal: $malId, type: MANGA) {\n id title { romaji english } } \n}\n";
22
- declare const followingActivitiesQuery = "\nquery ($page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(isFollowing: true, sort: ID_DESC) {\n ... on TextActivity {\n id type isLiked createdAt user { id name }\n }\n ... on ListActivity {\n id type isLiked status progress media { title { userPreferred } } createdAt user { id name }\n }\n ... on MessageActivity {\n id type isLiked message createdAt recipient { id name }\n }\n }\n }\n}\n";
23
- export { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaSearchQuery, popularQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userQuery, };
20
+ declare const malIdToAnilistAnimeId = "query ($malId: Int) {\n Media(idMal: $malId, type: ANIME) { id title { romaji english } } }\n";
21
+ declare const malIdToAnilistMangaId = "query ($malId: Int) {\n Media(idMal: $malId, type: MANGA) { id title { romaji english } } }\n";
22
+ declare const followingActivitiesQuery = "\nquery ($page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(isFollowing: true, sort: ID_DESC) {\n ... on TextActivity { id type isLiked createdAt user { id name } }\n ... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }\n ... on MessageActivity { id type isLiked message createdAt recipient { id name } }\n }\n }\n}\n";
23
+ declare const globalActivitiesQuery = "\nquery ($page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(sort: ID_DESC) {\n ... on TextActivity { id type isLiked createdAt user { id name } }\n ... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }\n ... on MessageActivity { id type isLiked message createdAt recipient { id name } }\n }\n }\n}\n";
24
+ declare const specificUserActivitiesQuery = "\nquery ($page: Int, $perPage: Int, $userId: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(userId: $userId, sort: ID_DESC) {\n ... on TextActivity { id type isLiked createdAt user { id name } }\n ... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }\n ... on MessageActivity { id type isLiked message createdAt recipient { id name } }\n }\n }\n}\n";
25
+ export { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaSearchQuery, popularQuery, specificUserActivitiesQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userQuery, };