@irfanshadikrishad/anilist 1.2.1-forbidden.1 → 1.2.1-forbidden.2

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.
@@ -13,13 +13,15 @@ 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 Spinner from "tiny-spinner";
16
17
  import { fetcher } from "./fetcher.js";
17
- import { AniList, MyAnimeList } from "./lists.js";
18
+ import { AniDB, AniList, MyAnimeList } from "./lists.js";
18
19
  import { deleteActivityMutation, likeActivityMutation, saveTextActivityMutation, } from "./mutations.js";
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, timestampToTimeAgo, } from "./workers.js";
20
+ import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, toggleFollowMutation, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.js";
21
+ import { activityBy, aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
21
22
  const home_dir = os.homedir();
22
23
  const save_path = path.join(home_dir, ".anilist_token");
24
+ const spinner = new Spinner();
23
25
  class Auth {
24
26
  /**
25
27
  * Get access-token from user
@@ -34,20 +36,29 @@ class Auth {
34
36
  message: "Please enter your AniList access token:",
35
37
  },
36
38
  ]);
39
+ if (!token) {
40
+ console.warn("\nNo token entered. Please try again.");
41
+ return null;
42
+ }
37
43
  return token;
38
44
  }
39
45
  catch (error) {
40
- console.error(`\nSomething went wrong. ${error.message}`);
46
+ console.error(`\nAn error occurred while getting the access token: ${error.message}`);
47
+ return null;
41
48
  }
42
49
  });
43
50
  }
44
51
  static StoreAccessToken(token) {
45
52
  return __awaiter(this, void 0, void 0, function* () {
46
53
  try {
54
+ if (!token) {
55
+ console.warn("\nNo token provided. Nothing to store.");
56
+ return;
57
+ }
47
58
  fs.writeFileSync(save_path, token, { encoding: "utf8" });
48
59
  }
49
60
  catch (error) {
50
- console.error(`\nError storing acess-token. ${error.message}`);
61
+ console.error(`\nError storing access token: ${error.message}`);
51
62
  }
52
63
  });
53
64
  }
@@ -63,6 +74,7 @@ class Auth {
63
74
  }
64
75
  catch (error) {
65
76
  console.error(`\nError retriving acess-token. ${error.message}`);
77
+ return null;
66
78
  }
67
79
  });
68
80
  }
@@ -109,7 +121,7 @@ class Auth {
109
121
  }
110
122
  static Myself() {
111
123
  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, _t, _u, _v, _w;
124
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
113
125
  try {
114
126
  if (yield Auth.isLoggedIn()) {
115
127
  const headers = {
@@ -130,30 +142,42 @@ class Auth {
130
142
  perPage: 10,
131
143
  });
132
144
  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
- 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}
145
+ // Get follower/following information
146
+ const req_followers = yield fetcher(userFollowersQuery, {
147
+ userId: user === null || user === void 0 ? void 0 : user.id,
148
+ });
149
+ const req_following = yield fetcher(userFollowingQuery, {
150
+ userId: user === null || user === void 0 ? void 0 : user.id,
151
+ });
152
+ const followersCount = ((_e = (_d = (_c = req_followers === null || req_followers === void 0 ? void 0 : req_followers.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.pageInfo) === null || _e === void 0 ? void 0 : _e.total) || 0;
153
+ const followingCount = ((_h = (_g = (_f = req_following === null || req_following === void 0 ? void 0 : req_following.data) === null || _f === void 0 ? void 0 : _f.Page) === null || _g === void 0 ? void 0 : _g.pageInfo) === null || _h === void 0 ? void 0 : _h.total) || 0;
154
+ console.log(`
155
+ ID: ${user === null || user === void 0 ? void 0 : user.id}
156
+ Name: ${user === null || user === void 0 ? void 0 : user.name}
157
+ siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
158
+ profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
159
+ timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
160
+ activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
161
+ donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
162
+ donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
163
+ unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
164
+ Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
165
+ Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
166
+
167
+ Followers: ${followersCount}
168
+ Following: ${followingCount}
169
+
170
+ Statistics (Anime):
171
+ Count: ${(_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.count}
172
+ Mean Score: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.anime) === null || _q === void 0 ? void 0 : _q.meanScore}
173
+ Minutes Watched: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.anime) === null || _s === void 0 ? void 0 : _s.minutesWatched}
174
+ Episodes Watched: ${(_u = (_t = user === null || user === void 0 ? void 0 : user.statistics) === null || _t === void 0 ? void 0 : _t.anime) === null || _u === void 0 ? void 0 : _u.episodesWatched}
175
+
176
+ Statistics (Manga):
177
+ Count: ${(_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.count}
178
+ Mean Score: ${(_y = (_x = user === null || user === void 0 ? void 0 : user.statistics) === null || _x === void 0 ? void 0 : _x.manga) === null || _y === void 0 ? void 0 : _y.meanScore}
179
+ Chapters Read: ${(_0 = (_z = user === null || user === void 0 ? void 0 : user.statistics) === null || _z === void 0 ? void 0 : _z.manga) === null || _0 === void 0 ? void 0 : _0.chaptersRead}
180
+ Volumes Read: ${(_2 = (_1 = user === null || user === void 0 ? void 0 : user.statistics) === null || _1 === void 0 ? void 0 : _1.manga) === null || _2 === void 0 ? void 0 : _2.volumesRead}
157
181
  `);
158
182
  console.log(`\nRecent Activities:`);
159
183
  if (activities.length > 0) {
@@ -181,15 +205,12 @@ Statistics (Manga):
181
205
  static isLoggedIn() {
182
206
  return __awaiter(this, void 0, void 0, function* () {
183
207
  try {
184
- if ((yield Auth.RetriveAccessToken()) !== null) {
185
- return true;
186
- }
187
- else {
188
- return false;
189
- }
208
+ const token = yield Auth.RetriveAccessToken();
209
+ return token !== null;
190
210
  }
191
211
  catch (error) {
192
- console.error(`\nError getting isLoggedIn. ${error.message}`);
212
+ console.error(`Error checking login status: ${error.message}`);
213
+ return false;
193
214
  }
194
215
  });
195
216
  }
@@ -203,15 +224,15 @@ Statistics (Manga):
203
224
  console.log(`\nLogout successful. See you soon, ${username}.`);
204
225
  }
205
226
  catch (error) {
206
- console.error("\nError logging out:", error);
227
+ console.error("\nFailed to remove the save file during logout:", error.message);
207
228
  }
208
229
  }
209
230
  else {
210
- console.error("\nYou may already be logged out.");
231
+ console.warn("\nNo active session found. You may already be logged out.");
211
232
  }
212
233
  }
213
234
  catch (error) {
214
- console.error(`\nError logging out. ${error.message}`);
235
+ console.error(`\nAn error occurred during logout: ${error.message}`);
215
236
  }
216
237
  });
217
238
  }
@@ -222,20 +243,7 @@ Statistics (Manga):
222
243
  console.warn(`\nUser not logged in.`);
223
244
  return null;
224
245
  }
225
- const token = yield Auth.RetriveAccessToken();
226
- const request = yield fetch(aniListEndpoint, {
227
- method: "POST",
228
- headers: {
229
- "Content-Type": "application/json",
230
- "Authorization": `Bearer ${token}`,
231
- },
232
- body: JSON.stringify({ query: currentUserQuery }),
233
- });
234
- if (!(request.status === 200)) {
235
- console.error(`Failed to fetch user data. Status: ${request.status}`);
236
- return null;
237
- }
238
- const { data } = yield request.json();
246
+ const { data } = yield fetcher(currentUserQuery, {});
239
247
  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;
240
248
  });
241
249
  }
@@ -246,20 +254,7 @@ Statistics (Manga):
246
254
  console.log(`\nUser not logged in.`);
247
255
  return null;
248
256
  }
249
- const token = yield Auth.RetriveAccessToken();
250
- const request = yield fetch(aniListEndpoint, {
251
- method: "POST",
252
- headers: {
253
- "Content-Type": "application/json",
254
- "Authorization": `Bearer ${token}`,
255
- },
256
- body: JSON.stringify({ query: currentUserQuery }),
257
- });
258
- if (!request.ok) {
259
- console.error(`Failed to fetch user data. Status: ${request.status}`);
260
- return null;
261
- }
262
- const { data } = yield request.json();
257
+ const { data } = yield fetcher(currentUserQuery, {});
263
258
  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;
264
259
  });
265
260
  }
@@ -267,72 +262,70 @@ Statistics (Manga):
267
262
  return __awaiter(this, void 0, void 0, function* () {
268
263
  var _a, _b, _c, _d, _e, _f;
269
264
  try {
270
- if (yield Auth.isLoggedIn()) {
271
- const { activityType } = yield inquirer.prompt([
272
- {
273
- type: "list",
274
- name: "activityType",
275
- message: "What type of activity you want to delete?",
276
- choices: [
277
- { name: "All Activity", value: 0 },
278
- { name: "Text Activity", value: 1 },
279
- { name: "Media List Activity", value: 2 },
280
- { name: "Anime List Activity", value: 3 },
281
- { name: "Manga List Activity", value: 4 },
282
- { name: "Message Activity", value: 5 },
283
- ],
284
- },
285
- ]);
286
- const queryMap = {
287
- 0: activityAllQuery,
288
- 1: activityTextQuery,
289
- 2: activityMediaList,
290
- 3: activityAnimeListQuery,
291
- 4: activityMangaListQuery,
292
- 5: activityMessageQuery,
293
- };
294
- const query = queryMap[activityType];
295
- let hasMoreActivities = true;
296
- let totalCount = 0;
297
- while (hasMoreActivities) {
298
- const response = yield fetcher(query, {
299
- page: 1,
300
- perPage: 50,
301
- userId: yield Auth.MyUserId(),
302
- });
303
- 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) {
304
- let count = 0;
305
- 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;
306
- if (!activities || activities.length === 0) {
307
- console.log(`\nNo more activities available.`);
308
- hasMoreActivities = false;
309
- }
310
- else {
311
- for (const act of activities) {
312
- // Ensure ID is present to avoid unintended errors
313
- if (act === null || act === void 0 ? void 0 : act.id) {
314
- const deleteResponse = yield fetcher(deleteActivityMutation, {
315
- id: act === null || act === void 0 ? void 0 : act.id,
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;
318
- count++;
319
- totalCount++;
320
- console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
321
- // Avoiding rate-limit
322
- yield new Promise((resolve) => setTimeout(resolve, 1100));
323
- }
324
- }
325
- }
265
+ if (!(yield Auth.isLoggedIn())) {
266
+ console.error(`\nPlease log in to delete your activities.`);
267
+ return;
268
+ }
269
+ const { activityType } = yield inquirer.prompt([
270
+ {
271
+ type: "list",
272
+ name: "activityType",
273
+ message: "What type of activity you want to delete?",
274
+ choices: [
275
+ { name: "All Activity", value: 0 },
276
+ { name: "Text Activity", value: 1 },
277
+ { name: "Media List Activity", value: 2 },
278
+ { name: "Anime List Activity", value: 3 },
279
+ { name: "Manga List Activity", value: 4 },
280
+ { name: "Message Activity", value: 5 },
281
+ ],
282
+ },
283
+ ]);
284
+ const queryMap = {
285
+ 0: activityAllQuery,
286
+ 1: activityTextQuery,
287
+ 2: activityMediaList,
288
+ 3: activityAnimeListQuery,
289
+ 4: activityMangaListQuery,
290
+ 5: activityMessageQuery,
291
+ };
292
+ const query = queryMap[activityType];
293
+ let hasMoreActivities = true;
294
+ let totalCount = 0;
295
+ while (hasMoreActivities) {
296
+ const response = yield fetcher(query, {
297
+ page: 1,
298
+ perPage: 50,
299
+ userId: yield Auth.MyUserId(),
300
+ });
301
+ 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) {
302
+ let count = 0;
303
+ 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;
304
+ if (!activities || activities.length === 0) {
305
+ console.log(`\nNo more activities available.`);
306
+ hasMoreActivities = false;
326
307
  }
327
308
  else {
328
- // In case of an unexpected null response, exit the loop
329
- console.log(`\nProbably deleted all the activities of this type.`);
330
- hasMoreActivities = false;
309
+ for (const act of activities) {
310
+ if (act === null || act === void 0 ? void 0 : act.id) {
311
+ const deleteResponse = yield fetcher(deleteActivityMutation, {
312
+ id: act === null || act === void 0 ? void 0 : act.id,
313
+ });
314
+ 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;
315
+ count++;
316
+ totalCount++;
317
+ console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
318
+ // Avoiding rate-limit
319
+ yield new Promise((resolve) => setTimeout(resolve, 1100));
320
+ }
321
+ }
331
322
  }
332
323
  }
333
- }
334
- else {
335
- console.error(`\nPlease log in to delete your activities.`);
324
+ else {
325
+ // In case of an unexpected null response, exit the loop
326
+ console.log(`\nProbably deleted all the activities of this type.`);
327
+ hasMoreActivities = false;
328
+ }
336
329
  }
337
330
  }
338
331
  catch (error) {
@@ -343,54 +336,51 @@ Statistics (Manga):
343
336
  static DeleteMyAnimeList() {
344
337
  return __awaiter(this, void 0, void 0, function* () {
345
338
  var _a, _b, _c, _d;
346
- if (yield Auth.isLoggedIn()) {
347
- const userID = yield Auth.MyUserId();
348
- if (userID) {
349
- const response = yield fetcher(currentUserAnimeList, { id: userID });
350
- if (response !== null) {
351
- 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;
352
- if (lists.length > 0) {
353
- const { selectedList } = yield inquirer.prompt([
354
- {
355
- type: "list",
356
- name: "selectedList",
357
- message: "Select an anime list:",
358
- choices: lists.map((list) => list.name),
359
- pageSize: 10,
360
- },
361
- ]);
362
- const selectedEntries = lists.find((list) => list.name === selectedList);
363
- if (selectedEntries) {
364
- console.log(`\nDeleting entries of '${selectedEntries.name}':`);
365
- for (const [, entry] of selectedEntries.entries.entries()) {
366
- if (entry === null || entry === void 0 ? void 0 : entry.id) {
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);
368
- yield new Promise((resolve) => setTimeout(resolve, 1100));
369
- }
370
- else {
371
- console.log(`No id in entry.`);
372
- console.log(entry);
373
- }
374
- }
339
+ if (!(yield Auth.isLoggedIn())) {
340
+ console.error(`\nPlease log in first to delete your lists.`);
341
+ return;
342
+ }
343
+ if (!(yield Auth.MyUserId())) {
344
+ console.log(`\nFailed getting current user Id.`);
345
+ return;
346
+ }
347
+ const response = yield fetcher(currentUserAnimeList, { id: yield Auth.MyUserId() });
348
+ if (response !== null) {
349
+ 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;
350
+ if (lists.length > 0) {
351
+ const { selectedList } = yield inquirer.prompt([
352
+ {
353
+ type: "list",
354
+ name: "selectedList",
355
+ message: "Select an anime list:",
356
+ choices: lists.map((list) => list.name),
357
+ pageSize: 10,
358
+ },
359
+ ]);
360
+ const selectedEntries = lists.find((list) => list.name === selectedList);
361
+ if (selectedEntries) {
362
+ console.log(`\nDeleting entries of '${selectedEntries.name}':`);
363
+ for (const [, entry] of selectedEntries.entries.entries()) {
364
+ if (entry === null || entry === void 0 ? void 0 : entry.id) {
365
+ 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
+ yield new Promise((resolve) => setTimeout(resolve, 1100));
375
367
  }
376
368
  else {
377
- console.log("No entries found.");
369
+ console.log(`No id in entry.`);
370
+ console.log(entry);
378
371
  }
379
372
  }
380
- else {
381
- console.log(`\nNo anime(s) found in any list.`);
382
- }
383
373
  }
384
374
  else {
385
- console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
375
+ console.log("No entries found.");
386
376
  }
387
377
  }
388
378
  else {
389
- console.log(`\nFailed getting current user Id.`);
379
+ console.log(`\nNo anime(s) found in any list.`);
390
380
  }
391
381
  }
392
382
  else {
393
- console.error(`\nPlease log in first to delete your lists.`);
383
+ console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
394
384
  }
395
385
  });
396
386
  }
@@ -417,54 +407,50 @@ Statistics (Manga):
417
407
  return __awaiter(this, void 0, void 0, function* () {
418
408
  var _a, _b, _c, _d;
419
409
  try {
420
- if (yield Auth.isLoggedIn()) {
421
- const userID = yield Auth.MyUserId();
422
- if (userID) {
423
- const response = yield fetcher(currentUserMangaList, { id: userID });
424
- if (response === null || response === void 0 ? void 0 : response.data) {
425
- 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;
426
- if (lists.length > 0) {
427
- const { selectedList } = yield inquirer.prompt([
428
- {
429
- type: "list",
430
- name: "selectedList",
431
- message: "Select a manga list:",
432
- choices: lists.map((list) => list.name),
433
- pageSize: 10,
434
- },
435
- ]);
436
- const selectedEntries = lists.find((list) => list.name === selectedList);
437
- if (selectedEntries) {
438
- console.log(`\nDeleting entries of '${selectedEntries.name}':`);
439
- for (const [, entry] of selectedEntries.entries.entries()) {
440
- if (entry === null || entry === void 0 ? void 0 : entry.id) {
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);
442
- yield new Promise((resolve) => setTimeout(resolve, 1100));
443
- }
444
- else {
445
- console.log(`No id in entry.`);
446
- console.log(entry);
447
- }
448
- }
449
- }
450
- else {
451
- console.error("\nNo entries found.");
452
- }
410
+ if (!(yield Auth.isLoggedIn())) {
411
+ console.error(`\nPlease log in first to delete your lists.`);
412
+ return;
413
+ }
414
+ if (!(yield Auth.MyUserId())) {
415
+ console.error(`\nFailed getting current user Id.`);
416
+ return;
417
+ }
418
+ const response = yield fetcher(currentUserMangaList, { id: yield Auth.MyUserId() });
419
+ if (!(response === null || response === void 0 ? void 0 : response.data)) {
420
+ console.error(`\nSomething went wrong. ${(_a = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _a === void 0 ? void 0 : _a.message}`);
421
+ return;
422
+ }
423
+ 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;
424
+ if (lists.length > 0) {
425
+ const { selectedList } = yield inquirer.prompt([
426
+ {
427
+ type: "list",
428
+ name: "selectedList",
429
+ message: "Select a manga list:",
430
+ choices: lists.map((list) => list.name),
431
+ pageSize: 10,
432
+ },
433
+ ]);
434
+ const selectedEntries = lists.find((list) => list.name === selectedList);
435
+ if (selectedEntries) {
436
+ console.log(`\nDeleting entries of '${selectedEntries.name}':`);
437
+ for (const [, entry] of selectedEntries.entries.entries()) {
438
+ if (entry === null || entry === void 0 ? void 0 : entry.id) {
439
+ 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);
440
+ yield new Promise((resolve) => setTimeout(resolve, 1100));
453
441
  }
454
442
  else {
455
- console.error(`\nNo manga(s) found in any list.`);
443
+ console.log(`No id in entry.`);
444
+ console.log(entry);
456
445
  }
457
446
  }
458
- else {
459
- console.error(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
460
- }
461
447
  }
462
448
  else {
463
- console.error(`\nFailed getting current user Id.`);
449
+ console.error("\nNo entries found.");
464
450
  }
465
451
  }
466
452
  else {
467
- console.error(`\nPlease log in first to delete your lists.`);
453
+ console.error(`\nNo manga(s) found in any list.`);
468
454
  }
469
455
  }
470
456
  catch (error) {
@@ -493,23 +479,20 @@ Statistics (Manga):
493
479
  }
494
480
  static Write(status) {
495
481
  return __awaiter(this, void 0, void 0, function* () {
496
- var _a;
497
482
  try {
498
483
  if (!(yield Auth.isLoggedIn())) {
499
484
  console.error(`\nPlease login to use this feature.`);
500
485
  return;
501
486
  }
502
- const data = yield fetcher(saveTextActivityMutation, {
503
- status: status +
504
- `<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
487
+ const { data } = yield fetcher(saveTextActivityMutation, {
488
+ status: status,
505
489
  });
506
490
  if (!data) {
507
491
  console.error(`\nSomething went wrong. ${data}.`);
508
492
  return;
509
493
  }
510
- const savedActivity = (_a = data.data) === null || _a === void 0 ? void 0 : _a.SaveTextActivity;
511
- if (savedActivity === null || savedActivity === void 0 ? void 0 : savedActivity.id) {
512
- console.log(`\n[${savedActivity.id}] status saved successfully!`);
494
+ if (data.SaveTextActivity.id) {
495
+ console.log(`\n[${data.SaveTextActivity.id}] status saved successfully!`);
513
496
  }
514
497
  }
515
498
  catch (error) {
@@ -528,6 +511,7 @@ Statistics (Manga):
528
511
  choices: [
529
512
  { name: "Exported JSON file.", value: 1 },
530
513
  { name: "MyAnimeList (XML)", value: 2 },
514
+ { name: "AniDB (json-large)", value: 3 },
531
515
  ],
532
516
  pageSize: 10,
533
517
  },
@@ -539,6 +523,9 @@ Statistics (Manga):
539
523
  case 2:
540
524
  yield MyAnimeList.importAnime();
541
525
  break;
526
+ case 3:
527
+ yield AniDB.importAnime();
528
+ break;
542
529
  default:
543
530
  console.log(`\nInvalid Choice.`);
544
531
  break;
@@ -583,7 +570,7 @@ Statistics (Manga):
583
570
  }
584
571
  static LikeFollowing() {
585
572
  return __awaiter(this, void 0, void 0, function* () {
586
- var _a, _b, _c, _d, _e;
573
+ var _a, _b, _c, _d;
587
574
  try {
588
575
  let page = 1;
589
576
  let hasMoreActivities = true;
@@ -603,14 +590,14 @@ Statistics (Manga):
603
590
  const like = yield fetcher(likeActivityMutation, {
604
591
  activityId: activ.id,
605
592
  });
606
- console.info(`[${activ.id}]\t${(_e = activ.user) === null || _e === void 0 ? void 0 : _e.name} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
593
+ console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
607
594
  }
608
595
  catch (error) {
609
596
  console.error(`Activity possibly deleted. ${error.message}`);
610
597
  }
611
598
  }
612
599
  else {
613
- console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}]\t${activ.user.name} already-liked`);
600
+ console.log(`${activityBy(activ)} 🔵`);
614
601
  }
615
602
  // avoiding rate-limit
616
603
  yield new Promise((resolve) => {
@@ -640,7 +627,7 @@ Statistics (Manga):
640
627
  }
641
628
  static Like(type) {
642
629
  return __awaiter(this, void 0, void 0, function* () {
643
- var _a, _b, _c, _d, _e;
630
+ var _a, _b, _c, _d;
644
631
  try {
645
632
  let page = 1;
646
633
  let hasMoreActivities = true;
@@ -663,14 +650,14 @@ Statistics (Manga):
663
650
  activityId: activ.id,
664
651
  });
665
652
  // const ToggleLike = like?.data?.ToggleLike
666
- console.info(`[${activ.id}]\t${(_e = activ.user) === null || _e === void 0 ? void 0 : _e.name} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
653
+ console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
667
654
  }
668
655
  catch (error) {
669
656
  console.error(`Activity possibly deleted. ${error.message}`);
670
657
  }
671
658
  }
672
659
  else {
673
- console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}]\t${activ.user.name} already-liked`);
660
+ console.log(`${activityBy(activ)} 🔵`);
674
661
  }
675
662
  // avoiding rate-limit
676
663
  yield new Promise((resolve) => {
@@ -694,7 +681,7 @@ Statistics (Manga):
694
681
  }
695
682
  static LikeSpecificUser() {
696
683
  return __awaiter(this, void 0, void 0, function* () {
697
- var _a, _b, _c, _d, _e, _f;
684
+ var _a, _b, _c, _d;
698
685
  try {
699
686
  const { username } = yield inquirer.prompt([
700
687
  {
@@ -727,14 +714,14 @@ Statistics (Manga):
727
714
  const like = yield fetcher(likeActivityMutation, {
728
715
  activityId: activ.id,
729
716
  });
730
- console.info(`[${activ.id}]\t${(_e = activ.user) === null || _e === void 0 ? void 0 : _e.name} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
717
+ console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
731
718
  }
732
719
  catch (error) {
733
720
  console.error(`Activity possibly deleted. ${error.message}`);
734
721
  }
735
722
  }
736
723
  else {
737
- console.log(`[${activ === null || activ === void 0 ? void 0 : activ.id}]\t${(_f = activ.user) === null || _f === void 0 ? void 0 : _f.name} already-liked`);
724
+ console.log(`${activityBy(activ)} 🔵`);
738
725
  }
739
726
  // Avoiding rate limit
740
727
  yield new Promise((resolve) => {
@@ -752,6 +739,86 @@ Statistics (Manga):
752
739
  }
753
740
  });
754
741
  }
742
+ static LikeFollowingActivityV2(perPage) {
743
+ return __awaiter(this, void 0, void 0, function* () {
744
+ var _a, _b, _c, _d, _e;
745
+ try {
746
+ if (!(yield Auth.isLoggedIn())) {
747
+ console.error(`\nPlease log in to use this feature.`);
748
+ return;
749
+ }
750
+ const allFollowingUsers = [];
751
+ let hasNextPage = true;
752
+ let page = 1;
753
+ let liked = 0;
754
+ // Fetch all following users
755
+ spinner.start(`Gathering following information...`);
756
+ while (hasNextPage) {
757
+ spinner.update(`Fetched page ${page}...`);
758
+ const followingUsers = yield fetcher(userFollowingQuery, {
759
+ userId: yield Auth.MyUserId(),
760
+ page,
761
+ });
762
+ if (!((_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.following)) {
763
+ console.error(`\nFailed to fetch following users.`);
764
+ return;
765
+ }
766
+ allFollowingUsers.push(...followingUsers.data.Page.following);
767
+ hasNextPage = followingUsers.data.Page.pageInfo.hasNextPage;
768
+ page++;
769
+ }
770
+ spinner.stop(`Got ${allFollowingUsers.length} following user.`);
771
+ // Extract the IDs of all following users
772
+ const followingUserIds = allFollowingUsers.map((user) => user.id);
773
+ console.log(`\nTotal Following: ${followingUserIds.length}\nApproximately ${followingUserIds.length * perPage} activities to like.\nWill take around ${((followingUserIds.length * perPage * 1200) /
774
+ 1000 /
775
+ 60).toFixed(2)} minutes.`);
776
+ // Traverse the array and fetch users' activities one by one
777
+ let userNumber = 0;
778
+ for (const userId of followingUserIds) {
779
+ userNumber++;
780
+ console.log(`\n[${userNumber}]\tID: ${userId}`);
781
+ // Fetch `perPage` activities for the current user
782
+ const activities = yield fetcher(specificUserActivitiesQuery, {
783
+ userId,
784
+ page: 1, // Always fetch from the first page
785
+ perPage,
786
+ });
787
+ if (!((_e = (_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) === null || _e === void 0 ? void 0 : _e.length)) {
788
+ console.log(`[${userNumber}] No activities found for User ID: ${userId}`);
789
+ continue;
790
+ }
791
+ const activiti = activities.data.Page.activities;
792
+ for (let i = 0; i < activiti.length; i++) {
793
+ const activ = activiti[i];
794
+ if (!activ.isLiked && activ.id) {
795
+ try {
796
+ const like = yield fetcher(likeActivityMutation, {
797
+ activityId: activ.id,
798
+ });
799
+ console.info(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
800
+ if (like === null || like === void 0 ? void 0 : like.data) {
801
+ liked++;
802
+ }
803
+ }
804
+ catch (error) {
805
+ console.error(`[${userNumber}/${i + 1}/${activiti.length}] Activity possibly deleted. ${error.message}`);
806
+ }
807
+ }
808
+ else {
809
+ console.log(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} 🔵`);
810
+ }
811
+ // Avoid rate-limiting
812
+ yield new Promise((resolve) => setTimeout(resolve, 1200));
813
+ }
814
+ }
815
+ console.log(`\n✅ All ${liked} activities liked successfully.`);
816
+ }
817
+ catch (error) {
818
+ console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
819
+ }
820
+ });
821
+ }
755
822
  static AutoLike() {
756
823
  return __awaiter(this, void 0, void 0, function* () {
757
824
  try {
@@ -792,4 +859,115 @@ Statistics (Manga):
792
859
  });
793
860
  }
794
861
  }
795
- export { Auth };
862
+ class Social {
863
+ /**
864
+ * Follow the users that follows you
865
+ */
866
+ static follow() {
867
+ return __awaiter(this, void 0, void 0, function* () {
868
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
869
+ try {
870
+ let pager = 1;
871
+ let hasNextPage = true;
872
+ let allFollowerUsers = [];
873
+ spinner.start("Fetching all the followers...");
874
+ while (hasNextPage) {
875
+ const followerUsers = yield fetcher(userFollowersQuery, {
876
+ userId: yield Auth.MyUserId(),
877
+ page: pager,
878
+ });
879
+ 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}...`);
880
+ 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)) {
881
+ hasNextPage = false;
882
+ }
883
+ 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) || []));
884
+ pager++;
885
+ }
886
+ spinner.stop("Fetched all the followers. Starting follow back.");
887
+ // Filter users that do no follow me
888
+ const notFollowing = allFollowerUsers
889
+ .filter(({ isFollowing }) => !isFollowing)
890
+ .map(({ id, name }) => ({ id: id, name: name }));
891
+ console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
892
+ if (notFollowing.length <= 0) {
893
+ console.log(`Probably followed back all the users.`);
894
+ return;
895
+ }
896
+ // Traverse and follow back
897
+ const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
898
+ const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
899
+ for (let nf of notFollowing) {
900
+ try {
901
+ const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
902
+ console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
903
+ `\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)}` +
904
+ `\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) ? "✅" : "🈵"}`);
905
+ }
906
+ catch (error) {
907
+ console.log(`automate_follow_toggle_follow: ${error.message}`);
908
+ }
909
+ }
910
+ console.log(`\n✅ Followed back ${notFollowing.length} users.`);
911
+ }
912
+ catch (error) {
913
+ console.log(`\nautomate_follow ${error.message}`);
914
+ }
915
+ });
916
+ }
917
+ /**
918
+ * Unfollow the users thats not following you
919
+ */
920
+ static unfollow() {
921
+ return __awaiter(this, void 0, void 0, function* () {
922
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
923
+ try {
924
+ let pager = 1;
925
+ let hasNextPage = true;
926
+ let allFollowingUsers = [];
927
+ spinner.start("Fetching all following users...");
928
+ while (hasNextPage) {
929
+ const followingUsers = yield fetcher(userFollowingQuery, {
930
+ userId: yield Auth.MyUserId(),
931
+ page: pager,
932
+ });
933
+ 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} ...`);
934
+ 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)) {
935
+ hasNextPage = false;
936
+ }
937
+ 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) || []));
938
+ pager++;
939
+ }
940
+ spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
941
+ // Filter users that do no follow me
942
+ const notFollowingMe = allFollowingUsers
943
+ .filter((user) => !user.isFollower)
944
+ .map((u3r) => ({ id: u3r.id, name: u3r.name }));
945
+ if (notFollowingMe.length <= 0) {
946
+ console.warn(`\nNot following list is empty!`);
947
+ spinner.stop(`No users to unfollow. Aborting process...`);
948
+ return;
949
+ }
950
+ spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
951
+ let nfmCount = 0;
952
+ console.log(`\n`);
953
+ for (let nfm of notFollowingMe) {
954
+ nfmCount++;
955
+ try {
956
+ const unfollow = yield fetcher(toggleFollowMutation, {
957
+ userId: nfm.id,
958
+ });
959
+ 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) ? "✅" : "🈵"}`);
960
+ }
961
+ catch (error) {
962
+ console.log(`unfollow_toggle_follow. ${error.message}`);
963
+ }
964
+ }
965
+ console.log(`\nTotal Unfollowed: ${nfmCount}`);
966
+ }
967
+ catch (error) {
968
+ console.error(`\nautomate_unfollow: ${error.message}`);
969
+ }
970
+ });
971
+ }
972
+ }
973
+ export { Auth, Social };