@duque.edits/sdk 1.0.8 → 1.0.87

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.
@@ -1,33 +1,77 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlayerManager = void 0;
4
- const structures_1 = require("../../structures");
5
- class PlayerManager extends structures_1.Collection {
4
+ const Collection_1 = require("../../structures/Collection");
5
+ class PlayerManager extends Collection_1.Collection {
6
6
  base_url;
7
- constructor(players, base_url) {
7
+ rest;
8
+ guild;
9
+ constructor(structure, base_url) {
8
10
  super("players");
9
11
  this.base_url = base_url;
10
- if (Array.isArray(players)) {
11
- for (let p of players) {
12
- if (!p.id)
13
- continue;
14
- this.set(p.id, p);
15
- }
16
- }
12
+ this.guild = structure.guild;
13
+ this.rest = structure.rest;
17
14
  }
18
- add(player) {
19
- if (Array.isArray(player)) {
20
- for (let p of player) {
15
+ _set(data) {
16
+ this.clear();
17
+ if (Array.isArray(data)) {
18
+ for (let p of data) {
21
19
  if (!p.id)
22
20
  continue;
23
- this.set(p.id, p);
21
+ this.set(p.id, {
22
+ id: p.id,
23
+ createdAt: p.createdAt ? new Date(p.createdAt) : new Date(),
24
+ updateAt: p.updateAt ? new Date(p.updateAt) : new Date(),
25
+ });
24
26
  }
25
27
  }
26
28
  else {
27
- if (!player.id)
29
+ if (!data.id)
28
30
  return;
29
- this.set(player.id, player);
31
+ this.set(data.id, {
32
+ id: data.id,
33
+ createdAt: data.createdAt ? new Date(data.createdAt) : new Date(),
34
+ updateAt: data.updateAt ? new Date(data.updateAt) : new Date(),
35
+ });
30
36
  }
37
+ return this;
38
+ }
39
+ /**
40
+ * Adds a player or an array of players to the structure.
41
+ * @param player A player or an array of players to be added
42
+ * @returns returns a collection of players
43
+ */
44
+ async add(player) {
45
+ let players = [];
46
+ if (Array.isArray(player)) {
47
+ for (let p of player)
48
+ this.has(p.id) ? null : players.push(p);
49
+ }
50
+ else
51
+ this.has(player.id) ? null : players.push(player);
52
+ const payload = { set: players };
53
+ const response = await this.rest.request({
54
+ method: "PATCH",
55
+ payload,
56
+ url: this.base_url,
57
+ });
58
+ return this._set(response.players);
59
+ }
60
+ /**
61
+ * Remover a player or an array of players.
62
+ * @param player The player or an array of players to be removed
63
+ * @returns Player manager
64
+ */
65
+ async remove(player) {
66
+ const ids = new Set(Array.isArray(player) ? player.map((p) => p.id) : [player.id]);
67
+ const players = this.toArray().filter((p) => !ids.has(p.id));
68
+ const payload = { set: players };
69
+ const response = await this.rest.request({
70
+ method: "PATCH",
71
+ payload,
72
+ url: this.base_url,
73
+ });
74
+ return this._set(response.players);
31
75
  }
32
76
  }
33
77
  exports.PlayerManager = PlayerManager;
@@ -69,7 +69,7 @@ class VipMemberManager extends base_1.BaseManager {
69
69
  const route = Routes_1.Routes.vipmembers.update(this.guild.id, id);
70
70
  const payload = { ...data, guild_id: this.guild.id };
71
71
  const response = await this.rest.request({
72
- method: "Patch",
72
+ method: "patch",
73
73
  url: route,
74
74
  payload,
75
75
  });
package/dist/rest/REST.js CHANGED
@@ -78,7 +78,6 @@ class REST extends events_1.default {
78
78
  Assertion_1.Assertion.assertString(method);
79
79
  Assertion_1.Assertion.assertString(this.clientKey);
80
80
  Assertion_1.Assertion.assertString(url);
81
- method = method.toUpperCase();
82
81
  url = this.formatUrl(Routes_1.Routes.base + url);
83
82
  const headers = new undici_1.Headers();
84
83
  headers.append("authorization", this.authKey);
@@ -88,7 +87,7 @@ class REST extends events_1.default {
88
87
  this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
89
88
  const body = { ...payload };
90
89
  const res = await (0, undici_1.request)(url, {
91
- method,
90
+ method: method.toUpperCase(),
92
91
  headers,
93
92
  body: JSON.stringify(body),
94
93
  });
@@ -2,8 +2,8 @@
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
- //base: "https://duque-api.up.railway.app/api/v1",
5
+ // base: "http://localhost:80/api/v1",
6
+ base: "https://duque-api.up.railway.app/api/v1",
7
7
  field: (field) => `/${field}`,
8
8
  fields: (...fields) => `${fields.join("/")}`,
9
9
  guilds: {
@@ -87,4 +87,3 @@ class Collection extends Map {
87
87
  }
88
88
  }
89
89
  exports.Collection = Collection;
90
- module.exports = { Collection };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildBet = void 0;
4
4
  const managers_1 = require("../../managers");
5
+ const PlayerManager_1 = require("../../managers/player/PlayerManager");
5
6
  const rest_1 = require("../../rest");
6
7
  class GuildBet {
7
8
  /** The bet's type */
@@ -53,9 +54,9 @@ class GuildBet {
53
54
  this.status = data?.status;
54
55
  this.maximumSize = data?.maximumSize;
55
56
  this.price = data?.price;
56
- this.players = data?.players;
57
57
  this.teams = data?.teams;
58
58
  this.channels = data?.channels;
59
+ this.players = new PlayerManager_1.PlayerManager(this, rest_1.Routes.guilds.bets.resource(this.guild_id, this._id, "players"));
59
60
  this.messages = new managers_1.MessagesManager(this, rest_1.Routes.guilds.bets.resource(this.guild_id, this._id, "messages"));
60
61
  this.winners = data?.winners;
61
62
  this.losers = data?.losers;
@@ -76,6 +77,8 @@ class GuildBet {
76
77
  }
77
78
  if (data?.messages?.length !== 0)
78
79
  this.messages.set(data.messages);
80
+ if (data?.players.length !== 0)
81
+ this.players._set(data.players);
79
82
  }
80
83
  toString() {
81
84
  return this._id;
@@ -88,9 +91,9 @@ class GuildBet {
88
91
  async addPlayer(player, queue_type) {
89
92
  if (this.players.length === 2)
90
93
  return this;
91
- if (this.players.some((p) => p.id === player.id))
94
+ if (this.players.has(player.id))
92
95
  return this;
93
- this.players.push(player);
96
+ this.players.set(player.id, player);
94
97
  if (queue_type) {
95
98
  const queue = this.queues.find((q) => q.type === queue_type);
96
99
  if (!queue)
@@ -103,19 +106,20 @@ class GuildBet {
103
106
  }
104
107
  }
105
108
  return await this.update({
106
- players: this.players,
109
+ players: this.players.toArray(),
107
110
  queues: this.queues,
108
111
  });
109
112
  }
110
113
  async removePlayer(player) {
111
114
  if (!this.players.some((p) => p.id === player.id))
112
115
  return this;
113
- this.players = this.players.filter((p) => p.id !== player.id);
116
+ let players = this.players.toArray();
117
+ players = this.players.filter((p) => p.id !== player.id).toArray();
114
118
  for (const q of this.queues) {
115
119
  q.players = q.players.filter((p) => p.id !== player.id);
116
120
  }
117
121
  return await this.update({
118
- players: this.players,
122
+ players: players,
119
123
  queues: this.queues,
120
124
  });
121
125
  }
@@ -143,6 +147,10 @@ class GuildBet {
143
147
  this.messages.set(data[key]);
144
148
  continue;
145
149
  }
150
+ if (key === "players") {
151
+ this.players._set(data[key]);
152
+ continue;
153
+ }
146
154
  if (key in this) {
147
155
  this[key] = data[key];
148
156
  }
@@ -173,6 +181,7 @@ class GuildBet {
173
181
  return {
174
182
  ...json,
175
183
  messages: this?.messages instanceof managers_1.MessagesManager ? this.messages?.cache?.toArray() : [],
184
+ players: this.players.toArray(),
176
185
  };
177
186
  }
178
187
  }
@@ -183,6 +183,16 @@ class GuildBetUser {
183
183
  });
184
184
  return this._updateInternals(response);
185
185
  }
186
+ async _update(data) {
187
+ const route = Routes_1.Routes.guilds.betusers.get(this.manager.guild.id, this.id);
188
+ let payload = {};
189
+ const response = await this.rest.request({
190
+ method: "put",
191
+ url: route,
192
+ payload,
193
+ });
194
+ return this._updateInternals(response);
195
+ }
186
196
  async delete() {
187
197
  const route = Routes_1.Routes.guilds.betusers.delete(this.manager.guild.id, this.id);
188
198
  const response = await this.rest.request({
@@ -29,6 +29,7 @@ class Guild {
29
29
  /** Guild Status */
30
30
  status;
31
31
  channels;
32
+ roulette_settings;
32
33
  /** Guild Prefix */
33
34
  prefix;
34
35
  /** Guild Creation Date */
@@ -73,6 +74,7 @@ class Guild {
73
74
  this.channels = data?.channels;
74
75
  this.shop = data?.shop;
75
76
  this.coin_symbol = data?.coin_symbol;
77
+ this.roulette_settings = data?.roulette_settings;
76
78
  this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
77
79
  this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
78
80
  this.permissionsManager = new managers_1.GuildPermissionManager(this);
@@ -236,6 +238,59 @@ class Guild {
236
238
  });
237
239
  return this._updateInternals(response);
238
240
  }
241
+ async updateRouletteSettings(data) {
242
+ const _data = {
243
+ roulette_settings: {
244
+ primary_color: !data.default
245
+ ? data.primary_color || this.roulette_settings.primary_color || "#161616"
246
+ : "#161616",
247
+ secondary_color: !data.default
248
+ ? data.secondary_color || this.roulette_settings.secondary_color || "#1A1A1A"
249
+ : "#1A1A1A",
250
+ tertiary_color: !data.default
251
+ ? data.tertiary_color || this.roulette_settings.tertiary_color || "#2D2D2D"
252
+ : "#2D2D2D",
253
+ text_color: !data.default ? data.text_color || this.roulette_settings.text_color || "#ffffff" : "#ffffff",
254
+ prizes: data.prizes || this.roulette_settings.prizes || [],
255
+ },
256
+ };
257
+ return this.update(_data);
258
+ }
259
+ async addRoulettePrize(prize) {
260
+ if (!prize.label) {
261
+ throw new Error("Prize label is required");
262
+ }
263
+ const prizes = this.roulette_settings.prizes;
264
+ const prizeIndex = prize._id
265
+ ? prizes.findIndex((p) => p._id === prize._id)
266
+ : prizes.findIndex((p) => p.label === prize.label);
267
+ const defaultProbability = prizes.length > 0 ? 1 / prizes.length : 0.1;
268
+ if (prizeIndex !== -1) {
269
+ const existing = prizes[prizeIndex];
270
+ prizes[prizeIndex] = {
271
+ label: prize.label,
272
+ custom_color: prize.custom_color ?? existing.custom_color,
273
+ custom_probability: prize.custom_probability ?? existing.custom_probability ?? defaultProbability,
274
+ _id: existing._id,
275
+ };
276
+ }
277
+ else {
278
+ prizes.push({
279
+ label: prize.label,
280
+ custom_color: prize.custom_color ?? "",
281
+ custom_probability: prize.custom_probability ?? defaultProbability,
282
+ });
283
+ }
284
+ await this.updateRouletteSettings({ prizes: prizes });
285
+ return this.roulette_settings.prizes.find((p) => p.label === prize.label);
286
+ }
287
+ async removeRoulettePrize(id) {
288
+ let prizes = this.roulette_settings.prizes;
289
+ if (!prizes.find((p) => p._id === id))
290
+ return this;
291
+ prizes = prizes.filter((p) => p._id !== id);
292
+ return this.updateRouletteSettings({ prizes });
293
+ }
239
294
  async _start() {
240
295
  await Promise.all([
241
296
  this.users.fetch(),
@@ -28,6 +28,7 @@ class GuildUser {
28
28
  creations;
29
29
  /** User's items */
30
30
  adverts;
31
+ roulette_turns;
31
32
  /** Creation Date */
32
33
  createdAt;
33
34
  /** Updated Date */
@@ -52,6 +53,7 @@ class GuildUser {
52
53
  this.mvps = data?.mvps;
53
54
  this.points = data?.points;
54
55
  this.creations = data?.creations;
56
+ this.roulette_turns = data.roulette_turns;
55
57
  this.daily = data?.daily;
56
58
  this.games = data?.games;
57
59
  this.blacklist = data?.blacklist;
@@ -201,7 +203,7 @@ class GuildUser {
201
203
  data.type = "add";
202
204
  const route = Routes_1.Routes.guilds.users.get(this.manager.guild.id, this.id);
203
205
  let payload = {};
204
- const numericFields = ["wins", "points", "losses", "mvps", "games", "creations"];
206
+ const numericFields = ["wins", "points", "losses", "mvps", "games", "creations", "roulette_turns"];
205
207
  const arrayFields = ["items", "original_channels", "adverts", "accessories"];
206
208
  if (data?.type === "add" || data?.type === "remove") {
207
209
  for (const key in data) {
@@ -37,4 +37,6 @@ var GuildChannelsType;
37
37
  GuildChannelsType["BetMobileCategory"] = "bet_mobile_category";
38
38
  GuildChannelsType["BetEmulatorCategory"] = "bet_emulator_category";
39
39
  GuildChannelsType["BetMixCategory"] = "bet_mix_category";
40
+ GuildChannelsType["RouletteLogs"] = "roulette_logs";
41
+ GuildChannelsType["Rules"] = "rules";
40
42
  })(GuildChannelsType || (exports.GuildChannelsType = GuildChannelsType = {}));
@@ -8,4 +8,5 @@ var GuildPermissionsTypes;
8
8
  GuildPermissionsTypes["ManageUsers"] = "manage_users";
9
9
  GuildPermissionsTypes["ViewQueueChannels"] = "view_queue_channels";
10
10
  GuildPermissionsTypes["MediatorRole"] = "mediator_role";
11
+ GuildPermissionsTypes["ManageRouletteRolls"] = "manage_roulette_rolls";
11
12
  })(GuildPermissionsTypes || (exports.GuildPermissionsTypes = GuildPermissionsTypes = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duque.edits/sdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.87",
4
4
  "main": "dist/index",
5
5
  "types": "./types/index.d.ts",
6
6
  "typings": "./types/index.d.ts",
@@ -21,7 +21,8 @@
21
21
  "test": "ts-node --transpile-only tests/index.ts",
22
22
  "match": "ts-node --transpile-only tests/match.ts",
23
23
  "guild": "ts-node --transpile-only tests/guild.ts",
24
- "user": "ts-node --transpile-only tests/user.ts"
24
+ "user": "ts-node --transpile-only tests/user.ts",
25
+ "bet": "ts-node --transpile-only tests/bet.ts"
25
26
  },
26
27
  "author": "Duque Edits jedits077@gmail.com",
27
28
  "license": "ISC",
@@ -1,8 +1,28 @@
1
- import { Collection } from "../../structures";
1
+ import { REST } from "../../rest";
2
+ import { Guild } from "../../structures/guild/Guild";
3
+ import { Collection } from "../../structures/Collection";
2
4
  import { APIPlayer } from "../../types";
3
- export type AddPlayer = APIPlayer[] | APIPlayer;
5
+ export type PlayerOption = APIPlayer[] | APIPlayer;
6
+ export type Structure = {
7
+ guild: Guild;
8
+ rest: REST;
9
+ };
4
10
  export declare class PlayerManager extends Collection<string, APIPlayer> {
5
11
  base_url: string;
6
- constructor(players: APIPlayer | APIPlayer[], base_url: string);
7
- add(player: AddPlayer): void;
12
+ readonly rest: REST;
13
+ readonly guild: Guild;
14
+ constructor(structure: Structure, base_url: string);
15
+ _set(data: PlayerOption): this;
16
+ /**
17
+ * Adds a player or an array of players to the structure.
18
+ * @param player A player or an array of players to be added
19
+ * @returns returns a collection of players
20
+ */
21
+ add(player: PlayerOption): Promise<this>;
22
+ /**
23
+ * Remover a player or an array of players.
24
+ * @param player The player or an array of players to be removed
25
+ * @returns Player manager
26
+ */
27
+ remove(player: PlayerOption): Promise<this>;
8
28
  }
@@ -1,4 +1,5 @@
1
1
  import { GuildBetManager, MessagesManager } from "../../managers";
2
+ import { PlayerManager } from "../../managers/player/PlayerManager";
2
3
  import { REST } from "../../rest";
3
4
  import { APIBetChannel, APIGuildBet, APIPlayer, BaseMatchModes, BetQueue, Confirm, Optional } from "../../types";
4
5
  import { Guild } from "../guild/Guild";
@@ -14,7 +15,7 @@ export declare class GuildBet {
14
15
  /** The bet's price */
15
16
  price: number;
16
17
  /** The bet's players */
17
- players: APIPlayer[];
18
+ players: PlayerManager;
18
19
  teams: APIPlayer[][];
19
20
  /** The bet's channel */
20
21
  channels: APIBetChannel[];
@@ -65,6 +65,7 @@ export declare class GuildBetUser implements APIGuildBetUser {
65
65
  update(data: Omit<Optional<APIGuildBetUser>, "daily"> & {
66
66
  type?: "add" | "remove";
67
67
  }): Promise<this>;
68
+ _update(data: Omit<Optional<APIGuildBetUser>, "daily">): Promise<this>;
68
69
  delete(): Promise<boolean>;
69
70
  toJSON(): Optional<APIGuildBetUser>;
70
71
  }
@@ -3,7 +3,7 @@ import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager"
3
3
  import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
4
4
  import { REST } from "../../rest/REST";
5
5
  import { APICode, APIGuildAdvert, APIGuildGroupedChannel, APIGuildPermissions, APIGuildShop, Daily, GuildPermissionsTypes, Optional, Permission } from "../../types/api";
6
- import { APIGuild, DailyCategories, GuildChannelsType, GuildModes, GuildPrices, GuildScores, GuildStatus, GuildTicketConfiguration } from "../../types/api/APIGuild";
6
+ import { APIGuild, DailyCategories, GuildChannelsType, GuildModes, GuildPrices, GuildScores, GuildStatus, GuildTicketConfiguration, RoulettePrize, RouletteSettings } from "../../types/api/APIGuild";
7
7
  export declare class Guild {
8
8
  /** The data of this guild */
9
9
  data: APIGuild;
@@ -27,6 +27,7 @@ export declare class Guild {
27
27
  /** Guild Status */
28
28
  status: GuildStatus;
29
29
  channels: APIGuildGroupedChannel[];
30
+ roulette_settings: RouletteSettings;
30
31
  /** Guild Prefix */
31
32
  prefix: string;
32
33
  /** Guild Creation Date */
@@ -64,6 +65,11 @@ export declare class Guild {
64
65
  addIdToChannel(type: GuildChannelsType, id: string | string[]): Promise<this>;
65
66
  setChannelIds(type: GuildChannelsType, ...ids: string[]): Promise<this>;
66
67
  removeIdInChannel(type: GuildChannelsType, id: string | string[]): Promise<this>;
68
+ updateRouletteSettings(data: Optional<RouletteSettings> & {
69
+ default?: boolean;
70
+ }): Promise<Guild>;
71
+ addRoulettePrize(prize: Optional<RoulettePrize>): Promise<RoulettePrize>;
72
+ removeRoulettePrize(id: string): Promise<Guild>;
67
73
  _start(): Promise<this>;
68
74
  _updateInternals(data: Optional<APIGuild>): this;
69
75
  fetch(): Promise<Guild>;
@@ -28,6 +28,7 @@ export declare class GuildUser implements APIGuildUser {
28
28
  creations: number;
29
29
  /** User's items */
30
30
  adverts: APIAdvert[];
31
+ roulette_turns: number;
31
32
  /** Creation Date */
32
33
  createdAt: Date;
33
34
  /** Updated Date */
@@ -6,7 +6,7 @@ import { GuildMatch } from "../structures/match/GuildMatch";
6
6
  import { GuildUser } from "../structures/user/GuildUser";
7
7
  export interface RequestOptions<Payload> {
8
8
  /** The request's method */
9
- method: string;
9
+ method: "patch" | "get" | "put" | "post" | "delete" | "options" | "head" | "PATCH" | "GET" | "PUT" | "POST" | "DELETE" | "OPTIONS" | "HEAD";
10
10
  /** The request's url */
11
11
  url: string;
12
12
  /** The request payload */
@@ -94,6 +94,20 @@ export interface APIGuild {
94
94
  max_advert_per_user: number;
95
95
  codes: APICode[];
96
96
  coin_symbol: string;
97
+ roulette_settings: RouletteSettings;
98
+ }
99
+ export interface RoulettePrize {
100
+ label: string;
101
+ custom_color: string;
102
+ custom_probability: number;
103
+ _id: string;
104
+ }
105
+ export interface RouletteSettings {
106
+ primary_color: string;
107
+ secondary_color: string;
108
+ tertiary_color: string;
109
+ text_color: string;
110
+ prizes: RoulettePrize[];
97
111
  }
98
112
  export declare enum GuildChannelsType {
99
113
  DailyRank = "daily_rank",
@@ -112,5 +126,7 @@ export declare enum GuildChannelsType {
112
126
  WaitingVC = "waiting_vc",
113
127
  BetMobileCategory = "bet_mobile_category",
114
128
  BetEmulatorCategory = "bet_emulator_category",
115
- BetMixCategory = "bet_mix_category"
129
+ BetMixCategory = "bet_mix_category",
130
+ RouletteLogs = "roulette_logs",
131
+ Rules = "rules"
116
132
  }
@@ -8,5 +8,6 @@ export declare enum GuildPermissionsTypes {
8
8
  ManageQueues = "manage_queues",
9
9
  ManageUsers = "manage_users",
10
10
  ViewQueueChannels = "view_queue_channels",
11
- MediatorRole = "mediator_role"
11
+ MediatorRole = "mediator_role",
12
+ ManageRouletteRolls = "manage_roulette_rolls"
12
13
  }
@@ -33,6 +33,7 @@ export interface APIGuildUser {
33
33
  accessories: Accessory[];
34
34
  /** User's original channels */
35
35
  original_channels: OriginalChannels;
36
+ roulette_turns: number;
36
37
  /** Creation Date */
37
38
  createdAt: Date;
38
39
  /** Updated Date */
@@ -1,8 +1,6 @@
1
1
  export interface APIPlayer {
2
2
  /** The player's id */
3
3
  id: string;
4
- /** The player's name */
5
- name?: string;
6
4
  /** When player was created */
7
5
  createdAt?: Date;
8
6
  /** Last time player was updated */