@irfanshadikrishad/anilist 1.0.0-forbidden.1 ā 1.0.0-forbidden.3
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 +115 -124
- package/LICENSE.md +382 -0
- package/README.md +255 -237
- package/bin/helpers/auth.d.ts +49 -9
- package/bin/helpers/auth.js +429 -287
- package/bin/helpers/fetcher.d.ts +3 -2
- package/bin/helpers/fetcher.js +29 -24
- package/bin/helpers/lists.d.ts +4 -1
- package/bin/helpers/lists.js +493 -384
- package/bin/helpers/queries.d.ts +7 -4
- package/bin/helpers/queries.js +23 -4
- package/bin/helpers/types.d.ts +340 -16
- package/bin/helpers/validation.d.ts +29 -0
- package/bin/helpers/validation.js +117 -0
- package/bin/helpers/workers.d.ts +21 -9
- package/bin/helpers/workers.js +213 -81
- package/bin/index.js +38 -10
- package/package.json +84 -73
- package/assets/binance.jpg +0 -0
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 { exit } from "process";
|
|
17
|
+
import Spinner from "tiny-spinner";
|
|
16
18
|
import { fetcher } from "./fetcher.js";
|
|
17
|
-
import { AniList, MyAnimeList } from "./lists.js";
|
|
19
|
+
import { AniDB, AniList, MyAnimeList } from "./lists.js";
|
|
18
20
|
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";
|
|
21
|
+
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, toggleFollowMutation, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.js";
|
|
22
|
+
import { activityBy, 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
|
}
|
|
@@ -109,7 +122,7 @@ class Auth {
|
|
|
109
122
|
}
|
|
110
123
|
static Myself() {
|
|
111
124
|
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;
|
|
125
|
+
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
126
|
try {
|
|
114
127
|
if (yield Auth.isLoggedIn()) {
|
|
115
128
|
const headers = {
|
|
@@ -130,33 +143,47 @@ class Auth {
|
|
|
130
143
|
perPage: 10,
|
|
131
144
|
});
|
|
132
145
|
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;
|
|
146
|
+
// Get follower/following information
|
|
147
|
+
const req_followers = yield fetcher(userFollowersQuery, {
|
|
148
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
149
|
+
});
|
|
150
|
+
const req_following = yield fetcher(userFollowingQuery, {
|
|
151
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
152
|
+
});
|
|
153
|
+
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;
|
|
154
|
+
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
155
|
console.log(`
|
|
134
156
|
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
135
157
|
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
136
158
|
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
137
|
-
profileColor: ${(
|
|
138
|
-
timeZone: ${(
|
|
139
|
-
activityMergeTime: ${(
|
|
159
|
+
profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
|
|
160
|
+
timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
|
|
161
|
+
activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
|
|
140
162
|
donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
|
|
141
163
|
donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
|
|
142
164
|
unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
|
|
143
165
|
Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
|
|
144
166
|
Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
|
|
167
|
+
|
|
168
|
+
Followers: ${followersCount}
|
|
169
|
+
Following: ${followingCount}
|
|
145
170
|
|
|
146
171
|
Statistics (Anime):
|
|
147
|
-
Count: ${(
|
|
148
|
-
Mean Score: ${(
|
|
149
|
-
Minutes Watched: ${(
|
|
172
|
+
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}
|
|
173
|
+
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}
|
|
174
|
+
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}
|
|
175
|
+
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
176
|
|
|
151
177
|
Statistics (Manga):
|
|
152
|
-
Count: ${(
|
|
153
|
-
|
|
154
|
-
|
|
178
|
+
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}
|
|
179
|
+
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}
|
|
180
|
+
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}
|
|
181
|
+
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
182
|
`);
|
|
156
183
|
console.log(`\nRecent Activities:`);
|
|
157
184
|
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)}`);
|
|
185
|
+
activities.map(({ status, progress, media, createdAt }) => {
|
|
186
|
+
console.log(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
160
187
|
});
|
|
161
188
|
}
|
|
162
189
|
return user;
|
|
@@ -179,15 +206,12 @@ Statistics (Manga):
|
|
|
179
206
|
static isLoggedIn() {
|
|
180
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
208
|
try {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
209
|
+
const token = yield Auth.RetriveAccessToken();
|
|
210
|
+
return token !== null;
|
|
188
211
|
}
|
|
189
212
|
catch (error) {
|
|
190
|
-
console.error(
|
|
213
|
+
console.error(`Error checking login status: ${error.message}`);
|
|
214
|
+
return false;
|
|
191
215
|
}
|
|
192
216
|
});
|
|
193
217
|
}
|
|
@@ -201,15 +225,15 @@ Statistics (Manga):
|
|
|
201
225
|
console.log(`\nLogout successful. See you soon, ${username}.`);
|
|
202
226
|
}
|
|
203
227
|
catch (error) {
|
|
204
|
-
console.error("\
|
|
228
|
+
console.error("\nFailed to remove the save file during logout:", error.message);
|
|
205
229
|
}
|
|
206
230
|
}
|
|
207
231
|
else {
|
|
208
|
-
console.
|
|
232
|
+
console.warn("\nNo active session found. You may already be logged out.");
|
|
209
233
|
}
|
|
210
234
|
}
|
|
211
235
|
catch (error) {
|
|
212
|
-
console.error(`\
|
|
236
|
+
console.error(`\nAn error occurred during logout: ${error.message}`);
|
|
213
237
|
}
|
|
214
238
|
});
|
|
215
239
|
}
|
|
@@ -217,23 +241,10 @@ Statistics (Manga):
|
|
|
217
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
242
|
var _a, _b;
|
|
219
243
|
if (!(yield Auth.isLoggedIn())) {
|
|
220
|
-
console.
|
|
244
|
+
console.warn(`\nUser not logged in.`);
|
|
221
245
|
return null;
|
|
222
246
|
}
|
|
223
|
-
const
|
|
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}`);
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
const { data } = yield request.json();
|
|
247
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
237
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;
|
|
238
249
|
});
|
|
239
250
|
}
|
|
@@ -244,20 +255,7 @@ Statistics (Manga):
|
|
|
244
255
|
console.log(`\nUser not logged in.`);
|
|
245
256
|
return null;
|
|
246
257
|
}
|
|
247
|
-
const
|
|
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();
|
|
258
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
261
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;
|
|
262
260
|
});
|
|
263
261
|
}
|
|
@@ -265,72 +263,70 @@ Statistics (Manga):
|
|
|
265
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
266
264
|
var _a, _b, _c, _d, _e, _f;
|
|
267
265
|
try {
|
|
268
|
-
if (yield Auth.isLoggedIn()) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
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
|
-
}
|
|
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;
|
|
324
308
|
}
|
|
325
309
|
else {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
+
}
|
|
329
323
|
}
|
|
330
324
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
+
}
|
|
334
330
|
}
|
|
335
331
|
}
|
|
336
332
|
catch (error) {
|
|
@@ -341,65 +337,51 @@ Statistics (Manga):
|
|
|
341
337
|
static DeleteMyAnimeList() {
|
|
342
338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
343
339
|
var _a, _b, _c, _d;
|
|
344
|
-
if (yield Auth.isLoggedIn()) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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,
|
|
352
359
|
},
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
})
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (lists.length > 0) {
|
|
362
|
-
const { selectedList } = yield inquirer.prompt([
|
|
363
|
-
{
|
|
364
|
-
type: "list",
|
|
365
|
-
name: "selectedList",
|
|
366
|
-
message: "Select an anime list:",
|
|
367
|
-
choices: lists.map((list) => list.name),
|
|
368
|
-
pageSize: 10,
|
|
369
|
-
},
|
|
370
|
-
]);
|
|
371
|
-
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
372
|
-
if (selectedEntries) {
|
|
373
|
-
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
374
|
-
for (const [_, entry] of selectedEntries.entries.entries()) {
|
|
375
|
-
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
376
|
-
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);
|
|
377
|
-
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
console.log(`No id in entry.`);
|
|
381
|
-
console.log(entry);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
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));
|
|
384
368
|
}
|
|
385
369
|
else {
|
|
386
|
-
console.log(
|
|
370
|
+
console.log(`No id in entry.`);
|
|
371
|
+
console.log(entry);
|
|
387
372
|
}
|
|
388
373
|
}
|
|
389
|
-
else {
|
|
390
|
-
console.log(`\nNo anime(s) found in any list.`);
|
|
391
|
-
}
|
|
392
374
|
}
|
|
393
375
|
else {
|
|
394
|
-
console.log(
|
|
376
|
+
console.log("No entries found.");
|
|
395
377
|
}
|
|
396
378
|
}
|
|
397
379
|
else {
|
|
398
|
-
console.log(`\
|
|
380
|
+
console.log(`\nNo anime(s) found in any list.`);
|
|
399
381
|
}
|
|
400
382
|
}
|
|
401
383
|
else {
|
|
402
|
-
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}`);
|
|
403
385
|
}
|
|
404
386
|
});
|
|
405
387
|
}
|
|
@@ -407,19 +389,8 @@ Statistics (Manga):
|
|
|
407
389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
390
|
var _a, _b, _c;
|
|
409
391
|
try {
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
headers: {
|
|
413
|
-
"content-type": "application/json",
|
|
414
|
-
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
415
|
-
},
|
|
416
|
-
body: JSON.stringify({
|
|
417
|
-
query: deleteMediaEntryMutation,
|
|
418
|
-
variables: { id },
|
|
419
|
-
}),
|
|
420
|
-
});
|
|
421
|
-
const response = yield request.json();
|
|
422
|
-
if (request.status === 200) {
|
|
392
|
+
const response = yield fetcher(deleteMediaEntryMutation, { id: id });
|
|
393
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
423
394
|
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;
|
|
424
395
|
console.log(`del ${title ? getTitle(title) : ""} ${deleted ? "ā
" : "ā"}`);
|
|
425
396
|
}
|
|
@@ -437,95 +408,69 @@ Statistics (Manga):
|
|
|
437
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
438
409
|
var _a, _b, _c, _d;
|
|
439
410
|
try {
|
|
440
|
-
if (yield Auth.isLoggedIn()) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
472
|
-
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);
|
|
473
|
-
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
console.log(`No id in entry.`);
|
|
477
|
-
console.log(entry);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
console.error("\nNo entries found.");
|
|
483
|
-
}
|
|
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));
|
|
484
442
|
}
|
|
485
443
|
else {
|
|
486
|
-
console.
|
|
444
|
+
console.log(`No id in entry.`);
|
|
445
|
+
console.log(entry);
|
|
487
446
|
}
|
|
488
447
|
}
|
|
489
|
-
else {
|
|
490
|
-
console.error(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
491
|
-
}
|
|
492
448
|
}
|
|
493
449
|
else {
|
|
494
|
-
console.error(
|
|
450
|
+
console.error("\nNo entries found.");
|
|
495
451
|
}
|
|
496
452
|
}
|
|
497
453
|
else {
|
|
498
|
-
console.error(`\
|
|
454
|
+
console.error(`\nNo manga(s) found in any list.`);
|
|
499
455
|
}
|
|
500
456
|
}
|
|
501
457
|
catch (error) {
|
|
502
|
-
console.error(`\nError deleting manga
|
|
458
|
+
console.error(`\nError deleting manga. ${error.message}`);
|
|
503
459
|
}
|
|
504
460
|
});
|
|
505
461
|
}
|
|
506
462
|
static DeleteMangaById(id, title) {
|
|
507
463
|
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
-
var _a, _b;
|
|
464
|
+
var _a, _b, _c, _d;
|
|
509
465
|
try {
|
|
510
|
-
const
|
|
511
|
-
method: "POST",
|
|
512
|
-
headers: {
|
|
513
|
-
"Content-Type": "application/json",
|
|
514
|
-
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
515
|
-
},
|
|
516
|
-
body: JSON.stringify({
|
|
517
|
-
query: deleteMangaEntryMutation,
|
|
518
|
-
variables: { id },
|
|
519
|
-
}),
|
|
520
|
-
});
|
|
521
|
-
const { data, errors } = yield request.json();
|
|
466
|
+
const response = yield fetcher(deleteMangaEntryMutation, { id });
|
|
522
467
|
const statusMessage = title ? getTitle(title) : "";
|
|
523
|
-
if (
|
|
524
|
-
const deleted = (_a =
|
|
468
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
469
|
+
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;
|
|
525
470
|
console.log(`del ${statusMessage} ${deleted ? "ā
" : "ā"}`);
|
|
526
471
|
}
|
|
527
472
|
else {
|
|
528
|
-
console.error(`Error deleting manga. ${(
|
|
473
|
+
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}`);
|
|
529
474
|
}
|
|
530
475
|
}
|
|
531
476
|
catch (error) {
|
|
@@ -535,25 +480,20 @@ Statistics (Manga):
|
|
|
535
480
|
}
|
|
536
481
|
static Write(status) {
|
|
537
482
|
return __awaiter(this, void 0, void 0, function* () {
|
|
538
|
-
var _a;
|
|
539
483
|
try {
|
|
540
484
|
if (!(yield Auth.isLoggedIn())) {
|
|
541
485
|
console.error(`\nPlease login to use this feature.`);
|
|
542
486
|
return;
|
|
543
487
|
}
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
`<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
|
|
548
|
-
};
|
|
549
|
-
const data = yield fetcher(query, variables);
|
|
488
|
+
const { data } = yield fetcher(saveTextActivityMutation, {
|
|
489
|
+
status: status,
|
|
490
|
+
});
|
|
550
491
|
if (!data) {
|
|
551
492
|
console.error(`\nSomething went wrong. ${data}.`);
|
|
552
493
|
return;
|
|
553
494
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
console.log(`\n[${savedActivity.id}] status saved successfully!`);
|
|
495
|
+
if (data.SaveTextActivity.id) {
|
|
496
|
+
console.log(`\n[${data.SaveTextActivity.id}] status saved successfully!`);
|
|
557
497
|
}
|
|
558
498
|
}
|
|
559
499
|
catch (error) {
|
|
@@ -572,6 +512,7 @@ Statistics (Manga):
|
|
|
572
512
|
choices: [
|
|
573
513
|
{ name: "Exported JSON file.", value: 1 },
|
|
574
514
|
{ name: "MyAnimeList (XML)", value: 2 },
|
|
515
|
+
{ name: "AniDB (json-large)", value: 3 },
|
|
575
516
|
],
|
|
576
517
|
pageSize: 10,
|
|
577
518
|
},
|
|
@@ -583,6 +524,9 @@ Statistics (Manga):
|
|
|
583
524
|
case 2:
|
|
584
525
|
yield MyAnimeList.importAnime();
|
|
585
526
|
break;
|
|
527
|
+
case 3:
|
|
528
|
+
yield AniDB.importAnime();
|
|
529
|
+
break;
|
|
586
530
|
default:
|
|
587
531
|
console.log(`\nInvalid Choice.`);
|
|
588
532
|
break;
|
|
@@ -627,7 +571,7 @@ Statistics (Manga):
|
|
|
627
571
|
}
|
|
628
572
|
static LikeFollowing() {
|
|
629
573
|
return __awaiter(this, void 0, void 0, function* () {
|
|
630
|
-
var _a, _b, _c, _d;
|
|
574
|
+
var _a, _b, _c, _d, _e, _f;
|
|
631
575
|
try {
|
|
632
576
|
let page = 1;
|
|
633
577
|
let hasMoreActivities = true;
|
|
@@ -639,22 +583,23 @@ Statistics (Manga):
|
|
|
639
583
|
perPage: 50,
|
|
640
584
|
});
|
|
641
585
|
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) {
|
|
586
|
+
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..`);
|
|
642
587
|
retryCount = 0; // Reset retry count on successful fetch
|
|
643
|
-
const activiti = (
|
|
588
|
+
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;
|
|
644
589
|
for (let activ of activiti) {
|
|
645
590
|
if (!activ.isLiked && activ.id) {
|
|
646
591
|
try {
|
|
647
592
|
const like = yield fetcher(likeActivityMutation, {
|
|
648
593
|
activityId: activ.id,
|
|
649
594
|
});
|
|
650
|
-
console.info(
|
|
595
|
+
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"}`);
|
|
651
596
|
}
|
|
652
597
|
catch (error) {
|
|
653
|
-
console.error(`Activity possibly deleted
|
|
598
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
654
599
|
}
|
|
655
600
|
}
|
|
656
601
|
else {
|
|
657
|
-
console.log(
|
|
602
|
+
console.log(`${activityBy(activ)} šµ`);
|
|
658
603
|
}
|
|
659
604
|
// avoiding rate-limit
|
|
660
605
|
yield new Promise((resolve) => {
|
|
@@ -665,13 +610,13 @@ Statistics (Manga):
|
|
|
665
610
|
}
|
|
666
611
|
else {
|
|
667
612
|
if (retryCount < maxRetries) {
|
|
613
|
+
spinner.start("Getting activities...");
|
|
668
614
|
retryCount++;
|
|
669
|
-
|
|
670
|
-
yield new Promise((resolve) => setTimeout(resolve,
|
|
615
|
+
spinner.update(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
|
|
616
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
671
617
|
}
|
|
672
618
|
else {
|
|
673
|
-
|
|
674
|
-
console.info(activities);
|
|
619
|
+
spinner.error(`Probably the end of activities after ${maxRetries} retries.`);
|
|
675
620
|
hasMoreActivities = false;
|
|
676
621
|
}
|
|
677
622
|
}
|
|
@@ -682,24 +627,22 @@ Statistics (Manga):
|
|
|
682
627
|
}
|
|
683
628
|
});
|
|
684
629
|
}
|
|
685
|
-
static
|
|
630
|
+
static LikeGlobal() {
|
|
686
631
|
return __awaiter(this, void 0, void 0, function* () {
|
|
687
|
-
var _a, _b, _c, _d;
|
|
632
|
+
var _a, _b, _c, _d, _e, _f;
|
|
688
633
|
try {
|
|
689
634
|
let page = 1;
|
|
690
635
|
let hasMoreActivities = true;
|
|
691
|
-
let
|
|
692
|
-
|
|
693
|
-
: type === 1
|
|
694
|
-
? globalActivitiesQuery
|
|
695
|
-
: followingActivitiesQuery;
|
|
636
|
+
let likedCount = 0;
|
|
637
|
+
spinner.start(`Getting global activities...`);
|
|
696
638
|
while (hasMoreActivities) {
|
|
697
|
-
const activities = yield fetcher(
|
|
639
|
+
const activities = yield fetcher(globalActivitiesQuery, {
|
|
698
640
|
page,
|
|
699
641
|
perPage: 50,
|
|
700
642
|
});
|
|
701
643
|
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) {
|
|
702
644
|
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;
|
|
645
|
+
spinner.success(`Got ${activiti.length} activities...`);
|
|
703
646
|
for (let activ of activiti) {
|
|
704
647
|
if (!activ.isLiked && activ.id) {
|
|
705
648
|
try {
|
|
@@ -707,26 +650,26 @@ Statistics (Manga):
|
|
|
707
650
|
activityId: activ.id,
|
|
708
651
|
});
|
|
709
652
|
// const ToggleLike = like?.data?.ToggleLike
|
|
710
|
-
|
|
653
|
+
likedCount++;
|
|
654
|
+
console.info(`${activityBy(activ, likedCount)} ${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"}`);
|
|
711
655
|
}
|
|
712
656
|
catch (error) {
|
|
713
|
-
console.error(`Activity possibly deleted
|
|
657
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
714
658
|
}
|
|
715
659
|
}
|
|
716
660
|
else {
|
|
717
|
-
console.log(
|
|
661
|
+
console.log(`${activityBy(activ)} šµ`);
|
|
718
662
|
}
|
|
719
663
|
// avoiding rate-limit
|
|
720
664
|
yield new Promise((resolve) => {
|
|
721
|
-
setTimeout(resolve,
|
|
665
|
+
setTimeout(resolve, 1500);
|
|
722
666
|
});
|
|
723
667
|
}
|
|
724
668
|
page++;
|
|
725
669
|
}
|
|
726
670
|
else {
|
|
727
671
|
// No more activities to like
|
|
728
|
-
|
|
729
|
-
console.info(activities);
|
|
672
|
+
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}`);
|
|
730
673
|
hasMoreActivities = false;
|
|
731
674
|
}
|
|
732
675
|
}
|
|
@@ -748,10 +691,12 @@ Statistics (Manga):
|
|
|
748
691
|
},
|
|
749
692
|
]);
|
|
750
693
|
const userDetails = yield fetcher(userQuery, { username: username });
|
|
751
|
-
|
|
694
|
+
spinner.start(`Getting activities by ${username}`);
|
|
695
|
+
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) {
|
|
752
696
|
let page = 1;
|
|
753
697
|
const perPage = 50;
|
|
754
|
-
const userId = (
|
|
698
|
+
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;
|
|
699
|
+
let likedCount = 0;
|
|
755
700
|
if (userId) {
|
|
756
701
|
while (true) {
|
|
757
702
|
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
@@ -759,30 +704,32 @@ Statistics (Manga):
|
|
|
759
704
|
perPage,
|
|
760
705
|
userId,
|
|
761
706
|
});
|
|
762
|
-
const activiti = (
|
|
707
|
+
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;
|
|
763
708
|
// Break the loop if no more activities are found
|
|
764
709
|
if (!activiti || activiti.length === 0) {
|
|
765
|
-
|
|
710
|
+
spinner.error("No more activities found.");
|
|
766
711
|
break;
|
|
767
712
|
}
|
|
713
|
+
spinner.success(`Got ${activiti.length} activities...`);
|
|
768
714
|
for (let activ of activiti) {
|
|
769
715
|
if (!activ.isLiked && activ.id) {
|
|
770
716
|
try {
|
|
771
717
|
const like = yield fetcher(likeActivityMutation, {
|
|
772
718
|
activityId: activ.id,
|
|
773
719
|
});
|
|
774
|
-
|
|
720
|
+
likedCount++;
|
|
721
|
+
console.info(`${activityBy(activ, likedCount)} ${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"}`);
|
|
775
722
|
}
|
|
776
723
|
catch (error) {
|
|
777
|
-
console.error(`Activity possibly deleted
|
|
724
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
778
725
|
}
|
|
779
726
|
}
|
|
780
727
|
else {
|
|
781
|
-
console.log(
|
|
728
|
+
console.log(`${activityBy(activ)} šµ`);
|
|
782
729
|
}
|
|
783
730
|
// Avoiding rate limit
|
|
784
731
|
yield new Promise((resolve) => {
|
|
785
|
-
setTimeout(resolve,
|
|
732
|
+
setTimeout(resolve, 1500);
|
|
786
733
|
});
|
|
787
734
|
}
|
|
788
735
|
// Go to the next page
|
|
@@ -790,12 +737,96 @@ Statistics (Manga):
|
|
|
790
737
|
}
|
|
791
738
|
}
|
|
792
739
|
}
|
|
740
|
+
else {
|
|
741
|
+
spinner.error(`User ${username} does not exist.`);
|
|
742
|
+
exit(1);
|
|
743
|
+
}
|
|
793
744
|
}
|
|
794
745
|
catch (error) {
|
|
795
746
|
console.error(`\nError from LikeSpecificUser. ${error.message}`);
|
|
796
747
|
}
|
|
797
748
|
});
|
|
798
749
|
}
|
|
750
|
+
static LikeFollowingActivityV2(perPage) {
|
|
751
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
752
|
+
var _a, _b, _c, _d, _e;
|
|
753
|
+
try {
|
|
754
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
755
|
+
console.error(`\nPlease log in to use this feature.`);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const allFollowingUsers = [];
|
|
759
|
+
let hasNextPage = true;
|
|
760
|
+
let page = 1;
|
|
761
|
+
let liked = 0;
|
|
762
|
+
// Fetch all following users
|
|
763
|
+
spinner.start(`Gathering following information...`);
|
|
764
|
+
while (hasNextPage) {
|
|
765
|
+
spinner.update(`Fetched page ${page}...`);
|
|
766
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
767
|
+
userId: yield Auth.MyUserId(),
|
|
768
|
+
page,
|
|
769
|
+
});
|
|
770
|
+
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)) {
|
|
771
|
+
console.error(`\nFailed to fetch following users.`);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
allFollowingUsers.push(...followingUsers.data.Page.following);
|
|
775
|
+
hasNextPage = followingUsers.data.Page.pageInfo.hasNextPage;
|
|
776
|
+
page++;
|
|
777
|
+
}
|
|
778
|
+
spinner.stop(`Got ${allFollowingUsers.length} following user.`);
|
|
779
|
+
// Extract the IDs of all following users
|
|
780
|
+
const followingUserIds = allFollowingUsers.map((user) => user.id);
|
|
781
|
+
console.log(`\nTotal Following: ${followingUserIds.length}\nApproximately ${followingUserIds.length * perPage} activities to like.\nWill take around ${((followingUserIds.length * perPage * 1200) /
|
|
782
|
+
1000 /
|
|
783
|
+
60).toFixed(2)} minutes.`);
|
|
784
|
+
// Traverse the array and fetch users' activities one by one
|
|
785
|
+
let userNumber = 0;
|
|
786
|
+
for (const userId of followingUserIds) {
|
|
787
|
+
userNumber++;
|
|
788
|
+
console.log(`\n[${userNumber}]\tID: ${userId}`);
|
|
789
|
+
// Fetch `perPage` activities for the current user
|
|
790
|
+
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
791
|
+
userId,
|
|
792
|
+
page: 1, // Always fetch from the first page
|
|
793
|
+
perPage,
|
|
794
|
+
});
|
|
795
|
+
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)) {
|
|
796
|
+
console.log(`[${userNumber}] No activities found for User ID: ${userId}`);
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
const activiti = activities.data.Page.activities;
|
|
800
|
+
for (let i = 0; i < activiti.length; i++) {
|
|
801
|
+
const activ = activiti[i];
|
|
802
|
+
if (!activ.isLiked && activ.id) {
|
|
803
|
+
try {
|
|
804
|
+
const like = yield fetcher(likeActivityMutation, {
|
|
805
|
+
activityId: activ.id,
|
|
806
|
+
});
|
|
807
|
+
console.info(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "ā
" : "ā"}`);
|
|
808
|
+
if (like === null || like === void 0 ? void 0 : like.data) {
|
|
809
|
+
liked++;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
catch (error) {
|
|
813
|
+
console.error(`[${userNumber}/${i + 1}/${activiti.length}] Activity possibly deleted. ${error.message}`);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
console.log(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} šµ`);
|
|
818
|
+
}
|
|
819
|
+
// Avoid rate-limiting
|
|
820
|
+
yield new Promise((resolve) => setTimeout(resolve, 1200));
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
console.log(`\nā
All ${liked} activities liked successfully.`);
|
|
824
|
+
}
|
|
825
|
+
catch (error) {
|
|
826
|
+
console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
}
|
|
799
830
|
static AutoLike() {
|
|
800
831
|
return __awaiter(this, void 0, void 0, function* () {
|
|
801
832
|
try {
|
|
@@ -821,7 +852,7 @@ Statistics (Manga):
|
|
|
821
852
|
yield this.LikeFollowing();
|
|
822
853
|
break;
|
|
823
854
|
case 2:
|
|
824
|
-
yield this.
|
|
855
|
+
yield this.LikeGlobal();
|
|
825
856
|
break;
|
|
826
857
|
case 3:
|
|
827
858
|
yield this.LikeSpecificUser();
|
|
@@ -836,4 +867,115 @@ Statistics (Manga):
|
|
|
836
867
|
});
|
|
837
868
|
}
|
|
838
869
|
}
|
|
839
|
-
|
|
870
|
+
class Social {
|
|
871
|
+
/**
|
|
872
|
+
* Follow the users that follows you
|
|
873
|
+
*/
|
|
874
|
+
static follow() {
|
|
875
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
876
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
877
|
+
try {
|
|
878
|
+
let pager = 1;
|
|
879
|
+
let hasNextPage = true;
|
|
880
|
+
let allFollowerUsers = [];
|
|
881
|
+
spinner.start("Fetching all the followers...");
|
|
882
|
+
while (hasNextPage) {
|
|
883
|
+
const followerUsers = yield fetcher(userFollowersQuery, {
|
|
884
|
+
userId: yield Auth.MyUserId(),
|
|
885
|
+
page: pager,
|
|
886
|
+
});
|
|
887
|
+
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}...`);
|
|
888
|
+
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)) {
|
|
889
|
+
hasNextPage = false;
|
|
890
|
+
}
|
|
891
|
+
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) || []));
|
|
892
|
+
pager++;
|
|
893
|
+
}
|
|
894
|
+
spinner.stop("Fetched all the followers. Starting follow back.");
|
|
895
|
+
// Filter users that do no follow me
|
|
896
|
+
const notFollowing = allFollowerUsers
|
|
897
|
+
.filter(({ isFollowing }) => !isFollowing)
|
|
898
|
+
.map(({ id, name }) => ({ id: id, name: name }));
|
|
899
|
+
console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
|
|
900
|
+
if (notFollowing.length <= 0) {
|
|
901
|
+
console.log(`Probably followed back all the users.`);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
// Traverse and follow back
|
|
905
|
+
const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
|
|
906
|
+
const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
|
|
907
|
+
for (let nf of notFollowing) {
|
|
908
|
+
try {
|
|
909
|
+
const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
|
|
910
|
+
console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
|
|
911
|
+
`\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)}` +
|
|
912
|
+
`\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) ? "ā
" : "šµ"}`);
|
|
913
|
+
}
|
|
914
|
+
catch (error) {
|
|
915
|
+
console.log(`automate_follow_toggle_follow: ${error.message}`);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
console.log(`\nā
Followed back ${notFollowing.length} users.`);
|
|
919
|
+
}
|
|
920
|
+
catch (error) {
|
|
921
|
+
console.log(`\nautomate_follow ${error.message}`);
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Unfollow the users thats not following you
|
|
927
|
+
*/
|
|
928
|
+
static unfollow() {
|
|
929
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
930
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
931
|
+
try {
|
|
932
|
+
let pager = 1;
|
|
933
|
+
let hasNextPage = true;
|
|
934
|
+
let allFollowingUsers = [];
|
|
935
|
+
spinner.start("Fetching all following users...");
|
|
936
|
+
while (hasNextPage) {
|
|
937
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
938
|
+
userId: yield Auth.MyUserId(),
|
|
939
|
+
page: pager,
|
|
940
|
+
});
|
|
941
|
+
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} ...`);
|
|
942
|
+
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)) {
|
|
943
|
+
hasNextPage = false;
|
|
944
|
+
}
|
|
945
|
+
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) || []));
|
|
946
|
+
pager++;
|
|
947
|
+
}
|
|
948
|
+
spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
|
|
949
|
+
// Filter users that do no follow me
|
|
950
|
+
const notFollowingMe = allFollowingUsers
|
|
951
|
+
.filter((user) => !user.isFollower)
|
|
952
|
+
.map((u3r) => ({ id: u3r.id, name: u3r.name }));
|
|
953
|
+
if (notFollowingMe.length <= 0) {
|
|
954
|
+
console.warn(`\nNot following list is empty!`);
|
|
955
|
+
spinner.stop(`No users to unfollow. Aborting process...`);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
|
|
959
|
+
let nfmCount = 0;
|
|
960
|
+
console.log(`\n`);
|
|
961
|
+
for (let nfm of notFollowingMe) {
|
|
962
|
+
nfmCount++;
|
|
963
|
+
try {
|
|
964
|
+
const unfollow = yield fetcher(toggleFollowMutation, {
|
|
965
|
+
userId: nfm.id,
|
|
966
|
+
});
|
|
967
|
+
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) ? "ā
" : "šµ"}`);
|
|
968
|
+
}
|
|
969
|
+
catch (error) {
|
|
970
|
+
console.log(`unfollow_toggle_follow. ${error.message}`);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
console.log(`\nTotal Unfollowed: ${nfmCount}`);
|
|
974
|
+
}
|
|
975
|
+
catch (error) {
|
|
976
|
+
console.error(`\nautomate_unfollow: ${error.message}`);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
export { Auth, Social };
|