@duque.edits/sdk 0.0.3 → 0.0.5

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.
Files changed (157) hide show
  1. package/{src/index.ts → dist/index.d.ts} +27 -30
  2. package/dist/index.js +43 -0
  3. package/dist/managers/bet/GuildBetManager.d.ts +32 -0
  4. package/dist/managers/bet/GuildBetManager.js +107 -0
  5. package/dist/managers/betuser/GuildBetUserManager.d.ts +30 -0
  6. package/dist/managers/betuser/GuildBetUserManager.js +94 -0
  7. package/dist/managers/channel/ChannelManager.d.ts +39 -0
  8. package/dist/managers/channel/ChannelManager.js +147 -0
  9. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +34 -0
  10. package/dist/managers/groupedchannel/GroupedChannelManager.js +92 -0
  11. package/dist/managers/guild/GuildManager.d.ts +24 -0
  12. package/dist/managers/guild/GuildManager.js +75 -0
  13. package/dist/managers/match/GuildMatchManager.d.ts +32 -0
  14. package/dist/managers/match/GuildMatchManager.js +103 -0
  15. package/dist/managers/mediator/GuildMediatorManager.d.ts +32 -0
  16. package/dist/managers/mediator/GuildMediatorManager.js +97 -0
  17. package/dist/managers/messages/MessagesManager.d.ts +32 -0
  18. package/dist/managers/messages/MessagesManager.js +82 -0
  19. package/dist/managers/permission/GuildPermissionManager.d.ts +26 -0
  20. package/dist/managers/permission/GuildPermissionManager.js +70 -0
  21. package/dist/managers/product/GuildProductManager.d.ts +32 -0
  22. package/dist/managers/product/GuildProductManager.js +102 -0
  23. package/dist/managers/ticket/GuildTicketManager.d.ts +32 -0
  24. package/dist/managers/ticket/GuildTicketManager.js +99 -0
  25. package/dist/managers/user/GuildUserManager.d.ts +32 -0
  26. package/dist/managers/user/GuildUserManager.js +106 -0
  27. package/dist/rest/APIEndpoints.d.ts +11 -0
  28. package/dist/rest/APIEndpoints.js +12 -0
  29. package/dist/rest/REST.d.ts +51 -0
  30. package/dist/rest/REST.js +96 -0
  31. package/dist/rest/Routes.d.ts +84 -0
  32. package/dist/rest/Routes.js +89 -0
  33. package/dist/structures/Collection.d.ts +17 -0
  34. package/dist/structures/Collection.js +87 -0
  35. package/dist/structures/bet/GuildBet.d.ts +86 -0
  36. package/dist/structures/bet/GuildBet.js +276 -0
  37. package/dist/structures/betuser/GuildBetUser.d.ts +82 -0
  38. package/dist/structures/betuser/GuildBetUser.js +194 -0
  39. package/dist/structures/channel/Channel.d.ts +31 -0
  40. package/dist/structures/channel/Channel.js +57 -0
  41. package/dist/structures/groupedchannel/GroupedChannel.d.ts +34 -0
  42. package/dist/structures/groupedchannel/GroupedChannel.js +121 -0
  43. package/dist/structures/guild/Guild.d.ts +89 -0
  44. package/dist/structures/guild/Guild.js +223 -0
  45. package/dist/structures/match/GuildMatch.d.ts +84 -0
  46. package/dist/structures/match/GuildMatch.js +327 -0
  47. package/dist/structures/mediator/GuildMediator.d.ts +41 -0
  48. package/dist/structures/mediator/GuildMediator.js +131 -0
  49. package/dist/structures/product/GuildProduct.d.ts +52 -0
  50. package/dist/structures/product/GuildProduct.js +175 -0
  51. package/dist/structures/shop/GuildShop.d.ts +34 -0
  52. package/dist/structures/shop/GuildShop.js +80 -0
  53. package/dist/structures/ticket/GuildTicket.d.ts +51 -0
  54. package/dist/structures/ticket/GuildTicket.js +170 -0
  55. package/dist/structures/user/GuildUser.d.ts +82 -0
  56. package/dist/structures/user/GuildUser.js +209 -0
  57. package/dist/types/api/APIBaseChannel.d.ts +10 -0
  58. package/dist/types/api/APIBaseChannel.js +2 -0
  59. package/dist/types/api/APIBetChannel.d.ts +10 -0
  60. package/dist/types/api/APIBetChannel.js +2 -0
  61. package/dist/types/api/APIBetMessage.d.ts +10 -0
  62. package/dist/types/api/APIBetMessage.js +2 -0
  63. package/dist/types/api/APIGuild.d.ts +92 -0
  64. package/dist/types/api/APIGuild.js +2 -0
  65. package/dist/types/api/APIGuildBet.d.ts +48 -0
  66. package/dist/types/api/APIGuildBet.js +2 -0
  67. package/dist/types/api/APIGuildBetUser.d.ts +32 -0
  68. package/dist/types/api/APIGuildBetUser.js +2 -0
  69. package/dist/types/api/APIGuildChannel.d.ts +10 -0
  70. package/dist/types/api/APIGuildChannel.js +2 -0
  71. package/dist/types/api/APIGuildEmoji.d.ts +12 -0
  72. package/dist/types/api/APIGuildEmoji.js +2 -0
  73. package/dist/types/api/APIGuildGroupedChannel.d.ts +10 -0
  74. package/dist/types/api/APIGuildGroupedChannel.js +2 -0
  75. package/dist/types/api/APIGuildMatch.d.ts +46 -0
  76. package/dist/types/api/APIGuildMatch.js +2 -0
  77. package/dist/types/api/APIGuildMediator.d.ts +13 -0
  78. package/dist/types/api/APIGuildMediator.js +3 -0
  79. package/dist/types/api/APIGuildMessage.d.ts +10 -0
  80. package/dist/types/api/APIGuildMessage.js +2 -0
  81. package/dist/types/api/APIGuildPermissions.d.ts +6 -0
  82. package/dist/types/api/APIGuildPermissions.js +2 -0
  83. package/dist/types/api/APIGuildRole.d.ts +10 -0
  84. package/dist/types/api/APIGuildRole.js +2 -0
  85. package/dist/types/api/APIGuildShop.d.ts +11 -0
  86. package/dist/types/api/APIGuildShop.js +2 -0
  87. package/dist/types/api/APIGuildTicket.d.ts +25 -0
  88. package/dist/types/api/APIGuildTicket.js +3 -0
  89. package/dist/types/api/APIGuildUser.d.ts +31 -0
  90. package/dist/types/api/APIGuildUser.js +2 -0
  91. package/dist/types/api/APIMessage.d.ts +12 -0
  92. package/dist/types/api/APIMessage.js +2 -0
  93. package/dist/types/api/APIPlayer.d.ts +10 -0
  94. package/dist/types/api/APIPlayer.js +2 -0
  95. package/dist/types/api/APIProduct.d.ts +19 -0
  96. package/dist/types/api/APIProduct.js +3 -0
  97. package/dist/types/api/index.d.ts +130 -0
  98. package/dist/types/api/index.js +35 -0
  99. package/{src/types/index.ts → dist/types/index.d.ts} +21 -24
  100. package/dist/types/index.js +37 -0
  101. package/dist/utils/Assertion.d.ts +32 -0
  102. package/dist/utils/Assertion.js +60 -0
  103. package/package.json +5 -1
  104. package/.gitattributes +0 -2
  105. package/src/managers/bet/GuildBetManager.ts +0 -117
  106. package/src/managers/betuser/GuildBetUserManager.ts +0 -103
  107. package/src/managers/channel/ChannelManager.ts +0 -168
  108. package/src/managers/groupedchannel/GroupedChannelManager.ts +0 -117
  109. package/src/managers/guild/GuildManager.ts +0 -84
  110. package/src/managers/match/GuildMatchManager.ts +0 -115
  111. package/src/managers/mediator/GuildMediatorManager.ts +0 -111
  112. package/src/managers/messages/MessagesManager.ts +0 -95
  113. package/src/managers/permission/GuildPermissionManager.ts +0 -88
  114. package/src/managers/product/GuildProductManager.ts +0 -115
  115. package/src/managers/ticket/GuildTicketManager.ts +0 -112
  116. package/src/managers/user/GuildUserManager.ts +0 -116
  117. package/src/rest/APIEndpoints.ts +0 -11
  118. package/src/rest/REST.ts +0 -126
  119. package/src/rest/Routes.ts +0 -143
  120. package/src/structures/Collection.ts +0 -85
  121. package/src/structures/bet/GuildBet.ts +0 -332
  122. package/src/structures/betuser/GuildBetUser.ts +0 -247
  123. package/src/structures/channel/Channel.ts +0 -78
  124. package/src/structures/groupedchannel/GroupedChannel.ts +0 -165
  125. package/src/structures/guild/Guild.ts +0 -302
  126. package/src/structures/match/GuildMatch.ts +0 -385
  127. package/src/structures/mediator/GuildMediator.ts +0 -175
  128. package/src/structures/product/GuildProduct.ts +0 -217
  129. package/src/structures/shop/GuildShop.ts +0 -98
  130. package/src/structures/ticket/GuildTicket.ts +0 -227
  131. package/src/structures/user/GuildUser.ts +0 -248
  132. package/src/types/api/APIBaseChannel.ts +0 -13
  133. package/src/types/api/APIBetChannel.ts +0 -13
  134. package/src/types/api/APIBetMessage.ts +0 -13
  135. package/src/types/api/APIGuild.ts +0 -123
  136. package/src/types/api/APIGuildBet.ts +0 -69
  137. package/src/types/api/APIGuildBetUser.ts +0 -46
  138. package/src/types/api/APIGuildChannel.ts +0 -13
  139. package/src/types/api/APIGuildEmoji.ts +0 -16
  140. package/src/types/api/APIGuildGroupedChannel.ts +0 -13
  141. package/src/types/api/APIGuildMatch.ts +0 -67
  142. package/src/types/api/APIGuildMediator.ts +0 -18
  143. package/src/types/api/APIGuildMessage.ts +0 -13
  144. package/src/types/api/APIGuildPermissions.ts +0 -7
  145. package/src/types/api/APIGuildRole.ts +0 -13
  146. package/src/types/api/APIGuildShop.ts +0 -15
  147. package/src/types/api/APIGuildTicket.ts +0 -36
  148. package/src/types/api/APIGuildUser.ts +0 -45
  149. package/src/types/api/APIMessage.ts +0 -16
  150. package/src/types/api/APIPlayer.ts +0 -13
  151. package/src/types/api/APIProduct.ts +0 -27
  152. package/src/types/api/index.ts +0 -180
  153. package/src/utils/Assertion.ts +0 -56
  154. package/src/v1/managers/channel/ChannelManager.ts +0 -167
  155. package/src/v1/managers/match/GuildMatchManager.ts +0 -114
  156. package/tests/index.ts +0 -86
  157. package/tsconfig.json +0 -15
@@ -1,302 +0,0 @@
1
- import { GuildBetManager } from "../../managers/bet/GuildBetManager";
2
- import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
3
- import { GroupedChannelManager } from "../../managers/groupedchannel/GroupedChannelManager";
4
- import { GuildMatchManager } from "../../managers/match/GuildMatchManager";
5
- import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
6
- import { MessagesManager } from "../../managers/messages/MessagesManager";
7
- import { GuildPermissionManager } from "../../managers/permission/GuildPermissionManager";
8
- import { GuildTicketManager } from "../../managers/ticket/GuildTicketManager";
9
- import { GuildUserManager } from "../../managers/user/GuildUserManager";
10
- import { REST } from "../../rest/REST";
11
- import { Routes } from "../../rest/Routes";
12
- import { GuildBlacklist } from "../../types/api";
13
- import { APIBetMessage } from "../../types/api/APIBetMessage";
14
- import {
15
- APIGuild,
16
- GuildScores,
17
- GuildStatus,
18
- GuildTicketConfiguration,
19
- } from "../../types/api/APIGuild";
20
- import { APIGuildEmoji } from "../../types/api/APIGuildEmoji";
21
- import { APIGuildMediator } from "../../types/api/APIGuildMediator";
22
- import { APIGuildPermissions } from "../../types/api/APIGuildPermissions";
23
- import { APIGuildRole } from "../../types/api/APIGuildRole";
24
- import { APIGuildShop } from "../../types/api/APIGuildShop";
25
- import { APIGuildTicket } from "../../types/api/APIGuildTicket";
26
- import { APIGuildUser } from "../../types/api/APIGuildUser";
27
- import { Assertion } from "../../utils/Assertion";
28
- import { GuildBetUser } from "../betuser/GuildBetUser";
29
- import { GuildShop } from "../shop/GuildShop";
30
- import { GuildUser } from "../user/GuildUser";
31
-
32
- /** The Guild */
33
- export class Guild {
34
- /** The data of this guild */
35
- data: APIGuild;
36
-
37
- /** The rest client */
38
- rest: REST;
39
-
40
- /** The guild's id */
41
- id: string;
42
-
43
- /** Guild's client key */
44
- clientKey: string;
45
-
46
- /** Guild Permissions */
47
- permissions: APIGuildPermissions;
48
-
49
- /** Guild Ticket */
50
- tickets: GuildTicketManager;
51
-
52
- /** Guild Ticket Configuration */
53
- ticketsConfiguration: GuildTicketConfiguration;
54
-
55
- /** Guild Daily Categories */
56
- dailyCategories: ["coins", "credit"];
57
-
58
- /** Guild Scores */
59
- scores: GuildScores;
60
-
61
- /** Guild Status */
62
- status: GuildStatus;
63
-
64
- /** Guild Channel */
65
- channels: GroupedChannelManager;
66
-
67
- /** Guild Categories */
68
- categories: GroupedChannelManager;
69
-
70
- /** Guild Blacklist */
71
- blacklist: GuildBlacklist;
72
-
73
- /** Guild Prefix */
74
- prefix: string;
75
-
76
- /** Guild Prices */
77
- pricesAvailable: number[];
78
-
79
- /** Guild Prices Used */
80
- pricesOn: number[];
81
-
82
- /** Guild Creation Date */
83
- createdAt: Date;
84
-
85
- /** Guild Updated Date */
86
- updatedAt: Date;
87
-
88
- /** Guild Bets */
89
- bets: GuildBetManager;
90
-
91
- /** Guild Users */
92
- users: GuildUserManager;
93
-
94
- /** Guild Bet Users */
95
- betUsers: GuildBetUserManager;
96
-
97
- /** Guild Matches */
98
- matches: GuildMatchManager;
99
-
100
- /** Guild Mediators */
101
- mediators: GuildMediatorManager;
102
-
103
- /** Guild Messages */
104
- messages: MessagesManager;
105
-
106
- /** Guild Emojis */
107
- emojis: APIGuildEmoji[];
108
-
109
- /** Guild Roles */
110
- roles: APIGuildRole[];
111
-
112
- /** Guild Shop */
113
- shop: GuildShop;
114
-
115
- permissionsManager: GuildPermissionManager;
116
-
117
- /**
118
- * The guild structure
119
- * @param data The guild's data
120
- * @param rest The rest client
121
- */
122
- constructor(data: APIGuild, rest: REST) {
123
- this.data = data;
124
- this.rest = rest;
125
-
126
- this.id = data?.id;
127
- this.clientKey = data?.clientKey;
128
- this.prefix = data?.prefix;
129
- this.status = data?.status;
130
-
131
- this.ticketsConfiguration = data?.ticketsConfiguration;
132
- this.dailyCategories = data?.dailyCategories;
133
- this.scores = data?.scores;
134
-
135
- this.messages = new MessagesManager(this, this.id, rest);
136
- this.roles = data?.roles;
137
- this.emojis = data?.emojis;
138
-
139
- this.blacklist = data?.blacklist;
140
- this.pricesAvailable = data?.pricesAvailable;
141
- this.pricesOn = data?.pricesOn;
142
-
143
- this.shop = new GuildShop(data?.shop, this, rest);
144
-
145
- this.mediators = new GuildMediatorManager(this, rest);
146
- this.bets = new GuildBetManager(this, rest);
147
- this.users = new GuildUserManager(this, rest);
148
- this.betUsers = new GuildBetUserManager(this, rest);
149
- this.matches = new GuildMatchManager(this, rest);
150
- this.channels = new GroupedChannelManager(this, "channels", rest);
151
- this.categories = new GroupedChannelManager(this, "categories", rest);
152
- this.tickets = new GuildTicketManager(this, rest);
153
- this.permissionsManager = new GuildPermissionManager(this, rest);
154
-
155
- this.bets.setAll(data?.bets);
156
- this.users.setAll(data?.users);
157
- this.betUsers.setAll(data?.betUsers);
158
- this.channels.setAll(data?.channels);
159
- this.categories.setAll(data?.categories);
160
- this.matches.setAll(data?.matches);
161
- this.mediators.setAll(data?.mediators);
162
- this.tickets.setAll(data?.tickets);
163
- this.permissionsManager.setAll(data?.permissions);
164
- this.messages.setAll(data?.messages);
165
-
166
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
167
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
168
- }
169
-
170
- async fetch(): Promise<Guild> {
171
- const route = Routes.guilds.get(this.id);
172
- const response = await this.rest.request<APIGuild, {}>({
173
- method: "get",
174
- url: route,
175
- });
176
- const guild = new Guild(response, this.rest);
177
- this.rest.guilds.cache.set(guild.id, guild);
178
-
179
- return guild;
180
- }
181
-
182
- async setBlacklist(
183
- value: boolean,
184
- user: GuildBetUser | GuildUser,
185
- adminId: string
186
- ) {
187
- Assertion.assertBoolean(value);
188
- Assertion.assertString(adminId);
189
- const is_in_blacklist = this.blacklist.find((u) => u.id == user.id);
190
- if (is_in_blacklist && value == true) return this;
191
-
192
- const route = Routes.guilds.resource(this.id, "blacklist");
193
- const payload = { id: user.id, name: user.name, adminId, value };
194
-
195
- const [response] = await Promise.all([
196
- this.rest.request<APIGuild, typeof payload>({
197
- method: "PATCH",
198
- url: route,
199
- payload,
200
- }),
201
- user.setBlacklist(value),
202
- ]);
203
- this.blacklist = response.blacklist;
204
- this.rest.guilds.cache.set(this.id, this);
205
- this.rest.emit("guildUpdate", this);
206
- return this;
207
- }
208
- async setStatus(key: keyof GuildStatus, status: string) {
209
- Assertion.assertString(status);
210
-
211
- status = status.toLowerCase();
212
-
213
- const route = Routes.fields(Routes.guilds.resource(this.id, "status"), key);
214
- const payload = { status };
215
- const response = await this.rest.request<APIGuild, typeof payload>({
216
- method: "PATCH",
217
- url: route,
218
- payload,
219
- });
220
-
221
- this.status = response.status;
222
- this.rest.guilds.cache.set(this.id, this);
223
- this.rest.emit("guildUpdate", this);
224
- return this;
225
- }
226
- async addPrice(price: number) {
227
- Assertion.assertNumber(price);
228
-
229
- const route = Routes.fields(
230
- Routes.guilds.resource(this.id, "price"),
231
- "pricesOn"
232
- );
233
- const payload = { price };
234
- const response = await this.rest.request<APIGuild, typeof payload>({
235
- method: "PATCH",
236
- url: route,
237
- payload,
238
- });
239
- this.pricesAvailable = response.pricesAvailable;
240
- this.pricesOn = response.pricesOn;
241
- this.rest.guilds.cache.set(this.id, this);
242
- this.rest.emit("guildUpdate", this);
243
- return this;
244
- }
245
- async removePrice(price: number) {
246
- Assertion.assertNumber(price);
247
-
248
- const route = Routes.fields(
249
- Routes.guilds.resource(this.id, "price"),
250
- "pricesOn"
251
- );
252
- const payload = { price };
253
- const response = await this.rest.request<APIGuild, typeof payload>({
254
- method: "DELETE",
255
- url: route,
256
- payload,
257
- });
258
-
259
- this.pricesAvailable = response.pricesAvailable;
260
- this.pricesOn = response.pricesOn;
261
- this.rest.guilds.cache.set(this.id, this);
262
- this.rest.emit("guildUpdate", this);
263
- return this;
264
- }
265
-
266
- async setPrefix(prefix: string) {
267
- Assertion.assertString(prefix);
268
-
269
- const route = Routes.fields(Routes.guilds.resource(this.id, "prefix"));
270
- const payload = { prefix };
271
- const response = await this.rest.request<APIGuild, typeof payload>({
272
- method: "PATCH",
273
- url: route,
274
- payload,
275
- });
276
-
277
- this.prefix = response.prefix;
278
- this.rest.guilds.cache.set(this.id, this);
279
- this.rest.emit("guildUpdate", this);
280
- return this;
281
- }
282
- async addDailyCategory(category: string) {
283
- Assertion.assertString(category);
284
-
285
- const route = Routes.fields(
286
- Routes.guilds.resource(this.id, "dailyCategories")
287
- );
288
- const categories = [...new Set([...this.dailyCategories, category])];
289
-
290
- const payload = { categories };
291
- const response = await this.rest.request<APIGuild, typeof payload>({
292
- method: "PATCH",
293
- url: route,
294
- payload,
295
- });
296
-
297
- this.dailyCategories = response.dailyCategories;
298
- this.rest.guilds.cache.set(this.id, this);
299
- this.rest.emit("guildUpdate", this);
300
- return this;
301
- }
302
- }
@@ -1,385 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Guild } from "../guild/Guild";
4
- import { APIGuildMatch } from "../../types/api/APIGuildMatch";
5
- import { APIPlayer } from "../../types/api/APIPlayer";
6
- import { APIBetChannel } from "../../types/api/APIBetChannel";
7
- import { BaseMatchModes, BaseMatchStatus, Confirm, Optional } from "../../types/api";
8
- import { Assertion } from "../../utils/Assertion";
9
- import { ChannelManager } from "../../managers/channel/ChannelManager";
10
- import { APIGuildMessage } from "../../types/api/APIGuildMessage";
11
- import { GuildMatchManager } from "../../managers/match/GuildMatchManager";
12
- import { MessagesManager } from "../../managers/messages/MessagesManager";
13
-
14
- export class GuildMatch {
15
- /** Match's type */
16
- type: BaseMatchModes;
17
-
18
- /** Match's status */
19
- status: BaseMatchStatus;
20
-
21
- /** Match's challenge */
22
- challenge: boolean;
23
-
24
- /** Match's players */
25
- players: APIPlayer[];
26
-
27
- /** Match's winners */
28
- winners: APIPlayer[];
29
-
30
- /** Match's losers */
31
- losers: APIPlayer[];
32
-
33
- /** Match;s messages */
34
- messages: MessagesManager;
35
-
36
- /** Matches channels */
37
- channels: ChannelManager<GuildMatch>;
38
-
39
- /** Match's maximum size */
40
- maximumSize: number;
41
-
42
- /** Match's kicked out */
43
- kickedOut: APIPlayer[];
44
-
45
- /** Match's team a */
46
- teamA: APIPlayer[];
47
-
48
- /** Match's team b */
49
- teamB: APIPlayer[];
50
-
51
- /** Match's confirmed */
52
- confirmed: Confirm[];
53
-
54
- /** Match's leaders */
55
- leaders: APIPlayer[];
56
-
57
- /** Match's mvp */
58
- mvpId: string;
59
-
60
- /** Match's creator id */
61
- creatorId: string;
62
-
63
- /** Match's room creator id */
64
- roomCreatorId: string;
65
-
66
- /** Creation Date */
67
- createdAt: Date;
68
-
69
- /** Updated Date */
70
- updatedAt: Date;
71
-
72
- /** Match's id */
73
- _id: string;
74
-
75
- manager: GuildMatchManager;
76
-
77
- /** The given guild */
78
- readonly guild: Guild;
79
-
80
- /** The rest client */
81
- readonly rest: REST;
82
- readonly key: string;
83
-
84
- /**
85
- * GuildMatch match
86
- * @param data The match's data
87
- * @param guild The guild
88
- * @param rest The rest client
89
- */
90
-
91
- constructor(data: APIGuildMatch, guild: Guild, manager: GuildMatchManager, rest: REST) {
92
- this._id = data?._id;
93
- this.manager = manager;
94
-
95
- this.challenge = data?.challenge;
96
- this.kickedOut = data?.kickedOut;
97
- this.leaders = data?.leaders;
98
- this.type = data?.type;
99
- this.status = data?.status;
100
- this.maximumSize = data?.maximumSize;
101
- this.players = data?.players;
102
- this.teamA = data?.teamA;
103
- this.teamB = data?.teamB;
104
- this.winners = data?.winners;
105
- this.losers = data?.losers;
106
- this.creatorId = data?.creatorId;
107
- this.roomCreatorId = data?.roomCreatorId;
108
- this.confirmed = data?.confirmed;
109
- this.mvpId = data?.mvpId;
110
-
111
- this.key = "matches";
112
- this.channels = new ChannelManager<GuildMatch>(guild, this, rest);
113
- this.messages = new MessagesManager(guild, this?._id, rest);
114
-
115
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
116
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
117
-
118
- this.guild = guild;
119
- this.rest = rest;
120
-
121
- this.channels.setAll(data?.channels);
122
- this.messages.setAll(data?.messages);
123
- }
124
-
125
- /**
126
- * Fetches the match
127
- * @returns New Instance of the match
128
- */
129
- async fetch(): Promise<GuildMatch> {
130
- const route = Routes.guilds.matches.get(this.guild.id, this._id);
131
- const response = await this.rest.request<APIGuildMatch, {}>({
132
- method: "get",
133
- url: route,
134
- });
135
-
136
- const match = new GuildMatch(response, this.guild, this.manager, this.rest);
137
- this.manager.cache.set(match._id, match);
138
- return match;
139
- }
140
- async addMessage(id: string, type: string, content?: string) {
141
- const response = await this.messages.create({
142
- userId: id,
143
- type: type as "img",
144
- content,
145
- });
146
-
147
- this.manager.cache.set(this._id, this);
148
- this.rest.matches.set(this._id, this);
149
- return response;
150
- }
151
- async addConfirmed(type: string, id: string): Promise<Confirm> {
152
- Assertion.assertString(type);
153
- Assertion.assertString(id);
154
-
155
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "confirmed");
156
- const payload = { type, id };
157
-
158
- const response = await this.rest.request<Confirm[], typeof payload>({
159
- method: "PATCH",
160
- url: route,
161
- payload,
162
- });
163
-
164
- this.rest.emit("matchUpdate", this);
165
-
166
- this.updatedAt = new Date();
167
- this.confirmed = response;
168
- this.rest.matches.set(this._id, this);
169
- this.manager.cache.set(this._id, this);
170
- return this.confirmed.find((c) => c.type === type);
171
- }
172
- async setConfirmed(set: Confirm[]): Promise<GuildMatch> {
173
- Assertion.assertObject(set);
174
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "confirmed");
175
-
176
- const response = await this.rest.request<Confirm[], typeof set>({
177
- method: "PATCH",
178
- url: route,
179
- payload: set,
180
- });
181
-
182
- this.confirmed = response;
183
- this.rest.matches.set(this._id, this);
184
- this.manager.cache.set(this._id, this);
185
- return this;
186
- }
187
-
188
- async setStatus(status: BaseMatchStatus): Promise<GuildMatch> {
189
- Assertion.assertString(status);
190
-
191
- const payload = { set: status.toLowerCase() };
192
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "status");
193
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
194
- method: "PATCH",
195
- url: route,
196
- payload,
197
- });
198
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
199
- this.status = response.status;
200
- this.rest.matches.set(this._id, this);
201
- this.manager.cache.set(this._id, this);
202
- return this;
203
- }
204
- async setWinners(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch> {
205
- if (!Array.isArray(players)) players = [players];
206
-
207
- const payload = { winners: players };
208
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "winners");
209
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
210
- method: "PATCH",
211
- url: route,
212
- payload,
213
- });
214
-
215
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
216
- this.winners = response.winners;
217
- this.rest.matches.set(this._id, this);
218
- this.manager.cache.set(this._id, this);
219
- return this;
220
- }
221
- async setLoser(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch> {
222
- if (!Array.isArray(players)) players = [players];
223
-
224
- const payload = { losers: players };
225
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "losers");
226
- const response = await this.rest.request<APIGuildMatch, {}>({
227
- method: "PATCH",
228
- url: route,
229
- payload,
230
- });
231
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
232
- this.losers = response.losers;
233
- this.rest.matches.set(this._id, this);
234
- this.manager.cache.set(this._id, this);
235
- return this;
236
- }
237
- async setMvp(userId: string): Promise<GuildMatch> {
238
- Assertion.assertString(userId);
239
-
240
- const payload = { id: userId };
241
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "mvp");
242
- const response = await this.rest.request<APIGuildMatch, {}>({
243
- method: "PATCH",
244
- url: route,
245
- payload,
246
- });
247
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
248
- this.mvpId = response.mvpId;
249
- this.rest.matches.set(this._id, this);
250
- this.manager.cache.set(this._id, this);
251
- return this;
252
- }
253
- async setRoomCreatorId(userId: string): Promise<GuildMatch> {
254
- Assertion.assertString(userId);
255
-
256
- const payload = { id: userId };
257
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "roomCreatorId");
258
- const response = await this.rest.request<APIGuildMatch, {}>({
259
- method: "PATCH",
260
- url: route,
261
- payload,
262
- });
263
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
264
- this.roomCreatorId = response.roomCreatorId;
265
- this.rest.matches.set(this._id, this);
266
- this.manager.cache.set(this._id, this);
267
- return this;
268
- }
269
- async kick(player: APIPlayer) {
270
- const payload = { ...player };
271
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "kickout");
272
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
273
- method: "PATCH",
274
- url: route,
275
- payload,
276
- });
277
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
278
- this.kickedOut = response.kickedOut;
279
- this.rest.matches.set(this._id, this);
280
- this.manager.cache.set(this._id, this);
281
- return this;
282
- }
283
- async addChannel(id: string, type: string): Promise<GuildMatch> {
284
- await this.channels.create(id, type);
285
- this.rest.matches.set(this._id, this);
286
- this.manager.cache.set(this._id, this);
287
- return this;
288
- }
289
-
290
- async setChannels(channels: APIBetChannel[]): Promise<GuildMatch> {
291
- Assertion.assertObject(channels);
292
-
293
- const payload = { set: channels };
294
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "channels");
295
- const response = await this.rest.request<APIGuildMatch, {}>({
296
- method: "PATCH",
297
- url: route,
298
- payload,
299
- });
300
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
301
- this.channels.setAll(response.channels);
302
- this.rest.matches.set(this._id, this);
303
- this.manager.cache.set(this._id, this);
304
- return this;
305
- }
306
-
307
- async addPlayer(id: string, name: string): Promise<GuildMatch> {
308
- Assertion.assertString(id);
309
- Assertion.assertString(name);
310
-
311
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "players");
312
- const payload = { id, name };
313
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
314
- method: "POST",
315
- url: route,
316
- payload,
317
- });
318
- console.log({ response });
319
-
320
- this.players = response.players;
321
- this.rest.matches.set(this._id, this);
322
- this.manager.cache.set(this._id, this);
323
- return this;
324
- }
325
- async removePlayer(id: string, name: string): Promise<GuildMatch> {
326
- Assertion.assertString(id);
327
- Assertion.assertString(name);
328
-
329
- const route = Routes.guilds.matches.resource(this.guild.id, this._id, "players", id);
330
- const payload = { id, name };
331
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
332
- method: "DELETE",
333
- url: route,
334
- payload,
335
- });
336
-
337
- this.players = response.players;
338
- this.rest.matches.set(this?._id, this);
339
- this.manager.cache.set(this?._id, this);
340
- return this;
341
- }
342
-
343
- async update(data: Optional<APIGuildMatch>): Promise<GuildMatch> {
344
- const route = Routes.guilds.matches.get(this.guild.id, this._id);
345
- const payload = data;
346
-
347
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
348
- method: "patch",
349
- url: route,
350
- payload,
351
- });
352
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
353
- for (const k in response) {
354
- if (k === "id" || k == "createdAt") continue;
355
- if (Object.hasOwn(this, k)) {
356
- if (k === "channels") {
357
- console.log({ chs: response["channels"] });
358
- this.channels.setAll(response["channels"]);
359
- console.log({ chs2: this.channels.cache });
360
- continue;
361
- }
362
- if (k === "messages") {
363
- this.messages.setAll(response["messages"]);
364
- continue;
365
- }
366
-
367
- (this as any)[k] = response[k as keyof APIGuildMatch];
368
- }
369
- }
370
-
371
- this.updatedAt = new Date();
372
- this.manager.cache.set(this._id, this);
373
- this.rest.matches.set(this._id, this);
374
- return this;
375
- }
376
- toJSON() {
377
- const json: Record<string, unknown> = {};
378
- for (const [key, value] of Object.entries(this)) {
379
- if (typeof value !== "function") {
380
- json[key] = value;
381
- }
382
- }
383
- return json;
384
- }
385
- }