@duque.edits/sdk 0.1.4 → 0.1.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 (119) hide show
  1. package/dist/index.js +4 -27
  2. package/dist/managers/base.js +26 -0
  3. package/dist/managers/buffer/BufferManager.js +8 -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 -29
  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 +124 -0
  12. package/dist/rest/REST.js +40 -21
  13. package/dist/rest/Routes.js +31 -17
  14. package/dist/rest/index.js +19 -0
  15. package/dist/structures/Collection.js +1 -1
  16. package/dist/structures/guild/Guild.js +72 -90
  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 +48 -40
  21. package/dist/structures/vipmember/VipMember.js +137 -0
  22. package/dist/types/api/APIGiveaway.js +2 -0
  23. package/dist/types/api/APILogMessage.js +2 -0
  24. package/dist/types/api/APIVipMember.js +2 -0
  25. package/dist/types/api/index.js +36 -0
  26. package/dist/types/index.js +1 -20
  27. package/dist/utils/getRandomNumber.js +6 -0
  28. package/package.json +11 -18
  29. package/types/index.d.ts +4 -0
  30. package/types/managers/base.d.ts +17 -0
  31. package/types/managers/buffer/BufferManager.d.ts +19 -0
  32. package/{dist → types}/managers/guild/GuildManager.d.ts +12 -4
  33. package/types/managers/index.d.ts +7 -0
  34. package/{dist → types}/managers/match/GuildMatchManager.d.ts +10 -12
  35. package/types/managers/message/MessagesManager.d.ts +17 -0
  36. package/types/managers/permission/GuildPermissionManager.d.ts +8 -0
  37. package/types/managers/ticket/TicketManager.d.ts +22 -0
  38. package/types/managers/user/GuildUserManager.d.ts +19 -0
  39. package/types/managers/vipmember/VipMemberManager.d.ts +33 -0
  40. package/types/rest/APIEndpoints.d.ts +11 -0
  41. package/{dist → types}/rest/REST.d.ts +9 -16
  42. package/{dist → types}/rest/Routes.d.ts +18 -2
  43. package/types/rest/index.d.ts +3 -0
  44. package/{dist → types}/structures/guild/Guild.d.ts +17 -29
  45. package/types/structures/index.d.ts +6 -0
  46. package/{dist → types}/structures/match/GuildMatch.d.ts +12 -22
  47. package/types/structures/ticket/Ticket.d.ts +30 -0
  48. package/{dist → types}/structures/user/GuildUser.d.ts +5 -3
  49. package/types/structures/vipmember/VipMember.d.ts +54 -0
  50. package/types/types/RestTypes.d.ts +34 -0
  51. package/types/types/api/APIGiveaway.d.ts +27 -0
  52. package/{dist → types}/types/api/APIGuild.d.ts +9 -2
  53. package/{dist → types}/types/api/APIGuildMatch.d.ts +9 -7
  54. package/types/types/api/APIGuildTicket.d.ts +16 -0
  55. package/{dist → types}/types/api/APIGuildUser.d.ts +3 -1
  56. package/types/types/api/APILogMessage.d.ts +7 -0
  57. package/types/types/api/APIMessage.d.ts +11 -0
  58. package/{dist → types}/types/api/APIPlayer.d.ts +1 -1
  59. package/types/types/api/APIVipMember.d.ts +20 -0
  60. package/{dist → types}/types/api/index.d.ts +23 -1
  61. package/types/types/index.d.ts +2 -0
  62. package/types/utils/getRandomNumber.d.ts +1 -0
  63. package/dist/index.d.ts +0 -27
  64. package/dist/managers/bet/GuildBetManager.d.ts +0 -35
  65. package/dist/managers/bet/GuildBetManager.js +0 -126
  66. package/dist/managers/betuser/GuildBetUserManager.d.ts +0 -36
  67. package/dist/managers/betuser/GuildBetUserManager.js +0 -151
  68. package/dist/managers/buffer/BufferManager.d.ts +0 -14
  69. package/dist/managers/channel/ChannelManager.d.ts +0 -39
  70. package/dist/managers/channel/ChannelManager.js +0 -148
  71. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +0 -34
  72. package/dist/managers/groupedchannel/GroupedChannelManager.js +0 -92
  73. package/dist/managers/mediator/GuildMediatorManager.d.ts +0 -32
  74. package/dist/managers/mediator/GuildMediatorManager.js +0 -98
  75. package/dist/managers/messages/MessagesManager.d.ts +0 -32
  76. package/dist/managers/messages/MessagesManager.js +0 -89
  77. package/dist/managers/permission/GuildPermissionManager.d.ts +0 -26
  78. package/dist/managers/product/GuildProductManager.d.ts +0 -32
  79. package/dist/managers/product/GuildProductManager.js +0 -103
  80. package/dist/managers/ticket/GuildTicketManager.d.ts +0 -32
  81. package/dist/managers/ticket/GuildTicketManager.js +0 -100
  82. package/dist/managers/user/GuildUserManager.d.ts +0 -33
  83. package/dist/rest/APIEndpoints.d.ts +0 -11
  84. package/dist/structures/bet/GuildBet.d.ts +0 -87
  85. package/dist/structures/bet/GuildBet.js +0 -284
  86. package/dist/structures/betuser/GuildBetUser.d.ts +0 -85
  87. package/dist/structures/betuser/GuildBetUser.js +0 -211
  88. package/dist/structures/channel/Channel.d.ts +0 -31
  89. package/dist/structures/channel/Channel.js +0 -57
  90. package/dist/structures/groupedchannel/GroupedChannel.d.ts +0 -34
  91. package/dist/structures/groupedchannel/GroupedChannel.js +0 -121
  92. package/dist/structures/mediator/GuildMediator.d.ts +0 -41
  93. package/dist/structures/mediator/GuildMediator.js +0 -131
  94. package/dist/structures/product/GuildProduct.d.ts +0 -52
  95. package/dist/structures/product/GuildProduct.js +0 -175
  96. package/dist/structures/shop/GuildShop.d.ts +0 -34
  97. package/dist/structures/shop/GuildShop.js +0 -80
  98. package/dist/structures/ticket/GuildTicket.d.ts +0 -52
  99. package/dist/structures/ticket/GuildTicket.js +0 -172
  100. package/dist/types/api/APIGuildTicket.d.ts +0 -26
  101. package/dist/types/api/APIMessage.d.ts +0 -12
  102. package/dist/types/index.d.ts +0 -21
  103. /package/dist/types/{api/APIGuildMessage.js → RestTypes.js} +0 -0
  104. /package/{dist → types}/structures/Collection.d.ts +0 -0
  105. /package/{dist → types}/types/api/APIBaseChannel.d.ts +0 -0
  106. /package/{dist → types}/types/api/APIBetChannel.d.ts +0 -0
  107. /package/{dist → types}/types/api/APIBetMessage.d.ts +0 -0
  108. /package/{dist → types}/types/api/APIGuildBet.d.ts +0 -0
  109. /package/{dist → types}/types/api/APIGuildBetUser.d.ts +0 -0
  110. /package/{dist → types}/types/api/APIGuildChannel.d.ts +0 -0
  111. /package/{dist → types}/types/api/APIGuildEmoji.d.ts +0 -0
  112. /package/{dist → types}/types/api/APIGuildGroupedChannel.d.ts +0 -0
  113. /package/{dist → types}/types/api/APIGuildMediator.d.ts +0 -0
  114. /package/{dist → types}/types/api/APIGuildMessage.d.ts +0 -0
  115. /package/{dist → types}/types/api/APIGuildPermissions.d.ts +0 -0
  116. /package/{dist → types}/types/api/APIGuildRole.d.ts +0 -0
  117. /package/{dist → types}/types/api/APIGuildShop.d.ts +0 -0
  118. /package/{dist → types}/types/api/APIProduct.d.ts +0 -0
  119. /package/{dist → types}/utils/Assertion.d.ts +0 -0
@@ -1,19 +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
7
  const Routes_1 = require("../../rest/Routes");
15
8
  const Assertion_1 = require("../../utils/Assertion");
16
- const GuildShop_1 = require("../shop/GuildShop");
9
+ const GuildUserManager_1 = require("../../managers/user/GuildUserManager");
10
+ const managers_1 = require("../../managers");
17
11
  /** The Guild */
18
12
  class Guild {
19
13
  /** The data of this guild */
@@ -22,14 +16,15 @@ class Guild {
22
16
  rest;
23
17
  /** The guild's id */
24
18
  id;
19
+ modes;
25
20
  /** Guild's client key */
26
21
  clientKey;
27
22
  /** Guild Permissions */
28
23
  permissions;
29
24
  /** Guild Ticket */
30
- tickets;
25
+ //tickets: GuildTicketManager;
31
26
  /** Guild Ticket Configuration */
32
- ticketsConfiguration;
27
+ tickets_configuration;
33
28
  /** Guild Daily Categories */
34
29
  dailyCategories;
35
30
  /** Guild Scores */
@@ -37,9 +32,9 @@ class Guild {
37
32
  /** Guild Status */
38
33
  status;
39
34
  /** Guild Channel */
40
- channels;
35
+ //channels: GroupedChannelManager;
41
36
  /** Guild Categories */
42
- categories;
37
+ // categories: GroupedChannelManager;
43
38
  /** Guild Blacklist */
44
39
  blacklist;
45
40
  /** Guild Prefix */
@@ -52,82 +47,67 @@ class Guild {
52
47
  createdAt;
53
48
  /** Guild Updated Date */
54
49
  updatedAt;
55
- /** Guild Bets */
56
- bets;
57
50
  /** Guild Users */
58
- users;
51
+ //users: GuildUserManager;
59
52
  /** Guild Bet Users */
60
- betUsers;
53
+ // betUsers: GuildBetUserManager;
61
54
  /** Guild Matches */
62
55
  matches;
63
- /** Guild Mediators */
64
- mediators;
65
- /** Guild Messages */
66
- messages;
67
56
  /** Guild Emojis */
68
57
  emojis;
69
58
  /** Guild Roles */
70
59
  roles;
71
60
  /** Guild Prices Used */
72
61
  prices;
73
- /** Guild Shop */
74
- shop;
75
62
  permissionsManager;
76
63
  buffer;
64
+ vipMembers;
65
+ users;
66
+ tickets;
77
67
  /**
78
68
  * The guild structure
79
69
  * @param data The guild's data
80
70
  * @param rest The rest client
81
71
  */
82
72
  constructor(data, rest) {
73
+ this.id = data?.id;
83
74
  this.data = data;
84
75
  this.rest = rest;
85
- this.id = data?.id;
86
76
  this.clientKey = data?.clientKey;
87
77
  this.prefix = data?.prefix;
88
78
  this.status = data?.status;
89
- this.ticketsConfiguration = data?.ticketsConfiguration;
79
+ this.tickets_configuration = data?.tickets_configuration;
90
80
  this.permissions = data?.permissions;
91
81
  this.dailyCategories = data?.dailyCategories;
92
82
  this.scores = data?.scores;
93
- this.messages = new MessagesManager_1.MessagesManager(this, this.id, rest);
83
+ this.modes = data?.modes;
94
84
  this.roles = data?.roles;
95
85
  this.emojis = data?.emojis;
96
86
  this.pricesAvailable = data?.pricesAvailable;
97
87
  this.pricesOn = data?.pricesOn;
98
88
  this.prices = data?.prices;
99
- this.shop = new GuildShop_1.GuildShop(data?.shop, this, rest);
100
89
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
101
90
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
102
- this.blacklist = [];
103
- for (let blacklisted of data?.blacklist) {
104
- this.blacklist.push({
105
- addedBy: blacklisted.addedBy,
106
- id: blacklisted.id,
107
- createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
108
- updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
109
- });
110
- }
111
- this.mediators = new GuildMediatorManager_1.GuildMediatorManager(this, rest);
112
- this.bets = new GuildBetManager_1.GuildBetManager(this, rest);
113
- this.users = new GuildUserManager_1.GuildUserManager(this, rest);
114
- this.betUsers = new GuildBetUserManager_1.GuildBetUserManager(this, rest);
115
- this.matches = new GuildMatchManager_1.GuildMatchManager(this, rest);
116
- this.channels = new GroupedChannelManager_1.GroupedChannelManager(this, "channels", rest);
117
- this.categories = new GroupedChannelManager_1.GroupedChannelManager(this, "categories", rest);
118
- this.tickets = new GuildTicketManager_1.GuildTicketManager(this, rest);
119
- this.permissionsManager = new GuildPermissionManager_1.GuildPermissionManager(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);
120
94
  this.buffer = new BufferManager_1.BufferManager(this);
121
- this.bets.setAll(data?.bets);
122
- this.users.setAll(data?.users);
123
- this.betUsers.setAll(data?.betUsers);
124
- this.channels.setAll(data?.channels);
125
- this.categories.setAll(data?.categories);
126
- this.matches.setAll(data?.matches);
127
- this.mediators.setAll(data?.mediators);
128
- this.tickets.setAll(data?.tickets);
129
- this.permissionsManager.setAll(data?.permissions);
130
- this.messages.setAll(data?.messages);
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;
131
111
  }
132
112
  async fetch() {
133
113
  const route = Routes_1.Routes.guilds.get(this.id);
@@ -135,43 +115,32 @@ class Guild {
135
115
  method: "get",
136
116
  url: route,
137
117
  });
138
- const guild = new Guild(response, this.rest);
139
- this.rest.guilds.cache.set(guild.id, guild);
140
- return guild;
118
+ return this._updateInternals(response);
141
119
  }
142
- async setBlacklist(value, user, adminId) {
143
- Assertion_1.Assertion.assertBoolean(value);
144
- Assertion_1.Assertion.assertString(adminId);
145
- const is_in_blacklist = this.blacklist.find((u) => u.id == user.id);
146
- if (is_in_blacklist && value === true)
147
- return this;
148
- const route = Routes_1.Routes.guilds.resource(this.id, "blacklist");
149
- const payload = { id: user.id, name: user.name, adminId, value };
150
- const [response] = await Promise.all([
151
- this.rest.request({
152
- method: "PATCH",
153
- url: route,
154
- payload,
155
- }),
156
- user.setBlacklist(value),
157
- ]);
158
- for (let blacklisted of response?.blacklist) {
159
- this.blacklist.push({
160
- addedBy: blacklisted.addedBy,
161
- id: blacklisted.id,
162
- createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
163
- updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
164
- });
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
+ }
165
133
  }
134
+ this.updatedAt = new Date();
166
135
  this.rest.guilds.cache.set(this.id, this);
167
136
  this.rest.emit("guildUpdate", this);
168
137
  return this;
169
138
  }
170
139
  async setStatus(key, status) {
171
- Assertion_1.Assertion.assertString(status);
172
- status = status.toLowerCase();
173
- const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "status"), key);
174
- 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 };
175
144
  const response = await this.rest.request({
176
145
  method: "PATCH",
177
146
  url: route,
@@ -185,7 +154,7 @@ class Guild {
185
154
  async addPrice(price) {
186
155
  Assertion_1.Assertion.assertNumber(price);
187
156
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "prices"), "used");
188
- const payload = { price };
157
+ const payload = { set: price };
189
158
  const response = await this.rest.request({
190
159
  method: "POST",
191
160
  url: route,
@@ -199,7 +168,7 @@ class Guild {
199
168
  async removePrice(price) {
200
169
  Assertion_1.Assertion.assertNumber(price);
201
170
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "prices"), "used", price.toString());
202
- const payload = { price };
171
+ const payload = { set: price };
203
172
  const response = await this.rest.request({
204
173
  method: "DELETE",
205
174
  url: route,
@@ -213,7 +182,7 @@ class Guild {
213
182
  async setPrefix(prefix) {
214
183
  Assertion_1.Assertion.assertString(prefix);
215
184
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "prefix"));
216
- const payload = { prefix };
185
+ const payload = { set: prefix };
217
186
  const response = await this.rest.request({
218
187
  method: "PATCH",
219
188
  url: route,
@@ -227,7 +196,7 @@ class Guild {
227
196
  async addDailyCategory(category) {
228
197
  Assertion_1.Assertion.assertString(category);
229
198
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resource(this.id, "dailyCategories"));
230
- const payload = { category };
199
+ const payload = { set: category };
231
200
  const response = await this.rest.request({
232
201
  method: "POST",
233
202
  url: route,
@@ -242,7 +211,7 @@ class Guild {
242
211
  Assertion_1.Assertion.assertString(category);
243
212
  const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resources(this.id, "dailyCategories", category));
244
213
  const categories = [...new Set([...this.dailyCategories, category])];
245
- const payload = { categories };
214
+ const payload = { set: categories };
246
215
  const response = await this.rest.request({
247
216
  method: "DELETE",
248
217
  url: route,
@@ -253,5 +222,18 @@ class Guild {
253
222
  this.rest.emit("guildUpdate", this);
254
223
  return this;
255
224
  }
225
+ async setScore(name, amount) {
226
+ const route = Routes_1.Routes.fields(Routes_1.Routes.guilds.resources(this.id, "scores", name));
227
+ const payload = { set: amount };
228
+ const response = await this.rest.request({
229
+ method: "patch",
230
+ url: route,
231
+ payload,
232
+ });
233
+ this.scores = response;
234
+ this.rest.guilds.cache.set(this.id, this);
235
+ this.rest.emit("guildUpdate", this);
236
+ return this;
237
+ }
256
238
  }
257
239
  exports.Guild = Guild;
@@ -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() {