Skip to content

Commit bc083f2

Browse files
committed
Add typings and fixes
1 parent ee8004b commit bc083f2

File tree

9 files changed

+222
-54
lines changed

9 files changed

+222
-54
lines changed

lib/Math/NumberLevels.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@ class NumberLevels {
3939
return "fact10";
4040
}
4141
}
42-
4342
module.exports = NumberLevels;

lib/RedGuyApi.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class RedGuyApi {
2+
3+
options = {};
4+
5+
constructor(token,options = {}) {
6+
options.token = token;
7+
8+
if(typeof options.v === "undefined") {
9+
options.v = "1.1";
10+
}
11+
12+
this.options = options;
13+
}
14+
15+
Math() {
16+
return new (require("./Math"))(this.options);
17+
}
18+
19+
Store() {
20+
return new (require("./Store"))(this.options);
21+
}
22+
23+
Users() {
24+
return new (require("./Users"))(this.options);
25+
}
26+
27+
Event() {
28+
return new (require("./Event"))(this.options);
29+
}
30+
31+
Teams() {
32+
return new (require("./Teams"))(this.options);
33+
}
34+
35+
Minecraft() {
36+
return new (require("./Minecraft"))(this.options);
37+
}
38+
}
39+
40+
module.exports = RedGuyApi;

lib/Store/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Json {
2525
.catch((error) => {
2626
reject(error);
2727
}).then((result) => {
28-
resolve(result.response);
28+
resolve(result.response.data);
2929
});
3030
});
3131
}

lib/Users/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ class Users {
1515
reject(error);
1616
}).then((result) => {
1717
let res = result.response;
18-
// noinspection JSCheckFunctionSignatures
1918
res.id = parseInt(res.id,10);
20-
resolve(result.response);
19+
resolve(res);
2120
});
2221
});
2322
}

lib/index.d.ts

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
export class RedGuyApi {
2+
constructor(token: string, options?: {v?:string});
3+
4+
Math(): Math;
5+
Store(): Store;
6+
Users(): Users;
7+
Event(): Event;
8+
Teams(): Teams;
9+
Minecraft(): Minecraft;
10+
}
11+
12+
13+
export class Math {
14+
constructor(options: {token: string, v: string});
15+
16+
get(level: string, number: number): Promise<BigInteger>;
17+
max(level: string): Promise<number>;
18+
}
19+
20+
export class NumberLevels {
21+
static get factorial(): string;
22+
static get superFactorial(): string;
23+
static get hyperFactorial(): string;
24+
static get megaFactorial(): string;
25+
static get gigaFactorial(): string;
26+
static get sixFactorial(): string;
27+
static get sevenFactorial(): string;
28+
static get eighthFactorial(): string;
29+
static get nineFactorial(): string;
30+
static get tenFactorial(): string;
31+
}
32+
33+
34+
export class Store {
35+
constructor(options: {token: string, v: string});
36+
37+
Json(): Json;
38+
}
39+
40+
export class Json {
41+
constructor(options: {token: string, v: string});
42+
43+
get(bukkit: string): Promise<object>;
44+
set(bukkit: string, data: object): Promise<{bukkitName: string, length: number}>;
45+
}
46+
47+
48+
export class Users {
49+
constructor(options: {token: string, v: string});
50+
51+
get(id: number, additional: Additional): Promise<{id: number, first_name?: string, last_name?: string, mine_nick?: string, avatar_url?: string, background_url?: string}>;
52+
Balance(): Balance;
53+
}
54+
55+
export class Additional {
56+
constructor();
57+
58+
mine_nick(): Additional
59+
avatar(): Additional
60+
background(): Additional
61+
getResult(): Additional
62+
}
63+
64+
export class Balance {
65+
constructor(options: {token: string, v: string});
66+
67+
get(id: number): Promise<number>;
68+
}
69+
70+
71+
export class Event {
72+
constructor(options: {token: string, v: string});
73+
74+
getStats(nick: string): Promise<{coins: number, wins: number, tokens: number, kills: number}>
75+
Coins(): Coins;
76+
Tokens(): Tokens;
77+
Wins(): Wins;
78+
Kills(): Kills;
79+
}
80+
81+
export class Coins {
82+
constructor(options: {token: string, v: string});
83+
84+
get(nick: string): Promise<number>;
85+
86+
add(nick: string, coins: number): Promise<{oldCoins: number, newCoins: number}>
87+
88+
set(nick: string, coins: number): Promise<{oldCoins: number, newCoins: number}>
89+
}
90+
91+
export class Tokens {
92+
constructor(options: {token: string, v: string});
93+
94+
get(nick: string): Promise<number>;
95+
96+
add(nick: string, tokens: number): Promise<{oldTokens: number, newTokens: number}>
97+
98+
set(nick: string, tokens: number): Promise<{oldTokens: number, newTokens: number}>
99+
}
100+
101+
export class Wins {
102+
constructor(options: {token: string, v: string});
103+
104+
get(nick: string): Promise<number>;
105+
106+
add(nick: string, wins: number): Promise<{oldWins: number, newWins: number}>
107+
108+
set(nick: string, wins: number): Promise<{oldWins: number, newWins: number}>
109+
}
110+
111+
export class Kills {
112+
constructor(options: {token: string, v: string});
113+
114+
get(nick: string): Promise<number>;
115+
116+
add(nick: string, kills: number): Promise<{oldKills: number, newKills: number}>
117+
118+
set(nick: string, kills: number): Promise<{oldKills: number, newKills: number}>
119+
}
120+
121+
122+
export class Teams {
123+
constructor(options: {token: string, v: string});
124+
125+
get(id: string ,socNet: string): Promise<[{id: number, companyId: number, companyName: string, nick: string, position: string}]>
126+
}
127+
128+
129+
export class Minecraft {
130+
constructor(options: {token: string, v: string})
131+
132+
serverinfo(ip: string,port?: number, type?: string): Promise<{
133+
description?: {
134+
extra: [{
135+
color: string,
136+
text: string
137+
}],
138+
text: string
139+
},
140+
modinfo?: {
141+
modList: [],
142+
type: string
143+
},
144+
players?: {
145+
max: number,
146+
online: number
147+
},
148+
version?: {
149+
name: string,
150+
protocol: string
151+
}
152+
}>
153+
}

lib/index.js

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
1-
// noinspection JSUnusedGlobalSymbols
2-
class RedGuyApi {
3-
4-
options = {};
5-
6-
constructor(token,options = {}) {
7-
options.token = token;
8-
9-
if(typeof options.v === "undefined") {
10-
options.v = "1.1";
11-
}
12-
13-
this.options = options;
14-
}
15-
16-
Math() {
17-
return new (require("./Math"))(this.options);
18-
}
19-
20-
Store() {
21-
return new (require("./Store"))(this.options);
22-
}
23-
24-
Users() {
25-
return new (require("./Users"))(this.options);
26-
}
27-
28-
Event() {
29-
return new (require("./Event"))(this.options);
30-
}
31-
32-
Teams() {
33-
return new (require("./Teams"))(this.options);
34-
}
35-
36-
Minecraft() {
37-
return new (require("./Minecraft"))(this.options);
38-
}
39-
}
40-
41-
module.exports = RedGuyApi;
1+
module.exports = {
2+
RedGuyApi: require("./RedGuyApi"),
3+
Math: require("./Math/index"),
4+
NumberLevels: require("./Math/NumberLevels"),
5+
Store: require("./Store/index"),
6+
Json: require("./Store/json"),
7+
Users: require("./Users/index"),
8+
Additional: require("./Users/Additional"),
9+
Balance: require("./Users/Balance"),
10+
Event: require("./Event/index"),
11+
Coins: require("./Event/Coins"),
12+
Tokens: require("./Event/Tokens"),
13+
Wins: require("./Event/Wins"),
14+
Kills: require("./Event/Kills"),
15+
Teams: require("./Teams/index"),
16+
Minecraft: require("./Minecraft/index")
17+
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "node-redguy-api",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Library to use redguy api",
55
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
67
"directories": {
78
"lib": "lib",
89
"test": "tests"
910
},
1011
"dependencies": {
11-
"axios": "^0.21.0"
12+
"axios": "^0.21.1"
1213
},
1314
"devDependencies": {},
1415
"scripts": {

tests/tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const RedGuyApi = require("../lib");
1+
const RedGuyApi = require("../lib").RedGuyApi;
22
const levels = require("../lib/Math/NumberLevels");
33
const additional = require("../lib/Users/Additional");
44

55
let api = new RedGuyApi(process.env.TOKEN);
66

77
let Math = api.Math();
88

9-
Math.get(levels.factorial,2).then((result) => {
9+
/*Math.get(levels.factorial,2).then((result) => {
1010
if(parseInt(result.toString(),10) === 2) {
1111
console.log("math.get - OK!");
1212
} else {
@@ -25,7 +25,7 @@ Math.max(levels.factorial).then((result) => {
2525
console.log("math.max - Error!");
2626
console.error(e);
2727
process.exit(-1);
28-
});
28+
});*/
2929

3030
let Store = api.Store();
3131
let ts = Date.now().valueOf();

0 commit comments

Comments
 (0)