From b44ba078980c0c62b98774378104a7279cc0bb2e Mon Sep 17 00:00:00 2001 From: MrScopes Date: Sun, 17 Jan 2021 22:07:42 -0500 Subject: [PATCH] v1.2.0 --- README.md | 5 +- package.json | 5 +- src/queries/queries.ts | 237 +++++++++++++++++++++++++++ src/structures/user/UserStructure.ts | 8 +- src/test.ts | 5 +- src/types/types.ts | 6 +- tsconfig.json | 1 + yarn.lock | 5 + 8 files changed, 263 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2c3265c..b73c07b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Create an issue on the repo or contact me on Discord @MrScopes#5548 ## Example ```js -const { Client } = require('anilist-js'); +const { Client } = require('anilist.js'); const AniList = new Client('API TOKEN'); // token is only required for some features (async () => { @@ -40,7 +40,7 @@ _Italics_ represents authorization required.

- _`.me()`_ -> Currently authorized user - `.getUser(id)` - - `.searchUsers(variables)` + - `.searchUsers(variables)`

- `.getStaff(id)` - `.searchStaff(variables)` @@ -68,6 +68,7 @@ _Italics_ represents authorization required. - `User >` - .info - _.follow()_ + - .getStats()

- `Staff >` - .info diff --git a/package.json b/package.json index e8dbadd..a7e3b76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anilist.js", - "version": "1.1.0", + "version": "1.2.0", "description": "Communicate with the AniList API.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,8 @@ "author": "MrScopes", "license": "ISC", "dependencies": { - "node-fetch": "^2.6.1" + "node-fetch": "^2.6.1", + "tslib": "^2.1.0" }, "devDependencies": { "@types/node-fetch": "^2.5.7", diff --git a/src/queries/queries.ts b/src/queries/queries.ts index a0fdd84..8c07f82 100644 --- a/src/queries/queries.ts +++ b/src/queries/queries.ts @@ -914,6 +914,243 @@ query ($id: Int) { } ` +export const UserStatsQuery = ` +query ($id: Int) { + User(id: $id) { + statistics { + anime { + count + meanScore + standardDeviation + minutesWatched + episodesWatched + chaptersRead + volumesRead + formats { + count + meanScore + minutesWatched + chaptersRead + mediaIds + format + } + statuses { + count + meanScore + minutesWatched + chaptersRead + mediaIds + status + } + scores { + count + meanScore + minutesWatched + chaptersRead + mediaIds + score + } + lengths { + count + meanScore + minutesWatched + chaptersRead + mediaIds + length + } + releaseYears { + count + meanScore + minutesWatched + chaptersRead + mediaIds + releaseYear + } + startYears { + count + meanScore + minutesWatched + chaptersRead + mediaIds + startYear + } + genres { + count + meanScore + minutesWatched + chaptersRead + mediaIds + genre + } + tags { + count + meanScore + minutesWatched + chaptersRead + mediaIds + tag { + id + } + } + countries { + count + meanScore + minutesWatched + chaptersRead + mediaIds + country + } + voiceActors { + count + meanScore + minutesWatched + chaptersRead + mediaIds + voiceActor { + id + } + characterIds + } + staff { + count + meanScore + minutesWatched + chaptersRead + mediaIds + staff { + id + } + } + studios { + count + meanScore + minutesWatched + chaptersRead + mediaIds + studio { + id + } + } + } + manga { + count + meanScore + standardDeviation + minutesWatched + episodesWatched + chaptersRead + volumesRead + formats { + count + meanScore + minutesWatched + chaptersRead + mediaIds + format + } + statuses { + count + meanScore + minutesWatched + chaptersRead + mediaIds + status + } + scores { + count + meanScore + minutesWatched + chaptersRead + mediaIds + score + } + lengths { + count + meanScore + minutesWatched + chaptersRead + mediaIds + length + } + releaseYears { + count + meanScore + minutesWatched + chaptersRead + mediaIds + releaseYear + } + startYears { + count + meanScore + minutesWatched + chaptersRead + mediaIds + startYear + } + genres { + count + meanScore + minutesWatched + chaptersRead + mediaIds + genre + } + tags { + count + meanScore + minutesWatched + chaptersRead + mediaIds + tag { + id + } + } + countries { + count + meanScore + minutesWatched + chaptersRead + mediaIds + country + } + voiceActors { + count + meanScore + minutesWatched + chaptersRead + mediaIds + voiceActor { + id + } + characterIds + } + staff { + count + meanScore + minutesWatched + chaptersRead + mediaIds + staff { + id + } + } + studios { + count + meanScore + minutesWatched + chaptersRead + mediaIds + studio { + id + } + } + } + } + } +} +` + export const UserSearchQuery = ` query ($id: Int, $name: String, $search: String, $sort: [UserSort], $page: Int, $perPage: Int) { Page(page: $page, perPage: $perPage) { diff --git a/src/structures/user/UserStructure.ts b/src/structures/user/UserStructure.ts index d584371..62be90d 100644 --- a/src/structures/user/UserStructure.ts +++ b/src/structures/user/UserStructure.ts @@ -1,6 +1,7 @@ import { Client } from '../..'; import { UserFollow } from '../../queries/mutations'; -import { User } from '../../types/types'; +import { UserStatsQuery } from '../../queries/queries'; +import { User, UserStatisticTypes } from '../../types/types'; /** Represents an AniList User. */ export class UserStructure { @@ -21,4 +22,9 @@ export class UserStructure { if (!this.client?.token) throw new Error('This feature requires you to be logged in.'); return this.client.utilities.APIRequest(UserFollow, { userId: this.info.id }, this.client); } + + /** Get this user's AniList stats. */ + async getStats(): Promise { + return this.client?.utilities.APIRequest(UserStatsQuery, { id: this.info.id }, this.client) + } } \ No newline at end of file diff --git a/src/test.ts b/src/test.ts index b7cadf3..8e73e41 100644 --- a/src/test.ts +++ b/src/test.ts @@ -4,6 +4,7 @@ import { Client } from './index'; const AniList = new Client(process.env.token); (async function () { - const media = await AniList.searchMedia({ genre_in: ['ACTION'] }); - console.log(media); + const user = await AniList.me(); + const stats = await user.getStats(); + console.log(stats); })(); \ No newline at end of file diff --git a/src/types/types.ts b/src/types/types.ts index 4830d0c..370ae4e 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -795,8 +795,10 @@ export type User = { mediaListOptions?: Maybe; /** The users favourites */ favourites?: Maybe; - /** The users anime & manga list statistics */ - statistics?: Maybe; + /** The users anime & manga list statistics + * + * **NOTE: USE .getStats() for this!** */ + statistics?: null; //Maybe; /** The number of unread notifications the user has */ unreadNotificationCount?: Maybe; /** The url for the user page on the AniList website */ diff --git a/tsconfig.json b/tsconfig.json index 096b70a..35f9642 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,5 +14,6 @@ "strict": true, "esModuleInterop": true, "emitDecoratorMetadata": true, + "importHelpers": true } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 51d5078..2082702 100644 --- a/yarn.lock +++ b/yarn.lock @@ -62,3 +62,8 @@ node-fetch@^2.6.1: version "2.6.1" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== + +tslib@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" + integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==