@duque.edits/sdk 1.0.4 → 1.0.5

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.
@@ -51,6 +51,10 @@ class GuildBetManager extends base_1.BaseManager {
51
51
  else {
52
52
  if (!data._id)
53
53
  return;
54
+ if (data instanceof structures_1.GuildBet) {
55
+ this.cache.set(data._id, data);
56
+ return data;
57
+ }
54
58
  const bet = new structures_1.GuildBet(data, this);
55
59
  this.cache.set(bet._id, bet);
56
60
  this.rest.bets.set(bet._id, bet);
@@ -79,6 +79,10 @@ class GuildMatchManager extends base_1.BaseManager {
79
79
  else {
80
80
  if (!data._id)
81
81
  return this.cache;
82
+ if (data instanceof GuildMatch_1.GuildMatch) {
83
+ this.cache.set(data._id, data);
84
+ return data;
85
+ }
82
86
  const match = new GuildMatch_1.GuildMatch(data, this);
83
87
  this.cache.set(match._id, match);
84
88
  return match;
@@ -6,8 +6,10 @@ class MessagesManager {
6
6
  cache;
7
7
  base_url;
8
8
  rest;
9
+ guild;
9
10
  constructor(structure, base_url) {
10
11
  this.rest = structure.rest;
12
+ this.guild = structure.guild;
11
13
  this.cache = new Collection_1.Collection("messages");
12
14
  this.base_url = base_url;
13
15
  }
@@ -27,21 +29,25 @@ class MessagesManager {
27
29
  else
28
30
  messages.push(data);
29
31
  const response = await this.rest.request({
30
- method: "POST",
32
+ method: "PATCH",
31
33
  url: this.base_url,
32
- payload: { messages },
34
+ payload: { set: messages },
33
35
  });
34
- for (let message of response)
35
- this.cache.set(message._id, message);
36
- return response;
36
+ return this.set(response.messages);
37
37
  }
38
- setAll(data) {
38
+ set(data) {
39
39
  if (Array.isArray(data)) {
40
- for (let message of data)
40
+ for (let message of data) {
41
+ if (!message._id)
42
+ continue;
41
43
  this.cache.set(message._id, message);
44
+ }
42
45
  }
43
- else
46
+ else {
47
+ if (!data._id)
48
+ return this.cache;
44
49
  this.cache.set(data._id, data);
50
+ }
45
51
  return this.cache;
46
52
  }
47
53
  }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerManager = void 0;
4
+ const structures_1 = require("../../structures");
5
+ class PlayerManager {
6
+ _cache;
7
+ constructor(players, base_url) {
8
+ this._cache = new structures_1.Collection();
9
+ if (Array.isArray(players)) {
10
+ for (let p of players) {
11
+ if (!p.id)
12
+ continue;
13
+ this._cache.set(p.id, p);
14
+ }
15
+ }
16
+ }
17
+ get(id) {
18
+ return this._cache.get(id);
19
+ }
20
+ add(player) {
21
+ if (Array.isArray(player)) {
22
+ for (let p of player) {
23
+ if (!p.id)
24
+ continue;
25
+ this._cache.set(p.id, p);
26
+ }
27
+ }
28
+ else {
29
+ if (!player.id)
30
+ return;
31
+ this._cache.set(player.id, player);
32
+ }
33
+ }
34
+ }
35
+ exports.PlayerManager = PlayerManager;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Routes = void 0;
4
4
  exports.Routes = {
5
5
  base: "https://duque-api.up.railway.app/api/v1",
6
+ //base: "http://localhost:80/api/v1",
6
7
  field: (field) => `/${field}`,
7
8
  fields: (...fields) => `${fields.join("/")}`,
8
9
  guilds: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildBet = void 0;
4
+ const managers_1 = require("../../managers");
4
5
  const rest_1 = require("../../rest");
5
6
  class GuildBet {
6
7
  /** The bet's type */
@@ -37,6 +38,7 @@ class GuildBet {
37
38
  /** Bet's id */
38
39
  _id;
39
40
  queues;
41
+ guild_id;
40
42
  rest;
41
43
  guild;
42
44
  manager;
@@ -45,6 +47,7 @@ class GuildBet {
45
47
  this.guild = manager.guild;
46
48
  this.rest = manager.rest;
47
49
  this._id = data?._id;
50
+ this.guild_id = data?.guild_id;
48
51
  this.type = data?.type;
49
52
  this.mode = data?.mode;
50
53
  this.status = data?.status;
@@ -53,7 +56,7 @@ class GuildBet {
53
56
  this.players = data?.players;
54
57
  this.teams = data?.teams;
55
58
  this.channels = data?.channels;
56
- this.messages = data?.messages;
59
+ this.messages = new managers_1.MessagesManager(this, rest_1.Routes.guilds.bets.resource(this.guild_id, this._id, "messages"));
57
60
  this.winners = data?.winners;
58
61
  this.losers = data?.losers;
59
62
  this.creatorId = data?.creatorId;
@@ -71,6 +74,8 @@ class GuildBet {
71
74
  createdAt: queue?.createdAt ? new Date(queue?.createdAt) : new Date(),
72
75
  });
73
76
  }
77
+ if (data?.messages?.length !== 0)
78
+ this.messages.set(data.messages);
74
79
  }
75
80
  toString() {
76
81
  return this._id;
@@ -155,7 +160,7 @@ class GuildBet {
155
160
  json[key] = value;
156
161
  }
157
162
  }
158
- return json;
163
+ return { ...json, messages: this.messages.cache.toArray() };
159
164
  }
160
165
  }
161
166
  exports.GuildBet = GuildBet;
@@ -102,8 +102,7 @@ class GuildBetUser {
102
102
  url: route,
103
103
  payload,
104
104
  });
105
- this._updateInternals(response);
106
- return this;
105
+ return this._updateInternals(response);
107
106
  }
108
107
  async updateProfile(data) {
109
108
  const _data = {
@@ -123,8 +122,7 @@ class GuildBetUser {
123
122
  url: route,
124
123
  payload: _data,
125
124
  });
126
- this._updateInternals(response);
127
- return this;
125
+ return this._updateInternals(response);
128
126
  }
129
127
  _updateInternals(data) {
130
128
  for (let key in data) {
@@ -183,8 +181,7 @@ class GuildBetUser {
183
181
  url: route,
184
182
  payload,
185
183
  });
186
- this._updateInternals(response);
187
- return this;
184
+ return this._updateInternals(response);
188
185
  }
189
186
  async delete() {
190
187
  const route = Routes_1.Routes.guilds.betusers.delete(this.manager.guild.id, this.id);
@@ -3,6 +3,7 @@ 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 managers_1 = require("../../managers");
6
7
  class GuildMatch {
7
8
  _id;
8
9
  selections;
@@ -63,7 +64,7 @@ class GuildMatch {
63
64
  this.admin_id = data?.admin_id;
64
65
  this.challenge = data?.challenge;
65
66
  this.players = data?.players;
66
- this.messages = data?.messages;
67
+ this.messages = new managers_1.MessagesManager(this, Routes_1.Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
67
68
  this.channels = data?.channels;
68
69
  this.type = data?.type;
69
70
  this.status = data?.status;
@@ -82,6 +83,8 @@ class GuildMatch {
82
83
  this.key = "matches";
83
84
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
84
85
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
86
+ if (data?.messages?.length !== 0)
87
+ this.messages.set(data.messages);
85
88
  }
86
89
  /**
87
90
  * Fetches the match
@@ -218,15 +221,18 @@ class GuildMatch {
218
221
  toJSON() {
219
222
  const json = {};
220
223
  for (const [key, value] of Object.entries(this)) {
224
+ const exclude = ["rest", "guilds", "guild", "manager"];
225
+ if (exclude.includes(key))
226
+ continue;
221
227
  if (typeof value !== "function") {
222
228
  json[key] = value;
223
229
  }
224
230
  }
225
- return json;
231
+ return { ...json, messages: this.messages.cache.toArray() };
226
232
  }
227
233
  _updateInternals(data) {
228
234
  for (let key in data) {
229
- if (key === "id" || key === "createdAt")
235
+ if (key === "id" || key === "createdAt" || key === "messages")
230
236
  continue;
231
237
  if (key in this) {
232
238
  this[key] = data[key];
@@ -235,6 +241,8 @@ class GuildMatch {
235
241
  this.bet = this.guild.bets.set(data.bet);
236
242
  }
237
243
  }
244
+ if (data?.messages?.length !== 0)
245
+ this.messages.set(data.messages);
238
246
  this.updatedAt = new Date();
239
247
  this.manager.set(this);
240
248
  return this;
@@ -10,4 +10,10 @@ var LogEntryTypes;
10
10
  LogEntryTypes["MatchClosed"] = "match_closed";
11
11
  LogEntryTypes["UserUpdated"] = "user_updated";
12
12
  LogEntryTypes["UserManaged"] = "user_managed";
13
+ LogEntryTypes["BetManaged"] = "bet_managed";
14
+ LogEntryTypes["BetMediador"] = "bet_mediador";
15
+ LogEntryTypes["BetInitiated"] = "bet_initiated";
16
+ LogEntryTypes["BetClosed"] = "bet_closed";
17
+ LogEntryTypes["BetAwaitingConfirmation"] = "bet_awaiting_confirmation";
18
+ LogEntryTypes["BetCanceled"] = "bet_canceled";
13
19
  })(LogEntryTypes || (exports.LogEntryTypes = LogEntryTypes = {}));
@@ -50,7 +50,6 @@ var STATES;
50
50
  __exportStar(require("./APIAdvert"), exports);
51
51
  __exportStar(require("./APIBaseChannel"), exports);
52
52
  __exportStar(require("./APIBetChannel"), exports);
53
- __exportStar(require("./APIBetMessage"), exports);
54
53
  __exportStar(require("./APICode"), exports);
55
54
  __exportStar(require("./APIGiveaway"), exports);
56
55
  __exportStar(require("./APIGuild"), exports);
@@ -66,7 +65,6 @@ __exportStar(require("./APIGuildShop"), exports);
66
65
  __exportStar(require("./APIGuildTicket"), exports);
67
66
  __exportStar(require("./APIGuildUser"), exports);
68
67
  __exportStar(require("./APILogEntry"), exports);
69
- __exportStar(require("./APILogMessage"), exports);
70
68
  __exportStar(require("./APIMessage"), exports);
71
69
  __exportStar(require("./APIMinesGame"), exports);
72
70
  __exportStar(require("./APIPlayer"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duque.edits/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index",
5
5
  "types": "./types/index.d.ts",
6
6
  "typings": "./types/index.d.ts",
@@ -11,5 +11,5 @@ export declare class GuildBetManager extends BaseManager<GuildBet> {
11
11
  fetch(options?: FetchOptions): Promise<GuildBet | Collection<string, GuildBet>>;
12
12
  create(data: Optional<APIGuildBet>): Promise<GuildBet>;
13
13
  delete(betId?: string): Promise<GuildBet>;
14
- set(data: Optional<APIGuildBet> | Optional<APIGuildBet>[]): GuildBet;
14
+ set(data: Optional<APIGuildBet> | Optional<APIGuildBet>[] | GuildBet): GuildBet;
15
15
  }
@@ -22,7 +22,7 @@ export declare class GuildMatchManager extends BaseManager<GuildMatch> {
22
22
  */
23
23
  fetch(options?: Optional<FetchOptions>): Promise<GuildMatch | Collection<string, GuildMatch>>;
24
24
  fetchAll(): Promise<Collection<string, GuildMatch>>;
25
- set(data: APIGuildMatch | APIGuildMatch[]): GuildMatch | Collection<string, GuildMatch>;
25
+ set(data: APIGuildMatch | APIGuildMatch[] | GuildMatch): GuildMatch | Collection<string, GuildMatch>;
26
26
  create(payload: Optional<APIGuildMatch>): Promise<GuildMatch>;
27
27
  delete(id?: string): Promise<GuildMatch | Collection<string, GuildMatch>>;
28
28
  }
@@ -1,17 +1,20 @@
1
1
  import { REST } from "../../rest";
2
+ import { Guild } from "../../structures";
2
3
  import { Collection } from "../../structures/Collection";
3
4
  import { APIMessage, Optional } from "../../types";
4
5
  type T<e> = e & {
5
6
  rest: REST;
7
+ guild: Guild;
6
8
  messages: MessagesManager<e>;
7
9
  };
8
10
  export declare class MessagesManager<Structure> {
9
11
  cache: Collection<string, APIMessage>;
10
12
  readonly base_url: string;
11
13
  readonly rest: REST;
14
+ readonly guild: Guild;
12
15
  constructor(structure: T<Structure>, base_url: string);
13
16
  fetch(): Promise<APIMessage>;
14
- create(data: Optional<APIMessage> | Optional<APIMessage>[]): Promise<APIMessage[]>;
15
- setAll(data: APIMessage | APIMessage[]): Collection<string, APIMessage>;
17
+ create(data: Optional<APIMessage> | Optional<APIMessage>[]): Promise<Collection<string, APIMessage>>;
18
+ set(data: APIMessage | APIMessage[]): Collection<string, APIMessage>;
16
19
  }
17
20
  export {};
@@ -0,0 +1,9 @@
1
+ import { Collection } from "../../structures";
2
+ import { APIPlayer } from "../../types";
3
+ export type AddPlayer = APIPlayer[] | APIPlayer;
4
+ export declare class PlayerManager {
5
+ _cache: Collection<string, APIPlayer>;
6
+ constructor(players: APIPlayer | APIPlayer[], base_url: string);
7
+ get(id: string): APIPlayer;
8
+ add(player: AddPlayer): void;
9
+ }
@@ -1,6 +1,6 @@
1
- import { GuildBetManager } from "../../managers";
1
+ import { GuildBetManager, MessagesManager } from "../../managers";
2
2
  import { REST } from "../../rest";
3
- import { APIBetChannel, APIGuildBet, APIMessage, APIPlayer, BaseMatchModes, BetQueue, Confirm, Optional } from "../../types";
3
+ import { APIBetChannel, APIGuildBet, 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 */
@@ -19,7 +19,7 @@ export declare class GuildBet {
19
19
  /** The bet's channel */
20
20
  channels: APIBetChannel[];
21
21
  /** The bet's messages */
22
- messages: APIMessage[];
22
+ messages: MessagesManager<GuildBet>;
23
23
  /** The id of the winner */
24
24
  winners: APIPlayer[];
25
25
  /** The id of the loser */
@@ -37,6 +37,7 @@ export declare class GuildBet {
37
37
  /** Bet's id */
38
38
  _id: string;
39
39
  queues: BetQueue[];
40
+ guild_id: string;
40
41
  rest: REST;
41
42
  guild: Guild;
42
43
  manager: GuildBetManager;
@@ -1,6 +1,6 @@
1
1
  import { REST } from "../../rest/REST";
2
2
  import { APIBaseChannel, APIGuildMatch, APIMessage, APIPlayer, BaseMatchModes, BaseMatchStatus, Confirm, MatchSelection, Optional } from "../../types";
3
- import { GuildMatchManager } from "../../managers";
3
+ import { GuildMatchManager, MessagesManager } from "../../managers";
4
4
  import { Guild } from "../guild/Guild";
5
5
  import { GuildBet } from "../bet/GuildBet";
6
6
  export declare class GuildMatch {
@@ -37,7 +37,7 @@ export declare class GuildMatch {
37
37
  createdAt: Date;
38
38
  /** Updated Date */
39
39
  updatedAt: Date;
40
- messages: APIMessage[];
40
+ messages: MessagesManager<GuildMatch>;
41
41
  /** Match's id */
42
42
  mvps: [];
43
43
  manager: GuildMatchManager;
@@ -60,7 +60,7 @@ export declare class GuildMatch {
60
60
  * @returns New Instance of the match
61
61
  */
62
62
  fetch(): Promise<GuildMatch>;
63
- addConfirmed(type: string, id: string | string[]): Promise<APIGuildMatch>;
63
+ addConfirmed(type: string, id: string | string[]): Promise<GuildMatch>;
64
64
  setConfirmed(set: Confirm[]): Promise<GuildMatch>;
65
65
  setStatus(status: BaseMatchStatus): Promise<GuildMatch>;
66
66
  setWinners(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
@@ -71,6 +71,8 @@ export declare class GuildMatch {
71
71
  kick(player: Optional<APIPlayer>): Promise<this>;
72
72
  update(data: Optional<APIGuildMatch>): Promise<GuildMatch>;
73
73
  delete(): Promise<boolean>;
74
- toJSON(): Record<string, unknown>;
74
+ toJSON(): {
75
+ messages: APIMessage[];
76
+ };
75
77
  _updateInternals(data: Optional<APIGuildMatch>): this;
76
78
  }
@@ -1,6 +1,6 @@
1
1
  import { GuildTicketManager } from "../../managers";
2
2
  import { REST } from "../../rest";
3
- import { APIGuildTicket, APILogMessage, Optional } from "../../types";
3
+ import { APIGuildTicket, APIMessage, Optional } from "../../types";
4
4
  import { Guild } from "../";
5
5
  export declare class GuildTicket implements APIGuildTicket {
6
6
  _id: string;
@@ -12,7 +12,7 @@ export declare class GuildTicket implements APIGuildTicket {
12
12
  closed_by_id: string;
13
13
  creator_id: string;
14
14
  customer_rating: number;
15
- messages: APILogMessage[];
15
+ messages: APIMessage[];
16
16
  createdAt: Date;
17
17
  updatedAt: Date;
18
18
  readonly rest: REST;
@@ -25,6 +25,6 @@ export declare class GuildTicket implements APIGuildTicket {
25
25
  setChannelId(id: string): Promise<GuildTicket>;
26
26
  setClosedById(id: string): Promise<GuildTicket>;
27
27
  setStatus(status: "on" | "off"): Promise<GuildTicket>;
28
- addMessage(message: Optional<APILogMessage>): Promise<GuildTicket>;
28
+ addMessage(message: Optional<APIMessage>): Promise<GuildTicket>;
29
29
  _updateInternals(data: Optional<APIGuildTicket>): this;
30
30
  }
@@ -70,5 +70,5 @@ export declare class GuildUser implements APIGuildUser {
70
70
  type?: "add" | "remove";
71
71
  }): Promise<this>;
72
72
  delete(): Promise<boolean>;
73
- toJSON(): Optional<APIGuildUser>;
73
+ toJSON(): APIGuildUser;
74
74
  }
@@ -23,6 +23,7 @@ export interface APIGuildBet {
23
23
  maximumSize: number;
24
24
  /** The bet's price */
25
25
  price: number;
26
+ guild_id: string;
26
27
  /** The bet's players */
27
28
  players: APIPlayer[];
28
29
  teams: APIPlayer[][];
@@ -1,4 +1,4 @@
1
- import { APILogMessage } from "./APILogMessage";
1
+ import { APIMessage } from "./APIMessage";
2
2
  export interface APIGuildTicket {
3
3
  /** Ticket's id */
4
4
  _id: string;
@@ -10,7 +10,7 @@ export interface APIGuildTicket {
10
10
  admin_id: string;
11
11
  customer_rating: number;
12
12
  closed_by_id: string;
13
- messages: APILogMessage[];
13
+ messages: APIMessage[];
14
14
  createdAt: Date;
15
15
  updatedAt: Date;
16
16
  }
@@ -5,7 +5,13 @@ export declare enum LogEntryTypes {
5
5
  MatchUpdated = "match_updated",
6
6
  MatchClosed = "match_closed",
7
7
  UserUpdated = "user_updated",
8
- UserManaged = "user_managed"
8
+ UserManaged = "user_managed",
9
+ BetManaged = "bet_managed",
10
+ BetMediador = "bet_mediador",
11
+ BetInitiated = "bet_initiated",
12
+ BetClosed = "bet_closed",
13
+ BetAwaitingConfirmation = "bet_awaiting_confirmation",
14
+ BetCanceled = "bet_canceled"
9
15
  }
10
16
  export interface APILogEntry {
11
17
  _id: string;
@@ -1,11 +1,9 @@
1
1
  export interface APIMessage {
2
- /** Message's content */
3
- content?: string | object;
4
2
  _id?: string;
5
- id?: string;
3
+ author_id?: string;
6
4
  extension?: string;
7
- /** Message's type */
8
- type: string;
5
+ /** Message's content */
6
+ content?: string | object;
9
7
  /** Creation Date */
10
8
  createdAt?: Date;
11
9
  /** Updated Date */
@@ -139,7 +139,6 @@ export interface StatusResponse {
139
139
  export * from "./APIAdvert";
140
140
  export * from "./APIBaseChannel";
141
141
  export * from "./APIBetChannel";
142
- export * from "./APIBetMessage";
143
142
  export * from "./APICode";
144
143
  export * from "./APIGiveaway";
145
144
  export * from "./APIGuild";
@@ -155,7 +154,6 @@ export * from "./APIGuildShop";
155
154
  export * from "./APIGuildTicket";
156
155
  export * from "./APIGuildUser";
157
156
  export * from "./APILogEntry";
158
- export * from "./APILogMessage";
159
157
  export * from "./APIMessage";
160
158
  export * from "./APIMinesGame";
161
159
  export * from "./APIPlayer";