This commit is contained in:
KillerBossOriginal 2023-12-07 17:15:38 +01:00
parent 9ec6768b56
commit ad971bbf03
5 changed files with 40 additions and 5 deletions

View file

@ -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.

View file

@ -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",

View file

@ -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<number>} 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<number>} - 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;
}
}

17
src/IAManager.ts Normal file
View file

@ -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;
}
}

View file

@ -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);
}
/**