@irfanshadikrishad/anilist 1.2.0-forbidden.1 → 1.2.1-forbidden.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +382 -382
- package/README.md +255 -245
- package/bin/helpers/auth.d.ts +48 -8
- package/bin/helpers/auth.js +415 -259
- package/bin/helpers/fetcher.d.ts +1 -1
- package/bin/helpers/lists.d.ts +5 -2
- package/bin/helpers/lists.js +317 -246
- package/bin/helpers/mutations.js +35 -35
- package/bin/helpers/queries.d.ts +7 -4
- package/bin/helpers/queries.js +173 -154
- package/bin/helpers/types.d.ts +349 -8
- package/bin/helpers/validation.d.ts +29 -0
- package/bin/helpers/validation.js +117 -0
- package/bin/helpers/workers.d.ts +8 -5
- package/bin/helpers/workers.js +155 -72
- package/bin/index.js +36 -5
- package/package.json +84 -80
- package/assets/binance.jpg +0 -0
package/bin/helpers/auth.js
CHANGED
|
@@ -13,13 +13,15 @@ import fetch from "node-fetch";
|
|
|
13
13
|
import open from "open";
|
|
14
14
|
import os from "os";
|
|
15
15
|
import path from "path";
|
|
16
|
+
import Spinner from "tiny-spinner";
|
|
16
17
|
import { fetcher } from "./fetcher.js";
|
|
17
|
-
import { AniList, MyAnimeList } from "./lists.js";
|
|
18
|
+
import { AniDB, AniList, MyAnimeList } from "./lists.js";
|
|
18
19
|
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";
|
|
20
|
+
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, toggleFollowMutation, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.js";
|
|
21
|
+
import { activityBy, aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
|
|
21
22
|
const home_dir = os.homedir();
|
|
22
23
|
const save_path = path.join(home_dir, ".anilist_token");
|
|
24
|
+
const spinner = new Spinner();
|
|
23
25
|
class Auth {
|
|
24
26
|
/**
|
|
25
27
|
* Get access-token from user
|
|
@@ -34,20 +36,29 @@ class Auth {
|
|
|
34
36
|
message: "Please enter your AniList access token:",
|
|
35
37
|
},
|
|
36
38
|
]);
|
|
39
|
+
if (!token) {
|
|
40
|
+
console.warn("\nNo token entered. Please try again.");
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
37
43
|
return token;
|
|
38
44
|
}
|
|
39
45
|
catch (error) {
|
|
40
|
-
console.error(`\
|
|
46
|
+
console.error(`\nAn error occurred while getting the access token: ${error.message}`);
|
|
47
|
+
return null;
|
|
41
48
|
}
|
|
42
49
|
});
|
|
43
50
|
}
|
|
44
51
|
static StoreAccessToken(token) {
|
|
45
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
53
|
try {
|
|
54
|
+
if (!token) {
|
|
55
|
+
console.warn("\nNo token provided. Nothing to store.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
47
58
|
fs.writeFileSync(save_path, token, { encoding: "utf8" });
|
|
48
59
|
}
|
|
49
60
|
catch (error) {
|
|
50
|
-
console.error(`\nError storing
|
|
61
|
+
console.error(`\nError storing access token: ${error.message}`);
|
|
51
62
|
}
|
|
52
63
|
});
|
|
53
64
|
}
|
|
@@ -63,6 +74,7 @@ class Auth {
|
|
|
63
74
|
}
|
|
64
75
|
catch (error) {
|
|
65
76
|
console.error(`\nError retriving acess-token. ${error.message}`);
|
|
77
|
+
return null;
|
|
66
78
|
}
|
|
67
79
|
});
|
|
68
80
|
}
|
|
@@ -109,7 +121,7 @@ class Auth {
|
|
|
109
121
|
}
|
|
110
122
|
static Myself() {
|
|
111
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
124
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
113
125
|
try {
|
|
114
126
|
if (yield Auth.isLoggedIn()) {
|
|
115
127
|
const headers = {
|
|
@@ -130,33 +142,47 @@ class Auth {
|
|
|
130
142
|
perPage: 10,
|
|
131
143
|
});
|
|
132
144
|
const activities = (_b = (_a = activiResponse === null || activiResponse === void 0 ? void 0 : activiResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
// Get follower/following information
|
|
146
|
+
const req_followers = yield fetcher(userFollowersQuery, {
|
|
147
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
148
|
+
});
|
|
149
|
+
const req_following = yield fetcher(userFollowingQuery, {
|
|
150
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
151
|
+
});
|
|
152
|
+
const followersCount = ((_e = (_d = (_c = req_followers === null || req_followers === void 0 ? void 0 : req_followers.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.pageInfo) === null || _e === void 0 ? void 0 : _e.total) || 0;
|
|
153
|
+
const followingCount = ((_h = (_g = (_f = req_following === null || req_following === void 0 ? void 0 : req_following.data) === null || _f === void 0 ? void 0 : _f.Page) === null || _g === void 0 ? void 0 : _g.pageInfo) === null || _h === void 0 ? void 0 : _h.total) || 0;
|
|
154
|
+
console.log(`
|
|
155
|
+
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
156
|
+
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
157
|
+
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
158
|
+
profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
|
|
159
|
+
timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
|
|
160
|
+
activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
|
|
161
|
+
donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
|
|
162
|
+
donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
|
|
163
|
+
unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
|
|
164
|
+
Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
|
|
165
|
+
Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
|
|
166
|
+
|
|
167
|
+
Followers: ${followersCount}
|
|
168
|
+
Following: ${followingCount}
|
|
169
|
+
|
|
170
|
+
Statistics (Anime):
|
|
171
|
+
Count: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.anime) === null || _o === void 0 ? void 0 : _o.count}
|
|
172
|
+
Mean Score: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.anime) === null || _q === void 0 ? void 0 : _q.meanScore}
|
|
173
|
+
Minutes Watched: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.anime) === null || _s === void 0 ? void 0 : _s.minutesWatched}
|
|
174
|
+
Episodes Watched: ${(_u = (_t = user === null || user === void 0 ? void 0 : user.statistics) === null || _t === void 0 ? void 0 : _t.anime) === null || _u === void 0 ? void 0 : _u.episodesWatched}
|
|
175
|
+
|
|
176
|
+
Statistics (Manga):
|
|
177
|
+
Count: ${(_w = (_v = user === null || user === void 0 ? void 0 : user.statistics) === null || _v === void 0 ? void 0 : _v.manga) === null || _w === void 0 ? void 0 : _w.count}
|
|
178
|
+
Mean Score: ${(_y = (_x = user === null || user === void 0 ? void 0 : user.statistics) === null || _x === void 0 ? void 0 : _x.manga) === null || _y === void 0 ? void 0 : _y.meanScore}
|
|
179
|
+
Chapters Read: ${(_0 = (_z = user === null || user === void 0 ? void 0 : user.statistics) === null || _z === void 0 ? void 0 : _z.manga) === null || _0 === void 0 ? void 0 : _0.chaptersRead}
|
|
180
|
+
Volumes Read: ${(_2 = (_1 = user === null || user === void 0 ? void 0 : user.statistics) === null || _1 === void 0 ? void 0 : _1.manga) === null || _2 === void 0 ? void 0 : _2.volumesRead}
|
|
155
181
|
`);
|
|
156
182
|
console.log(`\nRecent Activities:`);
|
|
157
183
|
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)}`);
|
|
184
|
+
activities.map(({ status, progress, media, createdAt }) => {
|
|
185
|
+
console.log(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
160
186
|
});
|
|
161
187
|
}
|
|
162
188
|
return user;
|
|
@@ -179,15 +205,12 @@ Statistics (Manga):
|
|
|
179
205
|
static isLoggedIn() {
|
|
180
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
207
|
try {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
208
|
+
const token = yield Auth.RetriveAccessToken();
|
|
209
|
+
return token !== null;
|
|
188
210
|
}
|
|
189
211
|
catch (error) {
|
|
190
|
-
console.error(
|
|
212
|
+
console.error(`Error checking login status: ${error.message}`);
|
|
213
|
+
return false;
|
|
191
214
|
}
|
|
192
215
|
});
|
|
193
216
|
}
|
|
@@ -201,15 +224,15 @@ Statistics (Manga):
|
|
|
201
224
|
console.log(`\nLogout successful. See you soon, ${username}.`);
|
|
202
225
|
}
|
|
203
226
|
catch (error) {
|
|
204
|
-
console.error("\
|
|
227
|
+
console.error("\nFailed to remove the save file during logout:", error.message);
|
|
205
228
|
}
|
|
206
229
|
}
|
|
207
230
|
else {
|
|
208
|
-
console.
|
|
231
|
+
console.warn("\nNo active session found. You may already be logged out.");
|
|
209
232
|
}
|
|
210
233
|
}
|
|
211
234
|
catch (error) {
|
|
212
|
-
console.error(`\
|
|
235
|
+
console.error(`\nAn error occurred during logout: ${error.message}`);
|
|
213
236
|
}
|
|
214
237
|
});
|
|
215
238
|
}
|
|
@@ -217,23 +240,10 @@ Statistics (Manga):
|
|
|
217
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
241
|
var _a, _b;
|
|
219
242
|
if (!(yield Auth.isLoggedIn())) {
|
|
220
|
-
console.
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
const token = yield Auth.RetriveAccessToken();
|
|
224
|
-
const request = yield fetch(aniListEndpoint, {
|
|
225
|
-
method: "POST",
|
|
226
|
-
headers: {
|
|
227
|
-
"Content-Type": "application/json",
|
|
228
|
-
"Authorization": `Bearer ${token}`,
|
|
229
|
-
},
|
|
230
|
-
body: JSON.stringify({ query: currentUserQuery }),
|
|
231
|
-
});
|
|
232
|
-
if (!(request.status === 200)) {
|
|
233
|
-
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
243
|
+
console.warn(`\nUser not logged in.`);
|
|
234
244
|
return null;
|
|
235
245
|
}
|
|
236
|
-
const { data } = yield
|
|
246
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
237
247
|
return (_b = (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
|
|
238
248
|
});
|
|
239
249
|
}
|
|
@@ -244,20 +254,7 @@ Statistics (Manga):
|
|
|
244
254
|
console.log(`\nUser not logged in.`);
|
|
245
255
|
return null;
|
|
246
256
|
}
|
|
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();
|
|
257
|
+
const { data } = yield fetcher(currentUserQuery, {});
|
|
261
258
|
return (_b = (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : null;
|
|
262
259
|
});
|
|
263
260
|
}
|
|
@@ -265,72 +262,70 @@ Statistics (Manga):
|
|
|
265
262
|
return __awaiter(this, void 0, void 0, function* () {
|
|
266
263
|
var _a, _b, _c, _d, _e, _f;
|
|
267
264
|
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
|
-
}
|
|
265
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
266
|
+
console.error(`\nPlease log in to delete your activities.`);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const { activityType } = yield inquirer.prompt([
|
|
270
|
+
{
|
|
271
|
+
type: "list",
|
|
272
|
+
name: "activityType",
|
|
273
|
+
message: "What type of activity you want to delete?",
|
|
274
|
+
choices: [
|
|
275
|
+
{ name: "All Activity", value: 0 },
|
|
276
|
+
{ name: "Text Activity", value: 1 },
|
|
277
|
+
{ name: "Media List Activity", value: 2 },
|
|
278
|
+
{ name: "Anime List Activity", value: 3 },
|
|
279
|
+
{ name: "Manga List Activity", value: 4 },
|
|
280
|
+
{ name: "Message Activity", value: 5 },
|
|
281
|
+
],
|
|
282
|
+
},
|
|
283
|
+
]);
|
|
284
|
+
const queryMap = {
|
|
285
|
+
0: activityAllQuery,
|
|
286
|
+
1: activityTextQuery,
|
|
287
|
+
2: activityMediaList,
|
|
288
|
+
3: activityAnimeListQuery,
|
|
289
|
+
4: activityMangaListQuery,
|
|
290
|
+
5: activityMessageQuery,
|
|
291
|
+
};
|
|
292
|
+
const query = queryMap[activityType];
|
|
293
|
+
let hasMoreActivities = true;
|
|
294
|
+
let totalCount = 0;
|
|
295
|
+
while (hasMoreActivities) {
|
|
296
|
+
const response = yield fetcher(query, {
|
|
297
|
+
page: 1,
|
|
298
|
+
perPage: 50,
|
|
299
|
+
userId: yield Auth.MyUserId(),
|
|
300
|
+
});
|
|
301
|
+
if ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities) {
|
|
302
|
+
let count = 0;
|
|
303
|
+
const activities = (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
|
|
304
|
+
if (!activities || activities.length === 0) {
|
|
305
|
+
console.log(`\nNo more activities available.`);
|
|
306
|
+
hasMoreActivities = false;
|
|
324
307
|
}
|
|
325
308
|
else {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
309
|
+
for (const act of activities) {
|
|
310
|
+
if (act === null || act === void 0 ? void 0 : act.id) {
|
|
311
|
+
const deleteResponse = yield fetcher(deleteActivityMutation, {
|
|
312
|
+
id: act === null || act === void 0 ? void 0 : act.id,
|
|
313
|
+
});
|
|
314
|
+
const isDeleted = (_f = (_e = deleteResponse === null || deleteResponse === void 0 ? void 0 : deleteResponse.data) === null || _e === void 0 ? void 0 : _e.DeleteActivity) === null || _f === void 0 ? void 0 : _f.deleted;
|
|
315
|
+
count++;
|
|
316
|
+
totalCount++;
|
|
317
|
+
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
318
|
+
// Avoiding rate-limit
|
|
319
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
329
322
|
}
|
|
330
323
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
324
|
+
else {
|
|
325
|
+
// In case of an unexpected null response, exit the loop
|
|
326
|
+
console.log(`\nProbably deleted all the activities of this type.`);
|
|
327
|
+
hasMoreActivities = false;
|
|
328
|
+
}
|
|
334
329
|
}
|
|
335
330
|
}
|
|
336
331
|
catch (error) {
|
|
@@ -341,54 +336,51 @@ Statistics (Manga):
|
|
|
341
336
|
static DeleteMyAnimeList() {
|
|
342
337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
343
338
|
var _a, _b, _c, _d;
|
|
344
|
-
if (yield Auth.isLoggedIn()) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
339
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
340
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!(yield Auth.MyUserId())) {
|
|
344
|
+
console.log(`\nFailed getting current user Id.`);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const response = yield fetcher(currentUserAnimeList, { id: yield Auth.MyUserId() });
|
|
348
|
+
if (response !== null) {
|
|
349
|
+
const lists = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.MediaListCollection) === null || _b === void 0 ? void 0 : _b.lists;
|
|
350
|
+
if (lists.length > 0) {
|
|
351
|
+
const { selectedList } = yield inquirer.prompt([
|
|
352
|
+
{
|
|
353
|
+
type: "list",
|
|
354
|
+
name: "selectedList",
|
|
355
|
+
message: "Select an anime list:",
|
|
356
|
+
choices: lists.map((list) => list.name),
|
|
357
|
+
pageSize: 10,
|
|
358
|
+
},
|
|
359
|
+
]);
|
|
360
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
361
|
+
if (selectedEntries) {
|
|
362
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
363
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
364
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
365
|
+
yield Auth.DeleteAnimeById(entry === null || entry === void 0 ? void 0 : entry.id, (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title);
|
|
366
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
373
367
|
}
|
|
374
368
|
else {
|
|
375
|
-
console.log(
|
|
369
|
+
console.log(`No id in entry.`);
|
|
370
|
+
console.log(entry);
|
|
376
371
|
}
|
|
377
372
|
}
|
|
378
|
-
else {
|
|
379
|
-
console.log(`\nNo anime(s) found in any list.`);
|
|
380
|
-
}
|
|
381
373
|
}
|
|
382
374
|
else {
|
|
383
|
-
console.log(
|
|
375
|
+
console.log("No entries found.");
|
|
384
376
|
}
|
|
385
377
|
}
|
|
386
378
|
else {
|
|
387
|
-
console.log(`\
|
|
379
|
+
console.log(`\nNo anime(s) found in any list.`);
|
|
388
380
|
}
|
|
389
381
|
}
|
|
390
382
|
else {
|
|
391
|
-
console.
|
|
383
|
+
console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
392
384
|
}
|
|
393
385
|
});
|
|
394
386
|
}
|
|
@@ -396,19 +388,8 @@ Statistics (Manga):
|
|
|
396
388
|
return __awaiter(this, void 0, void 0, function* () {
|
|
397
389
|
var _a, _b, _c;
|
|
398
390
|
try {
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
headers: {
|
|
402
|
-
"content-type": "application/json",
|
|
403
|
-
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
404
|
-
},
|
|
405
|
-
body: JSON.stringify({
|
|
406
|
-
query: deleteMediaEntryMutation,
|
|
407
|
-
variables: { id },
|
|
408
|
-
}),
|
|
409
|
-
});
|
|
410
|
-
const response = yield request.json();
|
|
411
|
-
if (request.status === 200) {
|
|
391
|
+
const response = yield fetcher(deleteMediaEntryMutation, { id: id });
|
|
392
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
412
393
|
const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
|
|
413
394
|
console.log(`del ${title ? getTitle(title) : ""} ${deleted ? "✅" : "❌"}`);
|
|
414
395
|
}
|
|
@@ -426,84 +407,69 @@ Statistics (Manga):
|
|
|
426
407
|
return __awaiter(this, void 0, void 0, function* () {
|
|
427
408
|
var _a, _b, _c, _d;
|
|
428
409
|
try {
|
|
429
|
-
if (yield Auth.isLoggedIn()) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
console.error("\nNo entries found.");
|
|
461
|
-
}
|
|
410
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
411
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (!(yield Auth.MyUserId())) {
|
|
415
|
+
console.error(`\nFailed getting current user Id.`);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const response = yield fetcher(currentUserMangaList, { id: yield Auth.MyUserId() });
|
|
419
|
+
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
420
|
+
console.error(`\nSomething went wrong. ${(_a = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const lists = (_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.MediaListCollection) === null || _c === void 0 ? void 0 : _c.lists;
|
|
424
|
+
if (lists.length > 0) {
|
|
425
|
+
const { selectedList } = yield inquirer.prompt([
|
|
426
|
+
{
|
|
427
|
+
type: "list",
|
|
428
|
+
name: "selectedList",
|
|
429
|
+
message: "Select a manga list:",
|
|
430
|
+
choices: lists.map((list) => list.name),
|
|
431
|
+
pageSize: 10,
|
|
432
|
+
},
|
|
433
|
+
]);
|
|
434
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
435
|
+
if (selectedEntries) {
|
|
436
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
437
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
438
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
439
|
+
yield Auth.DeleteMangaById(entry === null || entry === void 0 ? void 0 : entry.id, (_d = entry === null || entry === void 0 ? void 0 : entry.media) === null || _d === void 0 ? void 0 : _d.title);
|
|
440
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
462
441
|
}
|
|
463
442
|
else {
|
|
464
|
-
console.
|
|
443
|
+
console.log(`No id in entry.`);
|
|
444
|
+
console.log(entry);
|
|
465
445
|
}
|
|
466
446
|
}
|
|
467
|
-
else {
|
|
468
|
-
console.error(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
469
|
-
}
|
|
470
447
|
}
|
|
471
448
|
else {
|
|
472
|
-
console.error(
|
|
449
|
+
console.error("\nNo entries found.");
|
|
473
450
|
}
|
|
474
451
|
}
|
|
475
452
|
else {
|
|
476
|
-
console.error(`\
|
|
453
|
+
console.error(`\nNo manga(s) found in any list.`);
|
|
477
454
|
}
|
|
478
455
|
}
|
|
479
456
|
catch (error) {
|
|
480
|
-
console.error(`\nError deleting manga
|
|
457
|
+
console.error(`\nError deleting manga. ${error.message}`);
|
|
481
458
|
}
|
|
482
459
|
});
|
|
483
460
|
}
|
|
484
461
|
static DeleteMangaById(id, title) {
|
|
485
462
|
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
-
var _a, _b;
|
|
463
|
+
var _a, _b, _c, _d;
|
|
487
464
|
try {
|
|
488
|
-
const
|
|
489
|
-
method: "POST",
|
|
490
|
-
headers: {
|
|
491
|
-
"Content-Type": "application/json",
|
|
492
|
-
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
493
|
-
},
|
|
494
|
-
body: JSON.stringify({
|
|
495
|
-
query: deleteMangaEntryMutation,
|
|
496
|
-
variables: { id },
|
|
497
|
-
}),
|
|
498
|
-
});
|
|
499
|
-
const { data, errors } = yield request.json();
|
|
465
|
+
const response = yield fetcher(deleteMangaEntryMutation, { id });
|
|
500
466
|
const statusMessage = title ? getTitle(title) : "";
|
|
501
|
-
if (
|
|
502
|
-
const deleted = (_a =
|
|
467
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
468
|
+
const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
|
|
503
469
|
console.log(`del ${statusMessage} ${deleted ? "✅" : "❌"}`);
|
|
504
470
|
}
|
|
505
471
|
else {
|
|
506
|
-
console.error(`Error deleting manga. ${(
|
|
472
|
+
console.error(`Error deleting manga. ${(_d = (_c = response === null || response === void 0 ? void 0 : response.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
507
473
|
}
|
|
508
474
|
}
|
|
509
475
|
catch (error) {
|
|
@@ -513,25 +479,20 @@ Statistics (Manga):
|
|
|
513
479
|
}
|
|
514
480
|
static Write(status) {
|
|
515
481
|
return __awaiter(this, void 0, void 0, function* () {
|
|
516
|
-
var _a;
|
|
517
482
|
try {
|
|
518
483
|
if (!(yield Auth.isLoggedIn())) {
|
|
519
484
|
console.error(`\nPlease login to use this feature.`);
|
|
520
485
|
return;
|
|
521
486
|
}
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
`<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
|
|
526
|
-
};
|
|
527
|
-
const data = yield fetcher(query, variables);
|
|
487
|
+
const { data } = yield fetcher(saveTextActivityMutation, {
|
|
488
|
+
status: status,
|
|
489
|
+
});
|
|
528
490
|
if (!data) {
|
|
529
491
|
console.error(`\nSomething went wrong. ${data}.`);
|
|
530
492
|
return;
|
|
531
493
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
console.log(`\n[${savedActivity.id}] status saved successfully!`);
|
|
494
|
+
if (data.SaveTextActivity.id) {
|
|
495
|
+
console.log(`\n[${data.SaveTextActivity.id}] status saved successfully!`);
|
|
535
496
|
}
|
|
536
497
|
}
|
|
537
498
|
catch (error) {
|
|
@@ -550,6 +511,7 @@ Statistics (Manga):
|
|
|
550
511
|
choices: [
|
|
551
512
|
{ name: "Exported JSON file.", value: 1 },
|
|
552
513
|
{ name: "MyAnimeList (XML)", value: 2 },
|
|
514
|
+
{ name: "AniDB (json-large)", value: 3 },
|
|
553
515
|
],
|
|
554
516
|
pageSize: 10,
|
|
555
517
|
},
|
|
@@ -561,6 +523,9 @@ Statistics (Manga):
|
|
|
561
523
|
case 2:
|
|
562
524
|
yield MyAnimeList.importAnime();
|
|
563
525
|
break;
|
|
526
|
+
case 3:
|
|
527
|
+
yield AniDB.importAnime();
|
|
528
|
+
break;
|
|
564
529
|
default:
|
|
565
530
|
console.log(`\nInvalid Choice.`);
|
|
566
531
|
break;
|
|
@@ -625,14 +590,14 @@ Statistics (Manga):
|
|
|
625
590
|
const like = yield fetcher(likeActivityMutation, {
|
|
626
591
|
activityId: activ.id,
|
|
627
592
|
});
|
|
628
|
-
console.info(
|
|
593
|
+
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
629
594
|
}
|
|
630
595
|
catch (error) {
|
|
631
|
-
console.error(`Activity possibly deleted
|
|
596
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
632
597
|
}
|
|
633
598
|
}
|
|
634
599
|
else {
|
|
635
|
-
console.log(
|
|
600
|
+
console.log(`${activityBy(activ)} 🔵`);
|
|
636
601
|
}
|
|
637
602
|
// avoiding rate-limit
|
|
638
603
|
yield new Promise((resolve) => {
|
|
@@ -685,18 +650,18 @@ Statistics (Manga):
|
|
|
685
650
|
activityId: activ.id,
|
|
686
651
|
});
|
|
687
652
|
// const ToggleLike = like?.data?.ToggleLike
|
|
688
|
-
console.info(
|
|
653
|
+
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
689
654
|
}
|
|
690
655
|
catch (error) {
|
|
691
|
-
console.error(`Activity possibly deleted
|
|
656
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
692
657
|
}
|
|
693
658
|
}
|
|
694
659
|
else {
|
|
695
|
-
console.log(
|
|
660
|
+
console.log(`${activityBy(activ)} 🔵`);
|
|
696
661
|
}
|
|
697
662
|
// avoiding rate-limit
|
|
698
663
|
yield new Promise((resolve) => {
|
|
699
|
-
setTimeout(resolve,
|
|
664
|
+
setTimeout(resolve, 1500);
|
|
700
665
|
});
|
|
701
666
|
}
|
|
702
667
|
page++;
|
|
@@ -716,7 +681,7 @@ Statistics (Manga):
|
|
|
716
681
|
}
|
|
717
682
|
static LikeSpecificUser() {
|
|
718
683
|
return __awaiter(this, void 0, void 0, function* () {
|
|
719
|
-
var _a, _b, _c, _d
|
|
684
|
+
var _a, _b, _c, _d;
|
|
720
685
|
try {
|
|
721
686
|
const { username } = yield inquirer.prompt([
|
|
722
687
|
{
|
|
@@ -749,18 +714,18 @@ Statistics (Manga):
|
|
|
749
714
|
const like = yield fetcher(likeActivityMutation, {
|
|
750
715
|
activityId: activ.id,
|
|
751
716
|
});
|
|
752
|
-
console.info(
|
|
717
|
+
console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
753
718
|
}
|
|
754
719
|
catch (error) {
|
|
755
|
-
console.error(`Activity possibly deleted
|
|
720
|
+
console.error(`Activity possibly deleted. ${error.message}`);
|
|
756
721
|
}
|
|
757
722
|
}
|
|
758
723
|
else {
|
|
759
|
-
console.log(
|
|
724
|
+
console.log(`${activityBy(activ)} 🔵`);
|
|
760
725
|
}
|
|
761
726
|
// Avoiding rate limit
|
|
762
727
|
yield new Promise((resolve) => {
|
|
763
|
-
setTimeout(resolve,
|
|
728
|
+
setTimeout(resolve, 1500);
|
|
764
729
|
});
|
|
765
730
|
}
|
|
766
731
|
// Go to the next page
|
|
@@ -774,6 +739,86 @@ Statistics (Manga):
|
|
|
774
739
|
}
|
|
775
740
|
});
|
|
776
741
|
}
|
|
742
|
+
static LikeFollowingActivityV2(perPage) {
|
|
743
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
744
|
+
var _a, _b, _c, _d, _e;
|
|
745
|
+
try {
|
|
746
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
747
|
+
console.error(`\nPlease log in to use this feature.`);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const allFollowingUsers = [];
|
|
751
|
+
let hasNextPage = true;
|
|
752
|
+
let page = 1;
|
|
753
|
+
let liked = 0;
|
|
754
|
+
// Fetch all following users
|
|
755
|
+
spinner.start(`Gathering following information...`);
|
|
756
|
+
while (hasNextPage) {
|
|
757
|
+
spinner.update(`Fetched page ${page}...`);
|
|
758
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
759
|
+
userId: yield Auth.MyUserId(),
|
|
760
|
+
page,
|
|
761
|
+
});
|
|
762
|
+
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)) {
|
|
763
|
+
console.error(`\nFailed to fetch following users.`);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
allFollowingUsers.push(...followingUsers.data.Page.following);
|
|
767
|
+
hasNextPage = followingUsers.data.Page.pageInfo.hasNextPage;
|
|
768
|
+
page++;
|
|
769
|
+
}
|
|
770
|
+
spinner.stop(`Got ${allFollowingUsers.length} following user.`);
|
|
771
|
+
// Extract the IDs of all following users
|
|
772
|
+
const followingUserIds = allFollowingUsers.map((user) => user.id);
|
|
773
|
+
console.log(`\nTotal Following: ${followingUserIds.length}\nApproximately ${followingUserIds.length * perPage} activities to like.\nWill take around ${((followingUserIds.length * perPage * 1200) /
|
|
774
|
+
1000 /
|
|
775
|
+
60).toFixed(2)} minutes.`);
|
|
776
|
+
// Traverse the array and fetch users' activities one by one
|
|
777
|
+
let userNumber = 0;
|
|
778
|
+
for (const userId of followingUserIds) {
|
|
779
|
+
userNumber++;
|
|
780
|
+
console.log(`\n[${userNumber}]\tID: ${userId}`);
|
|
781
|
+
// Fetch `perPage` activities for the current user
|
|
782
|
+
const activities = yield fetcher(specificUserActivitiesQuery, {
|
|
783
|
+
userId,
|
|
784
|
+
page: 1, // Always fetch from the first page
|
|
785
|
+
perPage,
|
|
786
|
+
});
|
|
787
|
+
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)) {
|
|
788
|
+
console.log(`[${userNumber}] No activities found for User ID: ${userId}`);
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
const activiti = activities.data.Page.activities;
|
|
792
|
+
for (let i = 0; i < activiti.length; i++) {
|
|
793
|
+
const activ = activiti[i];
|
|
794
|
+
if (!activ.isLiked && activ.id) {
|
|
795
|
+
try {
|
|
796
|
+
const like = yield fetcher(likeActivityMutation, {
|
|
797
|
+
activityId: activ.id,
|
|
798
|
+
});
|
|
799
|
+
console.info(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
|
|
800
|
+
if (like === null || like === void 0 ? void 0 : like.data) {
|
|
801
|
+
liked++;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
console.error(`[${userNumber}/${i + 1}/${activiti.length}] Activity possibly deleted. ${error.message}`);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
console.log(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} 🔵`);
|
|
810
|
+
}
|
|
811
|
+
// Avoid rate-limiting
|
|
812
|
+
yield new Promise((resolve) => setTimeout(resolve, 1200));
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
console.log(`\n✅ All ${liked} activities liked successfully.`);
|
|
816
|
+
}
|
|
817
|
+
catch (error) {
|
|
818
|
+
console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
}
|
|
777
822
|
static AutoLike() {
|
|
778
823
|
return __awaiter(this, void 0, void 0, function* () {
|
|
779
824
|
try {
|
|
@@ -814,4 +859,115 @@ Statistics (Manga):
|
|
|
814
859
|
});
|
|
815
860
|
}
|
|
816
861
|
}
|
|
817
|
-
|
|
862
|
+
class Social {
|
|
863
|
+
/**
|
|
864
|
+
* Follow the users that follows you
|
|
865
|
+
*/
|
|
866
|
+
static follow() {
|
|
867
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
868
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
869
|
+
try {
|
|
870
|
+
let pager = 1;
|
|
871
|
+
let hasNextPage = true;
|
|
872
|
+
let allFollowerUsers = [];
|
|
873
|
+
spinner.start("Fetching all the followers...");
|
|
874
|
+
while (hasNextPage) {
|
|
875
|
+
const followerUsers = yield fetcher(userFollowersQuery, {
|
|
876
|
+
userId: yield Auth.MyUserId(),
|
|
877
|
+
page: pager,
|
|
878
|
+
});
|
|
879
|
+
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}...`);
|
|
880
|
+
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)) {
|
|
881
|
+
hasNextPage = false;
|
|
882
|
+
}
|
|
883
|
+
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) || []));
|
|
884
|
+
pager++;
|
|
885
|
+
}
|
|
886
|
+
spinner.stop("Fetched all the followers. Starting follow back.");
|
|
887
|
+
// Filter users that do no follow me
|
|
888
|
+
const notFollowing = allFollowerUsers
|
|
889
|
+
.filter(({ isFollowing }) => !isFollowing)
|
|
890
|
+
.map(({ id, name }) => ({ id: id, name: name }));
|
|
891
|
+
console.log(`\nTotal follower ${allFollowerUsers.length}.\nNot followed back ${notFollowing.length}\n`);
|
|
892
|
+
if (notFollowing.length <= 0) {
|
|
893
|
+
console.log(`Probably followed back all the users.`);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
// Traverse and follow back
|
|
897
|
+
const maxIdLength = Math.max(...notFollowing.map(({ id }) => String(id).length));
|
|
898
|
+
const maxNameLength = Math.max(...notFollowing.map(({ name }) => name.length));
|
|
899
|
+
for (let nf of notFollowing) {
|
|
900
|
+
try {
|
|
901
|
+
const follow = yield fetcher(toggleFollowMutation, { userId: nf.id });
|
|
902
|
+
console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
|
|
903
|
+
`\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)}` +
|
|
904
|
+
`\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) ? "✅" : "🈵"}`);
|
|
905
|
+
}
|
|
906
|
+
catch (error) {
|
|
907
|
+
console.log(`automate_follow_toggle_follow: ${error.message}`);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
console.log(`\n✅ Followed back ${notFollowing.length} users.`);
|
|
911
|
+
}
|
|
912
|
+
catch (error) {
|
|
913
|
+
console.log(`\nautomate_follow ${error.message}`);
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Unfollow the users thats not following you
|
|
919
|
+
*/
|
|
920
|
+
static unfollow() {
|
|
921
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
922
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
923
|
+
try {
|
|
924
|
+
let pager = 1;
|
|
925
|
+
let hasNextPage = true;
|
|
926
|
+
let allFollowingUsers = [];
|
|
927
|
+
spinner.start("Fetching all following users...");
|
|
928
|
+
while (hasNextPage) {
|
|
929
|
+
const followingUsers = yield fetcher(userFollowingQuery, {
|
|
930
|
+
userId: yield Auth.MyUserId(),
|
|
931
|
+
page: pager,
|
|
932
|
+
});
|
|
933
|
+
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} ...`);
|
|
934
|
+
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)) {
|
|
935
|
+
hasNextPage = false;
|
|
936
|
+
}
|
|
937
|
+
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) || []));
|
|
938
|
+
pager++;
|
|
939
|
+
}
|
|
940
|
+
spinner.update(`Fetching complete. Total got ${allFollowingUsers.length} users.`);
|
|
941
|
+
// Filter users that do no follow me
|
|
942
|
+
const notFollowingMe = allFollowingUsers
|
|
943
|
+
.filter((user) => !user.isFollower)
|
|
944
|
+
.map((u3r) => ({ id: u3r.id, name: u3r.name }));
|
|
945
|
+
if (notFollowingMe.length <= 0) {
|
|
946
|
+
console.warn(`\nNot following list is empty!`);
|
|
947
|
+
spinner.stop(`No users to unfollow. Aborting process...`);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
|
|
951
|
+
let nfmCount = 0;
|
|
952
|
+
console.log(`\n`);
|
|
953
|
+
for (let nfm of notFollowingMe) {
|
|
954
|
+
nfmCount++;
|
|
955
|
+
try {
|
|
956
|
+
const unfollow = yield fetcher(toggleFollowMutation, {
|
|
957
|
+
userId: nfm.id,
|
|
958
|
+
});
|
|
959
|
+
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) ? "✅" : "🈵"}`);
|
|
960
|
+
}
|
|
961
|
+
catch (error) {
|
|
962
|
+
console.log(`unfollow_toggle_follow. ${error.message}`);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
console.log(`\nTotal Unfollowed: ${nfmCount}`);
|
|
966
|
+
}
|
|
967
|
+
catch (error) {
|
|
968
|
+
console.error(`\nautomate_unfollow: ${error.message}`);
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
export { Auth, Social };
|