From ad971bbf03660fd5e57cd8db971bbce010224d1e Mon Sep 17 00:00:00 2001 From: KillerBossOriginal Date: Thu, 7 Dec 2023 17:15:38 +0100 Subject: [PATCH] 0.2.0 --- README.md | 5 ++++- package.json | 2 +- src/CreditsManager.ts | 18 +++++++++++++++--- src/IAManager.ts | 17 +++++++++++++++++ src/index.ts | 3 +++ 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/IAManager.ts diff --git a/README.md b/README.md index 3039f56..71299dc 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# template-npm-packages +# Thunder Network APIs +This package is for using Thunder Network's APIs like Internet Avatar or Credits system. + +WARNING: This may package is not stable, it can change at any time, like the API. diff --git a/package.json b/package.json index 13a3fff..d4ececa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tn-api.js", - "version": "0.1.1", + "version": "0.2.0", "description": "A Public Template for npm", "main": "build/index.js", "repository": "https://source.thundernetwork.org/ThunderNetworkRaD/tn-api.js", diff --git a/src/CreditsManager.ts b/src/CreditsManager.ts index cad4510..d6f2a75 100644 --- a/src/CreditsManager.ts +++ b/src/CreditsManager.ts @@ -10,14 +10,26 @@ export default class CreditsManager { } /** - * Retrieves the balance of a user with the given ID. + * Retrieves the balance for a given user ID. * - * @param {number} id - The ID of the user. + * @param {string|number} id - The ID of the user. * @return {Promise} The balance of the user. */ async balance(id: string|number) { let req = await axios.get(`${this.URL}/credits/${id}`); - if (req.status == 404) throw new Error("User not found"); + if (req.status == 404) throw new Error("User not Found"); + return req.data.credits; + } + + /** + * Sets the ID for the function. + * + * @param {number} id - The ID to set. + * @return {Promise} - The credits of the user. + */ + async set(id: number) { + let req = await axios.post(`${this.URL}/credits/${id}`); + if (req.status == 404) throw new Error("User not Found"); return req.data.credits; } } \ No newline at end of file diff --git a/src/IAManager.ts b/src/IAManager.ts new file mode 100644 index 0000000..6808e79 --- /dev/null +++ b/src/IAManager.ts @@ -0,0 +1,17 @@ +import axios from "axios"; + +export default class IAManager { + token: string | undefined; + URL = "https://api.thundernetwork.org"; + + constructor(customURL: string, token: string | undefined) { + this.URL = customURL || this.URL; + this.token = token; + } + + async get(id: number) { + let req = await axios.get(`${this.URL}/IA/${id}`); + if (req.status == 404) throw new Error("User not Found"); + return req.data.credits; + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 96fe2bc..3b67076 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,13 @@ import { io } from "socket.io-client"; import CreditsManager from "./CreditsManager.js"; import EventEmitter from 'node:events'; +import IAManager from "./IAManager.js"; export default class TNC extends EventEmitter { token: string | undefined; URL = "https://api.thundernetwork.org"; credits: CreditsManager; + IA: IAManager; id: string | undefined; /** @@ -22,6 +24,7 @@ export default class TNC extends EventEmitter { this.token = options.token; } this.credits = new CreditsManager(this.URL, this.token); + this.IA = new IAManager(this.URL, this.token); } /**