@irfanshadikrishad/anilist 1.3.0-forbidden.1 → 1.3.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.
@@ -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 { 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 { activityBy, aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
18
+ import { AniDB, AniList, MyAnimeList } from "./lists.js";
19
+ import { deleteActivityMutation, saveTextActivityMutation, } from "./mutations.js";
20
+ import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, toggleFollowMutation, userActivityQuery, userFollowersQuery, userFollowingQuery, } from "./queries.js";
21
+ import { 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;
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;
133
154
  console.log(`
134
155
  ID: ${user === null || user === void 0 ? void 0 : user.id}
135
156
  Name: ${user === null || user === void 0 ? void 0 : user.name}
136
157
  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}
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}
140
161
  donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
141
162
  donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
142
163
  unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
143
164
  Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
144
165
  Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
166
+
167
+ Followers: ${followersCount}
168
+ Following: ${followingCount}
145
169
 
146
170
  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}
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}
151
175
 
152
176
  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}
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;
@@ -581,215 +568,125 @@ Statistics (Manga):
581
568
  }
582
569
  });
583
570
  }
584
- static LikeFollowing() {
571
+ }
572
+ class Social {
573
+ /**
574
+ * Follow the users that follows you
575
+ */
576
+ static follow() {
585
577
  return __awaiter(this, void 0, void 0, function* () {
586
- var _a, _b, _c, _d;
578
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
587
579
  try {
588
- let page = 1;
589
- let hasMoreActivities = true;
590
- let retryCount = 0;
591
- const maxRetries = 5;
592
- while (hasMoreActivities) {
593
- const activities = yield fetcher(followingActivitiesQuery, {
594
- page,
595
- perPage: 50,
580
+ let pager = 1;
581
+ let hasNextPage = true;
582
+ let allFollowerUsers = [];
583
+ let followedBack = 0;
584
+ spinner.start("Fetching all the followers...");
585
+ while (hasNextPage) {
586
+ const followerUsers = yield fetcher(userFollowersQuery, {
587
+ userId: yield Auth.MyUserId(),
588
+ page: pager,
596
589
  });
597
- 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) {
598
- retryCount = 0; // Reset retry count on successful fetch
599
- 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;
600
- for (let activ of activiti) {
601
- if (!activ.isLiked && activ.id) {
602
- try {
603
- const like = yield fetcher(likeActivityMutation, {
604
- activityId: activ.id,
605
- });
606
- console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
607
- }
608
- catch (error) {
609
- console.error(`Activity possibly deleted. ${error.message}`);
610
- }
611
- }
612
- else {
613
- console.log(`${activityBy(activ)} 🔵`);
614
- }
615
- // avoiding rate-limit
616
- yield new Promise((resolve) => {
617
- setTimeout(resolve, 2000);
618
- });
619
- }
620
- page++;
621
- }
622
- else {
623
- if (retryCount < maxRetries) {
624
- retryCount++;
625
- console.warn(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
626
- yield new Promise((resolve) => setTimeout(resolve, 3000));
627
- }
628
- else {
629
- console.log(`\nProbably the end of activities after ${maxRetries} retries.`);
630
- console.info(activities);
631
- hasMoreActivities = false;
632
- }
590
+ 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}...`);
591
+ 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)) {
592
+ hasNextPage = false;
633
593
  }
594
+ 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) || []));
595
+ pager++;
634
596
  }
635
- }
636
- catch (error) {
637
- console.error(`\nError from likeFollowing. ${error.message}`);
638
- }
639
- });
640
- }
641
- static Like(type) {
642
- return __awaiter(this, void 0, void 0, function* () {
643
- var _a, _b, _c, _d;
644
- try {
645
- let page = 1;
646
- let hasMoreActivities = true;
647
- let activity = type === 0
648
- ? followingActivitiesQuery
649
- : type === 1
650
- ? globalActivitiesQuery
651
- : followingActivitiesQuery;
652
- while (hasMoreActivities) {
653
- const activities = yield fetcher(activity, {
654
- page,
655
- perPage: 50,
656
- });
657
- 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) {
658
- 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;
659
- for (let activ of activiti) {
660
- if (!activ.isLiked && activ.id) {
661
- try {
662
- const like = yield fetcher(likeActivityMutation, {
663
- activityId: activ.id,
664
- });
665
- // const ToggleLike = like?.data?.ToggleLike
666
- console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
667
- }
668
- catch (error) {
669
- console.error(`Activity possibly deleted. ${error.message}`);
670
- }
671
- }
672
- else {
673
- console.log(`${activityBy(activ)} 🔵`);
674
- }
675
- // avoiding rate-limit
676
- yield new Promise((resolve) => {
677
- setTimeout(resolve, 1500);
678
- });
597
+ spinner.stop("Fetched all the followers. Starting follow back.");
598
+ // Filter users that do no follow me
599
+ const notFollowing = allFollowerUsers
600
+ .filter(({ isFollowing }) => !isFollowing)
601
+ .map(({ id, name }) => ({ id: id, name: name }));
602
+ console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
603
+ if (notFollowing.length <= 0) {
604
+ console.log(`Probably followed back all the users.`);
605
+ return;
606
+ }
607
+ // Traverse and follow back
608
+ const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
609
+ const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
610
+ for (let nf of notFollowing) {
611
+ try {
612
+ const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
613
+ console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
614
+ `\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)}` +
615
+ `\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) ? "✅" : "🈵"}`);
616
+ // Count the followed back users
617
+ 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) {
618
+ followedBack++;
679
619
  }
680
- page++;
681
620
  }
682
- else {
683
- // No more activities to like
684
- console.log(`\nProbably the end of activities.`);
685
- console.info(activities);
686
- hasMoreActivities = false;
621
+ catch (error) {
622
+ console.log(`automate_follow_toggle_follow: ${error.message}`);
687
623
  }
688
624
  }
625
+ console.log(`\n✅ Followed back ${followedBack} users.`);
689
626
  }
690
627
  catch (error) {
691
- console.error(`\nError from likeFollowing. ${error.message}`);
628
+ console.log(`\nautomate_follow ${error.message}`);
692
629
  }
693
630
  });
694
631
  }
695
- static LikeSpecificUser() {
632
+ /**
633
+ * Unfollow the users thats not following you
634
+ */
635
+ static unfollow() {
696
636
  return __awaiter(this, void 0, void 0, function* () {
697
- var _a, _b, _c, _d;
637
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
698
638
  try {
699
- const { username } = yield inquirer.prompt([
700
- {
701
- type: "input",
702
- name: "username",
703
- message: "Username of the user:",
704
- },
705
- ]);
706
- const userDetails = yield fetcher(userQuery, { username: username });
707
- if (userDetails) {
708
- let page = 1;
709
- const perPage = 50;
710
- 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;
711
- if (userId) {
712
- while (true) {
713
- const activities = yield fetcher(specificUserActivitiesQuery, {
714
- page,
715
- perPage,
716
- userId,
717
- });
718
- 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;
719
- // Break the loop if no more activities are found
720
- if (!activiti || activiti.length === 0) {
721
- console.log("No more activities found.");
722
- break;
723
- }
724
- for (let activ of activiti) {
725
- if (!activ.isLiked && activ.id) {
726
- try {
727
- const like = yield fetcher(likeActivityMutation, {
728
- activityId: activ.id,
729
- });
730
- console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
731
- }
732
- catch (error) {
733
- console.error(`Activity possibly deleted. ${error.message}`);
734
- }
735
- }
736
- else {
737
- console.log(`${activityBy(activ)} 🔵`);
738
- }
739
- // Avoiding rate limit
740
- yield new Promise((resolve) => {
741
- setTimeout(resolve, 1500);
742
- });
743
- }
744
- // Go to the next page
745
- page += 1;
746
- }
639
+ let pager = 1;
640
+ let hasNextPage = true;
641
+ let allFollowingUsers = [];
642
+ let unfollowedUsers = 0;
643
+ spinner.start("Fetching all following users...");
644
+ while (hasNextPage) {
645
+ const followingUsers = yield fetcher(userFollowingQuery, {
646
+ userId: yield Auth.MyUserId(),
647
+ page: pager,
648
+ });
649
+ 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}...`);
650
+ 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)) {
651
+ hasNextPage = false;
747
652
  }
653
+ 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) || []));
654
+ pager++;
748
655
  }
749
- }
750
- catch (error) {
751
- console.error(`\nError from LikeSpecificUser. ${error.message}`);
752
- }
753
- });
754
- }
755
- static AutoLike() {
756
- return __awaiter(this, void 0, void 0, function* () {
757
- try {
758
- if (!(yield Auth.isLoggedIn())) {
759
- console.error(`\nPlease login to use this feature.`);
656
+ spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
657
+ // Filter users that do no follow me
658
+ const notFollowingMe = allFollowingUsers
659
+ .filter((user) => !user.isFollower)
660
+ .map((u3r) => ({ id: u3r.id, name: u3r.name }));
661
+ if (notFollowingMe.length <= 0) {
662
+ spinner.stop(`No users to unfollow. Exiting operation...`);
760
663
  return;
761
664
  }
762
- const { activityType } = yield inquirer.prompt([
763
- {
764
- type: "list",
765
- name: "activityType",
766
- message: "Select activity type:",
767
- choices: [
768
- { name: "Following", value: 1 },
769
- { name: "Global", value: 2 },
770
- { name: "Specific User", value: 3 },
771
- ],
772
- pageSize: 10,
773
- },
774
- ]);
775
- switch (activityType) {
776
- case 1:
777
- yield this.LikeFollowing();
778
- break;
779
- case 2:
780
- yield this.Like(1);
781
- break;
782
- case 3:
783
- yield this.LikeSpecificUser();
784
- break;
785
- default:
786
- console.error(`\nInvalid choice. (${activityType})`);
665
+ spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
666
+ let nfmCount = 0;
667
+ console.log(`\n`);
668
+ for (let nfm of notFollowingMe) {
669
+ nfmCount++;
670
+ try {
671
+ const unfollow = yield fetcher(toggleFollowMutation, {
672
+ userId: nfm.id,
673
+ });
674
+ 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) ? "✅" : "🈵"}`);
675
+ // Count the unfollowed users
676
+ if ((_p = (_o = unfollow === null || unfollow === void 0 ? void 0 : unfollow.data) === null || _o === void 0 ? void 0 : _o.ToggleFollow) === null || _p === void 0 ? void 0 : _p.id) {
677
+ unfollowedUsers++;
678
+ }
679
+ }
680
+ catch (error) {
681
+ console.log(`unfollow_toggle_follow. ${error.message}`);
682
+ }
787
683
  }
684
+ console.log(`\nTotal Unfollowed: ${unfollowedUsers} of ${nfmCount} users.`);
788
685
  }
789
686
  catch (error) {
790
- console.error(`\nError from autolike. ${error.message}`);
687
+ console.error(`\nautomate_unfollow: ${error.message}`);
791
688
  }
792
689
  });
793
690
  }
794
691
  }
795
- export { Auth };
692
+ export { Auth, Social };