@duque.edits/sdk 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -10
- package/dist/managers/player/PlayerManager.js +7 -9
- package/dist/rest/REST.js +2 -2
- package/dist/rest/Routes.js +2 -2
- package/dist/structures/Collection.js +4 -1
- package/dist/structures/bet/GuildBet.js +9 -1
- package/dist/structures/match/GuildMatch.js +42 -22
- package/dist/types/api/APIGuild.js +1 -0
- package/package.json +1 -1
- package/types/managers/player/PlayerManager.d.ts +2 -3
- package/types/structures/Collection.d.ts +1 -1
- package/types/structures/match/GuildMatch.d.ts +4 -6
- package/types/types/api/APIGuild.d.ts +2 -0
- package/types/types/api/APIGuildMatch.d.ts +2 -1
package/README.md
CHANGED
|
@@ -2,15 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
> You can use this package as base for your own sdk
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> **Version**: [2.5.3](https://www.npmjs.com/package/@duque.edits/rest)
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
|
|
9
|
+
- Rest Client.
|
|
10
|
+
- Guild Manager.
|
|
11
|
+
- Crate matches between players.
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
Create Match
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const { REST } = require("@duque.edits/sdk");
|
|
19
|
+
const client = new REST({
|
|
20
|
+
clientKey: "**************",
|
|
21
|
+
authKey: "**************",
|
|
22
|
+
guildId: "**************",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const guild = client.guilds.cache.get("**************");
|
|
26
|
+
const match = guild.matches.create({
|
|
27
|
+
type: "2v2",
|
|
28
|
+
creatorId: 1234,
|
|
29
|
+
});
|
|
30
|
+
```
|
|
@@ -2,33 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlayerManager = void 0;
|
|
4
4
|
const structures_1 = require("../../structures");
|
|
5
|
-
class PlayerManager {
|
|
6
|
-
|
|
5
|
+
class PlayerManager extends structures_1.Collection {
|
|
6
|
+
base_url;
|
|
7
7
|
constructor(players, base_url) {
|
|
8
|
-
|
|
8
|
+
super("players");
|
|
9
|
+
this.base_url = base_url;
|
|
9
10
|
if (Array.isArray(players)) {
|
|
10
11
|
for (let p of players) {
|
|
11
12
|
if (!p.id)
|
|
12
13
|
continue;
|
|
13
|
-
this.
|
|
14
|
+
this.set(p.id, p);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
get(id) {
|
|
18
|
-
return this._cache.get(id);
|
|
19
|
-
}
|
|
20
18
|
add(player) {
|
|
21
19
|
if (Array.isArray(player)) {
|
|
22
20
|
for (let p of player) {
|
|
23
21
|
if (!p.id)
|
|
24
22
|
continue;
|
|
25
|
-
this.
|
|
23
|
+
this.set(p.id, p);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
else {
|
|
29
27
|
if (!player.id)
|
|
30
28
|
return;
|
|
31
|
-
this.
|
|
29
|
+
this.set(player.id, player);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
}
|
package/dist/rest/REST.js
CHANGED
|
@@ -61,12 +61,12 @@ class REST extends events_1.default {
|
|
|
61
61
|
/** Initialize the caching sistem */
|
|
62
62
|
async init() {
|
|
63
63
|
if (!this.clientKey || !this.authKey || !this.guildId)
|
|
64
|
-
throw new Error("
|
|
64
|
+
throw new Error("Client key, auth key, and guildId is necessary");
|
|
65
65
|
await Promise.all([this.guilds.fetch({ guildId: this.guildId }), this.minesGames.fetch()]);
|
|
66
66
|
return this;
|
|
67
67
|
}
|
|
68
68
|
formatUrl(url) {
|
|
69
|
-
return url.endsWith("/") ? url.slice(0, url.length - 1) : url;
|
|
69
|
+
return (url.endsWith("/") ? url.slice(0, url.length - 1) : url) ?? "/status";
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Request Data from a certain url
|
package/dist/rest/Routes.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Routes = void 0;
|
|
4
4
|
exports.Routes = {
|
|
5
|
-
base: "
|
|
6
|
-
//base: "
|
|
5
|
+
base: "http://localhost:80/api/v1",
|
|
6
|
+
//base: "https://duque-api.up.railway.app/api/v1",
|
|
7
7
|
field: (field) => `/${field}`,
|
|
8
8
|
fields: (...fields) => `${fields.join("/")}`,
|
|
9
9
|
guilds: {
|
|
@@ -77,7 +77,10 @@ class Collection extends Map {
|
|
|
77
77
|
const sortedEntries = [...this.entries()].sort((ab, ba) => {
|
|
78
78
|
return compareFunction(ab[1], ba[1], this);
|
|
79
79
|
});
|
|
80
|
-
|
|
80
|
+
const coll = new Collection();
|
|
81
|
+
for (let [k, v] of sortedEntries)
|
|
82
|
+
coll.set(k, v);
|
|
83
|
+
return coll;
|
|
81
84
|
}
|
|
82
85
|
toString() {
|
|
83
86
|
return `${this.size}`;
|
|
@@ -147,6 +147,14 @@ class GuildBet {
|
|
|
147
147
|
this[key] = data[key];
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
+
if (data?.messages?.length !== 0) {
|
|
151
|
+
if (this?.messages instanceof managers_1.MessagesManager)
|
|
152
|
+
this.messages.set(data.messages);
|
|
153
|
+
else {
|
|
154
|
+
this.messages = new managers_1.MessagesManager(this, rest_1.Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
|
|
155
|
+
this.messages.set(data.messages);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
150
158
|
this.updatedAt = new Date();
|
|
151
159
|
this.createdAt = new Date(data.createdAt);
|
|
152
160
|
this.manager.set(this);
|
|
@@ -164,7 +172,7 @@ class GuildBet {
|
|
|
164
172
|
}
|
|
165
173
|
return {
|
|
166
174
|
...json,
|
|
167
|
-
messages: this?.messages
|
|
175
|
+
messages: this?.messages instanceof managers_1.MessagesManager ? this.messages?.cache?.toArray() : [],
|
|
168
176
|
};
|
|
169
177
|
}
|
|
170
178
|
}
|
|
@@ -4,6 +4,7 @@ exports.GuildMatch = void 0;
|
|
|
4
4
|
const Routes_1 = require("../../rest/Routes");
|
|
5
5
|
const Assertion_1 = require("../../utils/Assertion");
|
|
6
6
|
const managers_1 = require("../../managers");
|
|
7
|
+
const GuildBet_1 = require("../bet/GuildBet");
|
|
7
8
|
class GuildMatch {
|
|
8
9
|
_id;
|
|
9
10
|
selections;
|
|
@@ -96,7 +97,7 @@ class GuildMatch {
|
|
|
96
97
|
method: "get",
|
|
97
98
|
url: route,
|
|
98
99
|
});
|
|
99
|
-
return this._updateInternals(response);
|
|
100
|
+
return await this._updateInternals(response);
|
|
100
101
|
}
|
|
101
102
|
async addConfirmed(type, id) {
|
|
102
103
|
const confirmed = this.confirmed.find((c) => c.type === type);
|
|
@@ -119,7 +120,7 @@ class GuildMatch {
|
|
|
119
120
|
url: route,
|
|
120
121
|
payload: set,
|
|
121
122
|
});
|
|
122
|
-
return this._updateInternals(response);
|
|
123
|
+
return await this._updateInternals(response);
|
|
123
124
|
}
|
|
124
125
|
async setStatus(status) {
|
|
125
126
|
Assertion_1.Assertion.assertString(status);
|
|
@@ -130,7 +131,7 @@ class GuildMatch {
|
|
|
130
131
|
url: route,
|
|
131
132
|
payload,
|
|
132
133
|
});
|
|
133
|
-
return this._updateInternals(response);
|
|
134
|
+
return await this._updateInternals(response);
|
|
134
135
|
}
|
|
135
136
|
async setWinners(players) {
|
|
136
137
|
if (!Array.isArray(players))
|
|
@@ -142,7 +143,7 @@ class GuildMatch {
|
|
|
142
143
|
url: route,
|
|
143
144
|
payload,
|
|
144
145
|
});
|
|
145
|
-
return this._updateInternals(response);
|
|
146
|
+
return await this._updateInternals(response);
|
|
146
147
|
}
|
|
147
148
|
async setLoser(players) {
|
|
148
149
|
if (!Array.isArray(players))
|
|
@@ -154,7 +155,7 @@ class GuildMatch {
|
|
|
154
155
|
url: route,
|
|
155
156
|
payload,
|
|
156
157
|
});
|
|
157
|
-
return this._updateInternals(response);
|
|
158
|
+
return await this._updateInternals(response);
|
|
158
159
|
}
|
|
159
160
|
async setMvps(...usersId) {
|
|
160
161
|
const payload = { set: usersId };
|
|
@@ -164,7 +165,7 @@ class GuildMatch {
|
|
|
164
165
|
url: route,
|
|
165
166
|
payload,
|
|
166
167
|
});
|
|
167
|
-
return this._updateInternals(response);
|
|
168
|
+
return await this._updateInternals(response);
|
|
168
169
|
}
|
|
169
170
|
async setRoomCreatorId(userId) {
|
|
170
171
|
Assertion_1.Assertion.assertString(userId);
|
|
@@ -175,7 +176,7 @@ class GuildMatch {
|
|
|
175
176
|
url: route,
|
|
176
177
|
payload,
|
|
177
178
|
});
|
|
178
|
-
return this._updateInternals(response);
|
|
179
|
+
return await this._updateInternals(response);
|
|
179
180
|
}
|
|
180
181
|
async setRoomAdminId(userId) {
|
|
181
182
|
Assertion_1.Assertion.assertString(userId);
|
|
@@ -186,27 +187,31 @@ class GuildMatch {
|
|
|
186
187
|
url: route,
|
|
187
188
|
payload,
|
|
188
189
|
});
|
|
189
|
-
return this._updateInternals(response);
|
|
190
|
+
return await this._updateInternals(response);
|
|
190
191
|
}
|
|
191
192
|
async kick(player) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
193
|
+
this.players = this.players.filter((p) => p.id !== player.id);
|
|
194
|
+
this.leaders = this.leaders.filter((p) => p.id !== player.id);
|
|
195
|
+
const teamIndex = this.teams.findIndex((t) => t.some((p) => p.id === player.id));
|
|
196
|
+
if (teamIndex !== -1) {
|
|
197
|
+
let team = this.teams.find((t) => t.some((p) => p.id === player.id));
|
|
198
|
+
team = team.filter((p) => p.id === player.id);
|
|
199
|
+
this.teams[teamIndex] = team;
|
|
200
|
+
}
|
|
201
|
+
return await this.update(this.toJSON());
|
|
200
202
|
}
|
|
201
203
|
async update(data) {
|
|
202
204
|
const route = Routes_1.Routes.guilds.matches.get(this.guild.id, this._id);
|
|
205
|
+
if (data?.bet && data?.bet instanceof GuildBet_1.GuildBet) {
|
|
206
|
+
data.bet = data.bet.toJSON();
|
|
207
|
+
}
|
|
203
208
|
const response = await this.rest.request({
|
|
204
209
|
method: "patch",
|
|
205
210
|
url: route,
|
|
206
211
|
payload: data,
|
|
207
212
|
});
|
|
208
213
|
this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
|
|
209
|
-
return this._updateInternals(response);
|
|
214
|
+
return await this._updateInternals(response);
|
|
210
215
|
}
|
|
211
216
|
async delete() {
|
|
212
217
|
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id);
|
|
@@ -219,7 +224,7 @@ class GuildMatch {
|
|
|
219
224
|
return response;
|
|
220
225
|
}
|
|
221
226
|
toJSON() {
|
|
222
|
-
|
|
227
|
+
let json = {};
|
|
223
228
|
for (const [key, value] of Object.entries(this)) {
|
|
224
229
|
const exclude = ["rest", "guilds", "guild", "manager"];
|
|
225
230
|
if (exclude.includes(key))
|
|
@@ -228,9 +233,14 @@ class GuildMatch {
|
|
|
228
233
|
json[key] = value;
|
|
229
234
|
}
|
|
230
235
|
}
|
|
231
|
-
return {
|
|
236
|
+
return {
|
|
237
|
+
...json,
|
|
238
|
+
messages: this?.messages instanceof managers_1.MessagesManager ? this.messages?.cache?.toArray() : [],
|
|
239
|
+
};
|
|
232
240
|
}
|
|
233
|
-
_updateInternals(data) {
|
|
241
|
+
async _updateInternals(data) {
|
|
242
|
+
if (!data)
|
|
243
|
+
return;
|
|
234
244
|
for (let key in data) {
|
|
235
245
|
if (key === "id" || key === "createdAt" || key === "messages")
|
|
236
246
|
continue;
|
|
@@ -241,8 +251,18 @@ class GuildMatch {
|
|
|
241
251
|
this.bet = this.guild.bets.set(data.bet);
|
|
242
252
|
}
|
|
243
253
|
}
|
|
244
|
-
if (data?.messages?.length !== 0)
|
|
245
|
-
this
|
|
254
|
+
if (data?.messages?.length !== 0) {
|
|
255
|
+
if (this?.messages instanceof managers_1.MessagesManager)
|
|
256
|
+
this.messages.set(data.messages);
|
|
257
|
+
else {
|
|
258
|
+
this.messages = new managers_1.MessagesManager(this, Routes_1.Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
|
|
259
|
+
this.messages.set(data.messages);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (!(this.bet instanceof GuildBet_1.GuildBet) && data?.bet) {
|
|
263
|
+
this.bet =
|
|
264
|
+
this.guild.bets.cache.get(data._id) ?? (await this.guild.bets.fetch({ betId: data?.bet?._id }));
|
|
265
|
+
}
|
|
246
266
|
this.updatedAt = new Date();
|
|
247
267
|
this.manager.set(this);
|
|
248
268
|
return this;
|
|
@@ -27,6 +27,7 @@ var GuildChannelsType;
|
|
|
27
27
|
GuildChannelsType["VipMemebers"] = "vipmembers_category";
|
|
28
28
|
GuildChannelsType["QueueLogs"] = "queue_logs";
|
|
29
29
|
GuildChannelsType["UserLogs"] = "user_logs";
|
|
30
|
+
GuildChannelsType["TicketLogs"] = "ticket_logs";
|
|
30
31
|
GuildChannelsType["ManagingLogs"] = "managing_logs";
|
|
31
32
|
GuildChannelsType["NormalQueue"] = "normal_queue";
|
|
32
33
|
GuildChannelsType["ChallengeQueue"] = "challenge_queue";
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Collection } from "../../structures";
|
|
2
2
|
import { APIPlayer } from "../../types";
|
|
3
3
|
export type AddPlayer = APIPlayer[] | APIPlayer;
|
|
4
|
-
export declare class PlayerManager {
|
|
5
|
-
|
|
4
|
+
export declare class PlayerManager extends Collection<string, APIPlayer> {
|
|
5
|
+
base_url: string;
|
|
6
6
|
constructor(players: APIPlayer | APIPlayer[], base_url: string);
|
|
7
|
-
get(id: string): APIPlayer;
|
|
8
7
|
add(player: AddPlayer): void;
|
|
9
8
|
}
|
|
@@ -12,6 +12,6 @@ export declare class Collection<K, V> extends Map<K, V> {
|
|
|
12
12
|
map(callback: (value: V, key: K, Collection: this) => any): any[];
|
|
13
13
|
toArray(): V[];
|
|
14
14
|
toJSON(): Record<string, unknown>;
|
|
15
|
-
sort(compareFunction: (a: V, b: V, Collection: this) => any): Collection<
|
|
15
|
+
sort(compareFunction: (a: V, b: V, Collection: this) => any): Collection<K, V>;
|
|
16
16
|
toString(): string;
|
|
17
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { REST } from "../../rest/REST";
|
|
2
|
-
import { APIBaseChannel, APIGuildMatch,
|
|
2
|
+
import { APIBaseChannel, APIGuildMatch, APIPlayer, BaseMatchModes, BaseMatchStatus, Confirm, MatchSelection, Optional } from "../../types";
|
|
3
3
|
import { GuildMatchManager, MessagesManager } from "../../managers";
|
|
4
4
|
import { Guild } from "../guild/Guild";
|
|
5
5
|
import { GuildBet } from "../bet/GuildBet";
|
|
@@ -68,11 +68,9 @@ export declare class GuildMatch {
|
|
|
68
68
|
setMvps(...usersId: string[]): Promise<GuildMatch>;
|
|
69
69
|
setRoomCreatorId(userId: string): Promise<GuildMatch>;
|
|
70
70
|
setRoomAdminId(userId: string): Promise<GuildMatch>;
|
|
71
|
-
kick(player: Optional<APIPlayer>): Promise<
|
|
71
|
+
kick(player: Optional<APIPlayer>): Promise<GuildMatch>;
|
|
72
72
|
update(data: Optional<APIGuildMatch>): Promise<GuildMatch>;
|
|
73
73
|
delete(): Promise<boolean>;
|
|
74
|
-
toJSON():
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
_updateInternals(data: Optional<APIGuildMatch>): this;
|
|
74
|
+
toJSON(): Optional<APIGuildMatch>;
|
|
75
|
+
_updateInternals(data: Optional<APIGuildMatch>): Promise<this>;
|
|
78
76
|
}
|
|
@@ -7,6 +7,7 @@ export interface GuildTicketConfiguration {
|
|
|
7
7
|
/** Guild's categories */
|
|
8
8
|
categories: APITicketCategory[];
|
|
9
9
|
creationCategory: string;
|
|
10
|
+
deletionCategory: string;
|
|
10
11
|
rating_channel_id: string;
|
|
11
12
|
}
|
|
12
13
|
export interface GuildStatus {
|
|
@@ -102,6 +103,7 @@ export declare enum GuildChannelsType {
|
|
|
102
103
|
VipMemebers = "vipmembers_category",
|
|
103
104
|
QueueLogs = "queue_logs",
|
|
104
105
|
UserLogs = "user_logs",
|
|
106
|
+
TicketLogs = "ticket_logs",
|
|
105
107
|
ManagingLogs = "managing_logs",
|
|
106
108
|
NormalQueue = "normal_queue",
|
|
107
109
|
ChallengeQueue = "challenge_queue",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { APIGuildBet, BaseMatchModes, BaseMatchStatus, Confirm } from ".";
|
|
2
|
+
import { GuildBet } from "../../structures";
|
|
2
3
|
import { APIBaseChannel } from "./APIBaseChannel";
|
|
3
4
|
import { APIMessage } from "./APIMessage";
|
|
4
5
|
import { APIPlayer } from "./APIPlayer";
|
|
@@ -39,7 +40,7 @@ export interface APIGuildMatch {
|
|
|
39
40
|
creatorId: string;
|
|
40
41
|
/** Match's room creator id */
|
|
41
42
|
roomCreatorId: string;
|
|
42
|
-
bet: APIGuildBet;
|
|
43
|
+
bet: APIGuildBet | GuildBet;
|
|
43
44
|
/** Creation Date */
|
|
44
45
|
createdAt: Date;
|
|
45
46
|
/** Updated Date */
|