@irfanshadikrishad/anilist 1.3.3-forbidden.1 ā 1.4.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.
- package/LICENSE +373 -0
- package/LICENSE.md +382 -382
- package/README.md +266 -243
- package/bin/helpers/auth.d.ts +15 -4
- package/bin/helpers/auth.js +466 -248
- package/bin/helpers/lists.d.ts +1 -0
- package/bin/helpers/lists.js +175 -127
- package/bin/helpers/mutations.js +35 -35
- package/bin/helpers/queries.d.ts +8 -6
- package/bin/helpers/queries.js +179 -166
- package/bin/helpers/truncate.d.ts +6 -0
- package/bin/helpers/truncate.js +10 -0
- package/bin/helpers/types.d.ts +171 -68
- package/bin/helpers/validation.d.ts +29 -0
- package/bin/helpers/validation.js +117 -0
- package/bin/helpers/workers.d.ts +16 -7
- package/bin/helpers/workers.js +152 -99
- package/bin/index.js +32 -1
- package/package.json +86 -81
package/bin/helpers/auth.js
CHANGED
|
@@ -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
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, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.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";
|
|
20
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(`\
|
|
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
|
-
|
|
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
|
|
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
|
}
|
|
@@ -139,38 +155,38 @@ class Auth {
|
|
|
139
155
|
});
|
|
140
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;
|
|
141
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;
|
|
142
|
-
console.log(`
|
|
143
|
-
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
144
|
-
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
145
|
-
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
146
|
-
profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
|
|
147
|
-
timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
|
|
148
|
-
activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
|
|
149
|
-
donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
|
|
150
|
-
donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
|
|
151
|
-
unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
|
|
152
|
-
Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
|
|
153
|
-
Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
|
|
154
|
-
|
|
155
|
-
Followers: ${followersCount}
|
|
156
|
-
Following: ${followingCount}
|
|
157
|
-
|
|
158
|
-
Statistics (Anime):
|
|
159
|
-
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}
|
|
160
|
-
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}
|
|
161
|
-
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}
|
|
162
|
-
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}
|
|
163
|
-
|
|
164
|
-
Statistics (Manga):
|
|
165
|
-
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}
|
|
166
|
-
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}
|
|
167
|
-
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}
|
|
168
|
-
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}
|
|
158
|
+
console.log(`
|
|
159
|
+
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
160
|
+
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
161
|
+
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
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}
|
|
165
|
+
donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
|
|
166
|
+
donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
|
|
167
|
+
unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
|
|
168
|
+
Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
|
|
169
|
+
Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
|
|
170
|
+
|
|
171
|
+
Followers: ${followersCount}
|
|
172
|
+
Following: ${followingCount}
|
|
173
|
+
|
|
174
|
+
Statistics (Anime):
|
|
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}
|
|
179
|
+
|
|
180
|
+
Statistics (Manga):
|
|
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}
|
|
169
185
|
`);
|
|
170
186
|
console.log(`\nRecent Activities:`);
|
|
171
187
|
if (activities.length > 0) {
|
|
172
188
|
activities.map(({ status, progress, media, createdAt }) => {
|
|
173
|
-
|
|
189
|
+
responsiveOutput(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
174
190
|
});
|
|
175
191
|
}
|
|
176
192
|
return user;
|
|
@@ -193,15 +209,12 @@ Statistics (Manga):
|
|
|
193
209
|
static isLoggedIn() {
|
|
194
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
211
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
212
|
+
const token = yield Auth.RetriveAccessToken();
|
|
213
|
+
return token !== null;
|
|
202
214
|
}
|
|
203
215
|
catch (error) {
|
|
204
|
-
console.error(
|
|
216
|
+
console.error(`Error checking login status: ${error.message}`);
|
|
217
|
+
return false;
|
|
205
218
|
}
|
|
206
219
|
});
|
|
207
220
|
}
|
|
@@ -215,15 +228,15 @@ Statistics (Manga):
|
|
|
215
228
|
console.log(`\nLogout successful. See you soon, ${username}.`);
|
|
216
229
|
}
|
|
217
230
|
catch (error) {
|
|
218
|
-
console.error("\
|
|
231
|
+
console.error("\nFailed to remove the save file during logout:", error.message);
|
|
219
232
|
}
|
|
220
233
|
}
|
|
221
234
|
else {
|
|
222
|
-
console.
|
|
235
|
+
console.warn("\nNo active session found. You may already be logged out.");
|
|
223
236
|
}
|
|
224
237
|
}
|
|
225
238
|
catch (error) {
|
|
226
|
-
console.error(`\
|
|
239
|
+
console.error(`\nAn error occurred during logout: ${error.message}`);
|
|
227
240
|
}
|
|
228
241
|
});
|
|
229
242
|
}
|
|
@@ -234,20 +247,7 @@ Statistics (Manga):
|
|
|
234
247
|
console.warn(`\nUser not logged in.`);
|
|
235
248
|
return null;
|
|
236
249
|
}
|
|
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();
|
|
250
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
251
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;
|
|
252
252
|
});
|
|
253
253
|
}
|
|
@@ -258,20 +258,7 @@ Statistics (Manga):
|
|
|
258
258
|
console.log(`\nUser not logged in.`);
|
|
259
259
|
return null;
|
|
260
260
|
}
|
|
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();
|
|
261
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
275
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;
|
|
276
263
|
});
|
|
277
264
|
}
|
|
@@ -279,72 +266,70 @@ Statistics (Manga):
|
|
|
279
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
280
267
|
var _a, _b, _c, _d, _e, _f;
|
|
281
268
|
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
|
-
}
|
|
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;
|
|
338
311
|
}
|
|
339
312
|
else {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
}
|
|
343
326
|
}
|
|
344
327
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
+
}
|
|
348
333
|
}
|
|
349
334
|
}
|
|
350
335
|
catch (error) {
|
|
@@ -355,54 +340,51 @@ Statistics (Manga):
|
|
|
355
340
|
static DeleteMyAnimeList() {
|
|
356
341
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
342
|
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
|
-
}
|
|
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));
|
|
387
371
|
}
|
|
388
372
|
else {
|
|
389
|
-
console.log(
|
|
373
|
+
console.log(`No id in entry.`);
|
|
374
|
+
console.log(entry);
|
|
390
375
|
}
|
|
391
376
|
}
|
|
392
|
-
else {
|
|
393
|
-
console.log(`\nNo anime(s) found in any list.`);
|
|
394
|
-
}
|
|
395
377
|
}
|
|
396
378
|
else {
|
|
397
|
-
console.log(
|
|
379
|
+
console.log("No entries found.");
|
|
398
380
|
}
|
|
399
381
|
}
|
|
400
382
|
else {
|
|
401
|
-
console.log(`\
|
|
383
|
+
console.log(`\nNo anime(s) found in any list.`);
|
|
402
384
|
}
|
|
403
385
|
}
|
|
404
386
|
else {
|
|
405
|
-
console.
|
|
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}`);
|
|
406
388
|
}
|
|
407
389
|
});
|
|
408
390
|
}
|
|
@@ -429,54 +411,50 @@ Statistics (Manga):
|
|
|
429
411
|
return __awaiter(this, void 0, void 0, function* () {
|
|
430
412
|
var _a, _b, _c, _d;
|
|
431
413
|
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
|
-
}
|
|
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));
|
|
465
445
|
}
|
|
466
446
|
else {
|
|
467
|
-
console.
|
|
447
|
+
console.log(`No id in entry.`);
|
|
448
|
+
console.log(entry);
|
|
468
449
|
}
|
|
469
450
|
}
|
|
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
451
|
}
|
|
474
452
|
else {
|
|
475
|
-
console.error(
|
|
453
|
+
console.error("\nNo entries found.");
|
|
476
454
|
}
|
|
477
455
|
}
|
|
478
456
|
else {
|
|
479
|
-
console.error(`\
|
|
457
|
+
console.error(`\nNo manga(s) found in any list.`);
|
|
480
458
|
}
|
|
481
459
|
}
|
|
482
460
|
catch (error) {
|
|
@@ -505,23 +483,20 @@ Statistics (Manga):
|
|
|
505
483
|
}
|
|
506
484
|
static Write(status) {
|
|
507
485
|
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
-
var _a;
|
|
509
486
|
try {
|
|
510
487
|
if (!(yield Auth.isLoggedIn())) {
|
|
511
488
|
console.error(`\nPlease login to use this feature.`);
|
|
512
489
|
return;
|
|
513
490
|
}
|
|
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).*`,
|
|
491
|
+
const { data } = yield fetcher(saveTextActivityMutation, {
|
|
492
|
+
status: status,
|
|
517
493
|
});
|
|
518
494
|
if (!data) {
|
|
519
495
|
console.error(`\nSomething went wrong. ${data}.`);
|
|
520
496
|
return;
|
|
521
497
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
console.log(`\n[${savedActivity.id}] status saved successfully!`);
|
|
498
|
+
if (data.SaveTextActivity.id) {
|
|
499
|
+
console.log(`\n[${data.SaveTextActivity.id}] status saved successfully!`);
|
|
525
500
|
}
|
|
526
501
|
}
|
|
527
502
|
catch (error) {
|
|
@@ -599,34 +574,39 @@ Statistics (Manga):
|
|
|
599
574
|
}
|
|
600
575
|
static LikeFollowing() {
|
|
601
576
|
return __awaiter(this, void 0, void 0, function* () {
|
|
602
|
-
var _a, _b, _c, _d;
|
|
577
|
+
var _a, _b, _c, _d, _e, _f;
|
|
603
578
|
try {
|
|
604
579
|
let page = 1;
|
|
605
580
|
let hasMoreActivities = true;
|
|
606
581
|
let retryCount = 0;
|
|
607
582
|
const maxRetries = 5;
|
|
583
|
+
let likedCount = 0;
|
|
608
584
|
while (hasMoreActivities) {
|
|
609
585
|
const activities = yield fetcher(followingActivitiesQuery, {
|
|
610
586
|
page,
|
|
611
587
|
perPage: 50,
|
|
612
588
|
});
|
|
613
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..`);
|
|
614
591
|
retryCount = 0; // Reset retry count on successful fetch
|
|
615
|
-
const activiti = (
|
|
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;
|
|
616
593
|
for (let activ of activiti) {
|
|
617
594
|
if (!activ.isLiked && activ.id) {
|
|
618
595
|
try {
|
|
619
596
|
const like = yield fetcher(likeActivityMutation, {
|
|
620
597
|
activityId: activ.id,
|
|
621
598
|
});
|
|
622
|
-
|
|
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)}`);
|
|
623
603
|
}
|
|
624
604
|
catch (error) {
|
|
625
605
|
console.error(`Activity possibly deleted. ${error.message}`);
|
|
626
606
|
}
|
|
627
607
|
}
|
|
628
608
|
else {
|
|
629
|
-
|
|
609
|
+
responsiveOutput(`"šµ" ${activityBy(activ, likedCount)}`);
|
|
630
610
|
}
|
|
631
611
|
// avoiding rate-limit
|
|
632
612
|
yield new Promise((resolve) => {
|
|
@@ -637,13 +617,13 @@ Statistics (Manga):
|
|
|
637
617
|
}
|
|
638
618
|
else {
|
|
639
619
|
if (retryCount < maxRetries) {
|
|
620
|
+
spinner.start("Getting activities...");
|
|
640
621
|
retryCount++;
|
|
641
|
-
|
|
642
|
-
yield new Promise((resolve) => setTimeout(resolve,
|
|
622
|
+
spinner.update(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
|
|
623
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
643
624
|
}
|
|
644
625
|
else {
|
|
645
|
-
|
|
646
|
-
console.info(activities);
|
|
626
|
+
spinner.error(`Probably the end of activities after ${maxRetries} retries.`);
|
|
647
627
|
hasMoreActivities = false;
|
|
648
628
|
}
|
|
649
629
|
}
|
|
@@ -654,24 +634,22 @@ Statistics (Manga):
|
|
|
654
634
|
}
|
|
655
635
|
});
|
|
656
636
|
}
|
|
657
|
-
static
|
|
637
|
+
static LikeGlobal() {
|
|
658
638
|
return __awaiter(this, void 0, void 0, function* () {
|
|
659
|
-
var _a, _b, _c, _d;
|
|
639
|
+
var _a, _b, _c, _d, _e, _f;
|
|
660
640
|
try {
|
|
661
641
|
let page = 1;
|
|
662
642
|
let hasMoreActivities = true;
|
|
663
|
-
let
|
|
664
|
-
|
|
665
|
-
: type === 1
|
|
666
|
-
? globalActivitiesQuery
|
|
667
|
-
: followingActivitiesQuery;
|
|
643
|
+
let likedCount = 0;
|
|
644
|
+
spinner.start(`Getting global activities...`);
|
|
668
645
|
while (hasMoreActivities) {
|
|
669
|
-
const activities = yield fetcher(
|
|
646
|
+
const activities = yield fetcher(globalActivitiesQuery, {
|
|
670
647
|
page,
|
|
671
648
|
perPage: 50,
|
|
672
649
|
});
|
|
673
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) {
|
|
674
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...`);
|
|
675
653
|
for (let activ of activiti) {
|
|
676
654
|
if (!activ.isLiked && activ.id) {
|
|
677
655
|
try {
|
|
@@ -679,14 +657,15 @@ Statistics (Manga):
|
|
|
679
657
|
activityId: activ.id,
|
|
680
658
|
});
|
|
681
659
|
// const ToggleLike = like?.data?.ToggleLike
|
|
682
|
-
|
|
660
|
+
likedCount++;
|
|
661
|
+
responsiveOutput(`${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"} ${activityBy(activ, likedCount)}`);
|
|
683
662
|
}
|
|
684
663
|
catch (error) {
|
|
685
664
|
console.error(`Activity possibly deleted. ${error.message}`);
|
|
686
665
|
}
|
|
687
666
|
}
|
|
688
667
|
else {
|
|
689
|
-
|
|
668
|
+
responsiveOutput(`šµ ${activityBy(activ, likedCount)}`);
|
|
690
669
|
}
|
|
691
670
|
// avoiding rate-limit
|
|
692
671
|
yield new Promise((resolve) => {
|
|
@@ -697,8 +676,7 @@ Statistics (Manga):
|
|
|
697
676
|
}
|
|
698
677
|
else {
|
|
699
678
|
// No more activities to like
|
|
700
|
-
|
|
701
|
-
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}`);
|
|
702
680
|
hasMoreActivities = false;
|
|
703
681
|
}
|
|
704
682
|
}
|
|
@@ -710,7 +688,7 @@ Statistics (Manga):
|
|
|
710
688
|
}
|
|
711
689
|
static LikeSpecificUser() {
|
|
712
690
|
return __awaiter(this, void 0, void 0, function* () {
|
|
713
|
-
var _a, _b, _c, _d;
|
|
691
|
+
var _a, _b, _c, _d, _e, _f;
|
|
714
692
|
try {
|
|
715
693
|
const { username } = yield inquirer.prompt([
|
|
716
694
|
{
|
|
@@ -720,10 +698,12 @@ Statistics (Manga):
|
|
|
720
698
|
},
|
|
721
699
|
]);
|
|
722
700
|
const userDetails = yield fetcher(userQuery, { username: username });
|
|
723
|
-
|
|
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) {
|
|
724
703
|
let page = 1;
|
|
725
704
|
const perPage = 50;
|
|
726
|
-
const userId = (
|
|
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;
|
|
727
707
|
if (userId) {
|
|
728
708
|
while (true) {
|
|
729
709
|
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
@@ -731,26 +711,28 @@ Statistics (Manga):
|
|
|
731
711
|
perPage,
|
|
732
712
|
userId,
|
|
733
713
|
});
|
|
734
|
-
const activiti = (
|
|
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;
|
|
735
715
|
// Break the loop if no more activities are found
|
|
736
716
|
if (!activiti || activiti.length === 0) {
|
|
737
|
-
|
|
717
|
+
spinner.error("No more activities found.");
|
|
738
718
|
break;
|
|
739
719
|
}
|
|
720
|
+
spinner.success(`Got ${activiti.length} activities...`);
|
|
740
721
|
for (let activ of activiti) {
|
|
741
722
|
if (!activ.isLiked && activ.id) {
|
|
742
723
|
try {
|
|
743
724
|
const like = yield fetcher(likeActivityMutation, {
|
|
744
725
|
activityId: activ.id,
|
|
745
726
|
});
|
|
746
|
-
|
|
727
|
+
likedCount++;
|
|
728
|
+
responsiveOutput(`${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"} ${activityBy(activ, likedCount)}`);
|
|
747
729
|
}
|
|
748
730
|
catch (error) {
|
|
749
731
|
console.error(`Activity possibly deleted. ${error.message}`);
|
|
750
732
|
}
|
|
751
733
|
}
|
|
752
734
|
else {
|
|
753
|
-
|
|
735
|
+
responsiveOutput(`šµ ${activityBy(activ, likedCount)}`);
|
|
754
736
|
}
|
|
755
737
|
// Avoiding rate limit
|
|
756
738
|
yield new Promise((resolve) => {
|
|
@@ -762,12 +744,116 @@ Statistics (Manga):
|
|
|
762
744
|
}
|
|
763
745
|
}
|
|
764
746
|
}
|
|
747
|
+
else {
|
|
748
|
+
spinner.error(`User ${username} does not exist.`);
|
|
749
|
+
exit(1);
|
|
750
|
+
}
|
|
765
751
|
}
|
|
766
752
|
catch (error) {
|
|
767
753
|
console.error(`\nError from LikeSpecificUser. ${error.message}`);
|
|
768
754
|
}
|
|
769
755
|
});
|
|
770
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
|
+
// ------------------------
|
|
770
|
+
// Fetch all following users
|
|
771
|
+
// ------------------------
|
|
772
|
+
spinner.start(`Gathering following information...`);
|
|
773
|
+
while (hasNextPage) {
|
|
774
|
+
spinner.update(`Fetched page ${page}...`);
|
|
775
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
776
|
+
userId: yield Auth.MyUserId(),
|
|
777
|
+
page,
|
|
778
|
+
});
|
|
779
|
+
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)) {
|
|
780
|
+
console.error(`\nFailed to fetch following users.`);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
allFollowingUsers.push(...followingUsers.data.Page.following);
|
|
784
|
+
hasNextPage = followingUsers.data.Page.pageInfo.hasNextPage;
|
|
785
|
+
page++;
|
|
786
|
+
}
|
|
787
|
+
spinner.stop(`Got ${allFollowingUsers.length} following user.`);
|
|
788
|
+
// Extract the IDs of all following users
|
|
789
|
+
const followingUserIds = allFollowingUsers.map((user) => user.id);
|
|
790
|
+
// --------------------
|
|
791
|
+
// APPROXIMATE TIME
|
|
792
|
+
// --------------------
|
|
793
|
+
const totalActivities = followingUserIds.length * perPage;
|
|
794
|
+
const perActivityTimeInSec = 1;
|
|
795
|
+
const rateLimitTimeInSec = 60;
|
|
796
|
+
const batchSize = 29;
|
|
797
|
+
const batches = Math.floor(totalActivities / batchSize);
|
|
798
|
+
const remaining = totalActivities % batchSize;
|
|
799
|
+
const processingTime = batches * batchSize * perActivityTimeInSec +
|
|
800
|
+
remaining * perActivityTimeInSec;
|
|
801
|
+
const waitTime = (batches - 1) * rateLimitTimeInSec;
|
|
802
|
+
const totalWaitTimeInSec = processingTime + (batches > 0 ? waitTime : 0);
|
|
803
|
+
const hours = Math.floor(totalWaitTimeInSec / 3600);
|
|
804
|
+
const minutes = Math.floor((totalWaitTimeInSec % 3600) / 60);
|
|
805
|
+
const seconds = totalWaitTimeInSec % 60;
|
|
806
|
+
const time = `${String(hours).padStart(2, "0")}h ${String(minutes).padStart(2, "0")}m ${String(seconds).padStart(2, "0")}s`;
|
|
807
|
+
console.log(`\nTotal following: ${followingUserIds.length}\nApproximately ${totalActivities} to like.\nWill take around ${time}`);
|
|
808
|
+
// -------------------
|
|
809
|
+
// Traverse the array and
|
|
810
|
+
// fetch users' activities one by one
|
|
811
|
+
// -------------------
|
|
812
|
+
let userNumber = 0;
|
|
813
|
+
for (const userId of followingUserIds) {
|
|
814
|
+
userNumber++;
|
|
815
|
+
console.log(`\n[${userNumber}]\tID: ${userId}`);
|
|
816
|
+
// Fetch `perPage` activities for the current user
|
|
817
|
+
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
818
|
+
userId,
|
|
819
|
+
page: 1, // Always fetch from the first page
|
|
820
|
+
perPage,
|
|
821
|
+
});
|
|
822
|
+
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)) {
|
|
823
|
+
console.log(`[${userNumber}] No activities found for User ID: ${userId}`);
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
const activiti = activities.data.Page.activities;
|
|
827
|
+
for (let i = 0; i < activiti.length; i++) {
|
|
828
|
+
const activ = activiti[i];
|
|
829
|
+
if (!activ.isLiked && activ.id) {
|
|
830
|
+
try {
|
|
831
|
+
const like = yield fetcher(likeActivityMutation, {
|
|
832
|
+
activityId: activ.id,
|
|
833
|
+
});
|
|
834
|
+
responsiveOutput(`${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"} ${activityBy(activ, i + 1)}`);
|
|
835
|
+
if (like === null || like === void 0 ? void 0 : like.data) {
|
|
836
|
+
liked++;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
catch (error) {
|
|
840
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
responsiveOutput(`šµ ${activityBy(activ, i + 1)}`);
|
|
845
|
+
}
|
|
846
|
+
// Avoid rate-limiting
|
|
847
|
+
yield new Promise((resolve) => setTimeout(resolve, 1200));
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
console.log(`\nā
All ${liked} activities liked successfully.`);
|
|
851
|
+
}
|
|
852
|
+
catch (error) {
|
|
853
|
+
console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
}
|
|
771
857
|
static AutoLike() {
|
|
772
858
|
return __awaiter(this, void 0, void 0, function* () {
|
|
773
859
|
try {
|
|
@@ -781,9 +867,10 @@ Statistics (Manga):
|
|
|
781
867
|
name: "activityType",
|
|
782
868
|
message: "Select activity type:",
|
|
783
869
|
choices: [
|
|
784
|
-
{ name: "Following", value: 1 },
|
|
785
|
-
{ name: "
|
|
786
|
-
{ name: "
|
|
870
|
+
{ name: "Following ⢠v1", value: 1 },
|
|
871
|
+
{ name: "Following ⢠v2", value: 2 },
|
|
872
|
+
{ name: "Global", value: 3 },
|
|
873
|
+
{ name: "Specific User", value: 4 },
|
|
787
874
|
],
|
|
788
875
|
pageSize: 10,
|
|
789
876
|
},
|
|
@@ -792,10 +879,21 @@ Statistics (Manga):
|
|
|
792
879
|
case 1:
|
|
793
880
|
yield this.LikeFollowing();
|
|
794
881
|
break;
|
|
795
|
-
case 2:
|
|
796
|
-
yield
|
|
882
|
+
case 2: {
|
|
883
|
+
const { count } = yield inquirer.prompt([
|
|
884
|
+
{
|
|
885
|
+
type: "number",
|
|
886
|
+
name: "count",
|
|
887
|
+
message: "Likes to give:",
|
|
888
|
+
},
|
|
889
|
+
]);
|
|
890
|
+
yield this.LikeFollowingActivityV2(count);
|
|
797
891
|
break;
|
|
892
|
+
}
|
|
798
893
|
case 3:
|
|
894
|
+
yield this.LikeGlobal();
|
|
895
|
+
break;
|
|
896
|
+
case 4:
|
|
799
897
|
yield this.LikeSpecificUser();
|
|
800
898
|
break;
|
|
801
899
|
default:
|
|
@@ -808,4 +906,124 @@ Statistics (Manga):
|
|
|
808
906
|
});
|
|
809
907
|
}
|
|
810
908
|
}
|
|
811
|
-
|
|
909
|
+
class Social {
|
|
910
|
+
/**
|
|
911
|
+
* Follow the users that follows you
|
|
912
|
+
*/
|
|
913
|
+
static follow() {
|
|
914
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
915
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
916
|
+
try {
|
|
917
|
+
let pager = 1;
|
|
918
|
+
let hasNextPage = true;
|
|
919
|
+
let allFollowerUsers = [];
|
|
920
|
+
let followedBack = 0;
|
|
921
|
+
spinner.start("Fetching all the followers...");
|
|
922
|
+
while (hasNextPage) {
|
|
923
|
+
const followerUsers = yield fetcher(userFollowersQuery, {
|
|
924
|
+
userId: yield Auth.MyUserId(),
|
|
925
|
+
page: pager,
|
|
926
|
+
});
|
|
927
|
+
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}...`);
|
|
928
|
+
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)) {
|
|
929
|
+
hasNextPage = false;
|
|
930
|
+
}
|
|
931
|
+
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) || []));
|
|
932
|
+
pager++;
|
|
933
|
+
}
|
|
934
|
+
spinner.stop("Fetched all the followers. Starting follow back.");
|
|
935
|
+
// Filter users that do no follow me
|
|
936
|
+
const notFollowing = allFollowerUsers
|
|
937
|
+
.filter(({ isFollowing }) => !isFollowing)
|
|
938
|
+
.map(({ id, name }) => ({ id: id, name: name }));
|
|
939
|
+
console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
|
|
940
|
+
if (notFollowing.length <= 0) {
|
|
941
|
+
console.log(`Probably followed back all the users.`);
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
// Traverse and follow back
|
|
945
|
+
const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
|
|
946
|
+
const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
|
|
947
|
+
for (let nf of notFollowing) {
|
|
948
|
+
try {
|
|
949
|
+
const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
|
|
950
|
+
console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
|
|
951
|
+
`\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)}` +
|
|
952
|
+
`\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) ? "ā
" : "šµ"}`);
|
|
953
|
+
// Count the followed back users
|
|
954
|
+
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) {
|
|
955
|
+
followedBack++;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
catch (error) {
|
|
959
|
+
console.log(`automate_follow_toggle_follow: ${error.message}`);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
console.log(`\nā
Followed back ${followedBack} users.`);
|
|
963
|
+
}
|
|
964
|
+
catch (error) {
|
|
965
|
+
console.log(`\nautomate_follow ${error.message}`);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Unfollow the users thats not following you
|
|
971
|
+
*/
|
|
972
|
+
static unfollow() {
|
|
973
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
974
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
975
|
+
try {
|
|
976
|
+
let pager = 1;
|
|
977
|
+
let hasNextPage = true;
|
|
978
|
+
let allFollowingUsers = [];
|
|
979
|
+
let unfollowedUsers = 0;
|
|
980
|
+
spinner.start("Fetching all following users...");
|
|
981
|
+
while (hasNextPage) {
|
|
982
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
983
|
+
userId: yield Auth.MyUserId(),
|
|
984
|
+
page: pager,
|
|
985
|
+
});
|
|
986
|
+
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}...`);
|
|
987
|
+
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)) {
|
|
988
|
+
hasNextPage = false;
|
|
989
|
+
}
|
|
990
|
+
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) || []));
|
|
991
|
+
pager++;
|
|
992
|
+
}
|
|
993
|
+
spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
|
|
994
|
+
// Filter users that do no follow me
|
|
995
|
+
const notFollowingMe = allFollowingUsers
|
|
996
|
+
.filter((user) => !user.isFollower)
|
|
997
|
+
.map((u3r) => ({ id: u3r.id, name: u3r.name }));
|
|
998
|
+
if (notFollowingMe.length <= 0) {
|
|
999
|
+
spinner.stop(`No users to unfollow. Exiting operation...`);
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
|
|
1003
|
+
let nfmCount = 0;
|
|
1004
|
+
console.log(`\n`);
|
|
1005
|
+
for (let nfm of notFollowingMe) {
|
|
1006
|
+
nfmCount++;
|
|
1007
|
+
try {
|
|
1008
|
+
const unfollow = yield fetcher(toggleFollowMutation, {
|
|
1009
|
+
userId: nfm.id,
|
|
1010
|
+
});
|
|
1011
|
+
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) ? "ā
" : "šµ"}`);
|
|
1012
|
+
// Count the unfollowed users
|
|
1013
|
+
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) {
|
|
1014
|
+
unfollowedUsers++;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
catch (error) {
|
|
1018
|
+
console.log(`unfollow_toggle_follow. ${error.message}`);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
console.log(`\nTotal Unfollowed: ${unfollowedUsers} of ${nfmCount} users.`);
|
|
1022
|
+
}
|
|
1023
|
+
catch (error) {
|
|
1024
|
+
console.error(`\nautomate_unfollow: ${error.message}`);
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
export { Auth, Social };
|