@duque.edits/sdk 0.0.6 → 0.0.8

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 (30) hide show
  1. package/dist/managers/bet/GuildBetManager.d.ts +3 -0
  2. package/dist/managers/bet/GuildBetManager.js +22 -3
  3. package/dist/managers/betuser/GuildBetUserManager.d.ts +6 -0
  4. package/dist/managers/betuser/GuildBetUserManager.js +58 -1
  5. package/dist/managers/buffer/BufferManager.d.ts +14 -0
  6. package/dist/managers/buffer/BufferManager.js +32 -0
  7. package/dist/managers/channel/ChannelManager.d.ts +1 -1
  8. package/dist/managers/channel/ChannelManager.js +3 -2
  9. package/dist/managers/mediator/GuildMediatorManager.js +3 -2
  10. package/dist/managers/product/GuildProductManager.js +2 -1
  11. package/dist/managers/ticket/GuildTicketManager.js +3 -2
  12. package/dist/managers/user/GuildUserManager.d.ts +1 -0
  13. package/dist/managers/user/GuildUserManager.js +10 -1
  14. package/dist/structures/bet/GuildBet.d.ts +3 -2
  15. package/dist/structures/bet/GuildBet.js +35 -29
  16. package/dist/structures/betuser/GuildBetUser.d.ts +3 -0
  17. package/dist/structures/betuser/GuildBetUser.js +39 -21
  18. package/dist/structures/guild/Guild.d.ts +2 -0
  19. package/dist/structures/guild/Guild.js +14 -12
  20. package/dist/structures/match/GuildMatch.d.ts +1 -1
  21. package/dist/structures/match/GuildMatch.js +3 -3
  22. package/dist/structures/ticket/GuildTicket.d.ts +1 -0
  23. package/dist/structures/ticket/GuildTicket.js +5 -2
  24. package/dist/structures/user/GuildUser.d.ts +2 -0
  25. package/dist/structures/user/GuildUser.js +21 -0
  26. package/dist/types/api/APIGuildBetUser.d.ts +2 -0
  27. package/dist/types/api/APIGuildTicket.d.ts +1 -0
  28. package/dist/types/api/APIGuildTicket.js +0 -1
  29. package/dist/types/api/index.d.ts +4 -0
  30. package/package.json +1 -1
@@ -4,6 +4,7 @@ import { Collection } from "../../structures/Collection";
4
4
  import { Guild } from "../../structures/guild/Guild";
5
5
  import { Optional } from "../../types/api";
6
6
  import { APIGuildBet } from "../../types/api/APIGuildBet";
7
+ type OptionalGuildBet = Optional<APIGuildBet>;
7
8
  export declare class GuildBetManager {
8
9
  /** A cache of users */
9
10
  cache: Collection<string, GuildBet>;
@@ -18,6 +19,7 @@ export declare class GuildBetManager {
18
19
  */
19
20
  constructor(guild: Guild, rest: REST);
20
21
  create(payload: Optional<APIGuildBet>): Promise<GuildBet>;
22
+ createMany(bets: OptionalGuildBet[]): Promise<Collection<string, GuildBet>>;
21
23
  /**
22
24
  * Fetch a bet
23
25
  * @param id Id of the bet to fetch
@@ -30,3 +32,4 @@ export declare class GuildBetManager {
30
32
  delete(id: string): Promise<Collection<string, GuildBet>>;
31
33
  deleteAll(): Promise<boolean>;
32
34
  }
35
+ export {};
@@ -28,10 +28,29 @@ class GuildBetManager {
28
28
  const response = await this.rest.request({
29
29
  method: "POST",
30
30
  url: route,
31
+ payload,
31
32
  });
32
33
  const bet = this.set(response);
33
34
  return bet;
34
35
  }
36
+ async createMany(bets) {
37
+ Assertion_1.Assertion.assertArray(bets);
38
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, "bulk");
39
+ const payload = { bets };
40
+ const response = await this.rest.request({
41
+ method: "POST",
42
+ url: route,
43
+ payload,
44
+ });
45
+ this.rest.emit("betBulkCreate", response);
46
+ this.setAll(response);
47
+ const coll = new Collection_1.Collection();
48
+ for (let bt of response) {
49
+ const bet = new GuildBet_1.GuildBet(bt, this.guild, this, this.rest);
50
+ coll.set(bt._id, bet);
51
+ }
52
+ return coll;
53
+ }
35
54
  /**
36
55
  * Fetch a bet
37
56
  * @param id Id of the bet to fetch
@@ -65,7 +84,9 @@ class GuildBetManager {
65
84
  return this.cache;
66
85
  }
67
86
  set(data) {
68
- if (!data._id)
87
+ if (!data?._id)
88
+ return;
89
+ if (!this.guild)
69
90
  return;
70
91
  const bet = new GuildBet_1.GuildBet(data, this.guild, this, this.rest);
71
92
  this.cache.set(bet._id, bet);
@@ -79,7 +100,6 @@ class GuildBetManager {
79
100
  this.set(bet);
80
101
  return this.cache;
81
102
  }
82
- ;
83
103
  async delete(id) {
84
104
  Assertion_1.Assertion.assertString(id);
85
105
  const route = Routes_1.Routes.guilds.bets.delete(id, this.guild.id);
@@ -104,4 +124,3 @@ class GuildBetManager {
104
124
  }
105
125
  }
106
126
  exports.GuildBetManager = GuildBetManager;
107
- ;
@@ -2,6 +2,7 @@ import { REST } from "../../rest/REST";
2
2
  import { GuildBetUser } from "../../structures/betuser/GuildBetUser";
3
3
  import { Collection } from "../../structures/Collection";
4
4
  import { Guild } from "../../structures/guild/Guild";
5
+ import { APIPlayer, Optional } from "../../types";
5
6
  import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
6
7
  export declare class GuildBetUserManager {
7
8
  /** A cache of users */
@@ -16,8 +17,13 @@ export declare class GuildBetUserManager {
16
17
  * @param rest The rest client
17
18
  */
18
19
  constructor(guild: Guild, rest: REST);
20
+ updateMany(data: Optional<APIPlayer>[]): Promise<Collection<string, GuildBetUser>>;
21
+ update(id: string, data: Optional<APIGuildBetUser> & {
22
+ type: "add" | "remove";
23
+ }): Promise<GuildBetUser>;
19
24
  set(data: APIGuildBetUser): Collection<string, GuildBetUser>;
20
25
  setAll(data: APIGuildBetUser[]): Collection<string, GuildBetUser>;
26
+ resetAll(): Promise<Collection<string, GuildBetUser>>;
21
27
  /**
22
28
  * Fetch a user
23
29
  * @param id Id of the user to fetch
@@ -22,8 +22,56 @@ class GuildBetUserManager {
22
22
  this.rest = rest;
23
23
  this.cache = new Collection_1.Collection("betUsers");
24
24
  }
25
+ async updateMany(data) {
26
+ const route = Routes_1.Routes.guilds.resources(this.guild.id, "betUsers", "bulk");
27
+ const payload = { betUsers: data };
28
+ const response = await this.rest.request({
29
+ method: "PATCH",
30
+ url: route,
31
+ payload,
32
+ });
33
+ this.setAll(response);
34
+ return this.cache;
35
+ }
36
+ async update(id, data) {
37
+ const route = Routes_1.Routes.guilds.betUsers.update(this.guild.id, id);
38
+ const payload = {};
39
+ const numericFields = ["coins", "wins", "credit", "losses", "mvps", "games"];
40
+ const arrayFields = ["items", "betsPlayed"];
41
+ if (data.type === "add" || data.type === "remove") {
42
+ for (const key in data) {
43
+ if (key === "type")
44
+ continue;
45
+ const value = data[key];
46
+ if (numericFields.includes(key)) {
47
+ const current = this[key];
48
+ const num = value;
49
+ payload[key] = Math.max(0, data.type === "add" ? current + num : num - current);
50
+ }
51
+ else if (key === "blacklist") {
52
+ payload["blacklist"] = value;
53
+ }
54
+ else if (arrayFields.includes(key)) {
55
+ const current = this[key];
56
+ const incoming = value;
57
+ payload[key] =
58
+ data.type === "add"
59
+ ? [...new Set([...current, ...incoming])]
60
+ : current.filter((x) => !incoming.includes(x));
61
+ }
62
+ }
63
+ }
64
+ const response = await this.rest.request({
65
+ method: "patch",
66
+ url: route,
67
+ payload,
68
+ });
69
+ const user = new GuildBetUser_1.GuildBetUser(response, this, this.rest);
70
+ this.cache.set(user.id, user);
71
+ return user;
72
+ }
25
73
  set(data) {
26
- if (!data.id)
74
+ if (!data?.id)
27
75
  return;
28
76
  const user = new GuildBetUser_1.GuildBetUser(data, this, this.rest);
29
77
  this.rest.betUsers.set(user.id, user);
@@ -36,6 +84,15 @@ class GuildBetUserManager {
36
84
  this.set(user);
37
85
  return this.cache;
38
86
  }
87
+ async resetAll() {
88
+ const route = Routes_1.Routes.guilds.betUsers.getAll(this.guild.id);
89
+ const response = await this.rest.request({
90
+ method: "PUT",
91
+ url: route,
92
+ });
93
+ this.setAll(response);
94
+ return this.cache;
95
+ }
39
96
  /**
40
97
  * Fetch a user
41
98
  * @param id Id of the user to fetch
@@ -0,0 +1,14 @@
1
+ import { Collection } from "../../structures/Collection";
2
+ import { Guild } from "../../structures/guild/Guild";
3
+ import { APIGuildMatch, APIGuildTicket, Optional } from "../../types";
4
+ export declare class BufferManager {
5
+ matches: Collection<string, Optional<APIGuildMatch & {
6
+ id: string;
7
+ }>>;
8
+ tickets: Collection<string, Optional<APIGuildTicket & {
9
+ id: string;
10
+ }>>;
11
+ guild: Guild;
12
+ constructor(guild: Guild);
13
+ flush(key: "matches" | "tickets"): Promise<APIGuildMatch[] & APIGuildTicket[]>;
14
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const Collection_1 = require("../../structures/Collection");
6
+ class BufferManager {
7
+ matches;
8
+ tickets;
9
+ guild;
10
+ constructor(guild) {
11
+ this.matches = new Collection_1.Collection();
12
+ this.tickets = new Collection_1.Collection();
13
+ this.guild = guild;
14
+ }
15
+ async flush(key) {
16
+ const { rest } = this.guild;
17
+ const cache = this[key];
18
+ const { size, clear } = cache;
19
+ if (size >= 3) {
20
+ const response = await rest.request({
21
+ method: "POST",
22
+ url: Routes_1.Routes.guilds.resources(this.guild.id, key, "bulk"),
23
+ payload: { [key]: this[key].toArray() },
24
+ });
25
+ this.guild[key].setAll(response);
26
+ clear();
27
+ return response;
28
+ }
29
+ return;
30
+ }
31
+ }
32
+ exports.BufferManager = BufferManager;
@@ -25,7 +25,7 @@ export declare class ChannelManager<Structure extends GuildBet | GuildMatch> {
25
25
  * @param rest The rest client
26
26
  */
27
27
  constructor(guild: Guild, structure: Structure, rest: REST);
28
- create(id: string, type: string): Promise<Channel<Structure>>;
28
+ create(data: Optional<APIBaseChannel>): Promise<Channel<Structure>>;
29
29
  createMany(...channels: Channels[]): Promise<Collection<string, Channel<Structure>>>;
30
30
  deleteMany(...channels: Optional<APIBaseChannel>[]): Promise<Collection<string, Channel<Structure>>>;
31
31
  setAll(data: APIBaseChannel[]): Collection<string, Channel<Structure>>;
@@ -29,7 +29,8 @@ class ChannelManager {
29
29
  this.cache = new Collection_1.Collection("channels");
30
30
  this.baseUrl = Routes_1.Routes.guilds[structure.key].resource(guild.id, structure._id, "channels");
31
31
  }
32
- async create(id, type) {
32
+ async create(data) {
33
+ const { id, type } = data;
33
34
  Assertion_1.Assertion.assertString(id);
34
35
  Assertion_1.Assertion.assertString(type);
35
36
  const route = this.baseUrl;
@@ -76,7 +77,7 @@ class ChannelManager {
76
77
  return this.cache;
77
78
  }
78
79
  set(data) {
79
- if (!data.type)
80
+ if (!data?.type)
80
81
  return;
81
82
  const channel = new Channel_1.Channel({
82
83
  baseUrl: Routes_1.Routes.guilds[this.structure.key].resource(this.guild.id, this.structure._id, "channels"),
@@ -28,6 +28,7 @@ class GuildMediatorManager {
28
28
  const response = await this.rest.request({
29
29
  method: "POST",
30
30
  url: route,
31
+ payload,
31
32
  });
32
33
  const mediator = this.set(response);
33
34
  return mediator;
@@ -60,7 +61,7 @@ class GuildMediatorManager {
60
61
  if (!data.id)
61
62
  return;
62
63
  const mediator = new GuildMediator_1.GuildMediator(data, this.guild, this, this.rest);
63
- this.cache.set(data.id, mediator);
64
+ this.cache.set(data?.id, mediator);
64
65
  this.rest.mediators.set(mediator.id, mediator);
65
66
  return mediator;
66
67
  }
@@ -73,7 +74,7 @@ class GuildMediatorManager {
73
74
  }
74
75
  async delete(id) {
75
76
  Assertion_1.Assertion.assertString(id);
76
- const route = Routes_1.Routes.guilds.mediators.delete(id, this.guild.id);
77
+ const route = Routes_1.Routes.guilds.mediators.delete(this.guild.id, id);
77
78
  const mediator = this.cache.get(id);
78
79
  this.rest.emit("mediatorDelete", mediator);
79
80
  await this.rest.request({
@@ -28,6 +28,7 @@ class GuildProductManager {
28
28
  const response = await this.rest.request({
29
29
  method: "POST",
30
30
  url: route,
31
+ payload
31
32
  });
32
33
  const product = this.set(response);
33
34
  return product;
@@ -60,7 +61,7 @@ class GuildProductManager {
60
61
  return this.cache;
61
62
  }
62
63
  set(data) {
63
- if (!data.id)
64
+ if (!data?.id)
64
65
  return;
65
66
  const product = new GuildProduct_1.GuildProduct(data, this, this.rest);
66
67
  this.cache.set(data.id, product);
@@ -28,6 +28,7 @@ class GuildTicketManager {
28
28
  const response = await this.rest.request({
29
29
  method: "POST",
30
30
  url: route,
31
+ payload,
31
32
  });
32
33
  const ticket = this.set(response);
33
34
  return ticket;
@@ -60,10 +61,10 @@ class GuildTicketManager {
60
61
  return this.cache;
61
62
  }
62
63
  set(data) {
63
- if (!data.id)
64
+ if (!data?.id)
64
65
  return;
65
66
  const ticket = new GuildTicket_1.GuildTicket(data, this.guild, this, this.rest);
66
- this.cache.set(data.id.toString(), ticket);
67
+ this.cache.set(data?.id?.toString(), ticket);
67
68
  return ticket;
68
69
  }
69
70
  setAll(data) {
@@ -27,6 +27,7 @@ export declare class GuildUserManager {
27
27
  updateUser(id: string, name: string, data: Optional<APIGuildUser>): Promise<GuildUser>;
28
28
  set(data: APIGuildUser): GuildUser;
29
29
  setAll(data: APIGuildUser[]): Collection<string, GuildUser>;
30
+ resetAll(): Promise<Collection<string, GuildUser>>;
30
31
  delete(id: string): Promise<Collection<string, GuildUser>>;
31
32
  deleteAll(): Promise<boolean>;
32
33
  }
@@ -66,7 +66,7 @@ class GuildUserManager {
66
66
  return user;
67
67
  }
68
68
  set(data) {
69
- if (!data.id)
69
+ if (!data?.id)
70
70
  return;
71
71
  const user = new GuildUser_1.GuildUser(data, this, this.rest);
72
72
  this.cache.set(user?.id, user);
@@ -80,6 +80,15 @@ class GuildUserManager {
80
80
  this.set(user);
81
81
  return this.cache;
82
82
  }
83
+ async resetAll() {
84
+ const route = Routes_1.Routes.guilds.users.getAll(this.guild.id);
85
+ const response = await this.rest.request({
86
+ method: "PUT",
87
+ url: route,
88
+ });
89
+ this.setAll(response);
90
+ return this.cache;
91
+ }
83
92
  async delete(id) {
84
93
  Assertion_1.Assertion.assertString(id);
85
94
  const route = Routes_1.Routes.guilds.users.delete(id, this.guild.id);
@@ -75,11 +75,12 @@ export declare class GuildBet {
75
75
  setStatus(status: ExtendedMatchStatus): Promise<this>;
76
76
  setWinner(userId: string): Promise<string>;
77
77
  setLoser(userId: string): Promise<string>;
78
+ delete(): Promise<boolean>;
78
79
  addChannel(id: string, type: string): Promise<import("../..").Channel<GuildBet>>;
79
80
  addMessage(id: string, type: string, content?: string): Promise<import("../..").APIMessage>;
80
81
  setChannels(channels: APIBetChannel[]): Promise<ChannelManager<GuildBet>>;
81
- addPlayer(id: string, name: string): Promise<APIPlayer[]>;
82
- removePlayer(id: string, name: string): Promise<APIPlayer[]>;
82
+ addPlayer(player: Optional<APIPlayer>): Promise<APIPlayer[]>;
83
+ removePlayer(player: Optional<APIPlayer>): Promise<APIPlayer[]>;
83
84
  update(data: Optional<APIGuildBet>): Promise<this>;
84
85
  toJSON(): Record<string, unknown>;
85
86
  }
@@ -61,33 +61,33 @@ class GuildBet {
61
61
  * @param rest The rest client
62
62
  */
63
63
  constructor(data, guild, manager, rest) {
64
- this.type = data.type;
65
- this.mode = data.mode;
66
- this.status = data.status;
67
- this.maximumSize = data.maximumSize;
68
- this.price = data.price;
69
- this.payedBy = data.payedBy;
70
- this.players = data.players;
71
- this.teamA = data.teamA;
72
- this.teamB = data.teamB;
73
- this.winner = data.winner;
74
- this.loser = data.loser;
75
- this.creatorId = data.creatorId;
76
- this.mediatorId = data.mediatorId;
77
- this.confirmed = data.confirmed;
78
- this.embedMessageId = data.embedMessageId;
64
+ this.type = data?.type;
65
+ this.mode = data?.mode;
66
+ this.status = data?.status;
67
+ this.maximumSize = data?.maximumSize;
68
+ this.price = data?.price;
69
+ this.payedBy = data?.payedBy;
70
+ this.players = data?.players;
71
+ this.teamA = data?.teamA;
72
+ this.teamB = data?.teamB;
73
+ this.winner = data?.winner;
74
+ this.loser = data?.loser;
75
+ this.creatorId = data?.creatorId;
76
+ this.mediatorId = data?.mediatorId;
77
+ this.confirmed = data?.confirmed;
78
+ this.embedMessageId = data?.embedMessageId;
79
79
  this.winner = data?.winner;
80
80
  this.loser = data?.loser;
81
81
  this._id = data?._id;
82
- this.logs = data.logs;
82
+ this.logs = data?.logs;
83
+ this.guild = guild;
84
+ this.rest = rest;
83
85
  this.manager = manager;
84
86
  this.key = "bets";
85
87
  this.channels = new ChannelManager_1.ChannelManager(guild, this, rest);
86
- this.messages = new MessagesManager_1.MessagesManager(this?.guild, this?._id, rest);
88
+ this.messages = new MessagesManager_1.MessagesManager(this?.guild, `bets/${data?._id}`, rest);
87
89
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
88
90
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
89
- this.guild = guild;
90
- this.rest = rest;
91
91
  this.channels.setAll(data?.channels);
92
92
  this.messages.setAll(data?.messages);
93
93
  }
@@ -178,8 +178,16 @@ class GuildBet {
178
178
  this.manager.cache.set(this._id, this);
179
179
  return response.loser;
180
180
  }
181
+ async delete() {
182
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id);
183
+ const response = await this.rest.request({
184
+ method: "DELETE",
185
+ url: route,
186
+ });
187
+ return response;
188
+ }
181
189
  async addChannel(id, type) {
182
- const ch = await this.channels.create(id, type);
190
+ const ch = await this.channels.create({ id, type });
183
191
  this.manager.cache.set(this._id, this);
184
192
  return ch;
185
193
  }
@@ -207,11 +215,10 @@ class GuildBet {
207
215
  this.manager.cache.set(this._id, this);
208
216
  return this.channels;
209
217
  }
210
- async addPlayer(id, name) {
211
- Assertion_1.Assertion.assertString(id);
212
- Assertion_1.Assertion.assertString(name);
218
+ async addPlayer(player) {
219
+ Assertion_1.Assertion.assertObject(player);
213
220
  const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players");
214
- const payload = { id, name };
221
+ const payload = { ...player };
215
222
  const response = await this.rest.request({
216
223
  method: "POST",
217
224
  url: route,
@@ -221,11 +228,10 @@ class GuildBet {
221
228
  this.manager.cache.set(this._id, this);
222
229
  return this.players;
223
230
  }
224
- async removePlayer(id, name) {
225
- Assertion_1.Assertion.assertString(id);
226
- Assertion_1.Assertion.assertString(name);
227
- const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players", id);
228
- const payload = { id, name };
231
+ async removePlayer(player) {
232
+ Assertion_1.Assertion.assertObject(player);
233
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players", player.id);
234
+ const payload = { ...player };
229
235
  const response = await this.rest.request({
230
236
  method: "DELETE",
231
237
  url: route,
@@ -3,6 +3,7 @@ import { Daily, Items, Optional, ProfileCard } from "../../types/api";
3
3
  import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
4
4
  import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
5
5
  export declare class GuildBetUser implements APIGuildBetUser {
6
+ #private;
6
7
  /** User daily */
7
8
  daily: Omit<Daily, "points">;
8
9
  /** User's name */
@@ -23,6 +24,7 @@ export declare class GuildBetUser implements APIGuildBetUser {
23
24
  blacklist: boolean;
24
25
  /** User's coins */
25
26
  coins: number;
27
+ games: number;
26
28
  /** User's items */
27
29
  items: Items;
28
30
  /** User's profile card */
@@ -56,6 +58,7 @@ export declare class GuildBetUser implements APIGuildBetUser {
56
58
  * @returns GuildBetUser
57
59
  */
58
60
  add<K extends keyof BetUserAddOptions, V extends BetUserAddOptions[K]>(key: K, value: V): Promise<this>;
61
+ reset(): Promise<this>;
59
62
  /**
60
63
  * Set the user blacklist
61
64
  * @param value Value to set to
@@ -23,6 +23,7 @@ class GuildBetUser {
23
23
  blacklist;
24
24
  /** User's coins */
25
25
  coins;
26
+ games;
26
27
  /** User's items */
27
28
  items;
28
29
  /** User's profile card */
@@ -42,17 +43,18 @@ class GuildBetUser {
42
43
  * @param rest The rest client
43
44
  */
44
45
  constructor(data, manager, rest) {
45
- this.name = data.name;
46
- this.id = data.id;
47
- this.credit = data.credit;
48
- this.wins = data.wins;
49
- this.mvps = data.mvps;
50
- this.losses = data.losses;
51
- this.coins = data.coins;
52
- this.blacklist = data.blacklist;
53
- this.items = data.items;
54
- this.betsPlayed = data.betsPlayed;
55
- this.profileCard = data.profileCard;
46
+ this.name = data?.name;
47
+ this.id = data?.id;
48
+ this.credit = data?.credit;
49
+ this.wins = data?.wins;
50
+ this.mvps = data?.mvps;
51
+ this.losses = data?.losses;
52
+ this.games = data?.games;
53
+ this.coins = data?.coins;
54
+ this.blacklist = data?.blacklist;
55
+ this.items = data?.items;
56
+ this.betsPlayed = data?.betsPlayed;
57
+ this.profileCard = data?.profileCard;
56
58
  this.daily = data?.daily;
57
59
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
58
60
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
@@ -97,6 +99,27 @@ class GuildBetUser {
97
99
  this.rest.betUsers.set(this.id, this);
98
100
  return this;
99
101
  }
102
+ async reset() {
103
+ const route = Routes_1.Routes.guilds.betUsers.get(this.manager.guild.id, this.id);
104
+ const payload = { reset: true };
105
+ const response = await this.rest.request({
106
+ method: "DELETE",
107
+ url: route,
108
+ payload,
109
+ });
110
+ this.#updateData(response);
111
+ return this;
112
+ }
113
+ #updateData(data) {
114
+ for (const k in data) {
115
+ if (k === "id")
116
+ continue;
117
+ if (Object.hasOwn(this, k)) {
118
+ this[k] = data[k];
119
+ this.data[k] = data[k];
120
+ }
121
+ }
122
+ }
100
123
  /**
101
124
  * Set the user blacklist
102
125
  * @param value Value to set to
@@ -123,15 +146,9 @@ class GuildBetUser {
123
146
  async update(data) {
124
147
  const route = Routes_1.Routes.guilds.betUsers.get(this.manager.guild.id, this.id);
125
148
  const payload = {};
126
- const numericFields = [
127
- "coins",
128
- "wins",
129
- "credit",
130
- "losses",
131
- "mvps",
132
- ];
149
+ const numericFields = ["coins", "wins", "credit", "losses", "mvps", "games"];
133
150
  const arrayFields = ["items", "betsPlayed"];
134
- if (data.type === "add" || data.type === "remove") {
151
+ if (data?.type === "add" || data?.type === "remove") {
135
152
  for (const key in data) {
136
153
  if (key === "type")
137
154
  continue;
@@ -139,7 +156,7 @@ class GuildBetUser {
139
156
  if (numericFields.includes(key)) {
140
157
  const current = this[key];
141
158
  const num = value;
142
- payload[key] = Math.max(0, data.type === "add" ? current + num : num - current);
159
+ payload[key] = Math.max(0, data?.type === "add" ? current + num : num - current);
143
160
  }
144
161
  else if (key === "blacklist") {
145
162
  payload["blacklist"] = value;
@@ -148,7 +165,7 @@ class GuildBetUser {
148
165
  const current = this[key];
149
166
  const incoming = value;
150
167
  payload[key] =
151
- data.type === "add"
168
+ data?.type === "add"
152
169
  ? [...new Set([...current, ...incoming])]
153
170
  : current.filter((x) => !incoming.includes(x));
154
171
  }
@@ -166,6 +183,7 @@ class GuildBetUser {
166
183
  this[k] = response[k];
167
184
  }
168
185
  }
186
+ this.updatedAt = new Date();
169
187
  this.rest.betUsers.set(this.id, this);
170
188
  this.manager.cache.set(this.id, this);
171
189
  return this;
@@ -1,5 +1,6 @@
1
1
  import { GuildBetManager } from "../../managers/bet/GuildBetManager";
2
2
  import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
3
+ import { BufferManager } from "../../managers/buffer/BufferManager";
3
4
  import { GroupedChannelManager } from "../../managers/groupedchannel/GroupedChannelManager";
4
5
  import { GuildMatchManager } from "../../managers/match/GuildMatchManager";
5
6
  import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
@@ -73,6 +74,7 @@ export declare class Guild {
73
74
  /** Guild Shop */
74
75
  shop: GuildShop;
75
76
  permissionsManager: GuildPermissionManager;
77
+ buffer: BufferManager;
76
78
  /**
77
79
  * The guild structure
78
80
  * @param data The guild's data
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Guild = void 0;
4
4
  const GuildBetManager_1 = require("../../managers/bet/GuildBetManager");
5
5
  const GuildBetUserManager_1 = require("../../managers/betuser/GuildBetUserManager");
6
+ const BufferManager_1 = require("../../managers/buffer/BufferManager");
6
7
  const GroupedChannelManager_1 = require("../../managers/groupedchannel/GroupedChannelManager");
7
8
  const GuildMatchManager_1 = require("../../managers/match/GuildMatchManager");
8
9
  const GuildMediatorManager_1 = require("../../managers/mediator/GuildMediatorManager");
@@ -70,6 +71,7 @@ class Guild {
70
71
  /** Guild Shop */
71
72
  shop;
72
73
  permissionsManager;
74
+ buffer;
73
75
  /**
74
76
  * The guild structure
75
77
  * @param data The guild's data
@@ -92,6 +94,17 @@ class Guild {
92
94
  this.pricesAvailable = data?.pricesAvailable;
93
95
  this.pricesOn = data?.pricesOn;
94
96
  this.shop = new GuildShop_1.GuildShop(data?.shop, this, rest);
97
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
98
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
99
+ this.blacklist = [];
100
+ for (let blacklisted of data?.blacklist) {
101
+ this.blacklist.push({
102
+ addedBy: blacklisted.addedBy,
103
+ id: blacklisted.id,
104
+ createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
105
+ updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
106
+ });
107
+ }
95
108
  this.mediators = new GuildMediatorManager_1.GuildMediatorManager(this, rest);
96
109
  this.bets = new GuildBetManager_1.GuildBetManager(this, rest);
97
110
  this.users = new GuildUserManager_1.GuildUserManager(this, rest);
@@ -101,6 +114,7 @@ class Guild {
101
114
  this.categories = new GroupedChannelManager_1.GroupedChannelManager(this, "categories", rest);
102
115
  this.tickets = new GuildTicketManager_1.GuildTicketManager(this, rest);
103
116
  this.permissionsManager = new GuildPermissionManager_1.GuildPermissionManager(this, rest);
117
+ this.buffer = new BufferManager_1.BufferManager(this);
104
118
  this.bets.setAll(data?.bets);
105
119
  this.users.setAll(data?.users);
106
120
  this.betUsers.setAll(data?.betUsers);
@@ -111,17 +125,6 @@ class Guild {
111
125
  this.tickets.setAll(data?.tickets);
112
126
  this.permissionsManager.setAll(data?.permissions);
113
127
  this.messages.setAll(data?.messages);
114
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
115
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
116
- this.blacklist = [];
117
- for (let blacklisted of data?.blacklist) {
118
- this.blacklist.push({
119
- addedBy: blacklisted.addedBy,
120
- id: blacklisted.id,
121
- createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
122
- updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
123
- });
124
- }
125
128
  }
126
129
  async fetch() {
127
130
  const route = Routes_1.Routes.guilds.get(this.id);
@@ -159,7 +162,6 @@ class Guild {
159
162
  }
160
163
  this.rest.guilds.cache.set(this.id, this);
161
164
  this.rest.emit("guildUpdate", this);
162
- console.log({ bl: response?.blacklist });
163
165
  return this;
164
166
  }
165
167
  async setStatus(key, status) {
@@ -74,7 +74,7 @@ export declare class GuildMatch {
74
74
  setLoser(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
75
75
  setMvp(userId: string): Promise<GuildMatch>;
76
76
  setRoomCreatorId(userId: string): Promise<GuildMatch>;
77
- kick(player: APIPlayer): Promise<this>;
77
+ kick(player: Optional<APIPlayer>): Promise<this>;
78
78
  addChannel(id: string, type: string): Promise<GuildMatch>;
79
79
  setChannels(channels: APIBetChannel[]): Promise<GuildMatch>;
80
80
  addPlayer(id: string, name: string): Promise<GuildMatch>;
@@ -78,7 +78,7 @@ class GuildMatch {
78
78
  this.mvpId = data?.mvpId;
79
79
  this.key = "matches";
80
80
  this.channels = new ChannelManager_1.ChannelManager(guild, this, rest);
81
- this.messages = new MessagesManager_1.MessagesManager(guild, this?._id, rest);
81
+ this.messages = new MessagesManager_1.MessagesManager(guild, `matches/${data?._id}`, rest);
82
82
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
83
83
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
84
84
  this.guild = guild;
@@ -232,7 +232,7 @@ class GuildMatch {
232
232
  return this;
233
233
  }
234
234
  async addChannel(id, type) {
235
- await this.channels.create(id, type);
235
+ await this.channels.create({ id, type });
236
236
  this.rest.matches.set(this._id, this);
237
237
  this.manager.cache.set(this._id, this);
238
238
  return this;
@@ -271,7 +271,7 @@ class GuildMatch {
271
271
  async removePlayer(id, name) {
272
272
  Assertion_1.Assertion.assertString(id);
273
273
  Assertion_1.Assertion.assertString(name);
274
- const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "players", id);
274
+ const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this?._id, "players", id);
275
275
  const payload = { id, name };
276
276
  const response = await this.rest.request({
277
277
  method: "DELETE",
@@ -6,6 +6,7 @@ import { MessagesManager } from "../../managers/messages/MessagesManager";
6
6
  export declare class GuildTicket {
7
7
  /** Ticket's id */
8
8
  id: string;
9
+ _id: string;
9
10
  /** Ticket's creator id */
10
11
  creatorId: string;
11
12
  /** Ticket's admin id */
@@ -7,6 +7,7 @@ const MessagesManager_1 = require("../../managers/messages/MessagesManager");
7
7
  class GuildTicket {
8
8
  /** Ticket's id */
9
9
  id;
10
+ _id;
10
11
  /** Ticket's creator id */
11
12
  creatorId;
12
13
  /** Ticket's admin id */
@@ -39,7 +40,8 @@ class GuildTicket {
39
40
  * @param rest The rest client
40
41
  */
41
42
  constructor(data, guild, manager, rest) {
42
- this.id = data?.id.toString();
43
+ this.id = data?.id?.toString();
44
+ this._id = data?._id?.toString();
43
45
  this.creatorId = data?.creatorId;
44
46
  this.adminId = data?.adminId;
45
47
  this.customerRating = data.customerRating;
@@ -47,7 +49,7 @@ class GuildTicket {
47
49
  this.type = data?.type;
48
50
  this.status = data?.status;
49
51
  this.channelId = data?.channelId;
50
- this.messages = new MessagesManager_1.MessagesManager(this.guild, this.id, rest);
52
+ this.messages = new MessagesManager_1.MessagesManager(guild, `tickets/${data?.id}`, rest);
51
53
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
52
54
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
53
55
  this.guild = guild;
@@ -113,6 +115,7 @@ class GuildTicket {
113
115
  const response = await this.rest.request({
114
116
  method: "PATCH",
115
117
  url: route,
118
+ payload
116
119
  });
117
120
  this.customerRating = response.customerRating;
118
121
  this.manager.cache.set(this.id, this);
@@ -3,6 +3,7 @@ import { Accessory, Daily, Items, Optional, OriginalChannels } from "../../types
3
3
  import { APIGuildUser } from "../../types/api/APIGuildUser";
4
4
  import { GuildUserManager } from "../../managers/user/GuildUserManager";
5
5
  export declare class GuildUser implements APIGuildUser {
6
+ #private;
6
7
  /** User's id */
7
8
  id: string;
8
9
  /** User name */
@@ -62,6 +63,7 @@ export declare class GuildUser implements APIGuildUser {
62
63
  * @returns GuildUser
63
64
  */
64
65
  setBlacklist(value: boolean): Promise<this>;
66
+ reset(): Promise<this>;
65
67
  /**
66
68
  * Update certain property
67
69
  * @param data The new data to update with
@@ -118,6 +118,27 @@ class GuildUser {
118
118
  this.rest.users.set(this.id, this);
119
119
  return this;
120
120
  }
121
+ async reset() {
122
+ const route = Routes_1.Routes.guilds.users.get(this.manager.guild.id, this.id);
123
+ const payload = { reset: true };
124
+ const response = await this.rest.request({
125
+ method: "DELETE",
126
+ url: route,
127
+ payload,
128
+ });
129
+ this.#updateData(response);
130
+ return this;
131
+ }
132
+ #updateData(data) {
133
+ for (const k in data) {
134
+ if (k === "id")
135
+ continue;
136
+ if (Object.hasOwn(this, k)) {
137
+ this[k] = data[k];
138
+ this.data[k] = data[k];
139
+ }
140
+ }
141
+ }
121
142
  /**
122
143
  * Update certain property
123
144
  * @param data The new data to update with
@@ -15,6 +15,8 @@ export interface APIGuildBetUser {
15
15
  mvps: number;
16
16
  /** User's losses */
17
17
  losses: number;
18
+ /** User's games */
19
+ games: number;
18
20
  /** User's bets played */
19
21
  betsPlayed: string[];
20
22
  /** User's blacklist */
@@ -2,6 +2,7 @@ import { APIMessage } from "./APIMessage";
2
2
  export interface APIGuildTicket {
3
3
  /** Ticket's id */
4
4
  id: string;
5
+ _id: string;
5
6
  /** Ticket's creator id */
6
7
  creatorId: string;
7
8
  /** Ticket's admin id */
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
@@ -26,6 +26,10 @@ export interface LogMessage {
26
26
  userId: string;
27
27
  /** The message's type */
28
28
  type: string;
29
+ /** Creation Date */
30
+ createdAt: Date;
31
+ /** Updated Date */
32
+ updatedAt: Date;
29
33
  }
30
34
  /** Base match modes */
31
35
  export type BaseMatchModes = "1x1" | "2x2" | "3x3" | "4x4" | "5x5" | "6x6" | "1v1" | "2v2" | "3v3" | "4v4" | "5v5" | "6v6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duque.edits/sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "typings": "./dist/index.d.ts",