@irfanshadikrishad/anilist 1.2.0-forbidden.1 → 1.2.3-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.
@@ -17,7 +17,7 @@ import { fetcher } from "./fetcher.js";
17
17
  import { AniList, MyAnimeList } from "./lists.js";
18
18
  import { deleteActivityMutation, likeActivityMutation, saveTextActivityMutation, } from "./mutations.js";
19
19
  import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, userActivityQuery, userQuery, } from "./queries.js";
20
- import { aniListEndpoint, getTitle, redirectUri } from "./workers.js";
20
+ import { activityBy, aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
21
21
  const home_dir = os.homedir();
22
22
  const save_path = path.join(home_dir, ".anilist_token");
23
23
  class Auth {
@@ -109,7 +109,7 @@ class Auth {
109
109
  }
110
110
  static Myself() {
111
111
  return __awaiter(this, void 0, void 0, function* () {
112
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
112
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
113
113
  try {
114
114
  if (yield Auth.isLoggedIn()) {
115
115
  const headers = {
@@ -130,33 +130,35 @@ 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
+ Episodes Watched: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.anime) === null || _o === void 0 ? void 0 : _o.episodesWatched}
151
+
152
+ Statistics (Manga):
153
+ Count: ${(_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.count}
154
+ Mean Score: ${(_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.meanScore}
155
+ Chapters Read: ${(_u = (_t = user === null || user === void 0 ? void 0 : user.statistics) === null || _t === void 0 ? void 0 : _t.manga) === null || _u === void 0 ? void 0 : _u.chaptersRead}
156
+ Volumes Read: ${(_w = (_v = user === null || user === void 0 ? void 0 : user.statistics) === null || _v === void 0 ? void 0 : _v.manga) === null || _w === void 0 ? void 0 : _w.volumesRead}
155
157
  `);
156
158
  console.log(`\nRecent Activities:`);
157
159
  if (activities.length > 0) {
158
- activities.map(({ status, progress, media }) => {
159
- console.log(`${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
160
+ activities.map(({ status, progress, media, createdAt }) => {
161
+ console.log(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
160
162
  });
161
163
  }
162
164
  return user;
@@ -217,7 +219,7 @@ Statistics (Manga):
217
219
  return __awaiter(this, void 0, void 0, function* () {
218
220
  var _a, _b;
219
221
  if (!(yield Auth.isLoggedIn())) {
220
- console.log(`\nUser not logged in.`);
222
+ console.warn(`\nUser not logged in.`);
221
223
  return null;
222
224
  }
223
225
  const token = yield Auth.RetriveAccessToken();
@@ -281,8 +283,6 @@ Statistics (Manga):
281
283
  ],
282
284
  },
283
285
  ]);
284
- const userId = yield Auth.MyUserId();
285
- const variables = { page: 1, perPage: 100, userId };
286
286
  const queryMap = {
287
287
  0: activityAllQuery,
288
288
  1: activityTextQuery,
@@ -293,6 +293,7 @@ Statistics (Manga):
293
293
  };
294
294
  const query = queryMap[activityType];
295
295
  let hasMoreActivities = true;
296
+ let totalCount = 0;
296
297
  while (hasMoreActivities) {
297
298
  const response = yield fetcher(query, {
298
299
  page: 1,
@@ -315,7 +316,8 @@ Statistics (Manga):
315
316
  });
316
317
  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;
317
318
  count++;
318
- console.log(`[${count}/${activities.length}] ${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
319
+ totalCount++;
320
+ console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
319
321
  // Avoiding rate-limit
320
322
  yield new Promise((resolve) => setTimeout(resolve, 1100));
321
323
  }
@@ -360,7 +362,7 @@ Statistics (Manga):
360
362
  const selectedEntries = lists.find((list) => list.name === selectedList);
361
363
  if (selectedEntries) {
362
364
  console.log(`\nDeleting entries of '${selectedEntries.name}':`);
363
- for (const [_, entry] of selectedEntries.entries.entries()) {
365
+ for (const [, entry] of selectedEntries.entries.entries()) {
364
366
  if (entry === null || entry === void 0 ? void 0 : entry.id) {
365
367
  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);
366
368
  yield new Promise((resolve) => setTimeout(resolve, 1100));
@@ -396,19 +398,8 @@ Statistics (Manga):
396
398
  return __awaiter(this, void 0, void 0, function* () {
397
399
  var _a, _b, _c;
398
400
  try {
399
- const request = yield fetch(aniListEndpoint, {
400
- method: "POST",
401
- headers: {
402
- "content-type": "application/json",
403
- "Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
404
- },
405
- body: JSON.stringify({
406
- query: deleteMediaEntryMutation,
407
- variables: { id },
408
- }),
409
- });
410
- const response = yield request.json();
411
- if (request.status === 200) {
401
+ const response = yield fetcher(deleteMediaEntryMutation, { id: id });
402
+ if (response === null || response === void 0 ? void 0 : response.data) {
412
403
  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;
413
404
  console.log(`del ${title ? getTitle(title) : ""} ${deleted ? "✅" : "❌"}`);
414
405
  }
@@ -445,7 +436,7 @@ Statistics (Manga):
445
436
  const selectedEntries = lists.find((list) => list.name === selectedList);
446
437
  if (selectedEntries) {
447
438
  console.log(`\nDeleting entries of '${selectedEntries.name}':`);
448
- for (const [_, entry] of selectedEntries.entries.entries()) {
439
+ for (const [, entry] of selectedEntries.entries.entries()) {
449
440
  if (entry === null || entry === void 0 ? void 0 : entry.id) {
450
441
  yield Auth.DeleteMangaById(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);
451
442
  yield new Promise((resolve) => setTimeout(resolve, 1100));
@@ -477,33 +468,22 @@ Statistics (Manga):
477
468
  }
478
469
  }
479
470
  catch (error) {
480
- console.error(`\nError deleting manga.`);
471
+ console.error(`\nError deleting manga. ${error.message}`);
481
472
  }
482
473
  });
483
474
  }
484
475
  static DeleteMangaById(id, title) {
485
476
  return __awaiter(this, void 0, void 0, function* () {
486
- var _a, _b;
477
+ var _a, _b, _c, _d;
487
478
  try {
488
- const request = yield fetch(aniListEndpoint, {
489
- method: "POST",
490
- headers: {
491
- "Content-Type": "application/json",
492
- "Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
493
- },
494
- body: JSON.stringify({
495
- query: deleteMangaEntryMutation,
496
- variables: { id },
497
- }),
498
- });
499
- const { data, errors } = yield request.json();
479
+ const response = yield fetcher(deleteMangaEntryMutation, { id });
500
480
  const statusMessage = title ? getTitle(title) : "";
501
- if (request.ok) {
502
- const deleted = (_a = data === null || data === void 0 ? void 0 : data.DeleteMediaListEntry) === null || _a === void 0 ? void 0 : _a.deleted;
481
+ if (response === null || response === void 0 ? void 0 : response.data) {
482
+ 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;
503
483
  console.log(`del ${statusMessage} ${deleted ? "✅" : "❌"}`);
504
484
  }
505
485
  else {
506
- console.error(`Error deleting manga. ${(_b = errors === null || errors === void 0 ? void 0 : errors[0]) === null || _b === void 0 ? void 0 : _b.message}`);
486
+ 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}`);
507
487
  }
508
488
  }
509
489
  catch (error) {
@@ -519,12 +499,10 @@ Statistics (Manga):
519
499
  console.error(`\nPlease login to use this feature.`);
520
500
  return;
521
501
  }
522
- const query = saveTextActivityMutation;
523
- const variables = {
502
+ const data = yield fetcher(saveTextActivityMutation, {
524
503
  status: status +
525
504
  `<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
526
- };
527
- const data = yield fetcher(query, variables);
505
+ });
528
506
  if (!data) {
529
507
  console.error(`\nSomething went wrong. ${data}.`);
530
508
  return;
@@ -625,14 +603,14 @@ Statistics (Manga):
625
603
  const like = yield fetcher(likeActivityMutation, {
626
604
  activityId: activ.id,
627
605
  });
628
- console.info(`[${activ.id}] liked ${activ.user.name}`);
606
+ console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
629
607
  }
630
608
  catch (error) {
631
- console.error(`Activity possibly deleted.`);
609
+ console.error(`Activity possibly deleted. ${error.message}`);
632
610
  }
633
611
  }
634
612
  else {
635
- console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}] ${activ.user.name} already-liked`);
613
+ console.log(`${activityBy(activ)} 🔵`);
636
614
  }
637
615
  // avoiding rate-limit
638
616
  yield new Promise((resolve) => {
@@ -685,18 +663,18 @@ Statistics (Manga):
685
663
  activityId: activ.id,
686
664
  });
687
665
  // const ToggleLike = like?.data?.ToggleLike
688
- console.info(`[${activ.id}] liked ${activ.user.name}`);
666
+ console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
689
667
  }
690
668
  catch (error) {
691
- console.error(`Activity possibly deleted.`);
669
+ console.error(`Activity possibly deleted. ${error.message}`);
692
670
  }
693
671
  }
694
672
  else {
695
- console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}] ${activ.user.name} already-liked`);
673
+ console.log(`${activityBy(activ)} 🔵`);
696
674
  }
697
675
  // avoiding rate-limit
698
676
  yield new Promise((resolve) => {
699
- setTimeout(resolve, 2000);
677
+ setTimeout(resolve, 1500);
700
678
  });
701
679
  }
702
680
  page++;
@@ -716,7 +694,7 @@ Statistics (Manga):
716
694
  }
717
695
  static LikeSpecificUser() {
718
696
  return __awaiter(this, void 0, void 0, function* () {
719
- var _a, _b, _c, _d, _e, _f;
697
+ var _a, _b, _c, _d;
720
698
  try {
721
699
  const { username } = yield inquirer.prompt([
722
700
  {
@@ -749,18 +727,18 @@ Statistics (Manga):
749
727
  const like = yield fetcher(likeActivityMutation, {
750
728
  activityId: activ.id,
751
729
  });
752
- console.info(`[${activ.id}] liked ${(_e = activ.user) === null || _e === void 0 ? void 0 : _e.name}`);
730
+ console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
753
731
  }
754
732
  catch (error) {
755
- console.error(`Activity possibly deleted.`);
733
+ console.error(`Activity possibly deleted. ${error.message}`);
756
734
  }
757
735
  }
758
736
  else {
759
- console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}] ${(_f = activ.user) === null || _f === void 0 ? void 0 : _f.name} already liked`);
737
+ console.log(`${activityBy(activ)} 🔵`);
760
738
  }
761
739
  // Avoiding rate limit
762
740
  yield new Promise((resolve) => {
763
- setTimeout(resolve, 2000);
741
+ setTimeout(resolve, 1500);
764
742
  });
765
743
  }
766
744
  // Go to the next page
@@ -9,5 +9,5 @@
9
9
  * @param {object} variables - An object containing the variables for the query.
10
10
  * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
11
11
  */
12
- declare function fetcher(query: string, variables: object): Promise<any>;
12
+ declare function fetcher(query: string, variables: object): Promise<object | null>;
13
13
  export { fetcher };
@@ -5,7 +5,7 @@ declare class AniList {
5
5
  static exportManga(): Promise<void>;
6
6
  static MyAnime(): Promise<void>;
7
7
  static MyManga(): Promise<void>;
8
- static getTrendingAnime(count: number): Promise<any>;
8
+ static getTrendingAnime(count: number): Promise<void>;
9
9
  static getPopularAnime(count: number): Promise<void>;
10
10
  static getUpcomingAnime(count: number): Promise<void>;
11
11
  static getUserByUsername(username: string): Promise<void>;