@irfanshadikrishad/anilist 1.3.3-forbidden.1 → 1.4.0
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.
- package/{LICENSE.md → LICENSE} +115 -124
- package/README.md +266 -243
- package/bin/helpers/auth.d.ts +13 -7
- package/bin/helpers/auth.js +255 -373
- package/bin/helpers/lists.d.ts +1 -0
- package/bin/helpers/lists.js +175 -127
- package/bin/helpers/mutations.d.ts +1 -2
- package/bin/helpers/mutations.js +1 -6
- package/bin/helpers/queries.d.ts +9 -10
- package/bin/helpers/queries.js +23 -40
- package/bin/helpers/truncate.d.ts +6 -0
- package/bin/helpers/truncate.js +9 -0
- package/bin/helpers/types.d.ts +119 -68
- package/bin/helpers/validation.d.ts +29 -0
- package/bin/helpers/validation.js +117 -0
- package/bin/helpers/workers.d.ts +15 -7
- package/bin/helpers/workers.js +67 -34
- package/bin/index.js +30 -6
- package/package.json +85 -81
package/bin/helpers/auth.js
CHANGED
|
@@ -13,13 +13,16 @@ 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
18
|
import { AniDB, AniList, MyAnimeList } from "./lists.js";
|
|
18
|
-
import { deleteActivityMutation,
|
|
19
|
-
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation,
|
|
20
|
-
import {
|
|
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 { responsiveOutput } from "./truncate.js";
|
|
22
|
+
import { aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
|
|
21
23
|
const home_dir = os.homedir();
|
|
22
24
|
const save_path = path.join(home_dir, ".anilist_token");
|
|
25
|
+
const spinner = new Spinner();
|
|
23
26
|
class Auth {
|
|
24
27
|
/**
|
|
25
28
|
* Get access-token from user
|
|
@@ -34,20 +37,29 @@ class Auth {
|
|
|
34
37
|
message: "Please enter your AniList access token:",
|
|
35
38
|
},
|
|
36
39
|
]);
|
|
40
|
+
if (!token) {
|
|
41
|
+
console.warn("\nNo token entered. Please try again.");
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
37
44
|
return token;
|
|
38
45
|
}
|
|
39
46
|
catch (error) {
|
|
40
|
-
console.error(`\
|
|
47
|
+
console.error(`\nAn error occurred while getting the access token: ${error.message}`);
|
|
48
|
+
return null;
|
|
41
49
|
}
|
|
42
50
|
});
|
|
43
51
|
}
|
|
44
52
|
static StoreAccessToken(token) {
|
|
45
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
54
|
try {
|
|
55
|
+
if (!token) {
|
|
56
|
+
console.warn("\nNo token provided. Nothing to store.");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
47
59
|
fs.writeFileSync(save_path, token, { encoding: "utf8" });
|
|
48
60
|
}
|
|
49
61
|
catch (error) {
|
|
50
|
-
console.error(`\nError storing
|
|
62
|
+
console.error(`\nError storing access token: ${error.message}`);
|
|
51
63
|
}
|
|
52
64
|
});
|
|
53
65
|
}
|
|
@@ -63,6 +75,7 @@ class Auth {
|
|
|
63
75
|
}
|
|
64
76
|
catch (error) {
|
|
65
77
|
console.error(`\nError retriving acess-token. ${error.message}`);
|
|
78
|
+
return null;
|
|
66
79
|
}
|
|
67
80
|
});
|
|
68
81
|
}
|
|
@@ -170,7 +183,7 @@ Statistics (Manga):
|
|
|
170
183
|
console.log(`\nRecent Activities:`);
|
|
171
184
|
if (activities.length > 0) {
|
|
172
185
|
activities.map(({ status, progress, media, createdAt }) => {
|
|
173
|
-
|
|
186
|
+
responsiveOutput(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
174
187
|
});
|
|
175
188
|
}
|
|
176
189
|
return user;
|
|
@@ -193,15 +206,12 @@ Statistics (Manga):
|
|
|
193
206
|
static isLoggedIn() {
|
|
194
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
208
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
209
|
+
const token = yield Auth.RetriveAccessToken();
|
|
210
|
+
return token !== null;
|
|
202
211
|
}
|
|
203
212
|
catch (error) {
|
|
204
|
-
console.error(
|
|
213
|
+
console.error(`Error checking login status: ${error.message}`);
|
|
214
|
+
return false;
|
|
205
215
|
}
|
|
206
216
|
});
|
|
207
217
|
}
|
|
@@ -215,15 +225,15 @@ Statistics (Manga):
|
|
|
215
225
|
console.log(`\nLogout successful. See you soon, ${username}.`);
|
|
216
226
|
}
|
|
217
227
|
catch (error) {
|
|
218
|
-
console.error("\
|
|
228
|
+
console.error("\nFailed to remove the save file during logout:", error.message);
|
|
219
229
|
}
|
|
220
230
|
}
|
|
221
231
|
else {
|
|
222
|
-
console.
|
|
232
|
+
console.warn("\nNo active session found. You may already be logged out.");
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
235
|
catch (error) {
|
|
226
|
-
console.error(`\
|
|
236
|
+
console.error(`\nAn error occurred during logout: ${error.message}`);
|
|
227
237
|
}
|
|
228
238
|
});
|
|
229
239
|
}
|
|
@@ -234,20 +244,7 @@ Statistics (Manga):
|
|
|
234
244
|
console.warn(`\nUser not logged in.`);
|
|
235
245
|
return null;
|
|
236
246
|
}
|
|
237
|
-
const
|
|
238
|
-
const request = yield fetch(aniListEndpoint, {
|
|
239
|
-
method: "POST",
|
|
240
|
-
headers: {
|
|
241
|
-
"Content-Type": "application/json",
|
|
242
|
-
"Authorization": `Bearer ${token}`,
|
|
243
|
-
},
|
|
244
|
-
body: JSON.stringify({ query: currentUserQuery }),
|
|
245
|
-
});
|
|
246
|
-
if (!(request.status === 200)) {
|
|
247
|
-
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
const { data } = yield request.json();
|
|
247
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
251
248
|
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;
|
|
252
249
|
});
|
|
253
250
|
}
|
|
@@ -258,20 +255,7 @@ Statistics (Manga):
|
|
|
258
255
|
console.log(`\nUser not logged in.`);
|
|
259
256
|
return null;
|
|
260
257
|
}
|
|
261
|
-
const
|
|
262
|
-
const request = yield fetch(aniListEndpoint, {
|
|
263
|
-
method: "POST",
|
|
264
|
-
headers: {
|
|
265
|
-
"Content-Type": "application/json",
|
|
266
|
-
"Authorization": `Bearer ${token}`,
|
|
267
|
-
},
|
|
268
|
-
body: JSON.stringify({ query: currentUserQuery }),
|
|
269
|
-
});
|
|
270
|
-
if (!request.ok) {
|
|
271
|
-
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
const { data } = yield request.json();
|
|
258
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
275
259
|
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;
|
|
276
260
|
});
|
|
277
261
|
}
|
|
@@ -279,72 +263,70 @@ Statistics (Manga):
|
|
|
279
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
280
264
|
var _a, _b, _c, _d, _e, _f;
|
|
281
265
|
try {
|
|
282
|
-
if (yield Auth.isLoggedIn()) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
// Ensure ID is present to avoid unintended errors
|
|
325
|
-
if (act === null || act === void 0 ? void 0 : act.id) {
|
|
326
|
-
const deleteResponse = yield fetcher(deleteActivityMutation, {
|
|
327
|
-
id: act === null || act === void 0 ? void 0 : act.id,
|
|
328
|
-
});
|
|
329
|
-
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;
|
|
330
|
-
count++;
|
|
331
|
-
totalCount++;
|
|
332
|
-
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
333
|
-
// Avoiding rate-limit
|
|
334
|
-
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
266
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
267
|
+
console.error(`\nPlease log in to delete your activities.`);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const { activityType } = yield inquirer.prompt([
|
|
271
|
+
{
|
|
272
|
+
type: "list",
|
|
273
|
+
name: "activityType",
|
|
274
|
+
message: "What type of activity you want to delete?",
|
|
275
|
+
choices: [
|
|
276
|
+
{ name: "All Activity", value: 0 },
|
|
277
|
+
{ name: "Text Activity", value: 1 },
|
|
278
|
+
{ name: "Media List Activity", value: 2 },
|
|
279
|
+
{ name: "Anime List Activity", value: 3 },
|
|
280
|
+
{ name: "Manga List Activity", value: 4 },
|
|
281
|
+
{ name: "Message Activity", value: 5 },
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
]);
|
|
285
|
+
const queryMap = {
|
|
286
|
+
0: activityAllQuery,
|
|
287
|
+
1: activityTextQuery,
|
|
288
|
+
2: activityMediaList,
|
|
289
|
+
3: activityAnimeListQuery,
|
|
290
|
+
4: activityMangaListQuery,
|
|
291
|
+
5: activityMessageQuery,
|
|
292
|
+
};
|
|
293
|
+
const query = queryMap[activityType];
|
|
294
|
+
let hasMoreActivities = true;
|
|
295
|
+
let totalCount = 0;
|
|
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;
|
|
338
308
|
}
|
|
339
309
|
else {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
310
|
+
for (const act of activities) {
|
|
311
|
+
if (act === null || act === void 0 ? void 0 : act.id) {
|
|
312
|
+
const deleteResponse = yield fetcher(deleteActivityMutation, {
|
|
313
|
+
id: act === null || act === void 0 ? void 0 : act.id,
|
|
314
|
+
});
|
|
315
|
+
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;
|
|
316
|
+
count++;
|
|
317
|
+
totalCount++;
|
|
318
|
+
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
319
|
+
// Avoiding rate-limit
|
|
320
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
343
323
|
}
|
|
344
324
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
325
|
+
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;
|
|
329
|
+
}
|
|
348
330
|
}
|
|
349
331
|
}
|
|
350
332
|
catch (error) {
|
|
@@ -355,54 +337,51 @@ Statistics (Manga):
|
|
|
355
337
|
static DeleteMyAnimeList() {
|
|
356
338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
339
|
var _a, _b, _c, _d;
|
|
358
|
-
if (yield Auth.isLoggedIn()) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
340
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
341
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (!(yield Auth.MyUserId())) {
|
|
345
|
+
console.log(`\nFailed getting current user Id.`);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const response = yield fetcher(currentUserAnimeList, { id: yield Auth.MyUserId() });
|
|
349
|
+
if (response !== null) {
|
|
350
|
+
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;
|
|
351
|
+
if (lists.length > 0) {
|
|
352
|
+
const { selectedList } = yield inquirer.prompt([
|
|
353
|
+
{
|
|
354
|
+
type: "list",
|
|
355
|
+
name: "selectedList",
|
|
356
|
+
message: "Select an anime list:",
|
|
357
|
+
choices: lists.map((list) => list.name),
|
|
358
|
+
pageSize: 10,
|
|
359
|
+
},
|
|
360
|
+
]);
|
|
361
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
362
|
+
if (selectedEntries) {
|
|
363
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
364
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
365
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
366
|
+
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);
|
|
367
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
387
368
|
}
|
|
388
369
|
else {
|
|
389
|
-
console.log(
|
|
370
|
+
console.log(`No id in entry.`);
|
|
371
|
+
console.log(entry);
|
|
390
372
|
}
|
|
391
373
|
}
|
|
392
|
-
else {
|
|
393
|
-
console.log(`\nNo anime(s) found in any list.`);
|
|
394
|
-
}
|
|
395
374
|
}
|
|
396
375
|
else {
|
|
397
|
-
console.log(
|
|
376
|
+
console.log("No entries found.");
|
|
398
377
|
}
|
|
399
378
|
}
|
|
400
379
|
else {
|
|
401
|
-
console.log(`\
|
|
380
|
+
console.log(`\nNo anime(s) found in any list.`);
|
|
402
381
|
}
|
|
403
382
|
}
|
|
404
383
|
else {
|
|
405
|
-
console.
|
|
384
|
+
console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
406
385
|
}
|
|
407
386
|
});
|
|
408
387
|
}
|
|
@@ -429,54 +408,50 @@ Statistics (Manga):
|
|
|
429
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
430
409
|
var _a, _b, _c, _d;
|
|
431
410
|
try {
|
|
432
|
-
if (yield Auth.isLoggedIn()) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
console.error("\nNo entries found.");
|
|
464
|
-
}
|
|
411
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
412
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (!(yield Auth.MyUserId())) {
|
|
416
|
+
console.error(`\nFailed getting current user Id.`);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const response = yield fetcher(currentUserMangaList, { id: yield Auth.MyUserId() });
|
|
420
|
+
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
421
|
+
console.error(`\nSomething went wrong. ${(_a = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
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;
|
|
425
|
+
if (lists.length > 0) {
|
|
426
|
+
const { selectedList } = yield inquirer.prompt([
|
|
427
|
+
{
|
|
428
|
+
type: "list",
|
|
429
|
+
name: "selectedList",
|
|
430
|
+
message: "Select a manga list:",
|
|
431
|
+
choices: lists.map((list) => list.name),
|
|
432
|
+
pageSize: 10,
|
|
433
|
+
},
|
|
434
|
+
]);
|
|
435
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
436
|
+
if (selectedEntries) {
|
|
437
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
438
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
439
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
440
|
+
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);
|
|
441
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
465
442
|
}
|
|
466
443
|
else {
|
|
467
|
-
console.
|
|
444
|
+
console.log(`No id in entry.`);
|
|
445
|
+
console.log(entry);
|
|
468
446
|
}
|
|
469
447
|
}
|
|
470
|
-
else {
|
|
471
|
-
console.error(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
472
|
-
}
|
|
473
448
|
}
|
|
474
449
|
else {
|
|
475
|
-
console.error(
|
|
450
|
+
console.error("\nNo entries found.");
|
|
476
451
|
}
|
|
477
452
|
}
|
|
478
453
|
else {
|
|
479
|
-
console.error(`\
|
|
454
|
+
console.error(`\nNo manga(s) found in any list.`);
|
|
480
455
|
}
|
|
481
456
|
}
|
|
482
457
|
catch (error) {
|
|
@@ -505,23 +480,20 @@ Statistics (Manga):
|
|
|
505
480
|
}
|
|
506
481
|
static Write(status) {
|
|
507
482
|
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
-
var _a;
|
|
509
483
|
try {
|
|
510
484
|
if (!(yield Auth.isLoggedIn())) {
|
|
511
485
|
console.error(`\nPlease login to use this feature.`);
|
|
512
486
|
return;
|
|
513
487
|
}
|
|
514
|
-
const data = yield fetcher(saveTextActivityMutation, {
|
|
515
|
-
status: status
|
|
516
|
-
`<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
|
|
488
|
+
const { data } = yield fetcher(saveTextActivityMutation, {
|
|
489
|
+
status: status,
|
|
517
490
|
});
|
|
518
491
|
if (!data) {
|
|
519
492
|
console.error(`\nSomething went wrong. ${data}.`);
|
|
520
493
|
return;
|
|
521
494
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
console.log(`\n[${savedActivity.id}] status saved successfully!`);
|
|
495
|
+
if (data.SaveTextActivity.id) {
|
|
496
|
+
console.log(`\n[${data.SaveTextActivity.id}] status saved successfully!`);
|
|
525
497
|
}
|
|
526
498
|
}
|
|
527
499
|
catch (error) {
|
|
@@ -597,215 +569,125 @@ Statistics (Manga):
|
|
|
597
569
|
}
|
|
598
570
|
});
|
|
599
571
|
}
|
|
600
|
-
|
|
572
|
+
}
|
|
573
|
+
class Social {
|
|
574
|
+
/**
|
|
575
|
+
* Follow the users that follows you
|
|
576
|
+
*/
|
|
577
|
+
static follow() {
|
|
601
578
|
return __awaiter(this, void 0, void 0, function* () {
|
|
602
|
-
var _a, _b, _c, _d;
|
|
579
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
603
580
|
try {
|
|
604
|
-
let
|
|
605
|
-
let
|
|
606
|
-
let
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
581
|
+
let pager = 1;
|
|
582
|
+
let hasNextPage = true;
|
|
583
|
+
let allFollowerUsers = [];
|
|
584
|
+
let followedBack = 0;
|
|
585
|
+
spinner.start("Fetching all the followers...");
|
|
586
|
+
while (hasNextPage) {
|
|
587
|
+
const followerUsers = yield fetcher(userFollowersQuery, {
|
|
588
|
+
userId: yield Auth.MyUserId(),
|
|
589
|
+
page: pager,
|
|
612
590
|
});
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
for (let activ of activiti) {
|
|
617
|
-
if (!activ.isLiked && activ.id) {
|
|
618
|
-
try {
|
|
619
|
-
const like = yield fetcher(likeActivityMutation, {
|
|
620
|
-
activityId: activ.id,
|
|
621
|
-
});
|
|
622
|
-
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
623
|
-
}
|
|
624
|
-
catch (error) {
|
|
625
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
console.log(`${activityBy(activ)} 🔵`);
|
|
630
|
-
}
|
|
631
|
-
// avoiding rate-limit
|
|
632
|
-
yield new Promise((resolve) => {
|
|
633
|
-
setTimeout(resolve, 2000);
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
page++;
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
if (retryCount < maxRetries) {
|
|
640
|
-
retryCount++;
|
|
641
|
-
console.warn(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
|
|
642
|
-
yield new Promise((resolve) => setTimeout(resolve, 3000));
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
console.log(`\nProbably the end of activities after ${maxRetries} retries.`);
|
|
646
|
-
console.info(activities);
|
|
647
|
-
hasMoreActivities = false;
|
|
648
|
-
}
|
|
591
|
+
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}...`);
|
|
592
|
+
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)) {
|
|
593
|
+
hasNextPage = false;
|
|
649
594
|
}
|
|
595
|
+
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) || []));
|
|
596
|
+
pager++;
|
|
650
597
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
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) {
|
|
674
|
-
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;
|
|
675
|
-
for (let activ of activiti) {
|
|
676
|
-
if (!activ.isLiked && activ.id) {
|
|
677
|
-
try {
|
|
678
|
-
const like = yield fetcher(likeActivityMutation, {
|
|
679
|
-
activityId: activ.id,
|
|
680
|
-
});
|
|
681
|
-
// const ToggleLike = like?.data?.ToggleLike
|
|
682
|
-
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
683
|
-
}
|
|
684
|
-
catch (error) {
|
|
685
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
console.log(`${activityBy(activ)} 🔵`);
|
|
690
|
-
}
|
|
691
|
-
// avoiding rate-limit
|
|
692
|
-
yield new Promise((resolve) => {
|
|
693
|
-
setTimeout(resolve, 1500);
|
|
694
|
-
});
|
|
598
|
+
spinner.stop("Fetched all the followers. Starting follow back.");
|
|
599
|
+
// Filter users that do no follow me
|
|
600
|
+
const notFollowing = allFollowerUsers
|
|
601
|
+
.filter(({ isFollowing }) => !isFollowing)
|
|
602
|
+
.map(({ id, name }) => ({ id: id, name: name }));
|
|
603
|
+
console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
|
|
604
|
+
if (notFollowing.length <= 0) {
|
|
605
|
+
console.log(`Probably followed back all the users.`);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
// Traverse and follow back
|
|
609
|
+
const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
|
|
610
|
+
const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
|
|
611
|
+
for (let nf of notFollowing) {
|
|
612
|
+
try {
|
|
613
|
+
const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
|
|
614
|
+
console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
|
|
615
|
+
`\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)}` +
|
|
616
|
+
`\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) ? "✅" : "🈵"}`);
|
|
617
|
+
// Count the followed back users
|
|
618
|
+
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) {
|
|
619
|
+
followedBack++;
|
|
695
620
|
}
|
|
696
|
-
page++;
|
|
697
621
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
console.log(`\nProbably the end of activities.`);
|
|
701
|
-
console.info(activities);
|
|
702
|
-
hasMoreActivities = false;
|
|
622
|
+
catch (error) {
|
|
623
|
+
console.log(`automate_follow_toggle_follow: ${error.message}`);
|
|
703
624
|
}
|
|
704
625
|
}
|
|
626
|
+
console.log(`\n✅ Followed back ${followedBack} users.`);
|
|
705
627
|
}
|
|
706
628
|
catch (error) {
|
|
707
|
-
console.
|
|
629
|
+
console.log(`\nautomate_follow ${error.message}`);
|
|
708
630
|
}
|
|
709
631
|
});
|
|
710
632
|
}
|
|
711
|
-
|
|
633
|
+
/**
|
|
634
|
+
* Unfollow the users thats not following you
|
|
635
|
+
*/
|
|
636
|
+
static unfollow() {
|
|
712
637
|
return __awaiter(this, void 0, void 0, function* () {
|
|
713
|
-
var _a, _b, _c, _d;
|
|
638
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
714
639
|
try {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
while (true) {
|
|
729
|
-
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
730
|
-
page,
|
|
731
|
-
perPage,
|
|
732
|
-
userId,
|
|
733
|
-
});
|
|
734
|
-
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;
|
|
735
|
-
// Break the loop if no more activities are found
|
|
736
|
-
if (!activiti || activiti.length === 0) {
|
|
737
|
-
console.log("No more activities found.");
|
|
738
|
-
break;
|
|
739
|
-
}
|
|
740
|
-
for (let activ of activiti) {
|
|
741
|
-
if (!activ.isLiked && activ.id) {
|
|
742
|
-
try {
|
|
743
|
-
const like = yield fetcher(likeActivityMutation, {
|
|
744
|
-
activityId: activ.id,
|
|
745
|
-
});
|
|
746
|
-
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
747
|
-
}
|
|
748
|
-
catch (error) {
|
|
749
|
-
console.error(`Activity possibly deleted. ${error.message}`);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
else {
|
|
753
|
-
console.log(`${activityBy(activ)} 🔵`);
|
|
754
|
-
}
|
|
755
|
-
// Avoiding rate limit
|
|
756
|
-
yield new Promise((resolve) => {
|
|
757
|
-
setTimeout(resolve, 1500);
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
// Go to the next page
|
|
761
|
-
page += 1;
|
|
762
|
-
}
|
|
640
|
+
let pager = 1;
|
|
641
|
+
let hasNextPage = true;
|
|
642
|
+
let allFollowingUsers = [];
|
|
643
|
+
let unfollowedUsers = 0;
|
|
644
|
+
spinner.start("Fetching all following users...");
|
|
645
|
+
while (hasNextPage) {
|
|
646
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
647
|
+
userId: yield Auth.MyUserId(),
|
|
648
|
+
page: pager,
|
|
649
|
+
});
|
|
650
|
+
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}...`);
|
|
651
|
+
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)) {
|
|
652
|
+
hasNextPage = false;
|
|
763
653
|
}
|
|
654
|
+
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) || []));
|
|
655
|
+
pager++;
|
|
764
656
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
773
|
-
try {
|
|
774
|
-
if (!(yield Auth.isLoggedIn())) {
|
|
775
|
-
console.error(`\nPlease login to use this feature.`);
|
|
657
|
+
spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
|
|
658
|
+
// Filter users that do no follow me
|
|
659
|
+
const notFollowingMe = allFollowingUsers
|
|
660
|
+
.filter((user) => !user.isFollower)
|
|
661
|
+
.map((u3r) => ({ id: u3r.id, name: u3r.name }));
|
|
662
|
+
if (notFollowingMe.length <= 0) {
|
|
663
|
+
spinner.stop(`No users to unfollow. Exiting operation...`);
|
|
776
664
|
return;
|
|
777
665
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
]
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
yield this.Like(1);
|
|
797
|
-
break;
|
|
798
|
-
case 3:
|
|
799
|
-
yield this.LikeSpecificUser();
|
|
800
|
-
break;
|
|
801
|
-
default:
|
|
802
|
-
console.error(`\nInvalid choice. (${activityType})`);
|
|
666
|
+
spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
|
|
667
|
+
let nfmCount = 0;
|
|
668
|
+
console.log(`\n`);
|
|
669
|
+
for (let nfm of notFollowingMe) {
|
|
670
|
+
nfmCount++;
|
|
671
|
+
try {
|
|
672
|
+
const unfollow = yield fetcher(toggleFollowMutation, {
|
|
673
|
+
userId: nfm.id,
|
|
674
|
+
});
|
|
675
|
+
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) ? "✅" : "🈵"}`);
|
|
676
|
+
// Count the unfollowed users
|
|
677
|
+
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) {
|
|
678
|
+
unfollowedUsers++;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
catch (error) {
|
|
682
|
+
console.log(`unfollow_toggle_follow. ${error.message}`);
|
|
683
|
+
}
|
|
803
684
|
}
|
|
685
|
+
console.log(`\nTotal Unfollowed: ${unfollowedUsers} of ${nfmCount} users.`);
|
|
804
686
|
}
|
|
805
687
|
catch (error) {
|
|
806
|
-
console.error(`\
|
|
688
|
+
console.error(`\nautomate_unfollow: ${error.message}`);
|
|
807
689
|
}
|
|
808
690
|
});
|
|
809
691
|
}
|
|
810
692
|
}
|
|
811
|
-
export { Auth };
|
|
693
|
+
export { Auth, Social };
|