@duque.edits/sdk 0.0.4 → 0.0.6

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 (155) hide show
  1. package/{v1/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 +90 -0
  44. package/dist/structures/guild/Guild.js +254 -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 +208 -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 +93 -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/{v1/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 +15 -1
  104. package/.gitattributes +0 -2
  105. package/tests/index.ts +0 -86
  106. package/tsconfig.json +0 -15
  107. package/v1/managers/bet/GuildBetManager.ts +0 -117
  108. package/v1/managers/betuser/GuildBetUserManager.ts +0 -103
  109. package/v1/managers/channel/ChannelManager.ts +0 -168
  110. package/v1/managers/groupedchannel/GroupedChannelManager.ts +0 -117
  111. package/v1/managers/guild/GuildManager.ts +0 -84
  112. package/v1/managers/match/GuildMatchManager.ts +0 -115
  113. package/v1/managers/mediator/GuildMediatorManager.ts +0 -111
  114. package/v1/managers/messages/MessagesManager.ts +0 -95
  115. package/v1/managers/permission/GuildPermissionManager.ts +0 -88
  116. package/v1/managers/product/GuildProductManager.ts +0 -115
  117. package/v1/managers/ticket/GuildTicketManager.ts +0 -112
  118. package/v1/managers/user/GuildUserManager.ts +0 -116
  119. package/v1/rest/APIEndpoints.ts +0 -11
  120. package/v1/rest/REST.ts +0 -126
  121. package/v1/rest/Routes.ts +0 -143
  122. package/v1/structures/Collection.ts +0 -85
  123. package/v1/structures/bet/GuildBet.ts +0 -332
  124. package/v1/structures/betuser/GuildBetUser.ts +0 -247
  125. package/v1/structures/channel/Channel.ts +0 -78
  126. package/v1/structures/groupedchannel/GroupedChannel.ts +0 -165
  127. package/v1/structures/guild/Guild.ts +0 -302
  128. package/v1/structures/match/GuildMatch.ts +0 -385
  129. package/v1/structures/mediator/GuildMediator.ts +0 -175
  130. package/v1/structures/product/GuildProduct.ts +0 -217
  131. package/v1/structures/shop/GuildShop.ts +0 -98
  132. package/v1/structures/ticket/GuildTicket.ts +0 -227
  133. package/v1/structures/user/GuildUser.ts +0 -248
  134. package/v1/types/api/APIBaseChannel.ts +0 -13
  135. package/v1/types/api/APIBetChannel.ts +0 -13
  136. package/v1/types/api/APIBetMessage.ts +0 -13
  137. package/v1/types/api/APIGuild.ts +0 -123
  138. package/v1/types/api/APIGuildBet.ts +0 -69
  139. package/v1/types/api/APIGuildBetUser.ts +0 -46
  140. package/v1/types/api/APIGuildChannel.ts +0 -13
  141. package/v1/types/api/APIGuildEmoji.ts +0 -16
  142. package/v1/types/api/APIGuildGroupedChannel.ts +0 -13
  143. package/v1/types/api/APIGuildMatch.ts +0 -67
  144. package/v1/types/api/APIGuildMediator.ts +0 -18
  145. package/v1/types/api/APIGuildMessage.ts +0 -13
  146. package/v1/types/api/APIGuildPermissions.ts +0 -7
  147. package/v1/types/api/APIGuildRole.ts +0 -13
  148. package/v1/types/api/APIGuildShop.ts +0 -15
  149. package/v1/types/api/APIGuildTicket.ts +0 -36
  150. package/v1/types/api/APIGuildUser.ts +0 -45
  151. package/v1/types/api/APIMessage.ts +0 -16
  152. package/v1/types/api/APIPlayer.ts +0 -13
  153. package/v1/types/api/APIProduct.ts +0 -27
  154. package/v1/types/api/index.ts +0 -180
  155. package/v1/utils/Assertion.ts +0 -56
@@ -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
- }
@@ -1,175 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Guild } from "../guild/Guild";
4
- import { APIGuildMediator } from "../../types/api/APIGuildMediator";
5
- import { Optional } from "../../types/api";
6
- import { Assertion } from "../../utils/Assertion";
7
- import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
8
-
9
- export class GuildMediator {
10
- /** Mediator's id */
11
- id: string;
12
-
13
- /** Mediator's name */
14
- name: string;
15
-
16
- /** Mediator's links */
17
- paymentLinks: string[];
18
-
19
- /** Creation Date */
20
- createdAt: Date;
21
-
22
- /** Updated Date */
23
- updatedAt: Date;
24
-
25
- /** The given guild */
26
- readonly guild: Guild;
27
-
28
- /** The rest client */
29
- readonly rest: REST;
30
- readonly manager: GuildMediatorManager;
31
-
32
- /**
33
- * GuildMediator mediator
34
- * @param data The mediator's data
35
- * @param guild The guild
36
- * @param rest The rest client
37
- */
38
- constructor(
39
- data: APIGuildMediator,
40
- guild: Guild,
41
- manager: GuildMediatorManager,
42
- rest: REST
43
- ) {
44
- this.id = data.id;
45
- this.name = data.name;
46
- this.paymentLinks = data.paymentLinks;
47
-
48
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
49
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
50
-
51
- this.guild = guild;
52
- this.rest = rest;
53
- this.manager = manager;
54
- }
55
- /** String representation of this mediator */
56
- toString() {
57
- return `<@${this.id}>`;
58
- }
59
- /**
60
- * Fetches the mediator
61
- * @returns New Instance of the mediator
62
- */
63
- async fetch() {
64
- const route = Routes.guilds.mediators.get(this.guild.id, this.id);
65
- const response = await this.rest.request<APIGuildMediator, {}>({
66
- method: "get",
67
- url: route,
68
- });
69
-
70
- const med = new GuildMediator(
71
- response,
72
- this.guild,
73
- this.manager,
74
- this.rest
75
- );
76
- this.manager.cache.set(med.id, med);
77
- this.rest.mediators.set(med.id, med);
78
- return med;
79
- }
80
-
81
- async update(data: Optional<APIGuildMediator>) {
82
- const route = Routes.guilds.mediators.get(this.guild.id, this.id);
83
- const payload = data;
84
-
85
- const response = await this.rest.request<APIGuildMediator, typeof payload>({
86
- method: "patch",
87
- url: route,
88
- payload,
89
- });
90
- const med = new GuildMediator(
91
- response,
92
- this.guild,
93
- this.manager,
94
- this.rest
95
- );
96
- this.rest.emit("mediatorUpdate", this);
97
- for (const k in response) {
98
- if (k === "id") continue;
99
-
100
- if (Object.hasOwn(this, k)) {
101
- (this as any)[k] = response[k as keyof APIGuildMediator];
102
- }
103
- }
104
- this.manager.cache.set(med.id, med);
105
- this.rest.emit("mediatorUpdate", this, med);
106
- return this;
107
- }
108
-
109
- async delete() {
110
- const route = Routes.guilds.mediators.delete(this.guild.id, this.id);
111
- const response = await this.rest.request<boolean, {}>({
112
- method: "DELETE",
113
- url: route,
114
- });
115
-
116
- this.manager.cache.delete(this.id);
117
- this.rest.mediators.delete(this.id);
118
- this.rest.emit("mediatorUpdate", this);
119
- return response;
120
- }
121
- async setLinks(link: string) {
122
- Assertion.assertString(link);
123
-
124
- const route = Routes.guilds.mediators.resource(
125
- this.guild.id,
126
- this.id,
127
- "links"
128
- );
129
- const payload = { paymentLinks: [link], set: true };
130
- const response = await this.rest.request<APIGuildMediator, {}>({
131
- method: "PATCH",
132
- url: route,
133
- payload,
134
- });
135
-
136
- this.paymentLinks = response.paymentLinks;
137
- this.manager.cache.set(this.id, this);
138
- this.rest.mediators.set(this.id, this);
139
- this.rest.emit("mediatorUpdate", this);
140
- return this.paymentLinks;
141
- }
142
- async removeLink(link: string) {
143
- Assertion.assertString(link);
144
-
145
- const route = Routes.guilds.mediators.resource(
146
- this.guild.id,
147
- this.id,
148
- "links"
149
- );
150
-
151
- const payload = {
152
- paymentLinks: this.paymentLinks.filter((lm) => lm !== link),
153
- };
154
- const response = await this.rest.request<APIGuildMediator, {}>({
155
- method: "PATCH",
156
- url: route,
157
- payload,
158
- });
159
-
160
- this.paymentLinks = response.paymentLinks;
161
- this.manager.cache.set(this.id, this);
162
- this.rest.mediators.set(this.id, this);
163
- this.rest.emit("mediatorUpdate", this);
164
- return this.paymentLinks;
165
- }
166
- toJSON() {
167
- const json: Record<string, unknown> = {};
168
- for (const [key, value] of Object.entries(this)) {
169
- if (typeof value !== "function") {
170
- json[key] = value;
171
- }
172
- }
173
- return json;
174
- }
175
- }