Skip to content

Commit

Permalink
Add typings and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedGuys committed Jun 20, 2021
1 parent ee8004b commit bc083f2
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 54 deletions.
1 change: 0 additions & 1 deletion lib/Math/NumberLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ class NumberLevels {
return "fact10";
}
}

module.exports = NumberLevels;
40 changes: 40 additions & 0 deletions lib/RedGuyApi.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion lib/Store/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Json {
.catch((error) => {
reject(error);
}).then((result) => {
resolve(result.response);
resolve(result.response.data);
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
Expand Down
153 changes: 153 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<BigInteger>;
max(level: string): Promise<number>;
}

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


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

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

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

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

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
}
}>
}
58 changes: 17 additions & 41 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
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")
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const RedGuyApi = require("../lib");
const RedGuyApi = require("../lib").RedGuyApi;
const levels = require("../lib/Math/NumberLevels");
const additional = require("../lib/Users/Additional");

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 {
Expand All @@ -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();
Expand Down

0 comments on commit bc083f2

Please sign in to comment.