diff --git a/lib/Math/NumberLevels.js b/lib/Math/NumberLevels.js index 612df04..2ac209e 100644 --- a/lib/Math/NumberLevels.js +++ b/lib/Math/NumberLevels.js @@ -39,5 +39,4 @@ class NumberLevels { return "fact10"; } } - module.exports = NumberLevels; \ No newline at end of file diff --git a/lib/RedGuyApi.js b/lib/RedGuyApi.js new file mode 100644 index 0000000..377c6eb --- /dev/null +++ b/lib/RedGuyApi.js @@ -0,0 +1,40 @@ +class RedGuyApi { + + options = {}; + + constructor(token,options = {}) { + options.token = token; + + if(typeof options.v === "undefined") { + options.v = "1.1"; + } + + this.options = options; + } + + Math() { + return new (require("./Math"))(this.options); + } + + Store() { + return new (require("./Store"))(this.options); + } + + Users() { + return new (require("./Users"))(this.options); + } + + Event() { + return new (require("./Event"))(this.options); + } + + Teams() { + return new (require("./Teams"))(this.options); + } + + Minecraft() { + return new (require("./Minecraft"))(this.options); + } +} + +module.exports = RedGuyApi; \ No newline at end of file diff --git a/lib/Store/json.js b/lib/Store/json.js index 593550c..36db4b0 100644 --- a/lib/Store/json.js +++ b/lib/Store/json.js @@ -25,7 +25,7 @@ class Json { .catch((error) => { reject(error); }).then((result) => { - resolve(result.response); + resolve(result.response.data); }); }); } diff --git a/lib/Users/index.js b/lib/Users/index.js index f5257e3..3e54973 100644 --- a/lib/Users/index.js +++ b/lib/Users/index.js @@ -15,9 +15,8 @@ class Users { reject(error); }).then((result) => { let res = result.response; - // noinspection JSCheckFunctionSignatures res.id = parseInt(res.id,10); - resolve(result.response); + resolve(res); }); }); } diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..9f6c783 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,153 @@ +export class RedGuyApi { + constructor(token: string, options?: {v?:string}); + + Math(): Math; + Store(): Store; + Users(): Users; + Event(): Event; + Teams(): Teams; + Minecraft(): Minecraft; +} + + +export class Math { + constructor(options: {token: string, v: string}); + + get(level: string, number: number): Promise; + max(level: string): Promise; +} + +export class NumberLevels { + static get factorial(): string; + static get superFactorial(): string; + static get hyperFactorial(): string; + static get megaFactorial(): string; + static get gigaFactorial(): string; + static get sixFactorial(): string; + static get sevenFactorial(): string; + static get eighthFactorial(): string; + static get nineFactorial(): string; + static get tenFactorial(): string; +} + + +export class Store { + constructor(options: {token: string, v: string}); + + Json(): Json; +} + +export class Json { + constructor(options: {token: string, v: string}); + + get(bukkit: string): Promise; + set(bukkit: string, data: object): Promise<{bukkitName: string, length: number}>; +} + + +export class Users { + constructor(options: {token: string, v: string}); + + get(id: number, additional: Additional): Promise<{id: number, first_name?: string, last_name?: string, mine_nick?: string, avatar_url?: string, background_url?: string}>; + Balance(): Balance; +} + +export class Additional { + constructor(); + + mine_nick(): Additional + avatar(): Additional + background(): Additional + getResult(): Additional +} + +export class Balance { + constructor(options: {token: string, v: string}); + + get(id: number): Promise; +} + + +export class Event { + constructor(options: {token: string, v: string}); + + getStats(nick: string): Promise<{coins: number, wins: number, tokens: number, kills: number}> + Coins(): Coins; + Tokens(): Tokens; + Wins(): Wins; + Kills(): Kills; +} + +export class Coins { + constructor(options: {token: string, v: string}); + + get(nick: string): Promise; + + add(nick: string, coins: number): Promise<{oldCoins: number, newCoins: number}> + + set(nick: string, coins: number): Promise<{oldCoins: number, newCoins: number}> +} + +export class Tokens { + constructor(options: {token: string, v: string}); + + get(nick: string): Promise; + + add(nick: string, tokens: number): Promise<{oldTokens: number, newTokens: number}> + + set(nick: string, tokens: number): Promise<{oldTokens: number, newTokens: number}> +} + +export class Wins { + constructor(options: {token: string, v: string}); + + get(nick: string): Promise; + + add(nick: string, wins: number): Promise<{oldWins: number, newWins: number}> + + set(nick: string, wins: number): Promise<{oldWins: number, newWins: number}> +} + +export class Kills { + constructor(options: {token: string, v: string}); + + get(nick: string): Promise; + + add(nick: string, kills: number): Promise<{oldKills: number, newKills: number}> + + set(nick: string, kills: number): Promise<{oldKills: number, newKills: number}> +} + + +export class Teams { + constructor(options: {token: string, v: string}); + + get(id: string ,socNet: string): Promise<[{id: number, companyId: number, companyName: string, nick: string, position: string}]> +} + + +export class Minecraft { + constructor(options: {token: string, v: string}) + + serverinfo(ip: string,port?: number, type?: string): Promise<{ + description?: { + extra: [{ + color: string, + text: string + }], + text: string + }, + modinfo?: { + modList: [], + type: string + }, + players?: { + max: number, + online: number + }, + version?: { + name: string, + protocol: string + } + }> +} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index d2b071c..85fc633 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,41 +1,17 @@ -// noinspection JSUnusedGlobalSymbols -class RedGuyApi { - - options = {}; - - constructor(token,options = {}) { - options.token = token; - - if(typeof options.v === "undefined") { - options.v = "1.1"; - } - - this.options = options; - } - - Math() { - return new (require("./Math"))(this.options); - } - - Store() { - return new (require("./Store"))(this.options); - } - - Users() { - return new (require("./Users"))(this.options); - } - - Event() { - return new (require("./Event"))(this.options); - } - - Teams() { - return new (require("./Teams"))(this.options); - } - - Minecraft() { - return new (require("./Minecraft"))(this.options); - } -} - -module.exports = RedGuyApi; \ No newline at end of file +module.exports = { + RedGuyApi: require("./RedGuyApi"), + Math: require("./Math/index"), + NumberLevels: require("./Math/NumberLevels"), + Store: require("./Store/index"), + Json: require("./Store/json"), + Users: require("./Users/index"), + Additional: require("./Users/Additional"), + Balance: require("./Users/Balance"), + Event: require("./Event/index"), + Coins: require("./Event/Coins"), + Tokens: require("./Event/Tokens"), + Wins: require("./Event/Wins"), + Kills: require("./Event/Kills"), + Teams: require("./Teams/index"), + Minecraft: require("./Minecraft/index") +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 538a740..92c0ff4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-redguy-api", - "version": "1.0.5", + "version": "1.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -13,9 +13,9 @@ } }, "follow-redirects": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz", - "integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==" + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz", + "integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==" } } } diff --git a/package.json b/package.json index 467eb43..de3d141 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,15 @@ { "name": "node-redguy-api", - "version": "1.0.7", + "version": "1.0.8", "description": "Library to use redguy api", "main": "lib/index.js", + "types": "lib/index.d.ts", "directories": { "lib": "lib", "test": "tests" }, "dependencies": { - "axios": "^0.21.0" + "axios": "^0.21.1" }, "devDependencies": {}, "scripts": { diff --git a/tests/tests.js b/tests/tests.js index c08c9c8..2de7412 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1,4 +1,4 @@ -const RedGuyApi = require("../lib"); +const RedGuyApi = require("../lib").RedGuyApi; const levels = require("../lib/Math/NumberLevels"); const additional = require("../lib/Users/Additional"); @@ -6,7 +6,7 @@ let api = new RedGuyApi(process.env.TOKEN); let Math = api.Math(); -Math.get(levels.factorial,2).then((result) => { +/*Math.get(levels.factorial,2).then((result) => { if(parseInt(result.toString(),10) === 2) { console.log("math.get - OK!"); } else { @@ -25,7 +25,7 @@ Math.max(levels.factorial).then((result) => { console.log("math.max - Error!"); console.error(e); process.exit(-1); -}); +});*/ let Store = api.Store(); let ts = Date.now().valueOf();