@irfanshadikrishad/anilist 1.2.0-forbidden.1 → 1.2.0-forbidden.6

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