@duque.edits/sdk 0.1.5 → 0.1.7

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 (118) hide show
  1. package/dist/index.js +4 -31
  2. package/dist/managers/base.js +26 -0
  3. package/dist/managers/buffer/BufferManager.js +2 -2
  4. package/dist/managers/guild/GuildManager.js +42 -25
  5. package/dist/managers/index.js +23 -0
  6. package/dist/managers/match/GuildMatchManager.js +42 -31
  7. package/dist/managers/message/MessagesManager.js +48 -0
  8. package/dist/managers/permission/GuildPermissionManager.js +29 -52
  9. package/dist/managers/ticket/TicketManager.js +77 -0
  10. package/dist/managers/user/GuildUserManager.js +73 -85
  11. package/dist/managers/vipmember/VipMemberManager.js +23 -23
  12. package/dist/rest/REST.js +40 -24
  13. package/dist/rest/Routes.js +15 -17
  14. package/dist/rest/index.js +19 -0
  15. package/dist/structures/Collection.js +1 -1
  16. package/dist/structures/guild/Guild.js +59 -94
  17. package/dist/structures/index.js +22 -0
  18. package/dist/structures/match/GuildMatch.js +64 -111
  19. package/dist/structures/ticket/Ticket.js +119 -0
  20. package/dist/structures/user/GuildUser.js +46 -40
  21. package/dist/structures/vipmember/VipMember.js +5 -5
  22. package/dist/types/api/APILogMessage.js +2 -0
  23. package/dist/types/api/index.js +36 -0
  24. package/dist/types/index.js +1 -22
  25. package/package.json +11 -18
  26. package/types/index.d.ts +4 -0
  27. package/types/managers/base.d.ts +17 -0
  28. package/{dist → types}/managers/buffer/BufferManager.d.ts +2 -1
  29. package/{dist → types}/managers/guild/GuildManager.d.ts +12 -4
  30. package/types/managers/index.d.ts +7 -0
  31. package/{dist → types}/managers/match/GuildMatchManager.d.ts +10 -12
  32. package/types/managers/message/MessagesManager.d.ts +17 -0
  33. package/types/managers/permission/GuildPermissionManager.d.ts +8 -0
  34. package/types/managers/ticket/TicketManager.d.ts +22 -0
  35. package/types/managers/user/GuildUserManager.d.ts +19 -0
  36. package/{dist → types}/managers/vipmember/VipMemberManager.d.ts +8 -8
  37. package/types/rest/APIEndpoints.d.ts +11 -0
  38. package/{dist → types}/rest/REST.d.ts +9 -18
  39. package/{dist → types}/rest/Routes.d.ts +2 -2
  40. package/types/rest/index.d.ts +3 -0
  41. package/{dist → types}/structures/guild/Guild.d.ts +12 -29
  42. package/types/structures/index.d.ts +6 -0
  43. package/{dist → types}/structures/match/GuildMatch.d.ts +12 -22
  44. package/types/structures/ticket/Ticket.d.ts +30 -0
  45. package/{dist → types}/structures/user/GuildUser.d.ts +5 -3
  46. package/{dist → types}/structures/vipmember/VipMember.d.ts +1 -1
  47. package/types/types/RestTypes.d.ts +34 -0
  48. package/{dist → types}/types/api/APIGuild.d.ts +9 -2
  49. package/{dist → types}/types/api/APIGuildMatch.d.ts +9 -7
  50. package/types/types/api/APIGuildTicket.d.ts +16 -0
  51. package/{dist → types}/types/api/APIGuildUser.d.ts +3 -1
  52. package/types/types/api/APILogMessage.d.ts +7 -0
  53. package/{dist → types}/types/api/APIMessage.d.ts +3 -4
  54. package/{dist → types}/types/api/APIPlayer.d.ts +1 -1
  55. package/{dist → types}/types/api/index.d.ts +23 -1
  56. package/types/types/index.d.ts +2 -0
  57. package/dist/index.d.ts +0 -31
  58. package/dist/managers/bet/GuildBetManager.d.ts +0 -35
  59. package/dist/managers/bet/GuildBetManager.js +0 -126
  60. package/dist/managers/betuser/GuildBetUserManager.d.ts +0 -36
  61. package/dist/managers/betuser/GuildBetUserManager.js +0 -151
  62. package/dist/managers/channel/ChannelManager.d.ts +0 -39
  63. package/dist/managers/channel/ChannelManager.js +0 -148
  64. package/dist/managers/giveaway/GiveawayManager.d.ts +0 -16
  65. package/dist/managers/giveaway/GiveawayManager.js +0 -57
  66. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +0 -34
  67. package/dist/managers/groupedchannel/GroupedChannelManager.js +0 -92
  68. package/dist/managers/mediator/GuildMediatorManager.d.ts +0 -32
  69. package/dist/managers/mediator/GuildMediatorManager.js +0 -98
  70. package/dist/managers/messages/MessagesManager.d.ts +0 -32
  71. package/dist/managers/messages/MessagesManager.js +0 -89
  72. package/dist/managers/permission/GuildPermissionManager.d.ts +0 -26
  73. package/dist/managers/product/GuildProductManager.d.ts +0 -32
  74. package/dist/managers/product/GuildProductManager.js +0 -103
  75. package/dist/managers/ticket/GuildTicketManager.d.ts +0 -32
  76. package/dist/managers/ticket/GuildTicketManager.js +0 -100
  77. package/dist/managers/user/GuildUserManager.d.ts +0 -33
  78. package/dist/rest/APIEndpoints.d.ts +0 -11
  79. package/dist/structures/bet/GuildBet.d.ts +0 -87
  80. package/dist/structures/bet/GuildBet.js +0 -286
  81. package/dist/structures/betuser/GuildBetUser.d.ts +0 -85
  82. package/dist/structures/betuser/GuildBetUser.js +0 -211
  83. package/dist/structures/channel/Channel.d.ts +0 -31
  84. package/dist/structures/channel/Channel.js +0 -57
  85. package/dist/structures/giveaway/Giveaway.d.ts +0 -37
  86. package/dist/structures/giveaway/Giveaway.js +0 -208
  87. package/dist/structures/groupedchannel/GroupedChannel.d.ts +0 -34
  88. package/dist/structures/groupedchannel/GroupedChannel.js +0 -121
  89. package/dist/structures/mediator/GuildMediator.d.ts +0 -41
  90. package/dist/structures/mediator/GuildMediator.js +0 -131
  91. package/dist/structures/product/GuildProduct.d.ts +0 -52
  92. package/dist/structures/product/GuildProduct.js +0 -175
  93. package/dist/structures/shop/GuildShop.d.ts +0 -34
  94. package/dist/structures/shop/GuildShop.js +0 -80
  95. package/dist/structures/ticket/GuildTicket.d.ts +0 -52
  96. package/dist/structures/ticket/GuildTicket.js +0 -172
  97. package/dist/types/api/APIGuildTicket.d.ts +0 -26
  98. package/dist/types/index.d.ts +0 -23
  99. /package/dist/types/{api/APIGuildMessage.js → RestTypes.js} +0 -0
  100. /package/{dist → types}/structures/Collection.d.ts +0 -0
  101. /package/{dist → types}/types/api/APIBaseChannel.d.ts +0 -0
  102. /package/{dist → types}/types/api/APIBetChannel.d.ts +0 -0
  103. /package/{dist → types}/types/api/APIBetMessage.d.ts +0 -0
  104. /package/{dist → types}/types/api/APIGiveaway.d.ts +0 -0
  105. /package/{dist → types}/types/api/APIGuildBet.d.ts +0 -0
  106. /package/{dist → types}/types/api/APIGuildBetUser.d.ts +0 -0
  107. /package/{dist → types}/types/api/APIGuildChannel.d.ts +0 -0
  108. /package/{dist → types}/types/api/APIGuildEmoji.d.ts +0 -0
  109. /package/{dist → types}/types/api/APIGuildGroupedChannel.d.ts +0 -0
  110. /package/{dist → types}/types/api/APIGuildMediator.d.ts +0 -0
  111. /package/{dist → types}/types/api/APIGuildMessage.d.ts +0 -0
  112. /package/{dist → types}/types/api/APIGuildPermissions.d.ts +0 -0
  113. /package/{dist → types}/types/api/APIGuildRole.d.ts +0 -0
  114. /package/{dist → types}/types/api/APIGuildShop.d.ts +0 -0
  115. /package/{dist → types}/types/api/APIProduct.d.ts +0 -0
  116. /package/{dist → types}/types/api/APIVipMember.d.ts +0 -0
  117. /package/{dist → types}/utils/Assertion.d.ts +0 -0
  118. /package/{dist → types}/utils/getRandomNumber.d.ts +0 -0
@@ -1,20 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Guild = void 0;
4
- const GuildBetManager_1 = require("../../managers/bet/GuildBetManager");
5
- const GuildBetUserManager_1 = require("../../managers/betuser/GuildBetUserManager");
4
+ const GuildPermissionManager_1 = require("../../managers/permission/GuildPermissionManager");
6
5
  const BufferManager_1 = require("../../managers/buffer/BufferManager");
7
- const GroupedChannelManager_1 = require("../../managers/groupedchannel/GroupedChannelManager");
8
6
  const GuildMatchManager_1 = require("../../managers/match/GuildMatchManager");
9
- const GuildMediatorManager_1 = require("../../managers/mediator/GuildMediatorManager");
10
- const MessagesManager_1 = require("../../managers/messages/MessagesManager");
11
- const GuildPermissionManager_1 = require("../../managers/permission/GuildPermissionManager");
12
- const GuildTicketManager_1 = require("../../managers/ticket/GuildTicketManager");
13
- const GuildUserManager_1 = require("../../managers/user/GuildUserManager");
14
- const VipMemberManager_1 = require("../../managers/vipmember/VipMemberManager");
15
7
  const Routes_1 = require("../../rest/Routes");
16
8
  const Assertion_1 = require("../../utils/Assertion");
17
- const GuildShop_1 = require("../shop/GuildShop");
9
+ const GuildUserManager_1 = require("../../managers/user/GuildUserManager");
10
+ const managers_1 = require("../../managers");
18
11
  /** The Guild */
19
12
  class Guild {
20
13
  /** The data of this guild */
@@ -23,14 +16,15 @@ class Guild {
23
16
  rest;
24
17
  /** The guild's id */
25
18
  id;
19
+ modes;
26
20
  /** Guild's client key */
27
21
  clientKey;
28
22
  /** Guild Permissions */
29
23
  permissions;
30
24
  /** Guild Ticket */
31
- tickets;
25
+ //tickets: GuildTicketManager;
32
26
  /** Guild Ticket Configuration */
33
- ticketsConfiguration;
27
+ tickets_configuration;
34
28
  /** Guild Daily Categories */
35
29
  dailyCategories;
36
30
  /** Guild Scores */
@@ -38,9 +32,9 @@ class Guild {
38
32
  /** Guild Status */
39
33
  status;
40
34
  /** Guild Channel */
41
- channels;
35
+ //channels: GroupedChannelManager;
42
36
  /** Guild Categories */
43
- categories;
37
+ // categories: GroupedChannelManager;
44
38
  /** Guild Blacklist */
45
39
  blacklist;
46
40
  /** Guild Prefix */
@@ -53,85 +47,67 @@ class Guild {
53
47
  createdAt;
54
48
  /** Guild Updated Date */
55
49
  updatedAt;
56
- /** Guild Bets */
57
- bets;
58
50
  /** Guild Users */
59
- users;
51
+ //users: GuildUserManager;
60
52
  /** Guild Bet Users */
61
- betUsers;
53
+ // betUsers: GuildBetUserManager;
62
54
  /** Guild Matches */
63
55
  matches;
64
- /** Guild Mediators */
65
- mediators;
66
- /** Guild Messages */
67
- messages;
68
56
  /** Guild Emojis */
69
57
  emojis;
70
58
  /** Guild Roles */
71
59
  roles;
72
60
  /** Guild Prices Used */
73
61
  prices;
74
- /** Guild Shop */
75
- shop;
76
62
  permissionsManager;
77
63
  buffer;
78
64
  vipMembers;
65
+ users;
66
+ tickets;
79
67
  /**
80
68
  * The guild structure
81
69
  * @param data The guild's data
82
70
  * @param rest The rest client
83
71
  */
84
72
  constructor(data, rest) {
73
+ this.id = data?.id;
85
74
  this.data = data;
86
75
  this.rest = rest;
87
- this.id = data?.id;
88
76
  this.clientKey = data?.clientKey;
89
77
  this.prefix = data?.prefix;
90
78
  this.status = data?.status;
91
- this.ticketsConfiguration = data?.ticketsConfiguration;
79
+ this.tickets_configuration = data?.tickets_configuration;
92
80
  this.permissions = data?.permissions;
93
81
  this.dailyCategories = data?.dailyCategories;
94
82
  this.scores = data?.scores;
95
- this.messages = new MessagesManager_1.MessagesManager(this, this.id, rest);
83
+ this.modes = data?.modes;
96
84
  this.roles = data?.roles;
97
85
  this.emojis = data?.emojis;
98
86
  this.pricesAvailable = data?.pricesAvailable;
99
87
  this.pricesOn = data?.pricesOn;
100
88
  this.prices = data?.prices;
101
- this.shop = new GuildShop_1.GuildShop(data?.shop, this, rest);
102
89
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
103
90
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
104
- this.blacklist = [];
105
- for (let blacklisted of data?.blacklist) {
106
- this.blacklist.push({
107
- addedBy: blacklisted.addedBy,
108
- id: blacklisted.id,
109
- createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
110
- updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
111
- });
112
- }
113
- this.mediators = new GuildMediatorManager_1.GuildMediatorManager(this, rest);
114
- this.bets = new GuildBetManager_1.GuildBetManager(this, rest);
115
- this.users = new GuildUserManager_1.GuildUserManager(this, rest);
116
- this.betUsers = new GuildBetUserManager_1.GuildBetUserManager(this, rest);
117
- this.matches = new GuildMatchManager_1.GuildMatchManager(this, rest);
118
- this.channels = new GroupedChannelManager_1.GroupedChannelManager(this, "channels", rest);
119
- this.categories = new GroupedChannelManager_1.GroupedChannelManager(this, "categories", rest);
120
- this.tickets = new GuildTicketManager_1.GuildTicketManager(this, rest);
121
- this.permissionsManager = new GuildPermissionManager_1.GuildPermissionManager(this, rest);
122
- this.vipMembers = new VipMemberManager_1.VipMemberManager(this, rest);
91
+ this.permissionsManager = new GuildPermissionManager_1.GuildPermissionManager(this);
92
+ this.users = new GuildUserManager_1.GuildUserManager(this);
93
+ this.matches = new GuildMatchManager_1.GuildMatchManager(this);
123
94
  this.buffer = new BufferManager_1.BufferManager(this);
124
- this.bets.setAll(data?.bets);
125
- this.users.setAll(data?.users);
126
- this.betUsers.setAll(data?.betUsers);
127
- this.channels.setAll(data?.channels);
128
- this.categories.setAll(data?.categories);
129
- this.matches.setAll(data?.matches);
130
- this.mediators.setAll(data?.mediators);
131
- this.tickets.setAll(data?.tickets);
132
- this.permissionsManager.setAll(data?.permissions);
133
- this.messages.setAll(data?.messages);
134
- this.vipMembers.fetchAll();
95
+ this.tickets = new managers_1.TicketManager(this);
96
+ this.users.fetch();
97
+ this.tickets.fetch();
98
+ this.matches.fetch();
99
+ }
100
+ _updateInternals(data) {
101
+ for (let key in data) {
102
+ if (key === "id" || key === "createdAt")
103
+ continue;
104
+ if (key in this) {
105
+ this[key] = data[key];
106
+ }
107
+ }
108
+ this.updatedAt = new Date();
109
+ this.rest.guilds.cache.set(this.id, this);
110
+ return this;
135
111
  }
136
112
  async fetch() {
137
113
  const route = Routes_1.Routes.guilds.get(this.id);
@@ -139,43 +115,32 @@ class Guild {
139
115
  method: "get",
140
116
  url: route,
141
117
  });
142
- const guild = new Guild(response, this.rest);
143
- this.rest.guilds.cache.set(guild.id, guild);
144
- return guild;
118
+ return this._updateInternals(response);
145
119
  }
146
- async setBlacklist(value, user, adminId) {
147
- Assertion_1.Assertion.assertBoolean(value);
148
- Assertion_1.Assertion.assertString(adminId);
149
- const is_in_blacklist = this.blacklist.find((u) => u.id == user.id);
150
- if (is_in_blacklist && value === true)
151
- return this;
152
- const route = Routes_1.Routes.guilds.resource(this.id, "blacklist");
153
- const payload = { id: user.id, name: user.name, adminId, value };
154
- const [response] = await Promise.all([
155
- this.rest.request({
156
- method: "PATCH",
157
- url: route,
158
- payload,
159
- }),
160
- user.setBlacklist(value),
161
- ]);
162
- for (let blacklisted of response?.blacklist) {
163
- this.blacklist.push({
164
- addedBy: blacklisted.addedBy,
165
- id: blacklisted.id,
166
- createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
167
- updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
168
- });
120
+ async update(data) {
121
+ const route = Routes_1.Routes.guilds.get(this.id);
122
+ const response = await this.rest.request({
123
+ method: "patch",
124
+ url: route,
125
+ payload: data,
126
+ });
127
+ for (const k in response) {
128
+ if (k === "id" || k == "createdAt")
129
+ continue;
130
+ if (k in this) {
131
+ this[k] = response[k];
132
+ }
169
133
  }
134
+ this.updatedAt = new Date();
170
135
  this.rest.guilds.cache.set(this.id, this);
171
136
  this.rest.emit("guildUpdate", this);
172
137
  return this;
173
138
  }
174
139
  async setStatus(key, status) {
175
- Assertion_1.Assertion.assertString(status);
176
- status = status.toLowerCase();
177
- const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "status"), key);
178
- const payload = { status };
140
+ Assertion_1.Assertion.assertString(key);
141
+ this.status[key] = status;
142
+ const route = Routes_1.Routes.guilds.resource(this.id, "status");
143
+ const payload = { set: this.status };
179
144
  const response = await this.rest.request({
180
145
  method: "PATCH",
181
146
  url: route,
@@ -189,7 +154,7 @@ class Guild {
189
154
  async addPrice(price) {
190
155
  Assertion_1.Assertion.assertNumber(price);
191
156
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "prices"), "used");
192
- const payload = { price };
157
+ const payload = { set: price };
193
158
  const response = await this.rest.request({
194
159
  method: "POST",
195
160
  url: route,
@@ -203,7 +168,7 @@ class Guild {
203
168
  async removePrice(price) {
204
169
  Assertion_1.Assertion.assertNumber(price);
205
170
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "prices"), "used", price.toString());
206
- const payload = { price };
171
+ const payload = { set: price };
207
172
  const response = await this.rest.request({
208
173
  method: "DELETE",
209
174
  url: route,
@@ -217,7 +182,7 @@ class Guild {
217
182
  async setPrefix(prefix) {
218
183
  Assertion_1.Assertion.assertString(prefix);
219
184
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "prefix"));
220
- const payload = { prefix };
185
+ const payload = { set: prefix };
221
186
  const response = await this.rest.request({
222
187
  method: "PATCH",
223
188
  url: route,
@@ -231,7 +196,7 @@ class Guild {
231
196
  async addDailyCategory(category) {
232
197
  Assertion_1.Assertion.assertString(category);
233
198
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "dailyCategories"));
234
- const payload = { category };
199
+ const payload = { set: category };
235
200
  const response = await this.rest.request({
236
201
  method: "POST",
237
202
  url: route,
@@ -246,7 +211,7 @@ class Guild {
246
211
  Assertion_1.Assertion.assertString(category);
247
212
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resources(this.id, "dailyCategories", category));
248
213
  const categories = [...new Set([...this.dailyCategories, category])];
249
- const payload = { categories };
214
+ const payload = { set: categories };
250
215
  const response = await this.rest.request({
251
216
  method: "DELETE",
252
217
  url: route,
@@ -259,7 +224,7 @@ class Guild {
259
224
  }
260
225
  async setScore(name, amount) {
261
226
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resources(this.id, "scores", name));
262
- const payload = { amount };
227
+ const payload = { set: amount };
263
228
  const response = await this.rest.request({
264
229
  method: "patch",
265
230
  url: route,
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./guild/Guild"), exports);
18
+ __exportStar(require("./match/GuildMatch"), exports);
19
+ __exportStar(require("./user/GuildUser"), exports);
20
+ __exportStar(require("./vipmember/VipMember"), exports);
21
+ __exportStar(require("./ticket/Ticket"), exports);
22
+ __exportStar(require("./Collection"), exports);
@@ -3,39 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildMatch = void 0;
4
4
  const Routes_1 = require("../../rest/Routes");
5
5
  const Assertion_1 = require("../../utils/Assertion");
6
- const ChannelManager_1 = require("../../managers/channel/ChannelManager");
7
- const MessagesManager_1 = require("../../managers/messages/MessagesManager");
6
+ const MessagesManager_1 = require("../../managers/message/MessagesManager");
8
7
  class GuildMatch {
8
+ _id;
9
+ selections;
9
10
  /** Match's type */
10
11
  type;
12
+ channels;
13
+ guild_id;
11
14
  /** Match's status */
12
15
  status;
13
16
  /** Match's challenge */
14
17
  challenge;
15
18
  /** Match's players */
16
19
  players;
20
+ teams;
17
21
  /** Match's winners */
18
22
  winners;
19
23
  /** Match's losers */
20
24
  losers;
21
- /** Match;s messages */
22
- messages;
23
- /** Matches channels */
24
- channels;
25
25
  /** Match's maximum size */
26
26
  maximumSize;
27
27
  /** Match's kicked out */
28
28
  kickedOut;
29
- /** Match's team a */
30
- teamA;
31
- /** Match's team b */
32
- teamB;
33
29
  /** Match's confirmed */
34
30
  confirmed;
35
31
  /** Match's leaders */
36
32
  leaders;
37
- /** Match's mvp */
38
- mvpId;
39
33
  /** Match's creator id */
40
34
  creatorId;
41
35
  /** Match's room creator id */
@@ -44,8 +38,9 @@ class GuildMatch {
44
38
  createdAt;
45
39
  /** Updated Date */
46
40
  updatedAt;
41
+ messages;
47
42
  /** Match's id */
48
- _id;
43
+ mvps;
49
44
  manager;
50
45
  /** The given guild */
51
46
  guild;
@@ -58,33 +53,31 @@ class GuildMatch {
58
53
  * @param guild The guild
59
54
  * @param rest The rest client
60
55
  */
61
- constructor(data, guild, manager, rest) {
56
+ constructor(data, manager) {
62
57
  this._id = data?._id;
58
+ this.guild_id = data?.guild_id;
59
+ this.selections = data?.selections;
63
60
  this.manager = manager;
61
+ this.guild = manager.guild;
62
+ this.rest = manager.rest;
64
63
  this.challenge = data?.challenge;
64
+ this.teams = data?.teams;
65
65
  this.kickedOut = data?.kickedOut;
66
66
  this.leaders = data?.leaders;
67
67
  this.type = data?.type;
68
68
  this.status = data?.status;
69
69
  this.maximumSize = data?.maximumSize;
70
70
  this.players = data?.players;
71
- this.teamA = data?.teamA;
72
- this.teamB = data?.teamB;
73
71
  this.winners = data?.winners;
74
72
  this.losers = data?.losers;
75
73
  this.creatorId = data?.creatorId;
76
74
  this.roomCreatorId = data?.roomCreatorId;
77
75
  this.confirmed = data?.confirmed;
78
- this.mvpId = data?.mvpId;
76
+ this.mvps = data?.mvps;
79
77
  this.key = "matches";
80
- this.channels = new ChannelManager_1.ChannelManager(guild, this, rest);
81
- this.messages = new MessagesManager_1.MessagesManager(guild, `matches/${data?._id}`, rest);
82
78
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
83
79
  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);
80
+ this.messages = new MessagesManager_1.MessagesManager(this, Routes_1.Routes.guilds.matches.resource(data.guild_id, this._id, "messages"));
88
81
  }
89
82
  /**
90
83
  * Fetches the match
@@ -96,23 +89,27 @@ class GuildMatch {
96
89
  method: "get",
97
90
  url: route,
98
91
  });
99
- const match = new GuildMatch(response, this.guild, this.manager, this.rest);
92
+ const match = new GuildMatch(response, this.manager);
100
93
  this.manager.cache.set(match._id, match);
101
94
  return match;
102
95
  }
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
- }
96
+ /* async addMessage(id: string, type: string, content?: string) {
97
+ const response = await this.messages.create({
98
+ userId: id,
99
+ type: type as "img",
100
+ content,
101
+ });
102
+
103
+ this.manager.cache.set(this._id, this);
104
+ this.rest.matches.set(this._id, this);
105
+ return response;
106
+ } */
113
107
  async addConfirmed(type, id) {
114
108
  Assertion_1.Assertion.assertString(type);
115
109
  Assertion_1.Assertion.assertString(id);
110
+ /* const confirms = this.confirmed;
111
+ const con: Confirm = confirms.find((c) => c.type === type) ?? { count: 1, ids: [id], type };
112
+ */
116
113
  const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "confirmed");
117
114
  const payload = { type, id };
118
115
  const response = await this.rest.request({
@@ -120,11 +117,12 @@ class GuildMatch {
120
117
  url: route,
121
118
  payload,
122
119
  });
123
- this.rest.emit("matchUpdate", this);
124
- this.updatedAt = new Date();
120
+ this.rest.emit("matchUpdate", this, this);
125
121
  this.confirmed = response;
122
+ this.updatedAt = new Date();
126
123
  this.rest.matches.set(this._id, this);
127
124
  this.manager.cache.set(this._id, this);
125
+ this.guild.buffer.matches.set(this._id, this);
128
126
  return this.confirmed.find((c) => c.type === type);
129
127
  }
130
128
  async setConfirmed(set) {
@@ -138,6 +136,7 @@ class GuildMatch {
138
136
  this.confirmed = response;
139
137
  this.rest.matches.set(this._id, this);
140
138
  this.manager.cache.set(this._id, this);
139
+ this.guild.buffer.matches.set(this._id, this);
141
140
  return this;
142
141
  }
143
142
  async setStatus(status) {
@@ -149,159 +148,112 @@ class GuildMatch {
149
148
  url: route,
150
149
  payload,
151
150
  });
152
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
151
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
153
152
  this.status = response.status;
154
153
  this.rest.matches.set(this._id, this);
155
154
  this.manager.cache.set(this._id, this);
155
+ this.guild.buffer.matches.set(this._id, this);
156
156
  return this;
157
157
  }
158
158
  async setWinners(players) {
159
159
  if (!Array.isArray(players))
160
160
  players = [players];
161
- const payload = { winners: players };
161
+ const payload = { set: players };
162
162
  const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "winners");
163
163
  const response = await this.rest.request({
164
164
  method: "PATCH",
165
165
  url: route,
166
166
  payload,
167
167
  });
168
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
168
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
169
169
  this.winners = response.winners;
170
170
  this.rest.matches.set(this._id, this);
171
171
  this.manager.cache.set(this._id, this);
172
+ this.guild.buffer.matches.set(this._id, this);
172
173
  return this;
173
174
  }
174
175
  async setLoser(players) {
175
176
  if (!Array.isArray(players))
176
177
  players = [players];
177
- const payload = { losers: players };
178
+ const payload = { set: players };
178
179
  const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "losers");
179
180
  const response = await this.rest.request({
180
181
  method: "PATCH",
181
182
  url: route,
182
183
  payload,
183
184
  });
184
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
185
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
185
186
  this.losers = response.losers;
186
187
  this.rest.matches.set(this._id, this);
187
188
  this.manager.cache.set(this._id, this);
189
+ this.guild.buffer.matches.set(this._id, this);
188
190
  return this;
189
191
  }
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");
192
+ async setMvps(...usersId) {
193
+ const payload = { set: usersId };
194
+ const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "mvps");
194
195
  const response = await this.rest.request({
195
196
  method: "PATCH",
196
197
  url: route,
197
198
  payload,
198
199
  });
199
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
200
- this.mvpId = response.mvpId;
200
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
201
+ this.mvps = response.mvps;
201
202
  this.rest.matches.set(this._id, this);
202
203
  this.manager.cache.set(this._id, this);
204
+ this.guild.buffer.matches.set(this._id, this);
203
205
  return this;
204
206
  }
205
207
  async setRoomCreatorId(userId) {
206
208
  Assertion_1.Assertion.assertString(userId);
207
- const payload = { id: userId };
209
+ const payload = { set: userId };
208
210
  const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "roomCreatorId");
209
211
  const response = await this.rest.request({
210
212
  method: "PATCH",
211
213
  url: route,
212
214
  payload,
213
215
  });
214
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
216
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
215
217
  this.roomCreatorId = response.roomCreatorId;
216
218
  this.rest.matches.set(this._id, this);
217
219
  this.manager.cache.set(this._id, this);
220
+ this.guild.buffer.matches.set(this._id, this);
218
221
  return this;
219
222
  }
220
223
  async kick(player) {
221
- const payload = { ...player };
224
+ const payload = { set: player };
222
225
  const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "kickout");
223
226
  const response = await this.rest.request({
224
227
  method: "PATCH",
225
228
  url: route,
226
229
  payload,
227
230
  });
228
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
231
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
229
232
  this.kickedOut = response.kickedOut;
230
233
  this.rest.matches.set(this._id, this);
231
234
  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);
235
+ this.guild.buffer.matches.set(this._id, this);
284
236
  return this;
285
237
  }
286
238
  async update(data) {
287
239
  const route = Routes_1.Routes.guilds.matches.get(this.guild.id, this._id);
288
- const payload = data;
289
240
  const response = await this.rest.request({
290
241
  method: "patch",
291
242
  url: route,
292
- payload,
243
+ payload: data,
293
244
  });
294
- this.rest.emit("matchUpdate", this, new GuildMatch(response, this.guild, this.manager, this.rest));
245
+ this.rest.emit("matchUpdate", this, new GuildMatch(response, this.manager));
295
246
  for (const k in response) {
296
247
  if (k === "id" || k == "createdAt")
297
248
  continue;
298
249
  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;
250
+ /* if (k === "channels") {
251
+ ({ chs: response["channels"] });
252
+ this.channels.setAll(response["channels"]);
253
+ ({ chs2: this.channels.cache });
254
+ continue;
304
255
  }
256
+ */
305
257
  if (k === "messages") {
306
258
  this.messages.setAll(response["messages"]);
307
259
  continue;
@@ -312,6 +264,7 @@ class GuildMatch {
312
264
  this.updatedAt = new Date();
313
265
  this.manager.cache.set(this._id, this);
314
266
  this.rest.matches.set(this._id, this);
267
+ this.guild.buffer.matches.set(this._id, this);
315
268
  return this;
316
269
  }
317
270
  async delete() {