@duque.edits/sdk 1.0.2 → 1.0.4

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 (32) hide show
  1. package/dist/managers/bet/GuildBetManager.js +5 -0
  2. package/dist/managers/betuser/GuildBetUserManager.js +1 -2
  3. package/dist/managers/match/GuildMatchManager.js +8 -21
  4. package/dist/managers/mediator/GuildMediatorManager.js +94 -0
  5. package/dist/managers/ticket/TicketManager.js +1 -1
  6. package/dist/rest/REST.js +6 -1
  7. package/dist/rest/Routes.js +0 -1
  8. package/dist/structures/bet/GuildBet.js +40 -16
  9. package/dist/structures/betuser/GuildBetUser.js +8 -2
  10. package/dist/structures/guild/Guild.js +4 -0
  11. package/dist/structures/match/GuildMatch.js +30 -33
  12. package/dist/structures/mediator/GuildMediator.js +133 -0
  13. package/dist/structures/user/GuildUser.js +1 -1
  14. package/dist/types/api/APIGuildBet.js +5 -0
  15. package/dist/types/api/APIGuildMediator.js +0 -1
  16. package/dist/types/api/APIGuildPermissions.js +1 -0
  17. package/package.json +1 -1
  18. package/types/managers/bet/GuildBetManager.d.ts +1 -0
  19. package/types/managers/betuser/GuildBetUserManager.d.ts +1 -1
  20. package/types/managers/match/GuildMatchManager.d.ts +1 -2
  21. package/types/managers/mediator/GuildMediatorManager.d.ts +19 -0
  22. package/types/rest/REST.d.ts +3 -0
  23. package/types/structures/bet/GuildBet.d.ts +3 -2
  24. package/types/structures/betuser/GuildBetUser.d.ts +3 -0
  25. package/types/structures/guild/Guild.d.ts +2 -0
  26. package/types/structures/match/GuildMatch.d.ts +5 -1
  27. package/types/structures/mediator/GuildMediator.d.ts +50 -0
  28. package/types/types/api/APIGuildBet.d.ts +11 -0
  29. package/types/types/api/APIGuildBetUser.d.ts +1 -0
  30. package/types/types/api/APIGuildMatch.d.ts +3 -1
  31. package/types/types/api/APIGuildMediator.d.ts +7 -6
  32. package/types/types/api/APIGuildPermissions.d.ts +2 -1
@@ -26,6 +26,11 @@ class GuildBetManager extends base_1.BaseManager {
26
26
  const response = await this.rest.request({ url: route, method: "GET" });
27
27
  return this.set(response);
28
28
  }
29
+ async create(data) {
30
+ const route = rest_1.Routes.guilds.bets.create(this.guild.id);
31
+ const response = await this.rest.request({ url: route, method: "POST", payload: data });
32
+ return this.set(response);
33
+ }
29
34
  async delete(betId) {
30
35
  const route = rest_1.Routes.fields(this.base_url, betId);
31
36
  const response = await this.rest.request({ url: route, method: "DELETE" });
@@ -58,8 +58,7 @@ class GuildBetUserManager extends base_1.BaseManager {
58
58
  url: route,
59
59
  });
60
60
  this.cache.clear();
61
- this.set(response);
62
- return this.cache;
61
+ return this.set(response);
63
62
  }
64
63
  set(data) {
65
64
  if (!data)
@@ -16,7 +16,7 @@ class GuildMatchManager extends base_1.BaseManager {
16
16
  super(guild, guild.rest);
17
17
  this.guild = guild;
18
18
  this.rest = guild.rest;
19
- this.base_url = Routes_1.Routes.guilds.resource(guild.id, "matches");
19
+ this.base_url = Routes_1.Routes.guilds.matches.getAll(guild.id);
20
20
  this.cache = new Collection_1.Collection("matches");
21
21
  }
22
22
  /**
@@ -69,12 +69,16 @@ class GuildMatchManager extends base_1.BaseManager {
69
69
  return this.cache;
70
70
  if (Array.isArray(data)) {
71
71
  for (let _match of data) {
72
+ if (!_match._id)
73
+ continue;
72
74
  const match = new GuildMatch_1.GuildMatch(_match, this);
73
75
  this.cache.set(match._id, match);
74
76
  }
75
77
  return this.cache;
76
78
  }
77
79
  else {
80
+ if (!data._id)
81
+ return this.cache;
78
82
  const match = new GuildMatch_1.GuildMatch(data, this);
79
83
  this.cache.set(match._id, match);
80
84
  return match;
@@ -91,26 +95,9 @@ class GuildMatchManager extends base_1.BaseManager {
91
95
  return this.set(response);
92
96
  }
93
97
  async delete(id) {
94
- Assertion_1.Assertion.assertString(id);
95
- const route = Routes_1.Routes.guilds.matches.delete(id, this.guild.id);
96
- const match = this.cache.get(id);
97
- this.rest.emit("matchDelete", match);
98
- await this.rest.request({
99
- method: "DELETE",
100
- url: route,
101
- });
102
- this.cache.delete(id);
103
- return this.cache;
104
- }
105
- async deleteAll() {
106
- const route = Routes_1.Routes.guilds.matches.deleteAll(this.guild.id);
107
- this.rest.emit("matchesDelete", this.cache);
108
- const value = await this.rest.request({
109
- method: "DELETE",
110
- url: route,
111
- });
112
- this.cache.clear();
113
- return value;
98
+ const route = Routes_1.Routes.fields(this.base_url, id);
99
+ const response = await this.rest.request({ url: route, method: "DELETE" });
100
+ return this.set(response);
114
101
  }
115
102
  }
116
103
  exports.GuildMatchManager = GuildMatchManager;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildMediatorManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const GuildMediator_1 = require("../../structures/mediator/GuildMediator");
6
+ const Collection_1 = require("../../structures/Collection");
7
+ const base_1 = require("../base");
8
+ class GuildMediatorManager extends base_1.BaseManager {
9
+ constructor(guild) {
10
+ super(guild);
11
+ this.guild = guild;
12
+ this.rest = guild.rest;
13
+ this.base_url = Routes_1.Routes.guilds.mediators.getAll(guild.id);
14
+ this.cache = new Collection_1.Collection("mediators");
15
+ }
16
+ async fetch(options) {
17
+ if (options && options.cache)
18
+ return this.cache;
19
+ if (options && options.mediatorId) {
20
+ const route = Routes_1.Routes.fields(this.base_url, options.mediatorId);
21
+ const response = await this.rest.request({
22
+ method: "GET",
23
+ url: route,
24
+ });
25
+ return this.set(response);
26
+ }
27
+ const route = this.base_url;
28
+ const response = await this.rest.request({
29
+ method: "GET",
30
+ url: route,
31
+ });
32
+ this.set(response);
33
+ return this.cache;
34
+ }
35
+ async updateMany(...mediators) {
36
+ const route = this.base_url;
37
+ const response = await this.rest.request({
38
+ method: "PATCH",
39
+ url: route,
40
+ payload: { mediators },
41
+ });
42
+ return this.set(response);
43
+ }
44
+ async create(payload) {
45
+ const route = Routes_1.Routes.guilds.mediators.create(this.guild.id);
46
+ const response = await this.rest.request({
47
+ method: "POST",
48
+ url: route,
49
+ payload,
50
+ });
51
+ return this.set(response);
52
+ }
53
+ async deleteAll() {
54
+ const route = this.base_url;
55
+ await this.rest.request({
56
+ method: "DELETE",
57
+ url: route,
58
+ });
59
+ this.cache.clear();
60
+ }
61
+ async resetAll() {
62
+ const route = this.base_url;
63
+ const response = await this.rest.request({
64
+ method: "put",
65
+ url: route,
66
+ });
67
+ this.cache.clear();
68
+ this.set(response);
69
+ return this.cache;
70
+ }
71
+ set(data) {
72
+ if (!data)
73
+ return this.cache;
74
+ if (Array.isArray(data)) {
75
+ for (let _mediator of data) {
76
+ if (!_mediator.id)
77
+ return;
78
+ const mediator = new GuildMediator_1.GuildMediator(_mediator, this);
79
+ this.cache.set(mediator.id, mediator);
80
+ this.rest.mediators.set(mediator.id, mediator);
81
+ }
82
+ return this.cache;
83
+ }
84
+ else {
85
+ if (!data.id)
86
+ return;
87
+ const mediator = new GuildMediator_1.GuildMediator(data, this);
88
+ this.cache.set(mediator.id, mediator);
89
+ this.rest.mediators.set(mediator.id, mediator);
90
+ return mediator;
91
+ }
92
+ }
93
+ }
94
+ exports.GuildMediatorManager = GuildMediatorManager;
@@ -113,7 +113,7 @@ class GuildTicketManager {
113
113
  return this.cache;
114
114
  }
115
115
  else {
116
- if (data._id)
116
+ if (!data._id)
117
117
  return;
118
118
  const ticket = new structures_1.GuildTicket(data, this);
119
119
  this.cache.set(ticket._id, ticket);
package/dist/rest/REST.js CHANGED
@@ -37,6 +37,7 @@ class REST extends events_1.default {
37
37
  bets;
38
38
  tickets;
39
39
  vipmembers;
40
+ mediators;
40
41
  /**
41
42
  *
42
43
  * @param key The unique key for he client
@@ -54,6 +55,7 @@ class REST extends events_1.default {
54
55
  this.betusers = new Collection_1.Collection("rest:betusers");
55
56
  this.tickets = new Collection_1.Collection("rest:tickets");
56
57
  this.vipmembers = new Collection_1.Collection("rest:vipmembers");
58
+ this.mediators = new Collection_1.Collection("rest:mediators");
57
59
  this.setMaxListeners(999);
58
60
  }
59
61
  /** Initialize the caching sistem */
@@ -63,6 +65,9 @@ class REST extends events_1.default {
63
65
  await Promise.all([this.guilds.fetch({ guildId: this.guildId }), this.minesGames.fetch()]);
64
66
  return this;
65
67
  }
68
+ formatUrl(url) {
69
+ return url.endsWith("/") ? url.slice(0, url.length - 1) : url;
70
+ }
66
71
  /**
67
72
  * Request Data from a certain url
68
73
  * @param options
@@ -74,7 +79,7 @@ class REST extends events_1.default {
74
79
  Assertion_1.Assertion.assertString(this.clientKey);
75
80
  Assertion_1.Assertion.assertString(url);
76
81
  method = method.toUpperCase();
77
- url = Routes_1.Routes.base + url;
82
+ url = this.formatUrl(Routes_1.Routes.base + url);
78
83
  const headers = new undici_1.Headers();
79
84
  headers.append("authorization", this.authKey);
80
85
  headers.append("client_key", this.clientKey);
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Routes = void 0;
4
4
  exports.Routes = {
5
- //base: "http://localhost:80/api/v1",
6
5
  base: "https://duque-api.up.railway.app/api/v1",
7
6
  field: (field) => `/${field}`,
8
7
  fields: (...fields) => `${fields.join("/")}`,
@@ -36,6 +36,7 @@ class GuildBet {
36
36
  updatedAt;
37
37
  /** Bet's id */
38
38
  _id;
39
+ queues;
39
40
  rest;
40
41
  guild;
41
42
  manager;
@@ -60,6 +61,16 @@ class GuildBet {
60
61
  this.confirmed = data?.confirmed;
61
62
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
62
63
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
64
+ this.queues = [];
65
+ for (let queue of data.queues ?? []) {
66
+ this.queues.push({
67
+ _id: queue?._id,
68
+ type: queue?.type,
69
+ players: queue?.players,
70
+ updatedAt: queue?.updatedAt ? new Date(queue?.updatedAt) : new Date(),
71
+ createdAt: queue?.createdAt ? new Date(queue?.createdAt) : new Date(),
72
+ });
73
+ }
63
74
  }
64
75
  toString() {
65
76
  return this._id;
@@ -69,28 +80,41 @@ class GuildBet {
69
80
  const response = await this.rest.request({ url: route, method: "GET" });
70
81
  return this._updateInternals(response);
71
82
  }
72
- async addPlayer(player) {
73
- const isFull = this.players.length === 2;
74
- if (isFull)
83
+ async addPlayer(player, queue_type) {
84
+ if (this.players.length === 2)
75
85
  return this;
76
- const isPlayerIn = this.players.findIndex((p) => p.id === player.id);
77
- if (isPlayerIn !== -1)
86
+ if (this.players.some((p) => p.id === player.id))
78
87
  return this;
79
88
  this.players.push(player);
80
- const payload = { set: this.players };
81
- const route = rest_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players");
82
- const response = await this.rest.request({ method: "PATCH", payload, url: route });
83
- return this._updateInternals(response);
89
+ if (queue_type) {
90
+ const queue = this.queues.find((q) => q.type === queue_type);
91
+ if (!queue)
92
+ return this;
93
+ for (const q of this.queues) {
94
+ q.players = q.players.filter((p) => p.id !== player.id);
95
+ }
96
+ if (!queue.players.some((p) => p.id === player.id)) {
97
+ queue.players.push({ id: player.id });
98
+ }
99
+ }
100
+ await this.update({
101
+ players: this.players,
102
+ queues: this.queues,
103
+ });
104
+ return this;
84
105
  }
85
106
  async removePlayer(player) {
86
- const isPlayerIn = this.players.findIndex((p) => p.id === player.id);
87
- if (isPlayerIn === -1)
107
+ if (!this.players.some((p) => p.id === player.id))
88
108
  return this;
89
109
  this.players = this.players.filter((p) => p.id !== player.id);
90
- const payload = { set: this.players };
91
- const route = rest_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players");
92
- const response = await this.rest.request({ method: "PATCH", payload, url: route });
93
- return this._updateInternals(response);
110
+ for (const q of this.queues) {
111
+ q.players = q.players.filter((p) => p.id !== player.id);
112
+ }
113
+ await this.update({
114
+ players: this.players,
115
+ queues: this.queues,
116
+ });
117
+ return this;
94
118
  }
95
119
  async update(data) {
96
120
  const payload = data;
@@ -124,7 +148,7 @@ class GuildBet {
124
148
  toJSON() {
125
149
  let json = {};
126
150
  for (const [key, value] of Object.entries(this)) {
127
- const exclude = ["rest", "guilds", "manager"];
151
+ const exclude = ["rest", "guild", "manager"];
128
152
  if (exclude.includes(key))
129
153
  continue;
130
154
  if (typeof value !== "function") {
@@ -27,10 +27,12 @@ class GuildBetUser {
27
27
  createdAt;
28
28
  /** Updated Date */
29
29
  updatedAt;
30
+ consecutive_wins;
30
31
  /** The given manager */
31
32
  manager;
32
33
  /** The rest client */
33
34
  rest;
35
+ guild;
34
36
  /**
35
37
  * Bet user
36
38
  * @param data The user's data
@@ -42,11 +44,15 @@ class GuildBetUser {
42
44
  this.guild_id = data?.guild_id;
43
45
  this.manager = manager;
44
46
  this.rest = manager.rest;
47
+ this.guild = manager.guild;
45
48
  this.wins = data?.wins;
49
+ this.coins = data?.coins;
46
50
  this.losses = data?.losses;
51
+ this.credit = data?.credit;
47
52
  this.daily = data?.daily;
48
53
  this.games = data?.games;
49
54
  this.blacklist = data?.blacklist;
55
+ this.consecutive_wins = data?.consecutive_wins;
50
56
  this.profile = data?.profile;
51
57
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
52
58
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
@@ -144,7 +150,7 @@ class GuildBetUser {
144
150
  data.type = "add";
145
151
  const route = Routes_1.Routes.guilds.betusers.get(this.manager.guild.id, this.id);
146
152
  let payload = {};
147
- const numericFields = ["wins", "credit", "losses", "mvps", "games"];
153
+ const numericFields = ["wins", "credit", "losses", "mvps", "games", "coins"];
148
154
  const arrayFields = ["items", "original_channels", "adverts", "accessories"];
149
155
  if (data?.type === "add" || data?.type === "remove") {
150
156
  for (const key in data) {
@@ -193,7 +199,7 @@ class GuildBetUser {
193
199
  toJSON() {
194
200
  let json = {};
195
201
  for (const [key, value] of Object.entries(this)) {
196
- const exclude = ["rest", "guilds", "manager"];
202
+ const exclude = ["rest", "guilds", "guild", "manager"];
197
203
  if (exclude.includes(key))
198
204
  continue;
199
205
  if (typeof value !== "function") {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Guild = void 0;
4
4
  const managers_1 = require("../../managers");
5
5
  const GuildBetUserManager_1 = require("../../managers/betuser/GuildBetUserManager");
6
+ const GuildMediatorManager_1 = require("../../managers/mediator/GuildMediatorManager");
6
7
  const Routes_1 = require("../../rest/Routes");
7
8
  const Assertion_1 = require("../../utils/Assertion");
8
9
  class Guild {
@@ -46,6 +47,7 @@ class Guild {
46
47
  shop;
47
48
  betusers;
48
49
  bets;
50
+ mediators;
49
51
  adverts;
50
52
  codes;
51
53
  coin_symbol;
@@ -82,6 +84,7 @@ class Guild {
82
84
  this.logEntries = new managers_1.LogManager(this);
83
85
  this.betusers = new GuildBetUserManager_1.GuildBetUserManager(this);
84
86
  this.bets = new managers_1.GuildBetManager(this);
87
+ this.mediators = new GuildMediatorManager_1.GuildMediatorManager(this);
85
88
  this.adverts = [];
86
89
  for (let _adv of data?.adverts || []) {
87
90
  this.adverts.push({
@@ -242,6 +245,7 @@ class Guild {
242
245
  this.logEntries.fetch(),
243
246
  this.betusers.fetch(),
244
247
  this.bets.fetch(),
248
+ this.mediators.fetch(),
245
249
  ]);
246
250
  return this;
247
251
  }
@@ -41,6 +41,8 @@ class GuildMatch {
41
41
  /** Match's id */
42
42
  mvps;
43
43
  manager;
44
+ bet;
45
+ admin_id;
44
46
  /** The given guild */
45
47
  guild;
46
48
  /** The rest client */
@@ -58,12 +60,14 @@ class GuildMatch {
58
60
  this.manager = manager;
59
61
  this.guild = manager.guild;
60
62
  this.rest = manager.rest;
63
+ this.admin_id = data?.admin_id;
61
64
  this.challenge = data?.challenge;
62
65
  this.players = data?.players;
63
66
  this.messages = data?.messages;
64
67
  this.channels = data?.channels;
65
68
  this.type = data?.type;
66
69
  this.status = data?.status;
70
+ this.bet = this.guild.bets.cache.get(data?.bet?._id);
67
71
  this.mvps = data?.mvps;
68
72
  this.winners = data?.winners;
69
73
  this.losers = data?.losers;
@@ -89,41 +93,20 @@ class GuildMatch {
89
93
  method: "get",
90
94
  url: route,
91
95
  });
92
- const match = new GuildMatch(response, this.manager);
93
- this.manager.cache.set(match._id, match);
94
- return match;
96
+ return this._updateInternals(response);
95
97
  }
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
- } */
107
98
  async addConfirmed(type, id) {
108
- Assertion_1.Assertion.assertString(type);
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
- */
113
- const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "confirmed");
114
- const payload = { type, id };
115
- const response = await this.rest.request({
116
- method: "PATCH",
117
- url: route,
118
- payload,
119
- });
120
- this.rest.emit("matchUpdate", this, this);
121
- this.confirmed = response;
122
- this.updatedAt = new Date();
123
- this.rest.matches.set(this._id, this);
124
- this.manager.cache.set(this._id, this);
125
- this.guild.buffer.matches.set(this._id, this);
126
- return this.confirmed.find((c) => c.type === type);
99
+ const confirmed = this.confirmed.find((c) => c.type === type);
100
+ const idsToAdd = Array.isArray(id) ? id : [id];
101
+ if (!confirmed) {
102
+ this.confirmed.push({ type, ids: [...idsToAdd], count: idsToAdd.length });
103
+ }
104
+ else {
105
+ const chIndex = this.confirmed.findIndex((ch) => ch.type === type);
106
+ const mergedIds = [...new Set([...(confirmed.ids || []), ...idsToAdd])];
107
+ this.confirmed[chIndex] = { ...confirmed, ids: mergedIds, count: mergedIds.length };
108
+ }
109
+ return this.update({ confirmed: this.confirmed });
127
110
  }
128
111
  async setConfirmed(set) {
129
112
  Assertion_1.Assertion.assertObject(set);
@@ -191,6 +174,17 @@ class GuildMatch {
191
174
  });
192
175
  return this._updateInternals(response);
193
176
  }
177
+ async setRoomAdminId(userId) {
178
+ Assertion_1.Assertion.assertString(userId);
179
+ const payload = { set: userId };
180
+ const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "admin_id");
181
+ const response = await this.rest.request({
182
+ method: "PATCH",
183
+ url: route,
184
+ payload,
185
+ });
186
+ return this._updateInternals(response);
187
+ }
194
188
  async kick(player) {
195
189
  const payload = { set: player };
196
190
  const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "kickout");
@@ -237,6 +231,9 @@ class GuildMatch {
237
231
  if (key in this) {
238
232
  this[key] = data[key];
239
233
  }
234
+ if (key === "bet") {
235
+ this.bet = this.guild.bets.set(data.bet);
236
+ }
240
237
  }
241
238
  this.updatedAt = new Date();
242
239
  this.manager.set(this);
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildMediator = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ class GuildMediator {
6
+ /** User's name */
7
+ id;
8
+ guild_id;
9
+ /** User's games */
10
+ games;
11
+ paypal;
12
+ revolut;
13
+ mbway;
14
+ external_links;
15
+ /** Creation Date */
16
+ createdAt;
17
+ /** Updated Date */
18
+ updatedAt;
19
+ /** The given manager */
20
+ manager;
21
+ /** The rest client */
22
+ rest;
23
+ guild;
24
+ /**
25
+ * Bet user
26
+ * @param data The user's data
27
+ * @param manager The manager
28
+ * @param rest The rest client
29
+ */
30
+ constructor(data, manager) {
31
+ this.id = data?.id;
32
+ this.guild_id = data?.guild_id;
33
+ this.manager = manager;
34
+ this.rest = manager.rest;
35
+ this.guild = manager.guild;
36
+ this.games = data?.games;
37
+ this.paypal = data?.paypal;
38
+ this.revolut = data?.revolut;
39
+ this.mbway = data?.mbway;
40
+ this.external_links = data?.external_links;
41
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
42
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
43
+ }
44
+ /** String representation of this user */
45
+ toString() {
46
+ return `<@${this.id}>`;
47
+ }
48
+ /**
49
+ * Fetches the user
50
+ * @returns New Instance of the user
51
+ */
52
+ async fetch() {
53
+ const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
54
+ const response = await this.rest.request({
55
+ method: "get",
56
+ url: route,
57
+ });
58
+ const user = new GuildMediator(response, this.manager);
59
+ this.manager.cache.set(user.id, user);
60
+ this.rest.mediators.set(user.id, user);
61
+ return user;
62
+ }
63
+ async reset() {
64
+ const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
65
+ const payload = { reset: true };
66
+ const response = await this.rest.request({
67
+ method: "DELETE",
68
+ url: route,
69
+ payload,
70
+ });
71
+ return this._updateInternals(response);
72
+ }
73
+ _updateInternals(data) {
74
+ for (let key in data) {
75
+ if (key === "id" || key === "createdAt")
76
+ continue;
77
+ if (key in this) {
78
+ this[key] = data[key];
79
+ }
80
+ }
81
+ this.updatedAt = new Date();
82
+ this.createdAt = new Date(data.createdAt);
83
+ this.manager.set(this);
84
+ return this;
85
+ }
86
+ /**
87
+ * Update certain property
88
+ * @param data The new data to update with
89
+ * @returns
90
+ */
91
+ async update(data) {
92
+ const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
93
+ let payload = data;
94
+ const response = await this.rest.request({
95
+ method: "patch",
96
+ url: route,
97
+ payload,
98
+ });
99
+ return this._updateInternals(response);
100
+ }
101
+ async setPaymentlink(type, link) {
102
+ const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
103
+ let payload = { [type]: link };
104
+ const response = await this.rest.request({
105
+ method: "patch",
106
+ url: route,
107
+ payload,
108
+ });
109
+ return this._updateInternals(response);
110
+ }
111
+ async delete() {
112
+ const route = Routes_1.Routes.guilds.mediators.delete(this.manager.guild.id, this.id);
113
+ const response = await this.rest.request({
114
+ method: "DELETE",
115
+ url: route,
116
+ });
117
+ this.manager.cache.delete(this.id);
118
+ return response;
119
+ }
120
+ toJSON() {
121
+ let json = {};
122
+ for (const [key, value] of Object.entries(this)) {
123
+ const exclude = ["rest", "guilds", "guild", "manager"];
124
+ if (exclude.includes(key))
125
+ continue;
126
+ if (typeof value !== "function") {
127
+ json[key] = value;
128
+ }
129
+ }
130
+ return json;
131
+ }
132
+ }
133
+ exports.GuildMediator = GuildMediator;
@@ -265,7 +265,7 @@ class GuildUser {
265
265
  toJSON() {
266
266
  let json = {};
267
267
  for (const [key, value] of Object.entries(this)) {
268
- const exclude = ["rest", "guilds", "manager"];
268
+ const exclude = ["rest", "guilds", "guild", "manager"];
269
269
  if (exclude.includes(key))
270
270
  continue;
271
271
  if (typeof value !== "function") {
@@ -1,2 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BetChannelTypes = void 0;
4
+ var BetChannelTypes;
5
+ (function (BetChannelTypes) {
6
+ BetChannelTypes["CreationChannel"] = "creation_channel";
7
+ })(BetChannelTypes || (exports.BetChannelTypes = BetChannelTypes = {}));
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
@@ -7,4 +7,5 @@ var GuildPermissionsTypes;
7
7
  GuildPermissionsTypes["ManageQueues"] = "manage_queues";
8
8
  GuildPermissionsTypes["ManageUsers"] = "manage_users";
9
9
  GuildPermissionsTypes["ViewQueueChannels"] = "view_queue_channels";
10
+ GuildPermissionsTypes["MediatorRole"] = "mediator_role";
10
11
  })(GuildPermissionsTypes || (exports.GuildPermissionsTypes = GuildPermissionsTypes = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duque.edits/sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index",
5
5
  "types": "./types/index.d.ts",
6
6
  "typings": "./types/index.d.ts",
@@ -9,6 +9,7 @@ export declare class GuildBetManager extends BaseManager<GuildBet> {
9
9
  constructor(guild: Guild);
10
10
  toString(): number;
11
11
  fetch(options?: FetchOptions): Promise<GuildBet | Collection<string, GuildBet>>;
12
+ create(data: Optional<APIGuildBet>): Promise<GuildBet>;
12
13
  delete(betId?: string): Promise<GuildBet>;
13
14
  set(data: Optional<APIGuildBet> | Optional<APIGuildBet>[]): GuildBet;
14
15
  }
@@ -12,7 +12,7 @@ export declare class GuildBetUserManager extends BaseManager<GuildBetUser> {
12
12
  fetch(options?: FetchOptions): Promise<Collection<string, GuildBetUser> | GuildBetUser>;
13
13
  updateMany(...betusers: Optional<APIGuildBetUser>[]): Promise<Collection<string, GuildBetUser>>;
14
14
  deleteAll(): Promise<void>;
15
- resetAll(): Promise<Collection<string, GuildBetUser>>;
15
+ resetAll(): Promise<GuildBetUser | Collection<string, GuildBetUser>>;
16
16
  set(data: APIGuildBetUser | APIGuildBetUser[]): GuildBetUser | Collection<string, GuildBetUser>;
17
17
  }
18
18
  export {};
@@ -24,7 +24,6 @@ export declare class GuildMatchManager extends BaseManager<GuildMatch> {
24
24
  fetchAll(): Promise<Collection<string, GuildMatch>>;
25
25
  set(data: APIGuildMatch | APIGuildMatch[]): GuildMatch | Collection<string, GuildMatch>;
26
26
  create(payload: Optional<APIGuildMatch>): Promise<GuildMatch>;
27
- delete(id: string): Promise<Collection<string, GuildMatch>>;
28
- deleteAll(): Promise<boolean>;
27
+ delete(id?: string): Promise<GuildMatch | Collection<string, GuildMatch>>;
29
28
  }
30
29
  export {};
@@ -0,0 +1,19 @@
1
+ import { GuildMediator } from "../../structures/mediator/GuildMediator";
2
+ import { Collection } from "../../structures/Collection";
3
+ import { Guild } from "../../structures/guild/Guild";
4
+ import { Optional, APIGuildMediator } from "../../types";
5
+ import { BaseManager } from "../base";
6
+ type FetchOptions = {
7
+ mediatorId?: string;
8
+ cache?: boolean;
9
+ };
10
+ export declare class GuildMediatorManager extends BaseManager<GuildMediator> {
11
+ constructor(guild: Guild);
12
+ fetch(options?: FetchOptions): Promise<Collection<string, GuildMediator> | GuildMediator>;
13
+ updateMany(...mediators: Optional<APIGuildMediator>[]): Promise<Collection<string, GuildMediator>>;
14
+ create(payload: Optional<APIGuildMediator>): Promise<GuildMediator>;
15
+ deleteAll(): Promise<void>;
16
+ resetAll(): Promise<Collection<string, GuildMediator>>;
17
+ set(data: APIGuildMediator | APIGuildMediator[]): GuildMediator | Collection<string, GuildMediator>;
18
+ }
19
+ export {};
@@ -8,6 +8,7 @@ import { MinesGameManager } from "../managers";
8
8
  import { StatusResponse } from "../types";
9
9
  import { GuildBetUser } from "../structures/betuser/GuildBetUser";
10
10
  import { GuildBet, GuildTicket, VipMember } from "../structures";
11
+ import { GuildMediator } from "../structures/mediator/GuildMediator";
11
12
  interface ClientOptions {
12
13
  clientKey: string;
13
14
  guildId: string;
@@ -32,6 +33,7 @@ export declare class REST extends EventEmitter {
32
33
  bets: Collection<string, GuildBet>;
33
34
  tickets: Collection<string, GuildTicket>;
34
35
  vipmembers: Collection<string, VipMember>;
36
+ mediators: Collection<string, GuildMediator>;
35
37
  /**
36
38
  *
37
39
  * @param key The unique key for he client
@@ -39,6 +41,7 @@ export declare class REST extends EventEmitter {
39
41
  constructor(options: ClientOptions);
40
42
  /** Initialize the caching sistem */
41
43
  init(): Promise<this>;
44
+ formatUrl(url: string): string;
42
45
  /**
43
46
  * Request Data from a certain url
44
47
  * @param options
@@ -1,6 +1,6 @@
1
1
  import { GuildBetManager } from "../../managers";
2
2
  import { REST } from "../../rest";
3
- import { APIBetChannel, APIGuildBet, APIMessage, APIPlayer, BaseMatchModes, Confirm, Optional } from "../../types";
3
+ import { APIBetChannel, APIGuildBet, APIMessage, APIPlayer, BaseMatchModes, BetQueue, Confirm, Optional } from "../../types";
4
4
  import { Guild } from "../guild/Guild";
5
5
  export declare class GuildBet {
6
6
  /** The bet's type */
@@ -36,13 +36,14 @@ export declare class GuildBet {
36
36
  updatedAt: Date;
37
37
  /** Bet's id */
38
38
  _id: string;
39
+ queues: BetQueue[];
39
40
  rest: REST;
40
41
  guild: Guild;
41
42
  manager: GuildBetManager;
42
43
  constructor(data: Optional<APIGuildBet>, manager: GuildBetManager);
43
44
  toString(): string;
44
45
  fetch(): Promise<this>;
45
- addPlayer(player: APIPlayer): Promise<this>;
46
+ addPlayer(player: APIPlayer, queue_type?: string): Promise<this>;
46
47
  removePlayer(player: APIPlayer): Promise<this>;
47
48
  update(data: Optional<APIGuildBet>): Promise<this>;
48
49
  delete(): Promise<boolean>;
@@ -2,6 +2,7 @@ import { REST } from "../../rest/REST";
2
2
  import { Daily, Optional, Profile } from "../../types/api";
3
3
  import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
4
4
  import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
5
+ import { Guild } from "../guild/Guild";
5
6
  export declare class GuildBetUser implements APIGuildBetUser {
6
7
  /** User daily */
7
8
  daily: Omit<Daily, "points">;
@@ -27,10 +28,12 @@ export declare class GuildBetUser implements APIGuildBetUser {
27
28
  createdAt: Date;
28
29
  /** Updated Date */
29
30
  updatedAt: Date;
31
+ consecutive_wins: number;
30
32
  /** The given manager */
31
33
  readonly manager: GuildBetUserManager;
32
34
  /** The rest client */
33
35
  readonly rest: REST;
36
+ readonly guild: Guild;
34
37
  /**
35
38
  * Bet user
36
39
  * @param data The user's data
@@ -1,5 +1,6 @@
1
1
  import { BufferManager, GuildBetManager, GuildMatchManager, GuildPermissionManager, GuildTicketManager, GuildUserManager, LogManager, VipMemberManager } from "../../managers";
2
2
  import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
3
+ import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
3
4
  import { REST } from "../../rest/REST";
4
5
  import { APICode, APIGuildAdvert, APIGuildGroupedChannel, APIGuildPermissions, APIGuildShop, Daily, GuildPermissionsTypes, Optional, Permission } from "../../types/api";
5
6
  import { APIGuild, DailyCategories, GuildChannelsType, GuildModes, GuildPrices, GuildScores, GuildStatus, GuildTicketConfiguration } from "../../types/api/APIGuild";
@@ -44,6 +45,7 @@ export declare class Guild {
44
45
  shop: APIGuildShop;
45
46
  betusers: GuildBetUserManager;
46
47
  bets: GuildBetManager;
48
+ mediators: GuildMediatorManager;
47
49
  adverts: APIGuildAdvert[];
48
50
  codes: APICode[];
49
51
  coin_symbol: string;
@@ -2,6 +2,7 @@ import { REST } from "../../rest/REST";
2
2
  import { APIBaseChannel, APIGuildMatch, APIMessage, APIPlayer, BaseMatchModes, BaseMatchStatus, Confirm, MatchSelection, Optional } from "../../types";
3
3
  import { GuildMatchManager } from "../../managers";
4
4
  import { Guild } from "../guild/Guild";
5
+ import { GuildBet } from "../bet/GuildBet";
5
6
  export declare class GuildMatch {
6
7
  _id: string;
7
8
  selections: MatchSelection[];
@@ -40,6 +41,8 @@ export declare class GuildMatch {
40
41
  /** Match's id */
41
42
  mvps: [];
42
43
  manager: GuildMatchManager;
44
+ bet: GuildBet;
45
+ admin_id: string;
43
46
  /** The given guild */
44
47
  readonly guild: Guild;
45
48
  /** The rest client */
@@ -57,13 +60,14 @@ export declare class GuildMatch {
57
60
  * @returns New Instance of the match
58
61
  */
59
62
  fetch(): Promise<GuildMatch>;
60
- addConfirmed(type: string, id: string): Promise<Confirm>;
63
+ addConfirmed(type: string, id: string | string[]): Promise<APIGuildMatch>;
61
64
  setConfirmed(set: Confirm[]): Promise<GuildMatch>;
62
65
  setStatus(status: BaseMatchStatus): Promise<GuildMatch>;
63
66
  setWinners(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
64
67
  setLoser(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
65
68
  setMvps(...usersId: string[]): Promise<GuildMatch>;
66
69
  setRoomCreatorId(userId: string): Promise<GuildMatch>;
70
+ setRoomAdminId(userId: string): Promise<GuildMatch>;
67
71
  kick(player: Optional<APIPlayer>): Promise<this>;
68
72
  update(data: Optional<APIGuildMatch>): Promise<GuildMatch>;
69
73
  delete(): Promise<boolean>;
@@ -0,0 +1,50 @@
1
+ import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
2
+ import { REST } from "../../rest/REST";
3
+ import { Optional } from "../../types/api";
4
+ import { APIGuildMediator } from "../../types/api/APIGuildMediator";
5
+ import { Guild } from "../guild/Guild";
6
+ export declare class GuildMediator implements APIGuildMediator {
7
+ /** User's name */
8
+ id: string;
9
+ guild_id: string;
10
+ /** User's games */
11
+ games: number;
12
+ paypal: string;
13
+ revolut: string;
14
+ mbway: string;
15
+ external_links: string[];
16
+ /** Creation Date */
17
+ createdAt: Date;
18
+ /** Updated Date */
19
+ updatedAt: Date;
20
+ /** The given manager */
21
+ readonly manager: GuildMediatorManager;
22
+ /** The rest client */
23
+ readonly rest: REST;
24
+ readonly guild: Guild;
25
+ /**
26
+ * Bet user
27
+ * @param data The user's data
28
+ * @param manager The manager
29
+ * @param rest The rest client
30
+ */
31
+ constructor(data: APIGuildMediator, manager: GuildMediatorManager);
32
+ /** String representation of this user */
33
+ toString(): string;
34
+ /**
35
+ * Fetches the user
36
+ * @returns New Instance of the user
37
+ */
38
+ fetch(): Promise<GuildMediator>;
39
+ reset(): Promise<this>;
40
+ _updateInternals(data: Optional<APIGuildMediator>): this;
41
+ /**
42
+ * Update certain property
43
+ * @param data The new data to update with
44
+ * @returns
45
+ */
46
+ update(data: Optional<APIGuildMediator>): Promise<this>;
47
+ setPaymentlink(type: string, link: string): Promise<this>;
48
+ delete(): Promise<boolean>;
49
+ toJSON(): Optional<APIGuildMediator>;
50
+ }
@@ -2,6 +2,16 @@ import { BaseMatchModes, Confirm } from ".";
2
2
  import { APIBetChannel } from "./APIBetChannel";
3
3
  import { APIMessage } from "./APIMessage";
4
4
  import { APIPlayer } from "./APIPlayer";
5
+ export interface BetQueue {
6
+ _id: string;
7
+ type: string;
8
+ players: APIPlayer[];
9
+ createdAt: Date;
10
+ updatedAt: Date;
11
+ }
12
+ export declare enum BetChannelTypes {
13
+ CreationChannel = "creation_channel"
14
+ }
5
15
  export interface APIGuildBet {
6
16
  /** The bet's type */
7
17
  type: Omit<BaseMatchModes, "5x5" | "6x6" | "5v5" | "6v6">;
@@ -36,4 +46,5 @@ export interface APIGuildBet {
36
46
  updatedAt: Date;
37
47
  /** Bet's id */
38
48
  _id: string;
49
+ queues: BetQueue[];
39
50
  }
@@ -4,6 +4,7 @@ export interface APIGuildBetUser {
4
4
  /** User daily */
5
5
  daily: Omit<Daily, "points">;
6
6
  profile: Profile;
7
+ consecutive_wins: number;
7
8
  /** User's name */
8
9
  id: string;
9
10
  guild_id: string;
@@ -1,4 +1,4 @@
1
- import { BaseMatchModes, BaseMatchStatus, Confirm } from ".";
1
+ import { APIGuildBet, BaseMatchModes, BaseMatchStatus, Confirm } from ".";
2
2
  import { APIBaseChannel } from "./APIBaseChannel";
3
3
  import { APIMessage } from "./APIMessage";
4
4
  import { APIPlayer } from "./APIPlayer";
@@ -16,6 +16,7 @@ export interface APIGuildMatch {
16
16
  status: BaseMatchStatus;
17
17
  /** Match's challenge */
18
18
  challenge: boolean;
19
+ admin_id: string;
19
20
  /** Match's players */
20
21
  players: APIPlayer[];
21
22
  /** Match's winners */
@@ -38,6 +39,7 @@ export interface APIGuildMatch {
38
39
  creatorId: string;
39
40
  /** Match's room creator id */
40
41
  roomCreatorId: string;
42
+ bet: APIGuildBet;
41
43
  /** Creation Date */
42
44
  createdAt: Date;
43
45
  /** Updated Date */
@@ -1,11 +1,12 @@
1
- import { APIPlayer } from "./APIPlayer";
2
- export interface APIGuildMediator extends APIPlayer {
1
+ export interface APIGuildMediator {
3
2
  /** Mediator's id */
4
3
  id: string;
5
- /** Mediator's name */
6
- name: string;
7
- /** Mediator's links */
8
- paymentLinks: string[];
4
+ guild_id: string;
5
+ paypal: string;
6
+ revolut: string;
7
+ mbway: string;
8
+ external_links: string[];
9
+ games: number;
9
10
  /** Creation Date */
10
11
  createdAt: Date;
11
12
  /** Updated Date */
@@ -7,5 +7,6 @@ export declare enum GuildPermissionsTypes {
7
7
  ManageBot = "manage_bot",
8
8
  ManageQueues = "manage_queues",
9
9
  ManageUsers = "manage_users",
10
- ViewQueueChannels = "view_queue_channels"
10
+ ViewQueueChannels = "view_queue_channels",
11
+ MediatorRole = "mediator_role"
11
12
  }