@duque.edits/sdk 0.0.1
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/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/package.json +46 -0
- package/src/index.ts +30 -0
- package/src/managers/bet/GuildBetManager.ts +117 -0
- package/src/managers/betuser/GuildBetUserManager.ts +103 -0
- package/src/managers/channel/ChannelManager.ts +168 -0
- package/src/managers/groupedchannel/GroupedChannelManager.ts +117 -0
- package/src/managers/guild/GuildManager.ts +84 -0
- package/src/managers/match/GuildMatchManager.ts +115 -0
- package/src/managers/mediator/GuildMediatorManager.ts +111 -0
- package/src/managers/messages/MessagesManager.ts +95 -0
- package/src/managers/permission/GuildPermissionManager.ts +88 -0
- package/src/managers/product/GuildProductManager.ts +115 -0
- package/src/managers/ticket/GuildTicketManager.ts +112 -0
- package/src/managers/user/GuildUserManager.ts +116 -0
- package/src/rest/APIEndpoints.ts +11 -0
- package/src/rest/REST.ts +126 -0
- package/src/rest/Routes.ts +143 -0
- package/src/structures/Collection.ts +85 -0
- package/src/structures/bet/GuildBet.ts +332 -0
- package/src/structures/betuser/GuildBetUser.ts +247 -0
- package/src/structures/channel/Channel.ts +78 -0
- package/src/structures/groupedchannel/GroupedChannel.ts +165 -0
- package/src/structures/guild/Guild.ts +302 -0
- package/src/structures/match/GuildMatch.ts +385 -0
- package/src/structures/mediator/GuildMediator.ts +175 -0
- package/src/structures/product/GuildProduct.ts +217 -0
- package/src/structures/shop/GuildShop.ts +98 -0
- package/src/structures/ticket/GuildTicket.ts +227 -0
- package/src/structures/user/GuildUser.ts +248 -0
- package/src/types/api/APIBaseChannel.ts +13 -0
- package/src/types/api/APIBetChannel.ts +13 -0
- package/src/types/api/APIBetMessage.ts +13 -0
- package/src/types/api/APIGuild.ts +123 -0
- package/src/types/api/APIGuildBet.ts +69 -0
- package/src/types/api/APIGuildBetUser.ts +46 -0
- package/src/types/api/APIGuildChannel.ts +13 -0
- package/src/types/api/APIGuildEmoji.ts +16 -0
- package/src/types/api/APIGuildGroupedChannel.ts +13 -0
- package/src/types/api/APIGuildMatch.ts +67 -0
- package/src/types/api/APIGuildMediator.ts +18 -0
- package/src/types/api/APIGuildMessage.ts +13 -0
- package/src/types/api/APIGuildPermissions.ts +7 -0
- package/src/types/api/APIGuildRole.ts +13 -0
- package/src/types/api/APIGuildShop.ts +15 -0
- package/src/types/api/APIGuildTicket.ts +36 -0
- package/src/types/api/APIGuildUser.ts +45 -0
- package/src/types/api/APIMessage.ts +16 -0
- package/src/types/api/APIPlayer.ts +13 -0
- package/src/types/api/APIProduct.ts +27 -0
- package/src/types/api/index.ts +180 -0
- package/src/types/index.ts +24 -0
- package/src/utils/Assertion.ts +56 -0
- package/tests/index.ts +86 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { REST } from "../../rest/REST";
|
|
2
|
+
import { Routes } from "../../rest/Routes";
|
|
3
|
+
import { Guild } from "../guild/Guild";
|
|
4
|
+
import { APIGuildBet } from "../../types/api/APIGuildBet";
|
|
5
|
+
import { APIPlayer } from "../../types/api/APIPlayer";
|
|
6
|
+
import { APIBetChannel } from "../../types/api/APIBetChannel";
|
|
7
|
+
import { APIBetMessage } from "../../types/api/APIBetMessage";
|
|
8
|
+
import { BaseMatchModes, BaseMatchStatus, Confirm, Logs, Optional } from "../../types/api";
|
|
9
|
+
import { Assertion } from "../../utils/Assertion";
|
|
10
|
+
import { ChannelManager } from "../../managers/channel/ChannelManager";
|
|
11
|
+
import { GuildBetManager } from "../../managers/bet/GuildBetManager";
|
|
12
|
+
import { MessagesManager } from "../../managers/messages/MessagesManager";
|
|
13
|
+
|
|
14
|
+
type ExtendedMatchStatus = BaseMatchStatus | "waiting";
|
|
15
|
+
|
|
16
|
+
export class GuildBet {
|
|
17
|
+
/** The bet's type */
|
|
18
|
+
type: Omit<BaseMatchModes, "5x5" | "6x6" | "5v5" | "6v6">;
|
|
19
|
+
|
|
20
|
+
/** The bet's mode */
|
|
21
|
+
mode: "misto" | "emu" | "mob" | "MISTO" | "EMU" | "MOB";
|
|
22
|
+
|
|
23
|
+
/** The bet's status */
|
|
24
|
+
status: "off" | "created" | "on" | "shutted" | "waiting";
|
|
25
|
+
|
|
26
|
+
/** The bet's maximum size */
|
|
27
|
+
maximumSize: number;
|
|
28
|
+
|
|
29
|
+
/** The bet's price */
|
|
30
|
+
price: number;
|
|
31
|
+
|
|
32
|
+
/** Who has payed the bet */
|
|
33
|
+
payedBy: APIPlayer[];
|
|
34
|
+
|
|
35
|
+
/** The bet's players */
|
|
36
|
+
players: APIPlayer[];
|
|
37
|
+
|
|
38
|
+
/** An array of team a */
|
|
39
|
+
teamA: APIPlayer[];
|
|
40
|
+
|
|
41
|
+
/** An array of team b */
|
|
42
|
+
teamB: APIPlayer[];
|
|
43
|
+
|
|
44
|
+
/** The bet's channel */
|
|
45
|
+
channels: ChannelManager<GuildBet>;
|
|
46
|
+
|
|
47
|
+
/** THe bet's messages */
|
|
48
|
+
messages: MessagesManager;
|
|
49
|
+
|
|
50
|
+
/** The id of the winner */
|
|
51
|
+
winner: string;
|
|
52
|
+
|
|
53
|
+
/** The id of the loser */
|
|
54
|
+
loser: string;
|
|
55
|
+
|
|
56
|
+
/** The bet's creator id */
|
|
57
|
+
creatorId: string;
|
|
58
|
+
|
|
59
|
+
/** The bet's mediator */
|
|
60
|
+
mediatorId: string;
|
|
61
|
+
|
|
62
|
+
/** The bet's confirmers */
|
|
63
|
+
confirmed: Confirm[];
|
|
64
|
+
|
|
65
|
+
/** The bet's embed id */
|
|
66
|
+
embedMessageId: string;
|
|
67
|
+
|
|
68
|
+
/** The bet's logs */
|
|
69
|
+
logs: Logs;
|
|
70
|
+
|
|
71
|
+
/** Creation Date */
|
|
72
|
+
createdAt: Date;
|
|
73
|
+
|
|
74
|
+
/** Updated Date */
|
|
75
|
+
updatedAt: Date;
|
|
76
|
+
|
|
77
|
+
/** GuildBet's id */
|
|
78
|
+
_id: string;
|
|
79
|
+
|
|
80
|
+
/** The given guild */
|
|
81
|
+
readonly guild: Guild;
|
|
82
|
+
|
|
83
|
+
/** The rest client */
|
|
84
|
+
readonly rest: REST;
|
|
85
|
+
|
|
86
|
+
readonly key: string;
|
|
87
|
+
|
|
88
|
+
readonly manager: GuildBetManager;
|
|
89
|
+
/**
|
|
90
|
+
* GuildBet bet
|
|
91
|
+
* @param data The bet's data
|
|
92
|
+
* @param guild The guild
|
|
93
|
+
* @param rest The rest client
|
|
94
|
+
*/
|
|
95
|
+
constructor(data: APIGuildBet, guild: Guild, manager: GuildBetManager, rest: REST) {
|
|
96
|
+
this.type = data.type;
|
|
97
|
+
this.mode = data.mode;
|
|
98
|
+
this.status = data.status;
|
|
99
|
+
this.maximumSize = data.maximumSize;
|
|
100
|
+
this.price = data.price;
|
|
101
|
+
this.payedBy = data.payedBy;
|
|
102
|
+
this.players = data.players;
|
|
103
|
+
this.teamA = data.teamA;
|
|
104
|
+
this.teamB = data.teamB;
|
|
105
|
+
this.winner = data.winner;
|
|
106
|
+
this.loser = data.loser;
|
|
107
|
+
this.creatorId = data.creatorId;
|
|
108
|
+
this.mediatorId = data.mediatorId;
|
|
109
|
+
this.confirmed = data.confirmed;
|
|
110
|
+
this.embedMessageId = data.embedMessageId;
|
|
111
|
+
this.winner = data?.winner;
|
|
112
|
+
this.loser = data?.loser;
|
|
113
|
+
this._id = data?._id;
|
|
114
|
+
this.logs = data.logs;
|
|
115
|
+
|
|
116
|
+
this.manager = manager;
|
|
117
|
+
|
|
118
|
+
this.key = "bets";
|
|
119
|
+
this.channels = new ChannelManager<GuildBet>(guild, this, rest);
|
|
120
|
+
this.messages = new MessagesManager(this?.guild, this?._id, rest);
|
|
121
|
+
|
|
122
|
+
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
123
|
+
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
124
|
+
|
|
125
|
+
this.guild = guild;
|
|
126
|
+
this.rest = rest;
|
|
127
|
+
|
|
128
|
+
this.channels.setAll(data?.channels);
|
|
129
|
+
this.messages.setAll(data?.messages);
|
|
130
|
+
}
|
|
131
|
+
toString() {
|
|
132
|
+
return this._id || "1";
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Fetches the bet
|
|
136
|
+
* @returns New Instance of the bet
|
|
137
|
+
*/
|
|
138
|
+
async fetch() {
|
|
139
|
+
const route = Routes.guilds.bets.get(this.guild.id, this._id);
|
|
140
|
+
const response = await this.rest.request<APIGuildBet, {}>({
|
|
141
|
+
method: "get",
|
|
142
|
+
url: route,
|
|
143
|
+
});
|
|
144
|
+
const bt = new GuildBet(response, this.guild, this.manager, this.rest);
|
|
145
|
+
this.manager.cache.set(bt._id, bt);
|
|
146
|
+
return bt;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async addConfirmed(type: string, id: string) {
|
|
150
|
+
Assertion.assertString(type);
|
|
151
|
+
Assertion.assertString(id);
|
|
152
|
+
|
|
153
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "confirmed");
|
|
154
|
+
const payload = { entry: { type, id } };
|
|
155
|
+
|
|
156
|
+
const response = await this.rest.request<APIGuildBet, typeof payload>({
|
|
157
|
+
method: "PATCH",
|
|
158
|
+
url: route,
|
|
159
|
+
payload,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
163
|
+
this.confirmed = response.confirmed;
|
|
164
|
+
this.manager.cache.set(this._id, this);
|
|
165
|
+
return response.confirmed.find((cn) => cn.type == type);
|
|
166
|
+
}
|
|
167
|
+
async setConfirmed(set: Confirm[]) {
|
|
168
|
+
Assertion.assertObject(set);
|
|
169
|
+
|
|
170
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "confirmed");
|
|
171
|
+
|
|
172
|
+
const response = await this.rest.request<APIGuildBet, typeof set>({
|
|
173
|
+
method: "PATCH",
|
|
174
|
+
url: route,
|
|
175
|
+
payload: set,
|
|
176
|
+
});
|
|
177
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
178
|
+
this.confirmed = response.confirmed;
|
|
179
|
+
this.manager.cache.set(this._id, this);
|
|
180
|
+
return this.confirmed;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async setStatus(status: ExtendedMatchStatus) {
|
|
184
|
+
Assertion.assertString(status);
|
|
185
|
+
|
|
186
|
+
const payload = { set: status.toLowerCase() };
|
|
187
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "status");
|
|
188
|
+
const response = await this.rest.request<APIGuildBet, typeof payload>({
|
|
189
|
+
method: "PATCH",
|
|
190
|
+
url: route,
|
|
191
|
+
payload,
|
|
192
|
+
});
|
|
193
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
194
|
+
this.status = response.status;
|
|
195
|
+
this.manager.cache.set(this._id, this);
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
async setWinner(userId: string) {
|
|
199
|
+
Assertion.assertString(userId);
|
|
200
|
+
|
|
201
|
+
const payload = { set: userId };
|
|
202
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "winner");
|
|
203
|
+
const response = await this.rest.request<APIGuildBet, {}>({
|
|
204
|
+
method: "PATCH",
|
|
205
|
+
url: route,
|
|
206
|
+
payload,
|
|
207
|
+
});
|
|
208
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
209
|
+
this.winner = response.winner;
|
|
210
|
+
this.manager.cache.set(this._id, this);
|
|
211
|
+
return response.winner;
|
|
212
|
+
}
|
|
213
|
+
async setLoser(userId: string) {
|
|
214
|
+
Assertion.assertString(userId);
|
|
215
|
+
|
|
216
|
+
const payload = { set: userId };
|
|
217
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "loser");
|
|
218
|
+
const response = await this.rest.request<APIGuildBet, {}>({
|
|
219
|
+
method: "PATCH",
|
|
220
|
+
url: route,
|
|
221
|
+
payload,
|
|
222
|
+
});
|
|
223
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
224
|
+
this.loser = response.loser;
|
|
225
|
+
this.manager.cache.set(this._id, this);
|
|
226
|
+
return response.loser;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async addChannel(id: string, type: string) {
|
|
230
|
+
const ch = await this.channels.create(id, type);
|
|
231
|
+
this.manager.cache.set(this._id, this);
|
|
232
|
+
return ch;
|
|
233
|
+
}
|
|
234
|
+
async addMessage(id: string, type: string, content?: string) {
|
|
235
|
+
const response = await this.messages.create({
|
|
236
|
+
userId: id,
|
|
237
|
+
type: type as "img",
|
|
238
|
+
content,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
this.manager.cache.set(this._id, this);
|
|
242
|
+
this.rest.bets.set(this._id, this);
|
|
243
|
+
return response;
|
|
244
|
+
}
|
|
245
|
+
async setChannels(channels: APIBetChannel[]) {
|
|
246
|
+
Assertion.assertObject(channels);
|
|
247
|
+
|
|
248
|
+
const payload = { set: channels };
|
|
249
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "channels");
|
|
250
|
+
const response = await this.rest.request<APIGuildBet, {}>({
|
|
251
|
+
method: "PATCH",
|
|
252
|
+
url: route,
|
|
253
|
+
payload,
|
|
254
|
+
});
|
|
255
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
256
|
+
this.channels.setAll(response.channels);
|
|
257
|
+
this.manager.cache.set(this._id, this);
|
|
258
|
+
return this.channels;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async addPlayer(id: string, name: string) {
|
|
262
|
+
Assertion.assertString(id);
|
|
263
|
+
Assertion.assertString(name);
|
|
264
|
+
|
|
265
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "players");
|
|
266
|
+
const payload = { id, name };
|
|
267
|
+
const response = await this.rest.request<APIPlayer[], typeof payload>({
|
|
268
|
+
method: "POST",
|
|
269
|
+
url: route,
|
|
270
|
+
payload,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
this.players = response;
|
|
274
|
+
this.manager.cache.set(this._id, this);
|
|
275
|
+
return this.players;
|
|
276
|
+
}
|
|
277
|
+
async removePlayer(id: string, name: string) {
|
|
278
|
+
Assertion.assertString(id);
|
|
279
|
+
Assertion.assertString(name);
|
|
280
|
+
|
|
281
|
+
const route = Routes.guilds.bets.resource(this.guild.id, this._id, "players", id);
|
|
282
|
+
const payload = { id, name };
|
|
283
|
+
const response = await this.rest.request<APIPlayer[], typeof payload>({
|
|
284
|
+
method: "DELETE",
|
|
285
|
+
url: route,
|
|
286
|
+
payload,
|
|
287
|
+
});
|
|
288
|
+
this.players = response;
|
|
289
|
+
this.manager.cache.set(this._id, this);
|
|
290
|
+
return this.players;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async update(data: Optional<APIGuildBet>) {
|
|
294
|
+
const route = Routes.guilds.bets.get(this.guild.id, this._id);
|
|
295
|
+
const payload = data;
|
|
296
|
+
|
|
297
|
+
const response = await this.rest.request<APIGuildBet, typeof payload>({
|
|
298
|
+
method: "patch",
|
|
299
|
+
url: route,
|
|
300
|
+
payload,
|
|
301
|
+
});
|
|
302
|
+
this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
|
|
303
|
+
for (const k in response) {
|
|
304
|
+
if (k === "id") continue;
|
|
305
|
+
|
|
306
|
+
if (Object.hasOwn(this, k)) {
|
|
307
|
+
if (k === "channels") {
|
|
308
|
+
this.channels.setAll(response["channels"]);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (k === "messages") {
|
|
312
|
+
this.messages.setAll(response["messages"]);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
(this as any)[k] = response[k as keyof APIGuildBet];
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
this.rest.bets.set(this._id, this);
|
|
320
|
+
this.manager.cache.set(this._id, this);
|
|
321
|
+
return this;
|
|
322
|
+
}
|
|
323
|
+
toJSON() {
|
|
324
|
+
const json: Record<string, unknown> = {};
|
|
325
|
+
for (const [key, value] of Object.entries(this)) {
|
|
326
|
+
if (typeof value !== "function") {
|
|
327
|
+
json[key] = value;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return json;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { REST } from "../../rest/REST";
|
|
2
|
+
import { Routes } from "../../rest/Routes";
|
|
3
|
+
import { Daily, Items, Optional, ProfileCard } from "../../types/api";
|
|
4
|
+
import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
|
|
5
|
+
import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
|
|
6
|
+
|
|
7
|
+
export class GuildBetUser implements APIGuildBetUser {
|
|
8
|
+
/** User daily */
|
|
9
|
+
daily: Omit<Daily, "points">;
|
|
10
|
+
|
|
11
|
+
/** User's name */
|
|
12
|
+
name: string;
|
|
13
|
+
|
|
14
|
+
/** User's name */
|
|
15
|
+
id: string;
|
|
16
|
+
|
|
17
|
+
/** User's credit */
|
|
18
|
+
credit: number;
|
|
19
|
+
|
|
20
|
+
/** User's wins */
|
|
21
|
+
wins: number;
|
|
22
|
+
|
|
23
|
+
/** User's mvps */
|
|
24
|
+
mvps: number;
|
|
25
|
+
|
|
26
|
+
/** User's losses */
|
|
27
|
+
losses: number;
|
|
28
|
+
|
|
29
|
+
/** User's bets played */
|
|
30
|
+
betsPlayed: string[];
|
|
31
|
+
|
|
32
|
+
/** User's blacklist */
|
|
33
|
+
blacklist: boolean;
|
|
34
|
+
|
|
35
|
+
/** User's coins */
|
|
36
|
+
coins: number;
|
|
37
|
+
|
|
38
|
+
/** User's items */
|
|
39
|
+
items: Items;
|
|
40
|
+
|
|
41
|
+
/** User's profile card */
|
|
42
|
+
profileCard: ProfileCard;
|
|
43
|
+
|
|
44
|
+
/** Creation Date */
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
|
|
47
|
+
/** Updated Date */
|
|
48
|
+
updatedAt: Date;
|
|
49
|
+
|
|
50
|
+
/** The given manager */
|
|
51
|
+
readonly manager: GuildBetUserManager;
|
|
52
|
+
|
|
53
|
+
/** The rest client */
|
|
54
|
+
readonly rest: REST;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Bet user
|
|
58
|
+
* @param data The user's data
|
|
59
|
+
* @param manager The manager
|
|
60
|
+
* @param rest The rest client
|
|
61
|
+
*/
|
|
62
|
+
constructor(data: APIGuildBetUser, manager: GuildBetUserManager, rest: REST) {
|
|
63
|
+
this.name = data.name;
|
|
64
|
+
this.id = data.id;
|
|
65
|
+
this.credit = data.credit;
|
|
66
|
+
this.wins = data.wins;
|
|
67
|
+
this.mvps = data.mvps;
|
|
68
|
+
this.losses = data.losses;
|
|
69
|
+
this.coins = data.coins;
|
|
70
|
+
this.blacklist = data.blacklist;
|
|
71
|
+
this.items = data.items;
|
|
72
|
+
this.betsPlayed = data.betsPlayed;
|
|
73
|
+
this.profileCard = data.profileCard;
|
|
74
|
+
this.daily = data?.daily;
|
|
75
|
+
|
|
76
|
+
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
77
|
+
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
78
|
+
|
|
79
|
+
this.manager = manager;
|
|
80
|
+
this.rest = rest;
|
|
81
|
+
}
|
|
82
|
+
/** String representation of this user */
|
|
83
|
+
toString() {
|
|
84
|
+
return `<@${this.id}>`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Fetches the user
|
|
88
|
+
* @returns New Instance of the user
|
|
89
|
+
*/
|
|
90
|
+
async fetch() {
|
|
91
|
+
const route = Routes.guilds.betUsers.get(this.manager.guild.id, this.id);
|
|
92
|
+
const response = await this.rest.request<APIGuildBetUser, {}>({
|
|
93
|
+
method: "get",
|
|
94
|
+
url: route,
|
|
95
|
+
});
|
|
96
|
+
const user = new GuildBetUser(response, this.manager, this.rest);
|
|
97
|
+
|
|
98
|
+
this.manager.cache.set(user.id, user);
|
|
99
|
+
this.rest.betUsers.set(user.id, user);
|
|
100
|
+
return user;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Add a propery
|
|
105
|
+
* @param key The desired key
|
|
106
|
+
* @param value The desired value
|
|
107
|
+
* @returns GuildBetUser
|
|
108
|
+
*/
|
|
109
|
+
async add<K extends keyof BetUserAddOptions, V extends BetUserAddOptions[K]>(
|
|
110
|
+
key: K,
|
|
111
|
+
value: V
|
|
112
|
+
) {
|
|
113
|
+
const route = Routes.guilds.betUsers.resource(
|
|
114
|
+
this.manager.guild.id,
|
|
115
|
+
this.id,
|
|
116
|
+
key
|
|
117
|
+
);
|
|
118
|
+
const payload = { [key]: value, name: this.name };
|
|
119
|
+
|
|
120
|
+
const resp = await this.rest.request<APIGuildBetUser, typeof payload>({
|
|
121
|
+
method: "patch",
|
|
122
|
+
url: route,
|
|
123
|
+
payload,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
this[key] = resp[key];
|
|
127
|
+
this.manager.cache.set(this.id, this);
|
|
128
|
+
this.rest.betUsers.set(this.id, this);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Set the user blacklist
|
|
134
|
+
* @param value Value to set to
|
|
135
|
+
* @returns GuildBetUser
|
|
136
|
+
*/
|
|
137
|
+
async setBlacklist(value: boolean) {
|
|
138
|
+
const route = Routes.guilds.betUsers.resource(
|
|
139
|
+
this.manager.guild.id,
|
|
140
|
+
this.id,
|
|
141
|
+
"blacklist"
|
|
142
|
+
);
|
|
143
|
+
const payload = { value, name: this.name };
|
|
144
|
+
await this.rest.request<APIGuildBetUser, typeof payload>({
|
|
145
|
+
method: "patch",
|
|
146
|
+
url: route,
|
|
147
|
+
payload,
|
|
148
|
+
});
|
|
149
|
+
this.blacklist = value;
|
|
150
|
+
this.manager.cache.set(this.id, this);
|
|
151
|
+
this.rest.betUsers.set(this.id, this);
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Update certain property
|
|
157
|
+
* @param data The new data to update with
|
|
158
|
+
* @returns
|
|
159
|
+
*/
|
|
160
|
+
async update(
|
|
161
|
+
data: Omit<Optional<APIGuildBetUser>, "daily"> & { type?: "add" | "remove" }
|
|
162
|
+
) {
|
|
163
|
+
const route = Routes.guilds.betUsers.get(this.manager.guild.id, this.id);
|
|
164
|
+
const payload: Record<string, any> = {};
|
|
165
|
+
|
|
166
|
+
const numericFields = [
|
|
167
|
+
"coins",
|
|
168
|
+
"wins",
|
|
169
|
+
"credit",
|
|
170
|
+
"losses",
|
|
171
|
+
"mvps",
|
|
172
|
+
] as const;
|
|
173
|
+
const arrayFields = ["items", "betsPlayed"] as const;
|
|
174
|
+
|
|
175
|
+
if (data.type === "add" || data.type === "remove") {
|
|
176
|
+
for (const key in data) {
|
|
177
|
+
if (key === "type") continue;
|
|
178
|
+
|
|
179
|
+
const value = data[key as keyof typeof data];
|
|
180
|
+
|
|
181
|
+
if (numericFields.includes(key as any)) {
|
|
182
|
+
const current = this[key as keyof typeof this] as number;
|
|
183
|
+
const num = value as number;
|
|
184
|
+
payload[key] = Math.max(
|
|
185
|
+
0,
|
|
186
|
+
data.type === "add" ? current + num : num - current
|
|
187
|
+
);
|
|
188
|
+
} else if (key === "blacklist") {
|
|
189
|
+
payload["blacklist"] = value;
|
|
190
|
+
} else if (arrayFields.includes(key as any)) {
|
|
191
|
+
const current = this[key as keyof typeof this] as any[];
|
|
192
|
+
const incoming = value as any[];
|
|
193
|
+
|
|
194
|
+
payload[key] =
|
|
195
|
+
data.type === "add"
|
|
196
|
+
? [...new Set([...current, ...incoming])]
|
|
197
|
+
: current.filter((x) => !incoming.includes(x));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const response = await this.rest.request<APIGuildBetUser, typeof payload>({
|
|
203
|
+
method: "patch",
|
|
204
|
+
url: route,
|
|
205
|
+
payload,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
for (const k in response) {
|
|
209
|
+
if (k === "id") continue;
|
|
210
|
+
if (Object.hasOwn(this, k)) {
|
|
211
|
+
(this as any)[k] = response[k as keyof APIGuildBetUser];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
this.rest.betUsers.set(this.id, this);
|
|
215
|
+
this.manager.cache.set(this.id, this);
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
async delete() {
|
|
219
|
+
const route = Routes.guilds.betUsers.delete(this.manager.guild.id, this.id);
|
|
220
|
+
const response = await this.rest.request<boolean, {}>({
|
|
221
|
+
method: "DELETE",
|
|
222
|
+
url: route,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
this.rest.emit("betUserDelete", this);
|
|
226
|
+
this.manager.cache.delete(this.id);
|
|
227
|
+
this.rest.betUsers.set(this.id, this);
|
|
228
|
+
return response;
|
|
229
|
+
}
|
|
230
|
+
toJSON() {
|
|
231
|
+
const json: Record<string, unknown> = {};
|
|
232
|
+
for (const [key, value] of Object.entries(this)) {
|
|
233
|
+
if (typeof value !== "function") {
|
|
234
|
+
json[key] = value;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return json;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export type BetUserAddOptions = {
|
|
242
|
+
coins: number;
|
|
243
|
+
credit: number;
|
|
244
|
+
wins: number;
|
|
245
|
+
losses: number;
|
|
246
|
+
mvps: number;
|
|
247
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ChannelManager } from "../../managers/channel/ChannelManager";
|
|
2
|
+
import { REST } from "../../rest/REST";
|
|
3
|
+
import { APIBaseChannel } from "../../types/api/APIBaseChannel";
|
|
4
|
+
import { APIBetChannel } from "../../types/api/APIBetChannel";
|
|
5
|
+
import { Assertion } from "../../utils/Assertion";
|
|
6
|
+
import { GuildBet } from "../bet/GuildBet";
|
|
7
|
+
import { Guild } from "../guild/Guild";
|
|
8
|
+
import { GuildMatch } from "../match/GuildMatch";
|
|
9
|
+
|
|
10
|
+
export interface ChannelData<S extends GuildBet | GuildMatch> {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
|
|
13
|
+
data: APIBaseChannel;
|
|
14
|
+
guild: Guild;
|
|
15
|
+
manager: ChannelManager<S>;
|
|
16
|
+
}
|
|
17
|
+
export class Channel<S extends GuildBet | GuildMatch> {
|
|
18
|
+
/** Channel's type */
|
|
19
|
+
type: string;
|
|
20
|
+
|
|
21
|
+
/** Channel's id */
|
|
22
|
+
id: string;
|
|
23
|
+
|
|
24
|
+
/** Creation Date */
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
|
|
27
|
+
/** Updated Date */
|
|
28
|
+
updatedAt: Date;
|
|
29
|
+
|
|
30
|
+
data: ChannelData<S>;
|
|
31
|
+
rest: REST;
|
|
32
|
+
baseUrl: string;
|
|
33
|
+
guild: Guild;
|
|
34
|
+
manager: ChannelManager<S>;
|
|
35
|
+
constructor(data: ChannelData<S>, rest: REST) {
|
|
36
|
+
this.type = data?.data?.type;
|
|
37
|
+
this.id = data?.data?.id;
|
|
38
|
+
this.createdAt = data?.data?.createdAt
|
|
39
|
+
? new Date(data?.data?.createdAt)
|
|
40
|
+
: new Date();
|
|
41
|
+
this.updatedAt = data?.data?.updatedAt
|
|
42
|
+
? new Date(data?.data?.updatedAt)
|
|
43
|
+
: new Date();
|
|
44
|
+
|
|
45
|
+
this.guild = data?.guild;
|
|
46
|
+
|
|
47
|
+
this.manager = data?.manager;
|
|
48
|
+
this.baseUrl = data.baseUrl;
|
|
49
|
+
|
|
50
|
+
this.data = data;
|
|
51
|
+
this.rest = rest;
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
return `<#${this.id}>`;
|
|
55
|
+
}
|
|
56
|
+
async setId(id: string) {
|
|
57
|
+
Assertion.assertString(id);
|
|
58
|
+
|
|
59
|
+
const payload = { id };
|
|
60
|
+
const response = await this.rest.request<APIBetChannel, typeof payload>({
|
|
61
|
+
method: "PATCH",
|
|
62
|
+
url: this.baseUrl,
|
|
63
|
+
payload,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
this.id = response.id;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
async delete() {
|
|
70
|
+
await this.rest.request<APIBetChannel, {}>({
|
|
71
|
+
method: "delete",
|
|
72
|
+
url: this.baseUrl,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
this.manager.cache.delete(this.type);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
}
|