@duque.edits/sdk 0.0.4 → 0.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.
Files changed (155) hide show
  1. package/{v1/index.ts → dist/index.d.ts} +27 -30
  2. package/dist/index.js +43 -0
  3. package/dist/managers/bet/GuildBetManager.d.ts +32 -0
  4. package/dist/managers/bet/GuildBetManager.js +107 -0
  5. package/dist/managers/betuser/GuildBetUserManager.d.ts +30 -0
  6. package/dist/managers/betuser/GuildBetUserManager.js +94 -0
  7. package/dist/managers/channel/ChannelManager.d.ts +39 -0
  8. package/dist/managers/channel/ChannelManager.js +147 -0
  9. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +34 -0
  10. package/dist/managers/groupedchannel/GroupedChannelManager.js +92 -0
  11. package/dist/managers/guild/GuildManager.d.ts +24 -0
  12. package/dist/managers/guild/GuildManager.js +75 -0
  13. package/dist/managers/match/GuildMatchManager.d.ts +32 -0
  14. package/dist/managers/match/GuildMatchManager.js +103 -0
  15. package/dist/managers/mediator/GuildMediatorManager.d.ts +32 -0
  16. package/dist/managers/mediator/GuildMediatorManager.js +97 -0
  17. package/dist/managers/messages/MessagesManager.d.ts +32 -0
  18. package/dist/managers/messages/MessagesManager.js +82 -0
  19. package/dist/managers/permission/GuildPermissionManager.d.ts +26 -0
  20. package/dist/managers/permission/GuildPermissionManager.js +70 -0
  21. package/dist/managers/product/GuildProductManager.d.ts +32 -0
  22. package/dist/managers/product/GuildProductManager.js +102 -0
  23. package/dist/managers/ticket/GuildTicketManager.d.ts +32 -0
  24. package/dist/managers/ticket/GuildTicketManager.js +99 -0
  25. package/dist/managers/user/GuildUserManager.d.ts +32 -0
  26. package/dist/managers/user/GuildUserManager.js +106 -0
  27. package/dist/rest/APIEndpoints.d.ts +11 -0
  28. package/dist/rest/APIEndpoints.js +12 -0
  29. package/dist/rest/REST.d.ts +51 -0
  30. package/dist/rest/REST.js +96 -0
  31. package/dist/rest/Routes.d.ts +84 -0
  32. package/dist/rest/Routes.js +89 -0
  33. package/dist/structures/Collection.d.ts +17 -0
  34. package/dist/structures/Collection.js +87 -0
  35. package/dist/structures/bet/GuildBet.d.ts +86 -0
  36. package/dist/structures/bet/GuildBet.js +276 -0
  37. package/dist/structures/betuser/GuildBetUser.d.ts +82 -0
  38. package/dist/structures/betuser/GuildBetUser.js +194 -0
  39. package/dist/structures/channel/Channel.d.ts +31 -0
  40. package/dist/structures/channel/Channel.js +57 -0
  41. package/dist/structures/groupedchannel/GroupedChannel.d.ts +34 -0
  42. package/dist/structures/groupedchannel/GroupedChannel.js +121 -0
  43. package/dist/structures/guild/Guild.d.ts +89 -0
  44. package/dist/structures/guild/Guild.js +223 -0
  45. package/dist/structures/match/GuildMatch.d.ts +84 -0
  46. package/dist/structures/match/GuildMatch.js +327 -0
  47. package/dist/structures/mediator/GuildMediator.d.ts +41 -0
  48. package/dist/structures/mediator/GuildMediator.js +131 -0
  49. package/dist/structures/product/GuildProduct.d.ts +52 -0
  50. package/dist/structures/product/GuildProduct.js +175 -0
  51. package/dist/structures/shop/GuildShop.d.ts +34 -0
  52. package/dist/structures/shop/GuildShop.js +80 -0
  53. package/dist/structures/ticket/GuildTicket.d.ts +51 -0
  54. package/dist/structures/ticket/GuildTicket.js +170 -0
  55. package/dist/structures/user/GuildUser.d.ts +82 -0
  56. package/dist/structures/user/GuildUser.js +209 -0
  57. package/dist/types/api/APIBaseChannel.d.ts +10 -0
  58. package/dist/types/api/APIBaseChannel.js +2 -0
  59. package/dist/types/api/APIBetChannel.d.ts +10 -0
  60. package/dist/types/api/APIBetChannel.js +2 -0
  61. package/dist/types/api/APIBetMessage.d.ts +10 -0
  62. package/dist/types/api/APIBetMessage.js +2 -0
  63. package/dist/types/api/APIGuild.d.ts +92 -0
  64. package/dist/types/api/APIGuild.js +2 -0
  65. package/dist/types/api/APIGuildBet.d.ts +48 -0
  66. package/dist/types/api/APIGuildBet.js +2 -0
  67. package/dist/types/api/APIGuildBetUser.d.ts +32 -0
  68. package/dist/types/api/APIGuildBetUser.js +2 -0
  69. package/dist/types/api/APIGuildChannel.d.ts +10 -0
  70. package/dist/types/api/APIGuildChannel.js +2 -0
  71. package/dist/types/api/APIGuildEmoji.d.ts +12 -0
  72. package/dist/types/api/APIGuildEmoji.js +2 -0
  73. package/dist/types/api/APIGuildGroupedChannel.d.ts +10 -0
  74. package/dist/types/api/APIGuildGroupedChannel.js +2 -0
  75. package/dist/types/api/APIGuildMatch.d.ts +46 -0
  76. package/dist/types/api/APIGuildMatch.js +2 -0
  77. package/dist/types/api/APIGuildMediator.d.ts +13 -0
  78. package/dist/types/api/APIGuildMediator.js +3 -0
  79. package/dist/types/api/APIGuildMessage.d.ts +10 -0
  80. package/dist/types/api/APIGuildMessage.js +2 -0
  81. package/dist/types/api/APIGuildPermissions.d.ts +6 -0
  82. package/dist/types/api/APIGuildPermissions.js +2 -0
  83. package/dist/types/api/APIGuildRole.d.ts +10 -0
  84. package/dist/types/api/APIGuildRole.js +2 -0
  85. package/dist/types/api/APIGuildShop.d.ts +11 -0
  86. package/dist/types/api/APIGuildShop.js +2 -0
  87. package/dist/types/api/APIGuildTicket.d.ts +25 -0
  88. package/dist/types/api/APIGuildTicket.js +3 -0
  89. package/dist/types/api/APIGuildUser.d.ts +31 -0
  90. package/dist/types/api/APIGuildUser.js +2 -0
  91. package/dist/types/api/APIMessage.d.ts +12 -0
  92. package/dist/types/api/APIMessage.js +2 -0
  93. package/dist/types/api/APIPlayer.d.ts +10 -0
  94. package/dist/types/api/APIPlayer.js +2 -0
  95. package/dist/types/api/APIProduct.d.ts +19 -0
  96. package/dist/types/api/APIProduct.js +3 -0
  97. package/dist/types/api/index.d.ts +130 -0
  98. package/dist/types/api/index.js +35 -0
  99. package/{v1/types/index.ts → dist/types/index.d.ts} +21 -24
  100. package/dist/types/index.js +37 -0
  101. package/dist/utils/Assertion.d.ts +32 -0
  102. package/dist/utils/Assertion.js +60 -0
  103. package/package.json +5 -1
  104. package/.gitattributes +0 -2
  105. package/tests/index.ts +0 -86
  106. package/tsconfig.json +0 -15
  107. package/v1/managers/bet/GuildBetManager.ts +0 -117
  108. package/v1/managers/betuser/GuildBetUserManager.ts +0 -103
  109. package/v1/managers/channel/ChannelManager.ts +0 -168
  110. package/v1/managers/groupedchannel/GroupedChannelManager.ts +0 -117
  111. package/v1/managers/guild/GuildManager.ts +0 -84
  112. package/v1/managers/match/GuildMatchManager.ts +0 -115
  113. package/v1/managers/mediator/GuildMediatorManager.ts +0 -111
  114. package/v1/managers/messages/MessagesManager.ts +0 -95
  115. package/v1/managers/permission/GuildPermissionManager.ts +0 -88
  116. package/v1/managers/product/GuildProductManager.ts +0 -115
  117. package/v1/managers/ticket/GuildTicketManager.ts +0 -112
  118. package/v1/managers/user/GuildUserManager.ts +0 -116
  119. package/v1/rest/APIEndpoints.ts +0 -11
  120. package/v1/rest/REST.ts +0 -126
  121. package/v1/rest/Routes.ts +0 -143
  122. package/v1/structures/Collection.ts +0 -85
  123. package/v1/structures/bet/GuildBet.ts +0 -332
  124. package/v1/structures/betuser/GuildBetUser.ts +0 -247
  125. package/v1/structures/channel/Channel.ts +0 -78
  126. package/v1/structures/groupedchannel/GroupedChannel.ts +0 -165
  127. package/v1/structures/guild/Guild.ts +0 -302
  128. package/v1/structures/match/GuildMatch.ts +0 -385
  129. package/v1/structures/mediator/GuildMediator.ts +0 -175
  130. package/v1/structures/product/GuildProduct.ts +0 -217
  131. package/v1/structures/shop/GuildShop.ts +0 -98
  132. package/v1/structures/ticket/GuildTicket.ts +0 -227
  133. package/v1/structures/user/GuildUser.ts +0 -248
  134. package/v1/types/api/APIBaseChannel.ts +0 -13
  135. package/v1/types/api/APIBetChannel.ts +0 -13
  136. package/v1/types/api/APIBetMessage.ts +0 -13
  137. package/v1/types/api/APIGuild.ts +0 -123
  138. package/v1/types/api/APIGuildBet.ts +0 -69
  139. package/v1/types/api/APIGuildBetUser.ts +0 -46
  140. package/v1/types/api/APIGuildChannel.ts +0 -13
  141. package/v1/types/api/APIGuildEmoji.ts +0 -16
  142. package/v1/types/api/APIGuildGroupedChannel.ts +0 -13
  143. package/v1/types/api/APIGuildMatch.ts +0 -67
  144. package/v1/types/api/APIGuildMediator.ts +0 -18
  145. package/v1/types/api/APIGuildMessage.ts +0 -13
  146. package/v1/types/api/APIGuildPermissions.ts +0 -7
  147. package/v1/types/api/APIGuildRole.ts +0 -13
  148. package/v1/types/api/APIGuildShop.ts +0 -15
  149. package/v1/types/api/APIGuildTicket.ts +0 -36
  150. package/v1/types/api/APIGuildUser.ts +0 -45
  151. package/v1/types/api/APIMessage.ts +0 -16
  152. package/v1/types/api/APIPlayer.ts +0 -13
  153. package/v1/types/api/APIProduct.ts +0 -27
  154. package/v1/types/api/index.ts +0 -180
  155. package/v1/utils/Assertion.ts +0 -56
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Routes = exports.Route = void 0;
4
+ const Route = (route) => route;
5
+ exports.Route = Route;
6
+ exports.Routes = {
7
+ //base: "http://localhost:3000/api/v1",
8
+ base: "https://duquedev.up.railway.app/api/v1",
9
+ field: (field) => `${field}`,
10
+ fields: (...fields) => `${fields.join("/")}`,
11
+ guilds: {
12
+ create: () => `/guilds`,
13
+ get: (guildId) => `/guilds/${guildId}`,
14
+ getAll: () => `/guilds`,
15
+ delete: (guildId) => `/guilds/${guildId}`,
16
+ deleteAll: () => `/guilds`,
17
+ resource: (guildId, resource) => `/guilds/${guildId}/${resource}`,
18
+ resources: (guildId, ...resourcess) => `/guilds/${guildId}/${resourcess.join("/")}`,
19
+ users: {
20
+ create: (guildId) => `/guilds/${guildId}/users`,
21
+ update: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
22
+ getAll: (guildId) => `/guilds/${guildId}/users`,
23
+ get: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
24
+ delete: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
25
+ deleteAll: (guildId) => `/guilds/${guildId}/users`,
26
+ resource: (guildId, userId, resource) => `/guilds/${guildId}/users/${userId}/${resource}`,
27
+ },
28
+ betUsers: {
29
+ getAll: (guildId) => `/guilds/${guildId}/betusers`,
30
+ get: (guildId, userId) => `/guilds/${guildId}/betusers/${userId}`,
31
+ create: (guildId) => `/guilds/${guildId}/betusers`,
32
+ update: (guildId, userId) => `/guilds/${guildId}/betusers/${userId}`,
33
+ delete: (guildId, userId) => `/guilds/${guildId}/betusers/${userId}`,
34
+ deleteAll: (guildId) => `/guilds/${guildId}/betusers`,
35
+ resource: (guildId, userId, resourceName) => `/guilds/${guildId}/betusers/${userId}/${resourceName}`,
36
+ },
37
+ matches: {
38
+ getAll: (guildId) => `/guilds/${guildId}/matches`,
39
+ get: (guildId, matchId) => `/guilds/${guildId}/matches/${matchId}`,
40
+ create: (guildId) => `/guilds/${guildId}/matches`,
41
+ update: (guildId, matchId) => `/guilds/${guildId}/matches/${matchId}`,
42
+ delete: (guildId, matchId) => `/guilds/${guildId}/matches/${matchId}`,
43
+ deleteAll: (guildId) => `/guilds/${guildId}/matches`,
44
+ resource: (guildId, matchId, ...resources) => `/guilds/${guildId}/matches/${matchId}/${resources.join("/")}`,
45
+ },
46
+ bets: {
47
+ getAll: (guildId) => `/guilds/${guildId}/bets`,
48
+ get: (guildId, betId) => `/guilds/${guildId}/bets/${betId}`,
49
+ create: (guildId) => `/guilds/${guildId}/bets`,
50
+ update: (guildId, betId) => `/guilds/${guildId}/bets/${betId}`,
51
+ delete: (guildId, betId) => `/guilds/${guildId}/bets/${betId}`,
52
+ deleteAll: (guildId) => `/guilds/${guildId}/bets`,
53
+ resource: (guildId, betId, ...resources) => `/guilds/${guildId}/bets/${betId}/${resources.join("/")}`,
54
+ },
55
+ tickets: {
56
+ getAll: (guildId) => `/guilds/${guildId}/tickets`,
57
+ get: (guildId, ticketId) => `/guilds/${guildId}/tickets/${ticketId}`,
58
+ create: (guildId) => `/guilds/${guildId}/tickets`,
59
+ update: (guildId, ticketId) => `/guilds/${guildId}/tickets/${ticketId}`,
60
+ delete: (guildId, ticketId) => `/guilds/${guildId}/tickets/${ticketId}`,
61
+ deleteAll: (guildId) => `/guilds/${guildId}/tickets`,
62
+ resource: (guildId, ticketId, ...resources) => `/guilds/${guildId}/tickets/${ticketId}/${resources.join("/")}`,
63
+ },
64
+ mediators: {
65
+ getAll: (guildId) => `/guilds/${guildId}/mediators`,
66
+ get: (guildId, mediatorId) => `/guilds/${guildId}/mediators/${mediatorId}`,
67
+ create: (guildId) => `/guilds/${guildId}/mediators`,
68
+ update: (guildId, mediatorId) => `/guilds/${guildId}/mediators/${mediatorId}`,
69
+ delete: (guildId, mediatorId) => `/guilds/${guildId}/mediators/${mediatorId}`,
70
+ deleteAll: (guildId) => `/guilds/${guildId}/mediators`,
71
+ resource: (guildId, mediatorId, ...resources) => `/guilds/${guildId}/mediators/${mediatorId}/${resources.join("/")}`,
72
+ },
73
+ shop: {
74
+ get: (guildId) => `/guilds/${guildId}/shop`,
75
+ update: (guildId) => `/guilds/${guildId}/shop`,
76
+ delete: (guildId) => `/guilds/${guildId}/shop/ `,
77
+ resource: (guildId, ...resources) => `/guilds/${guildId}/shop/${resources.join("/")}`,
78
+ products: {
79
+ getAll: (guildId) => `/guilds/${guildId}/shop/products`,
80
+ get: (guildId, productId) => `/guilds/${guildId}/shop/${productId}/products`,
81
+ create: (guildId) => `/guilds/${guildId}/shop/products`,
82
+ update: (guildId, productId) => `/guilds/${guildId}/shop/products/${productId}`,
83
+ delete: (guildId, productId) => `/guilds/${guildId}/shop/products/${productId}`,
84
+ deleteAll: (guildId) => `/guilds/${guildId}/products/shop`,
85
+ resource: (guildId, productId, ...resources) => `/guilds/${guildId}/shop/products/${productId}/${resources.join("/")}`,
86
+ },
87
+ },
88
+ },
89
+ };
@@ -0,0 +1,17 @@
1
+ export declare class Collection<K, V> extends Map<K, V> {
2
+ key: string;
3
+ constructor(key?: string, data?: Iterable<V>);
4
+ at(index: number): V;
5
+ has(key: K): boolean;
6
+ get first(): V;
7
+ get last(): V;
8
+ get length(): number;
9
+ find(predicate: (value: V, key: K, Collection: this) => any): V;
10
+ filter(predicate: (value: V, key: K, Collection: this) => any): Collection<K, V>;
11
+ some(predicate: (value: V, key: K, Collection: this) => any): Collection<unknown, any>;
12
+ map(callback: (value: V, key: K, Collection: this) => any): any[];
13
+ toArray(): V[];
14
+ toJSON(): Record<string, unknown>;
15
+ sort(compareFunction: (a: V, b: V, Collection: this) => any): Collection<unknown, [K, V]>;
16
+ toString(): string;
17
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Collection = void 0;
4
+ class Collection extends Map {
5
+ key;
6
+ constructor(key, data) {
7
+ super();
8
+ this.key = key;
9
+ if (data && Array.isArray(data) && key) {
10
+ if (data.length > 0)
11
+ return;
12
+ for (let v of data)
13
+ this.set(key, v);
14
+ }
15
+ }
16
+ at(index) {
17
+ if (index < 0 || index >= this.size) {
18
+ return undefined;
19
+ }
20
+ let i = 0;
21
+ for (let [key, value] of this) {
22
+ if (i === index) {
23
+ return value;
24
+ }
25
+ i++;
26
+ }
27
+ }
28
+ has(key) {
29
+ return this.get(key) !== undefined ? true : false;
30
+ }
31
+ get first() {
32
+ return this.values().next().value;
33
+ }
34
+ get last() {
35
+ return [...this.values()].at(-1);
36
+ }
37
+ get length() {
38
+ return this.toArray().length;
39
+ }
40
+ find(predicate) {
41
+ for (const [key, value] of this) {
42
+ if (predicate(value, key, this))
43
+ return value;
44
+ }
45
+ return undefined;
46
+ }
47
+ filter(predicate) {
48
+ const results = new Collection("", []);
49
+ for (const [key, value] of this) {
50
+ if (predicate(value, key, this))
51
+ results.set(key, value);
52
+ }
53
+ return results;
54
+ }
55
+ some(predicate) {
56
+ const results = new Collection("", []);
57
+ for (const [key, value] of this) {
58
+ if (predicate(value, key, this))
59
+ results.set(key, value);
60
+ }
61
+ return results;
62
+ }
63
+ map(callback) {
64
+ return [...this].map(([key, val]) => callback(val, key, this));
65
+ }
66
+ toArray() {
67
+ return [...this.values()];
68
+ }
69
+ toJSON() {
70
+ let obj = {};
71
+ for (let [k, v] of this.entries()) {
72
+ obj[`${k}`] = v;
73
+ }
74
+ return obj;
75
+ }
76
+ sort(compareFunction) {
77
+ const sortedEntries = [...this.entries()].sort((ab, ba) => {
78
+ return compareFunction(ab[1], ba[1], this);
79
+ });
80
+ return new Collection(this.key, sortedEntries);
81
+ }
82
+ toString() {
83
+ return `${this.size}`;
84
+ }
85
+ }
86
+ exports.Collection = Collection;
87
+ module.exports = { Collection };
@@ -0,0 +1,86 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { Guild } from "../guild/Guild";
3
+ import { APIGuildBet } from "../../types/api/APIGuildBet";
4
+ import { APIPlayer } from "../../types/api/APIPlayer";
5
+ import { APIBetChannel } from "../../types/api/APIBetChannel";
6
+ import { BaseMatchModes, BaseMatchStatus, Confirm, Logs, Optional } from "../../types/api";
7
+ import { ChannelManager } from "../../managers/channel/ChannelManager";
8
+ import { GuildBetManager } from "../../managers/bet/GuildBetManager";
9
+ import { MessagesManager } from "../../managers/messages/MessagesManager";
10
+ type ExtendedMatchStatus = BaseMatchStatus | "waiting";
11
+ export declare class GuildBet {
12
+ /** The bet's type */
13
+ type: Omit<BaseMatchModes, "5x5" | "6x6" | "5v5" | "6v6">;
14
+ /** The bet's mode */
15
+ mode: "misto" | "emu" | "mob" | "MISTO" | "EMU" | "MOB";
16
+ /** The bet's status */
17
+ status: "off" | "created" | "on" | "shutted" | "waiting";
18
+ /** The bet's maximum size */
19
+ maximumSize: number;
20
+ /** The bet's price */
21
+ price: number;
22
+ /** Who has payed the bet */
23
+ payedBy: APIPlayer[];
24
+ /** The bet's players */
25
+ players: APIPlayer[];
26
+ /** An array of team a */
27
+ teamA: APIPlayer[];
28
+ /** An array of team b */
29
+ teamB: APIPlayer[];
30
+ /** The bet's channel */
31
+ channels: ChannelManager<GuildBet>;
32
+ /** THe bet's messages */
33
+ messages: MessagesManager;
34
+ /** The id of the winner */
35
+ winner: string;
36
+ /** The id of the loser */
37
+ loser: string;
38
+ /** The bet's creator id */
39
+ creatorId: string;
40
+ /** The bet's mediator */
41
+ mediatorId: string;
42
+ /** The bet's confirmers */
43
+ confirmed: Confirm[];
44
+ /** The bet's embed id */
45
+ embedMessageId: string;
46
+ /** The bet's logs */
47
+ logs: Logs;
48
+ /** Creation Date */
49
+ createdAt: Date;
50
+ /** Updated Date */
51
+ updatedAt: Date;
52
+ /** GuildBet's id */
53
+ _id: string;
54
+ /** The given guild */
55
+ readonly guild: Guild;
56
+ /** The rest client */
57
+ readonly rest: REST;
58
+ readonly key: string;
59
+ readonly manager: GuildBetManager;
60
+ /**
61
+ * GuildBet bet
62
+ * @param data The bet's data
63
+ * @param guild The guild
64
+ * @param rest The rest client
65
+ */
66
+ constructor(data: APIGuildBet, guild: Guild, manager: GuildBetManager, rest: REST);
67
+ toString(): string;
68
+ /**
69
+ * Fetches the bet
70
+ * @returns New Instance of the bet
71
+ */
72
+ fetch(): Promise<GuildBet>;
73
+ addConfirmed(type: string, id: string): Promise<Confirm>;
74
+ setConfirmed(set: Confirm[]): Promise<Confirm[]>;
75
+ setStatus(status: ExtendedMatchStatus): Promise<this>;
76
+ setWinner(userId: string): Promise<string>;
77
+ setLoser(userId: string): Promise<string>;
78
+ addChannel(id: string, type: string): Promise<import("../..").Channel<GuildBet>>;
79
+ addMessage(id: string, type: string, content?: string): Promise<import("../..").APIMessage>;
80
+ setChannels(channels: APIBetChannel[]): Promise<ChannelManager<GuildBet>>;
81
+ addPlayer(id: string, name: string): Promise<APIPlayer[]>;
82
+ removePlayer(id: string, name: string): Promise<APIPlayer[]>;
83
+ update(data: Optional<APIGuildBet>): Promise<this>;
84
+ toJSON(): Record<string, unknown>;
85
+ }
86
+ export {};
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildBet = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const Assertion_1 = require("../../utils/Assertion");
6
+ const ChannelManager_1 = require("../../managers/channel/ChannelManager");
7
+ const MessagesManager_1 = require("../../managers/messages/MessagesManager");
8
+ class GuildBet {
9
+ /** The bet's type */
10
+ type;
11
+ /** The bet's mode */
12
+ mode;
13
+ /** The bet's status */
14
+ status;
15
+ /** The bet's maximum size */
16
+ maximumSize;
17
+ /** The bet's price */
18
+ price;
19
+ /** Who has payed the bet */
20
+ payedBy;
21
+ /** The bet's players */
22
+ players;
23
+ /** An array of team a */
24
+ teamA;
25
+ /** An array of team b */
26
+ teamB;
27
+ /** The bet's channel */
28
+ channels;
29
+ /** THe bet's messages */
30
+ messages;
31
+ /** The id of the winner */
32
+ winner;
33
+ /** The id of the loser */
34
+ loser;
35
+ /** The bet's creator id */
36
+ creatorId;
37
+ /** The bet's mediator */
38
+ mediatorId;
39
+ /** The bet's confirmers */
40
+ confirmed;
41
+ /** The bet's embed id */
42
+ embedMessageId;
43
+ /** The bet's logs */
44
+ logs;
45
+ /** Creation Date */
46
+ createdAt;
47
+ /** Updated Date */
48
+ updatedAt;
49
+ /** GuildBet's id */
50
+ _id;
51
+ /** The given guild */
52
+ guild;
53
+ /** The rest client */
54
+ rest;
55
+ key;
56
+ manager;
57
+ /**
58
+ * GuildBet bet
59
+ * @param data The bet's data
60
+ * @param guild The guild
61
+ * @param rest The rest client
62
+ */
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;
79
+ this.winner = data?.winner;
80
+ this.loser = data?.loser;
81
+ this._id = data?._id;
82
+ this.logs = data.logs;
83
+ this.manager = manager;
84
+ this.key = "bets";
85
+ this.channels = new ChannelManager_1.ChannelManager(guild, this, rest);
86
+ this.messages = new MessagesManager_1.MessagesManager(this?.guild, this?._id, rest);
87
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
88
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
89
+ this.guild = guild;
90
+ this.rest = rest;
91
+ this.channels.setAll(data?.channels);
92
+ this.messages.setAll(data?.messages);
93
+ }
94
+ toString() {
95
+ return this._id || "1";
96
+ }
97
+ /**
98
+ * Fetches the bet
99
+ * @returns New Instance of the bet
100
+ */
101
+ async fetch() {
102
+ const route = Routes_1.Routes.guilds.bets.get(this.guild.id, this._id);
103
+ const response = await this.rest.request({
104
+ method: "get",
105
+ url: route,
106
+ });
107
+ const bt = new GuildBet(response, this.guild, this.manager, this.rest);
108
+ this.manager.cache.set(bt._id, bt);
109
+ return bt;
110
+ }
111
+ async addConfirmed(type, id) {
112
+ Assertion_1.Assertion.assertString(type);
113
+ Assertion_1.Assertion.assertString(id);
114
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "confirmed");
115
+ const payload = { entry: { type, id } };
116
+ const response = await this.rest.request({
117
+ method: "PATCH",
118
+ url: route,
119
+ payload,
120
+ });
121
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
122
+ this.confirmed = response.confirmed;
123
+ this.manager.cache.set(this._id, this);
124
+ return response.confirmed.find((cn) => cn.type == type);
125
+ }
126
+ async setConfirmed(set) {
127
+ Assertion_1.Assertion.assertObject(set);
128
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "confirmed");
129
+ const response = await this.rest.request({
130
+ method: "PATCH",
131
+ url: route,
132
+ payload: set,
133
+ });
134
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
135
+ this.confirmed = response.confirmed;
136
+ this.manager.cache.set(this._id, this);
137
+ return this.confirmed;
138
+ }
139
+ async setStatus(status) {
140
+ Assertion_1.Assertion.assertString(status);
141
+ const payload = { set: status.toLowerCase() };
142
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "status");
143
+ const response = await this.rest.request({
144
+ method: "PATCH",
145
+ url: route,
146
+ payload,
147
+ });
148
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
149
+ this.status = response.status;
150
+ this.manager.cache.set(this._id, this);
151
+ return this;
152
+ }
153
+ async setWinner(userId) {
154
+ Assertion_1.Assertion.assertString(userId);
155
+ const payload = { set: userId };
156
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "winner");
157
+ const response = await this.rest.request({
158
+ method: "PATCH",
159
+ url: route,
160
+ payload,
161
+ });
162
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
163
+ this.winner = response.winner;
164
+ this.manager.cache.set(this._id, this);
165
+ return response.winner;
166
+ }
167
+ async setLoser(userId) {
168
+ Assertion_1.Assertion.assertString(userId);
169
+ const payload = { set: userId };
170
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "loser");
171
+ const response = await this.rest.request({
172
+ method: "PATCH",
173
+ url: route,
174
+ payload,
175
+ });
176
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
177
+ this.loser = response.loser;
178
+ this.manager.cache.set(this._id, this);
179
+ return response.loser;
180
+ }
181
+ async addChannel(id, type) {
182
+ const ch = await this.channels.create(id, type);
183
+ this.manager.cache.set(this._id, this);
184
+ return ch;
185
+ }
186
+ async addMessage(id, type, content) {
187
+ const response = await this.messages.create({
188
+ userId: id,
189
+ type: type,
190
+ content,
191
+ });
192
+ this.manager.cache.set(this._id, this);
193
+ this.rest.bets.set(this._id, this);
194
+ return response;
195
+ }
196
+ async setChannels(channels) {
197
+ Assertion_1.Assertion.assertObject(channels);
198
+ const payload = { set: channels };
199
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "channels");
200
+ const response = await this.rest.request({
201
+ method: "PATCH",
202
+ url: route,
203
+ payload,
204
+ });
205
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
206
+ this.channels.setAll(response.channels);
207
+ this.manager.cache.set(this._id, this);
208
+ return this.channels;
209
+ }
210
+ async addPlayer(id, name) {
211
+ Assertion_1.Assertion.assertString(id);
212
+ Assertion_1.Assertion.assertString(name);
213
+ const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players");
214
+ const payload = { id, name };
215
+ const response = await this.rest.request({
216
+ method: "POST",
217
+ url: route,
218
+ payload,
219
+ });
220
+ this.players = response;
221
+ this.manager.cache.set(this._id, this);
222
+ return this.players;
223
+ }
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 };
229
+ const response = await this.rest.request({
230
+ method: "DELETE",
231
+ url: route,
232
+ payload,
233
+ });
234
+ this.players = response;
235
+ this.manager.cache.set(this._id, this);
236
+ return this.players;
237
+ }
238
+ async update(data) {
239
+ const route = Routes_1.Routes.guilds.bets.get(this.guild.id, this._id);
240
+ const payload = data;
241
+ const response = await this.rest.request({
242
+ method: "patch",
243
+ url: route,
244
+ payload,
245
+ });
246
+ this.rest.emit("betUpdate", this, new GuildBet(response, this.guild, this.manager, this.rest));
247
+ for (const k in response) {
248
+ if (k === "id")
249
+ continue;
250
+ if (Object.hasOwn(this, k)) {
251
+ if (k === "channels") {
252
+ this.channels.setAll(response["channels"]);
253
+ continue;
254
+ }
255
+ if (k === "messages") {
256
+ this.messages.setAll(response["messages"]);
257
+ continue;
258
+ }
259
+ this[k] = response[k];
260
+ }
261
+ }
262
+ this.rest.bets.set(this._id, this);
263
+ this.manager.cache.set(this._id, this);
264
+ return this;
265
+ }
266
+ toJSON() {
267
+ const json = {};
268
+ for (const [key, value] of Object.entries(this)) {
269
+ if (typeof value !== "function") {
270
+ json[key] = value;
271
+ }
272
+ }
273
+ return json;
274
+ }
275
+ }
276
+ exports.GuildBet = GuildBet;
@@ -0,0 +1,82 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { Daily, Items, Optional, ProfileCard } from "../../types/api";
3
+ import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
4
+ import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
5
+ export declare class GuildBetUser implements APIGuildBetUser {
6
+ /** User daily */
7
+ daily: Omit<Daily, "points">;
8
+ /** User's name */
9
+ name: string;
10
+ /** User's name */
11
+ id: string;
12
+ /** User's credit */
13
+ credit: number;
14
+ /** User's wins */
15
+ wins: number;
16
+ /** User's mvps */
17
+ mvps: number;
18
+ /** User's losses */
19
+ losses: number;
20
+ /** User's bets played */
21
+ betsPlayed: string[];
22
+ /** User's blacklist */
23
+ blacklist: boolean;
24
+ /** User's coins */
25
+ coins: number;
26
+ /** User's items */
27
+ items: Items;
28
+ /** User's profile card */
29
+ profileCard: ProfileCard;
30
+ /** Creation Date */
31
+ createdAt: Date;
32
+ /** Updated Date */
33
+ updatedAt: Date;
34
+ /** The given manager */
35
+ readonly manager: GuildBetUserManager;
36
+ /** The rest client */
37
+ readonly rest: REST;
38
+ /**
39
+ * Bet user
40
+ * @param data The user's data
41
+ * @param manager The manager
42
+ * @param rest The rest client
43
+ */
44
+ constructor(data: APIGuildBetUser, manager: GuildBetUserManager, rest: REST);
45
+ /** String representation of this user */
46
+ toString(): string;
47
+ /**
48
+ * Fetches the user
49
+ * @returns New Instance of the user
50
+ */
51
+ fetch(): Promise<GuildBetUser>;
52
+ /**
53
+ * Add a propery
54
+ * @param key The desired key
55
+ * @param value The desired value
56
+ * @returns GuildBetUser
57
+ */
58
+ add<K extends keyof BetUserAddOptions, V extends BetUserAddOptions[K]>(key: K, value: V): Promise<this>;
59
+ /**
60
+ * Set the user blacklist
61
+ * @param value Value to set to
62
+ * @returns GuildBetUser
63
+ */
64
+ setBlacklist(value: boolean): Promise<this>;
65
+ /**
66
+ * Update certain property
67
+ * @param data The new data to update with
68
+ * @returns
69
+ */
70
+ update(data: Omit<Optional<APIGuildBetUser>, "daily"> & {
71
+ type?: "add" | "remove";
72
+ }): Promise<this>;
73
+ delete(): Promise<boolean>;
74
+ toJSON(): Record<string, unknown>;
75
+ }
76
+ export type BetUserAddOptions = {
77
+ coins: number;
78
+ credit: number;
79
+ wins: number;
80
+ losses: number;
81
+ mvps: number;
82
+ };