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