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