@duque.edits/sdk 1.0.87 → 1.1.0

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 (310) hide show
  1. package/dist/index-BHHXH2xN.d.mts +1379 -0
  2. package/dist/index-C87LbIta.d.ts +1379 -0
  3. package/dist/index.d.mts +22 -0
  4. package/dist/index.d.ts +22 -0
  5. package/dist/index.js +4054 -19
  6. package/dist/index.mjs +4007 -0
  7. package/dist/managers/automaticmessage/AutomaticMessageManager.d.mts +20 -0
  8. package/dist/managers/automaticmessage/AutomaticMessageManager.d.ts +20 -0
  9. package/dist/managers/automaticmessage/AutomaticMessageManager.js +798 -0
  10. package/dist/managers/automaticmessage/AutomaticMessageManager.mjs +790 -0
  11. package/dist/managers/base.d.mts +20 -0
  12. package/dist/managers/base.d.ts +20 -0
  13. package/dist/managers/base.js +124 -15
  14. package/dist/managers/base.mjs +104 -0
  15. package/dist/managers/bet/GuildBetManager.d.mts +20 -0
  16. package/dist/managers/bet/GuildBetManager.d.ts +20 -0
  17. package/dist/managers/bet/GuildBetManager.js +947 -58
  18. package/dist/managers/bet/GuildBetManager.mjs +946 -0
  19. package/dist/managers/betuser/GuildBetUserManager.d.mts +20 -0
  20. package/dist/managers/betuser/GuildBetUserManager.d.ts +20 -0
  21. package/dist/managers/betuser/GuildBetUserManager.js +506 -78
  22. package/dist/managers/betuser/GuildBetUserManager.mjs +489 -0
  23. package/dist/managers/buffer/BufferManager.d.mts +20 -0
  24. package/dist/managers/buffer/BufferManager.d.ts +20 -0
  25. package/dist/managers/buffer/BufferManager.js +247 -37
  26. package/dist/managers/buffer/BufferManager.mjs +223 -0
  27. package/dist/managers/guild/GuildManager.d.mts +20 -0
  28. package/dist/managers/guild/GuildManager.d.ts +20 -0
  29. package/dist/managers/guild/GuildManager.js +3598 -87
  30. package/dist/managers/guild/GuildManager.mjs +3600 -0
  31. package/dist/managers/index.d.mts +20 -0
  32. package/dist/managers/index.d.ts +20 -0
  33. package/dist/managers/index.js +3766 -29
  34. package/dist/managers/index.mjs +3745 -0
  35. package/dist/managers/logs/LogManager.d.mts +20 -0
  36. package/dist/managers/logs/LogManager.d.ts +20 -0
  37. package/dist/managers/logs/LogManager.js +721 -55
  38. package/dist/managers/logs/LogManager.mjs +726 -0
  39. package/dist/managers/match/GuildMatchManager.d.mts +20 -0
  40. package/dist/managers/match/GuildMatchManager.d.ts +20 -0
  41. package/dist/managers/match/GuildMatchManager.js +1285 -95
  42. package/dist/managers/match/GuildMatchManager.mjs +1289 -0
  43. package/dist/managers/mediator/GuildMediatorManager.d.mts +20 -0
  44. package/dist/managers/mediator/GuildMediatorManager.d.ts +20 -0
  45. package/dist/managers/mediator/GuildMediatorManager.js +434 -86
  46. package/dist/managers/mediator/GuildMediatorManager.mjs +417 -0
  47. package/dist/managers/message/MessagesManager.d.mts +20 -0
  48. package/dist/managers/message/MessagesManager.d.ts +20 -0
  49. package/dist/managers/message/MessagesManager.js +158 -55
  50. package/dist/managers/message/MessagesManager.mjs +134 -0
  51. package/dist/managers/minesgame/MinesGameManager.d.mts +20 -0
  52. package/dist/managers/minesgame/MinesGameManager.d.ts +20 -0
  53. package/dist/managers/minesgame/MinesGameManager.js +714 -61
  54. package/dist/managers/minesgame/MinesGameManager.mjs +712 -0
  55. package/dist/managers/permission/GuildPermissionManager.d.mts +20 -0
  56. package/dist/managers/permission/GuildPermissionManager.d.ts +20 -0
  57. package/dist/managers/permission/GuildPermissionManager.js +277 -55
  58. package/dist/managers/permission/GuildPermissionManager.mjs +253 -0
  59. package/dist/managers/player/PlayerManager.d.mts +20 -0
  60. package/dist/managers/player/PlayerManager.d.ts +20 -0
  61. package/dist/managers/player/PlayerManager.js +174 -71
  62. package/dist/managers/player/PlayerManager.mjs +155 -0
  63. package/dist/managers/ticket/TicketManager.d.mts +20 -0
  64. package/dist/managers/ticket/TicketManager.d.ts +20 -0
  65. package/dist/managers/ticket/TicketManager.js +812 -116
  66. package/dist/managers/ticket/TicketManager.mjs +813 -0
  67. package/dist/managers/user/GuildUserManager.d.mts +20 -0
  68. package/dist/managers/user/GuildUserManager.d.ts +20 -0
  69. package/dist/managers/user/GuildUserManager.js +574 -90
  70. package/dist/managers/user/GuildUserManager.mjs +554 -0
  71. package/dist/managers/vipmember/VipMemberManager.d.mts +20 -0
  72. package/dist/managers/vipmember/VipMemberManager.d.ts +20 -0
  73. package/dist/managers/vipmember/VipMemberManager.js +525 -114
  74. package/dist/managers/vipmember/VipMemberManager.mjs +510 -0
  75. package/dist/rest/APIEndpoints.d.mts +12 -0
  76. package/{types → dist}/rest/APIEndpoints.d.ts +4 -3
  77. package/dist/rest/APIEndpoints.js +40 -10
  78. package/dist/rest/APIEndpoints.mjs +19 -0
  79. package/dist/rest/REST.d.mts +20 -0
  80. package/dist/rest/REST.d.ts +20 -0
  81. package/dist/rest/REST.js +3828 -112
  82. package/dist/rest/REST.mjs +3832 -0
  83. package/dist/rest/Routes.d.mts +104 -0
  84. package/{types → dist}/rest/Routes.d.ts +7 -3
  85. package/dist/rest/Routes.js +124 -98
  86. package/dist/rest/Routes.mjs +104 -0
  87. package/dist/rest/index.d.mts +22 -0
  88. package/dist/rest/index.d.ts +22 -0
  89. package/dist/rest/index.js +3856 -18
  90. package/dist/rest/index.mjs +3847 -0
  91. package/dist/structures/Collection.d.mts +19 -0
  92. package/{types → dist}/structures/Collection.d.ts +3 -1
  93. package/dist/structures/Collection.js +102 -81
  94. package/dist/structures/Collection.mjs +87 -0
  95. package/dist/structures/automaticmessage/AutomaticMessage.d.mts +20 -0
  96. package/dist/structures/automaticmessage/AutomaticMessage.d.ts +20 -0
  97. package/dist/structures/automaticmessage/AutomaticMessage.js +613 -0
  98. package/dist/structures/automaticmessage/AutomaticMessage.mjs +605 -0
  99. package/dist/structures/bet/GuildBet.d.mts +20 -0
  100. package/dist/structures/bet/GuildBet.d.ts +20 -0
  101. package/dist/structures/bet/GuildBet.js +861 -169
  102. package/dist/structures/bet/GuildBet.mjs +872 -0
  103. package/dist/structures/betuser/GuildBetUser.d.mts +20 -0
  104. package/dist/structures/betuser/GuildBetUser.d.ts +20 -0
  105. package/dist/structures/betuser/GuildBetUser.js +323 -201
  106. package/dist/structures/betuser/GuildBetUser.mjs +316 -0
  107. package/dist/structures/guild/Guild.d.mts +20 -0
  108. package/dist/structures/guild/Guild.d.ts +20 -0
  109. package/dist/structures/guild/Guild.js +3499 -452
  110. package/dist/structures/guild/Guild.mjs +3513 -0
  111. package/dist/structures/index.d.mts +20 -0
  112. package/dist/structures/index.d.ts +20 -0
  113. package/dist/structures/index.js +3610 -26
  114. package/dist/structures/index.mjs +3593 -0
  115. package/dist/structures/logentry/LogEntry.d.mts +20 -0
  116. package/dist/structures/logentry/LogEntry.d.ts +20 -0
  117. package/dist/structures/logentry/LogEntry.js +568 -62
  118. package/dist/structures/logentry/LogEntry.mjs +566 -0
  119. package/dist/structures/match/GuildMatch.d.mts +20 -0
  120. package/dist/structures/match/GuildMatch.d.ts +20 -0
  121. package/dist/structures/match/GuildMatch.js +1165 -250
  122. package/dist/structures/match/GuildMatch.mjs +1178 -0
  123. package/dist/structures/mediator/GuildMediator.d.mts +20 -0
  124. package/dist/structures/mediator/GuildMediator.d.ts +20 -0
  125. package/dist/structures/mediator/GuildMediator.js +252 -124
  126. package/dist/structures/mediator/GuildMediator.mjs +236 -0
  127. package/dist/structures/minesgame/MinesGame.d.mts +20 -0
  128. package/dist/structures/minesgame/MinesGame.d.ts +20 -0
  129. package/dist/structures/minesgame/MinesGame.js +574 -68
  130. package/dist/structures/minesgame/MinesGame.mjs +570 -0
  131. package/dist/structures/ticket/Ticket.d.mts +20 -0
  132. package/dist/structures/ticket/Ticket.d.ts +20 -0
  133. package/dist/structures/ticket/Ticket.js +621 -115
  134. package/dist/structures/ticket/Ticket.mjs +617 -0
  135. package/dist/structures/user/GuildUser.d.mts +20 -0
  136. package/dist/structures/user/GuildUser.d.ts +20 -0
  137. package/dist/structures/user/GuildUser.js +374 -257
  138. package/dist/structures/user/GuildUser.mjs +372 -0
  139. package/dist/structures/vipmember/VipMember.d.mts +20 -0
  140. package/dist/structures/vipmember/VipMember.d.ts +20 -0
  141. package/dist/structures/vipmember/VipMember.js +261 -123
  142. package/dist/structures/vipmember/VipMember.mjs +250 -0
  143. package/dist/types/RestTypes.d.mts +20 -0
  144. package/dist/types/RestTypes.d.ts +20 -0
  145. package/dist/types/RestTypes.js +17 -1
  146. package/dist/types/RestTypes.mjs +0 -0
  147. package/dist/types/api/APIAdvert.d.mts +13 -0
  148. package/{types → dist}/types/api/APIAdvert.d.ts +3 -1
  149. package/dist/types/api/APIAdvert.js +17 -1
  150. package/dist/types/api/APIAdvert.mjs +0 -0
  151. package/dist/types/api/APIAutomaticMessage.d.mts +20 -0
  152. package/dist/types/api/APIAutomaticMessage.d.ts +20 -0
  153. package/dist/types/api/APIAutomaticMessage.js +18 -0
  154. package/dist/types/api/APIAutomaticMessage.mjs +0 -0
  155. package/dist/types/api/APIBaseChannel.d.mts +12 -0
  156. package/{types → dist}/types/api/APIBaseChannel.d.ts +3 -1
  157. package/dist/types/api/APIBaseChannel.js +17 -1
  158. package/dist/types/api/APIBaseChannel.mjs +0 -0
  159. package/{types/types/api/APIGuildEmoji.d.ts → dist/types/api/APIBetChannel.d.mts} +6 -6
  160. package/{types → dist}/types/api/APIBetChannel.d.ts +3 -1
  161. package/dist/types/api/APIBetChannel.js +17 -1
  162. package/dist/types/api/APIBetChannel.mjs +0 -0
  163. package/dist/types/api/APICode.d.mts +12 -0
  164. package/{types → dist}/types/api/APICode.d.ts +3 -1
  165. package/dist/types/api/APICode.js +17 -1
  166. package/dist/types/api/APICode.mjs +0 -0
  167. package/dist/types/api/APIGiveaway.d.mts +29 -0
  168. package/{types → dist}/types/api/APIGiveaway.d.ts +5 -3
  169. package/dist/types/api/APIGiveaway.js +17 -1
  170. package/dist/types/api/APIGiveaway.mjs +0 -0
  171. package/dist/types/api/APIGuild.d.mts +20 -0
  172. package/dist/types/api/APIGuild.d.ts +20 -0
  173. package/dist/types/api/APIGuild.js +72 -41
  174. package/dist/types/api/APIGuild.mjs +46 -0
  175. package/dist/types/api/APIGuildAdvert.d.mts +10 -0
  176. package/{types → dist}/types/api/APIGuildAdvert.d.ts +3 -1
  177. package/dist/types/api/APIGuildAdvert.js +17 -1
  178. package/dist/types/api/APIGuildAdvert.mjs +0 -0
  179. package/dist/types/api/APIGuildBet.d.mts +20 -0
  180. package/dist/types/api/APIGuildBet.d.ts +20 -0
  181. package/dist/types/api/APIGuildBet.js +32 -6
  182. package/dist/types/api/APIGuildBet.mjs +8 -0
  183. package/dist/types/api/APIGuildBetUser.d.mts +20 -0
  184. package/dist/types/api/APIGuildBetUser.d.ts +20 -0
  185. package/dist/types/api/APIGuildBetUser.js +17 -1
  186. package/dist/types/api/APIGuildBetUser.mjs +0 -0
  187. package/{types/types/api/APIGuildMessage.d.ts → dist/types/api/APIGuildChannel.d.mts} +5 -3
  188. package/{types → dist}/types/api/APIGuildChannel.d.ts +3 -1
  189. package/dist/types/api/APIGuildChannel.js +17 -1
  190. package/dist/types/api/APIGuildChannel.mjs +0 -0
  191. package/dist/types/api/APIGuildGroupedChannel.d.mts +20 -0
  192. package/dist/types/api/APIGuildGroupedChannel.d.ts +20 -0
  193. package/dist/types/api/APIGuildGroupedChannel.js +17 -1
  194. package/dist/types/api/APIGuildGroupedChannel.mjs +0 -0
  195. package/dist/types/api/APIGuildMatch.d.mts +20 -0
  196. package/dist/types/api/APIGuildMatch.d.ts +20 -0
  197. package/dist/types/api/APIGuildMatch.js +39 -11
  198. package/dist/types/api/APIGuildMatch.mjs +14 -0
  199. package/dist/types/api/APIGuildMediator.d.mts +16 -0
  200. package/{types → dist}/types/api/APIGuildMediator.d.ts +3 -1
  201. package/dist/types/api/APIGuildMediator.js +17 -1
  202. package/dist/types/api/APIGuildMediator.mjs +0 -0
  203. package/dist/types/api/APIGuildPermissions.d.mts +15 -0
  204. package/{types → dist}/types/api/APIGuildPermissions.d.ts +5 -3
  205. package/dist/types/api/APIGuildPermissions.js +37 -11
  206. package/dist/types/api/APIGuildPermissions.mjs +13 -0
  207. package/dist/types/api/APIGuildShop.d.mts +15 -0
  208. package/{types → dist}/types/api/APIGuildShop.d.ts +6 -2
  209. package/dist/types/api/APIGuildShop.js +17 -1
  210. package/dist/types/api/APIGuildShop.mjs +0 -0
  211. package/dist/types/api/APIGuildTicket.d.mts +19 -0
  212. package/{types → dist}/types/api/APIGuildTicket.d.ts +5 -2
  213. package/dist/types/api/APIGuildTicket.js +17 -1
  214. package/dist/types/api/APIGuildTicket.mjs +0 -0
  215. package/dist/types/api/APIGuildUser.d.mts +20 -0
  216. package/dist/types/api/APIGuildUser.d.ts +20 -0
  217. package/dist/types/api/APIGuildUser.js +17 -1
  218. package/dist/types/api/APIGuildUser.mjs +0 -0
  219. package/dist/types/api/APILogEntry.d.mts +32 -0
  220. package/{types → dist}/types/api/APILogEntry.d.ts +4 -2
  221. package/dist/types/api/APILogEntry.js +44 -18
  222. package/dist/types/api/APILogEntry.mjs +20 -0
  223. package/dist/types/api/APIMessage.d.mts +13 -0
  224. package/{types → dist}/types/api/APIMessage.d.ts +3 -1
  225. package/dist/types/api/APIMessage.js +17 -1
  226. package/dist/types/api/APIMessage.mjs +0 -0
  227. package/dist/types/api/APIMinesGame.d.mts +15 -0
  228. package/{types → dist}/types/api/APIMinesGame.d.ts +3 -1
  229. package/dist/types/api/APIMinesGame.js +17 -1
  230. package/dist/types/api/APIMinesGame.mjs +0 -0
  231. package/dist/types/api/APIPlayer.d.mts +10 -0
  232. package/{types → dist}/types/api/APIPlayer.d.ts +3 -1
  233. package/dist/types/api/APIPlayer.js +17 -1
  234. package/dist/types/api/APIPlayer.mjs +0 -0
  235. package/dist/types/api/APIProduct.d.mts +22 -0
  236. package/{types → dist}/types/api/APIProduct.d.ts +5 -2
  237. package/dist/types/api/APIProduct.js +17 -2
  238. package/dist/types/api/APIProduct.mjs +0 -0
  239. package/dist/types/api/APIVipMember.d.mts +22 -0
  240. package/{types → dist}/types/api/APIVipMember.d.ts +3 -1
  241. package/dist/types/api/APIVipMember.js +17 -1
  242. package/dist/types/api/APIVipMember.mjs +0 -0
  243. package/dist/types/api/index.d.mts +20 -0
  244. package/dist/types/api/index.d.ts +20 -0
  245. package/dist/types/api/index.js +171 -70
  246. package/dist/types/api/index.mjs +135 -0
  247. package/dist/types/index.d.mts +20 -0
  248. package/dist/types/index.d.ts +20 -0
  249. package/dist/types/index.js +171 -16
  250. package/dist/types/index.mjs +135 -0
  251. package/dist/utils/Assertion.d.mts +34 -0
  252. package/{types → dist}/utils/Assertion.d.ts +3 -1
  253. package/dist/utils/Assertion.js +76 -59
  254. package/dist/utils/Assertion.mjs +52 -0
  255. package/dist/utils/getRandomNumber.d.mts +3 -0
  256. package/dist/utils/getRandomNumber.d.ts +3 -0
  257. package/dist/utils/getRandomNumber.js +29 -3
  258. package/dist/utils/getRandomNumber.mjs +7 -0
  259. package/dist/utils/randomKeyGenerator.d.mts +3 -0
  260. package/dist/utils/randomKeyGenerator.d.ts +3 -0
  261. package/dist/utils/randomKeyGenerator.js +33 -0
  262. package/dist/utils/randomKeyGenerator.mjs +8 -0
  263. package/package.json +12 -6
  264. package/dist/types/api/APIBetMessage.js +0 -2
  265. package/dist/types/api/APIGuildEmoji.js +0 -2
  266. package/dist/types/api/APIGuildRole.js +0 -2
  267. package/dist/types/api/APILogMessage.js +0 -2
  268. package/types/index.d.ts +0 -4
  269. package/types/managers/base.d.ts +0 -14
  270. package/types/managers/bet/GuildBetManager.d.ts +0 -15
  271. package/types/managers/betuser/GuildBetUserManager.d.ts +0 -18
  272. package/types/managers/buffer/BufferManager.d.ts +0 -19
  273. package/types/managers/guild/GuildManager.d.ts +0 -32
  274. package/types/managers/index.d.ts +0 -14
  275. package/types/managers/logs/LogManager.d.ts +0 -10
  276. package/types/managers/match/GuildMatchManager.d.ts +0 -29
  277. package/types/managers/mediator/GuildMediatorManager.d.ts +0 -19
  278. package/types/managers/message/MessagesManager.d.ts +0 -20
  279. package/types/managers/minesgame/MinesGameManager.d.ts +0 -17
  280. package/types/managers/permission/GuildPermissionManager.d.ts +0 -8
  281. package/types/managers/player/PlayerManager.d.ts +0 -28
  282. package/types/managers/ticket/TicketManager.d.ts +0 -24
  283. package/types/managers/user/GuildUserManager.d.ts +0 -18
  284. package/types/managers/vipmember/VipMemberManager.d.ts +0 -32
  285. package/types/rest/REST.d.ts +0 -56
  286. package/types/rest/index.d.ts +0 -3
  287. package/types/structures/bet/GuildBet.d.ts +0 -54
  288. package/types/structures/betuser/GuildBetUser.d.ts +0 -71
  289. package/types/structures/guild/Guild.d.ts +0 -85
  290. package/types/structures/index.d.ts +0 -11
  291. package/types/structures/logentry/LogEntry.d.ts +0 -28
  292. package/types/structures/match/GuildMatch.d.ts +0 -76
  293. package/types/structures/mediator/GuildMediator.d.ts +0 -50
  294. package/types/structures/minesgame/MinesGame.d.ts +0 -23
  295. package/types/structures/ticket/Ticket.d.ts +0 -30
  296. package/types/structures/user/GuildUser.d.ts +0 -75
  297. package/types/structures/vipmember/VipMember.d.ts +0 -54
  298. package/types/types/RestTypes.d.ts +0 -47
  299. package/types/types/api/APIBetMessage.d.ts +0 -10
  300. package/types/types/api/APIGuild.d.ts +0 -132
  301. package/types/types/api/APIGuildBet.d.ts +0 -51
  302. package/types/types/api/APIGuildBetUser.d.ts +0 -27
  303. package/types/types/api/APIGuildGroupedChannel.d.ts +0 -7
  304. package/types/types/api/APIGuildMatch.d.ts +0 -58
  305. package/types/types/api/APIGuildRole.d.ts +0 -10
  306. package/types/types/api/APIGuildUser.d.ts +0 -41
  307. package/types/types/api/APILogMessage.d.ts +0 -7
  308. package/types/types/api/index.d.ts +0 -161
  309. package/types/types/index.d.ts +0 -2
  310. package/types/utils/getRandomNumber.d.ts +0 -1
package/dist/rest/REST.js CHANGED
@@ -1,122 +1,3838 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.REST = void 0;
7
- const dotenv_1 = __importDefault(require("dotenv"));
8
- dotenv_1.default.config();
9
- const events_1 = __importDefault(require("events"));
10
- const Assertion_1 = require("../utils/Assertion");
11
- const undici_1 = require("undici");
12
- const Routes_1 = require("./Routes");
13
- const GuildManager_1 = require("../managers/guild/GuildManager");
14
- const Collection_1 = require("../structures/Collection");
15
- const managers_1 = require("../managers");
16
- const Reset = "\x1b[0m";
17
- const FgGreen = "\x1b[32m";
18
- const FgRed = "\x1b[31m";
19
- const FgBlue = "\x1b[34m";
20
- const FgCyan = "\x1b[36m";
21
- /**
22
- * The main class of this package
23
- */
24
- class REST extends events_1.default {
25
- /**
26
- * The unique key for client
27
- */
28
- clientKey;
29
- authKey;
30
- guildId;
31
- /** The guild manager */
32
- guilds;
33
- minesGames;
34
- users;
35
- betusers;
36
- matches;
37
- bets;
38
- tickets;
39
- vipmembers;
40
- mediators;
41
- /**
42
- *
43
- * @param key The unique key for he client
44
- */
45
- constructor(options) {
46
- super({ captureRejections: true });
47
- this.clientKey = options.clientKey ?? "";
48
- this.authKey = options.authKey ?? "";
49
- this.guildId = options.guildId ?? "";
50
- this.guilds = new GuildManager_1.GuildManager(this);
51
- this.minesGames = new managers_1.MinesGameManager(this);
52
- this.users = new Collection_1.Collection("rest:users");
53
- this.matches = new Collection_1.Collection("rest:matches");
54
- this.bets = new Collection_1.Collection("rest:bets");
55
- this.betusers = new Collection_1.Collection("rest:betusers");
56
- this.tickets = new Collection_1.Collection("rest:tickets");
57
- this.vipmembers = new Collection_1.Collection("rest:vipmembers");
58
- this.mediators = new Collection_1.Collection("rest:mediators");
59
- this.setMaxListeners(999);
60
- }
61
- /** Initialize the caching sistem */
62
- async init() {
63
- if (!this.clientKey || !this.authKey || !this.guildId)
64
- throw new Error("Client key, auth key, and guildId is necessary");
65
- await Promise.all([this.guilds.fetch({ guildId: this.guildId }), this.minesGames.fetch()]);
66
- return this;
67
- }
68
- formatUrl(url) {
69
- return (url.endsWith("/") ? url.slice(0, url.length - 1) : url) ?? "/status";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
37
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
38
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
39
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
40
+
41
+ // node_modules/dotenv/package.json
42
+ var require_package = __commonJS({
43
+ "node_modules/dotenv/package.json"(exports2, module2) {
44
+ module2.exports = {
45
+ name: "dotenv",
46
+ version: "16.6.1",
47
+ description: "Loads environment variables from .env file",
48
+ main: "lib/main.js",
49
+ types: "lib/main.d.ts",
50
+ exports: {
51
+ ".": {
52
+ types: "./lib/main.d.ts",
53
+ require: "./lib/main.js",
54
+ default: "./lib/main.js"
55
+ },
56
+ "./config": "./config.js",
57
+ "./config.js": "./config.js",
58
+ "./lib/env-options": "./lib/env-options.js",
59
+ "./lib/env-options.js": "./lib/env-options.js",
60
+ "./lib/cli-options": "./lib/cli-options.js",
61
+ "./lib/cli-options.js": "./lib/cli-options.js",
62
+ "./package.json": "./package.json"
63
+ },
64
+ scripts: {
65
+ "dts-check": "tsc --project tests/types/tsconfig.json",
66
+ lint: "standard",
67
+ pretest: "npm run lint && npm run dts-check",
68
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
69
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
70
+ prerelease: "npm test",
71
+ release: "standard-version"
72
+ },
73
+ repository: {
74
+ type: "git",
75
+ url: "git://github.com/motdotla/dotenv.git"
76
+ },
77
+ homepage: "https://github.com/motdotla/dotenv#readme",
78
+ funding: "https://dotenvx.com",
79
+ keywords: [
80
+ "dotenv",
81
+ "env",
82
+ ".env",
83
+ "environment",
84
+ "variables",
85
+ "config",
86
+ "settings"
87
+ ],
88
+ readmeFilename: "README.md",
89
+ license: "BSD-2-Clause",
90
+ devDependencies: {
91
+ "@types/node": "^18.11.3",
92
+ decache: "^4.6.2",
93
+ sinon: "^14.0.1",
94
+ standard: "^17.0.0",
95
+ "standard-version": "^9.5.0",
96
+ tap: "^19.2.0",
97
+ typescript: "^4.8.4"
98
+ },
99
+ engines: {
100
+ node: ">=12"
101
+ },
102
+ browser: {
103
+ fs: false
104
+ }
105
+ };
106
+ }
107
+ });
108
+
109
+ // node_modules/dotenv/lib/main.js
110
+ var require_main = __commonJS({
111
+ "node_modules/dotenv/lib/main.js"(exports2, module2) {
112
+ "use strict";
113
+ var fs = require("fs");
114
+ var path = require("path");
115
+ var os = require("os");
116
+ var crypto = require("crypto");
117
+ var packageJson = require_package();
118
+ var version = packageJson.version;
119
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
120
+ function parse(src) {
121
+ const obj = {};
122
+ let lines = src.toString();
123
+ lines = lines.replace(/\r\n?/mg, "\n");
124
+ let match;
125
+ while ((match = LINE.exec(lines)) != null) {
126
+ const key = match[1];
127
+ let value = match[2] || "";
128
+ value = value.trim();
129
+ const maybeQuote = value[0];
130
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
131
+ if (maybeQuote === '"') {
132
+ value = value.replace(/\\n/g, "\n");
133
+ value = value.replace(/\\r/g, "\r");
134
+ }
135
+ obj[key] = value;
136
+ }
137
+ return obj;
70
138
  }
71
- /**
72
- * Request Data from a certain url
73
- * @param options
74
- * @returns
75
- */
76
- async request(options) {
77
- let { method, url, payload } = options;
78
- Assertion_1.Assertion.assertString(method);
79
- Assertion_1.Assertion.assertString(this.clientKey);
80
- Assertion_1.Assertion.assertString(url);
81
- url = this.formatUrl(Routes_1.Routes.base + url);
82
- const headers = new undici_1.Headers();
83
- headers.append("authorization", this.authKey);
84
- headers.append("client_key", this.clientKey);
85
- headers.append("Content-Type", "application/json");
86
- const before = Date.now();
87
- this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
88
- const body = { ...payload };
89
- const res = await (0, undici_1.request)(url, {
90
- method: method.toUpperCase(),
91
- headers,
92
- body: JSON.stringify(body),
139
+ function _parseVault(options) {
140
+ options = options || {};
141
+ const vaultPath = _vaultPath(options);
142
+ options.path = vaultPath;
143
+ const result = DotenvModule.configDotenv(options);
144
+ if (!result.parsed) {
145
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
146
+ err.code = "MISSING_DATA";
147
+ throw err;
148
+ }
149
+ const keys = _dotenvKey(options).split(",");
150
+ const length = keys.length;
151
+ let decrypted;
152
+ for (let i = 0; i < length; i++) {
153
+ try {
154
+ const key = keys[i].trim();
155
+ const attrs = _instructions(result, key);
156
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
157
+ break;
158
+ } catch (error) {
159
+ if (i + 1 >= length) {
160
+ throw error;
161
+ }
162
+ }
163
+ }
164
+ return DotenvModule.parse(decrypted);
165
+ }
166
+ function _warn(message) {
167
+ console.log(`[dotenv@${version}][WARN] ${message}`);
168
+ }
169
+ function _debug(message) {
170
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
171
+ }
172
+ function _log(message) {
173
+ console.log(`[dotenv@${version}] ${message}`);
174
+ }
175
+ function _dotenvKey(options) {
176
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
177
+ return options.DOTENV_KEY;
178
+ }
179
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
180
+ return process.env.DOTENV_KEY;
181
+ }
182
+ return "";
183
+ }
184
+ function _instructions(result, dotenvKey) {
185
+ let uri;
186
+ try {
187
+ uri = new URL(dotenvKey);
188
+ } catch (error) {
189
+ if (error.code === "ERR_INVALID_URL") {
190
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
191
+ err.code = "INVALID_DOTENV_KEY";
192
+ throw err;
193
+ }
194
+ throw error;
195
+ }
196
+ const key = uri.password;
197
+ if (!key) {
198
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
199
+ err.code = "INVALID_DOTENV_KEY";
200
+ throw err;
201
+ }
202
+ const environment = uri.searchParams.get("environment");
203
+ if (!environment) {
204
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
205
+ err.code = "INVALID_DOTENV_KEY";
206
+ throw err;
207
+ }
208
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
209
+ const ciphertext = result.parsed[environmentKey];
210
+ if (!ciphertext) {
211
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
212
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
213
+ throw err;
214
+ }
215
+ return { ciphertext, key };
216
+ }
217
+ function _vaultPath(options) {
218
+ let possibleVaultPath = null;
219
+ if (options && options.path && options.path.length > 0) {
220
+ if (Array.isArray(options.path)) {
221
+ for (const filepath of options.path) {
222
+ if (fs.existsSync(filepath)) {
223
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
224
+ }
225
+ }
226
+ } else {
227
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
228
+ }
229
+ } else {
230
+ possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
231
+ }
232
+ if (fs.existsSync(possibleVaultPath)) {
233
+ return possibleVaultPath;
234
+ }
235
+ return null;
236
+ }
237
+ function _resolveHome(envPath) {
238
+ return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
239
+ }
240
+ function _configVault(options) {
241
+ const debug = Boolean(options && options.debug);
242
+ const quiet = options && "quiet" in options ? options.quiet : true;
243
+ if (debug || !quiet) {
244
+ _log("Loading env from encrypted .env.vault");
245
+ }
246
+ const parsed = DotenvModule._parseVault(options);
247
+ let processEnv = process.env;
248
+ if (options && options.processEnv != null) {
249
+ processEnv = options.processEnv;
250
+ }
251
+ DotenvModule.populate(processEnv, parsed, options);
252
+ return { parsed };
253
+ }
254
+ function configDotenv(options) {
255
+ const dotenvPath = path.resolve(process.cwd(), ".env");
256
+ let encoding = "utf8";
257
+ const debug = Boolean(options && options.debug);
258
+ const quiet = options && "quiet" in options ? options.quiet : true;
259
+ if (options && options.encoding) {
260
+ encoding = options.encoding;
261
+ } else {
262
+ if (debug) {
263
+ _debug("No encoding is specified. UTF-8 is used by default");
264
+ }
265
+ }
266
+ let optionPaths = [dotenvPath];
267
+ if (options && options.path) {
268
+ if (!Array.isArray(options.path)) {
269
+ optionPaths = [_resolveHome(options.path)];
270
+ } else {
271
+ optionPaths = [];
272
+ for (const filepath of options.path) {
273
+ optionPaths.push(_resolveHome(filepath));
274
+ }
275
+ }
276
+ }
277
+ let lastError;
278
+ const parsedAll = {};
279
+ for (const path2 of optionPaths) {
280
+ try {
281
+ const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
282
+ DotenvModule.populate(parsedAll, parsed, options);
283
+ } catch (e) {
284
+ if (debug) {
285
+ _debug(`Failed to load ${path2} ${e.message}`);
286
+ }
287
+ lastError = e;
288
+ }
289
+ }
290
+ let processEnv = process.env;
291
+ if (options && options.processEnv != null) {
292
+ processEnv = options.processEnv;
293
+ }
294
+ DotenvModule.populate(processEnv, parsedAll, options);
295
+ if (debug || !quiet) {
296
+ const keysCount = Object.keys(parsedAll).length;
297
+ const shortPaths = [];
298
+ for (const filePath of optionPaths) {
299
+ try {
300
+ const relative = path.relative(process.cwd(), filePath);
301
+ shortPaths.push(relative);
302
+ } catch (e) {
303
+ if (debug) {
304
+ _debug(`Failed to load ${filePath} ${e.message}`);
305
+ }
306
+ lastError = e;
307
+ }
308
+ }
309
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")}`);
310
+ }
311
+ if (lastError) {
312
+ return { parsed: parsedAll, error: lastError };
313
+ } else {
314
+ return { parsed: parsedAll };
315
+ }
316
+ }
317
+ function config(options) {
318
+ if (_dotenvKey(options).length === 0) {
319
+ return DotenvModule.configDotenv(options);
320
+ }
321
+ const vaultPath = _vaultPath(options);
322
+ if (!vaultPath) {
323
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
324
+ return DotenvModule.configDotenv(options);
325
+ }
326
+ return DotenvModule._configVault(options);
327
+ }
328
+ function decrypt(encrypted, keyStr) {
329
+ const key = Buffer.from(keyStr.slice(-64), "hex");
330
+ let ciphertext = Buffer.from(encrypted, "base64");
331
+ const nonce = ciphertext.subarray(0, 12);
332
+ const authTag = ciphertext.subarray(-16);
333
+ ciphertext = ciphertext.subarray(12, -16);
334
+ try {
335
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
336
+ aesgcm.setAuthTag(authTag);
337
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
338
+ } catch (error) {
339
+ const isRange = error instanceof RangeError;
340
+ const invalidKeyLength = error.message === "Invalid key length";
341
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
342
+ if (isRange || invalidKeyLength) {
343
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
344
+ err.code = "INVALID_DOTENV_KEY";
345
+ throw err;
346
+ } else if (decryptionFailed) {
347
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
348
+ err.code = "DECRYPTION_FAILED";
349
+ throw err;
350
+ } else {
351
+ throw error;
352
+ }
353
+ }
354
+ }
355
+ function populate(processEnv, parsed, options = {}) {
356
+ const debug = Boolean(options && options.debug);
357
+ const override = Boolean(options && options.override);
358
+ if (typeof parsed !== "object") {
359
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
360
+ err.code = "OBJECT_REQUIRED";
361
+ throw err;
362
+ }
363
+ for (const key of Object.keys(parsed)) {
364
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
365
+ if (override === true) {
366
+ processEnv[key] = parsed[key];
367
+ }
368
+ if (debug) {
369
+ if (override === true) {
370
+ _debug(`"${key}" is already defined and WAS overwritten`);
371
+ } else {
372
+ _debug(`"${key}" is already defined and was NOT overwritten`);
373
+ }
374
+ }
375
+ } else {
376
+ processEnv[key] = parsed[key];
377
+ }
378
+ }
379
+ }
380
+ var DotenvModule = {
381
+ configDotenv,
382
+ _configVault,
383
+ _parseVault,
384
+ config,
385
+ decrypt,
386
+ parse,
387
+ populate
388
+ };
389
+ module2.exports.configDotenv = DotenvModule.configDotenv;
390
+ module2.exports._configVault = DotenvModule._configVault;
391
+ module2.exports._parseVault = DotenvModule._parseVault;
392
+ module2.exports.config = DotenvModule.config;
393
+ module2.exports.decrypt = DotenvModule.decrypt;
394
+ module2.exports.parse = DotenvModule.parse;
395
+ module2.exports.populate = DotenvModule.populate;
396
+ module2.exports = DotenvModule;
397
+ }
398
+ });
399
+
400
+ // src/rest/REST.ts
401
+ var REST_exports = {};
402
+ __export(REST_exports, {
403
+ REST: () => REST8
404
+ });
405
+ module.exports = __toCommonJS(REST_exports);
406
+ var import_dotenv = __toESM(require_main());
407
+ var import_events = __toESM(require("events"));
408
+
409
+ // src/utils/Assertion.ts
410
+ var Assertion = class {
411
+ constructor() {
412
+ }
413
+ /**
414
+ * Tests if given key is a string
415
+ * @param key Key to test
416
+ */
417
+ static assertString(key) {
418
+ if (typeof key !== "string") throw new Error(`${key} must be a string`);
419
+ if (!key || key === "") throw new Error(`${key} must be a string`);
420
+ return true;
421
+ }
422
+ /**
423
+ * Tests if given key is a number
424
+ * @param key Key to test
425
+ */
426
+ static assertNumber(key) {
427
+ if (typeof key !== "number") throw new Error(`${key} must be a number`);
428
+ return true;
429
+ }
430
+ /**
431
+ * Tests if given key is a boolean
432
+ * @param key Key to test
433
+ */
434
+ static assertBoolean(key) {
435
+ if (typeof key !== "boolean") throw new Error(`${key} must be a boolean`);
436
+ return true;
437
+ }
438
+ /**
439
+ * Tests if given key is an array
440
+ * @param key Key to test
441
+ */
442
+ static assertArray(key) {
443
+ if (!Array.isArray(key)) throw new Error(`${key} must be an array`);
444
+ return true;
445
+ }
446
+ /**
447
+ * Tests if given key is an object
448
+ * @param key Key to test
449
+ */
450
+ static assertObject(key) {
451
+ if (typeof key !== "object") throw new Error(`${key} must be an object`);
452
+ return true;
453
+ }
454
+ toString() {
455
+ return "string, number, boolean, array, object";
456
+ }
457
+ };
458
+
459
+ // src/rest/REST.ts
460
+ var import_undici = require("undici");
461
+
462
+ // src/rest/Routes.ts
463
+ var Routes = {
464
+ //base: "http://localhost:80/api/v1",
465
+ base: "https://duque-api.up.railway.app/api/v1",
466
+ field: (field) => `/${field}`,
467
+ fields: (...fields) => `${fields.join("/")}`,
468
+ guilds: {
469
+ create: () => `/guilds`,
470
+ get: (guildId) => `/guilds/${guildId}`,
471
+ getAll: () => `/guilds`,
472
+ delete: (guildId) => `/guilds/${guildId}`,
473
+ deleteAll: () => `/guilds`,
474
+ resource: (guildId, ...resources) => `/guilds/${guildId}/manage/${resources.join("/")}`,
475
+ resources: (guildId, ...resources) => `/guilds/${guildId}/manage/${resources.join("/")}`,
476
+ users: {
477
+ create: (guildId) => `/guilds/${guildId}/users`,
478
+ update: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
479
+ getAll: (guildId) => `/guilds/${guildId}/users`,
480
+ get: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
481
+ delete: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
482
+ deleteAll: (guildId) => `/guilds/${guildId}/users`,
483
+ resource: (guildId, userId, ...resource) => `/guilds/${guildId}/users/${userId}/${resource.join("/")}`
484
+ },
485
+ betusers: {
486
+ getAll: (guildId) => `/guilds/${guildId}/betusers`,
487
+ get: (guildId, userId) => `/guilds/${guildId}/betusers/${userId}`,
488
+ create: (guildId) => `/guilds/${guildId}/betusers`,
489
+ update: (guildId, userId) => `/guilds/${guildId}/betusers/${userId}`,
490
+ delete: (guildId, userId) => `/guilds/${guildId}/betusers/${userId}`,
491
+ deleteAll: (guildId) => `/guilds/${guildId}/betusers`,
492
+ resource: (guildId, userId, resourceName) => `/guilds/${guildId}/betusers/${userId}/${resourceName}`
493
+ },
494
+ matches: {
495
+ getAll: (guildId) => `/guilds/${guildId}/matches`,
496
+ get: (guildId, matchId) => `/guilds/${guildId}/matches/${matchId}`,
497
+ create: (guildId) => `/guilds/${guildId}/matches`,
498
+ update: (guildId, matchId) => `/guilds/${guildId}/matches/${matchId}`,
499
+ delete: (guildId, matchId) => `/guilds/${guildId}/matches/${matchId}`,
500
+ deleteAll: (guildId) => `/guilds/${guildId}/matches`,
501
+ resource: (guildId, matchId, ...resources) => `/guilds/${guildId}/matches/${matchId}/${resources.join("/")}`
502
+ },
503
+ bets: {
504
+ getAll: (guildId) => `/guilds/${guildId}/bets`,
505
+ get: (guildId, betId) => `/guilds/${guildId}/bets/${betId}`,
506
+ create: (guildId) => `/guilds/${guildId}/bets`,
507
+ update: (guildId, betId) => `/guilds/${guildId}/bets/${betId}`,
508
+ delete: (guildId, betId) => `/guilds/${guildId}/bets/${betId}`,
509
+ deleteAll: (guildId) => `/guilds/${guildId}/bets`,
510
+ resource: (guildId, betId, ...resources) => `/guilds/${guildId}/bets/${betId}/${resources.join("/")}`
511
+ },
512
+ tickets: {
513
+ getAll: (guildId) => `/guilds/${guildId}/tickets`,
514
+ get: (guildId, ticketId) => `/guilds/${guildId}/tickets/${ticketId}`,
515
+ create: (guildId) => `/guilds/${guildId}/tickets`,
516
+ update: (guildId, ticketId) => `/guilds/${guildId}/tickets/${ticketId}`,
517
+ delete: (guildId, ticketId) => `/guilds/${guildId}/tickets/${ticketId}`,
518
+ deleteAll: (guildId) => `/guilds/${guildId}/tickets`,
519
+ resource: (guildId, ticketId, ...resources) => `/guilds/${guildId}/tickets/${ticketId}/${resources.join("/")}`
520
+ },
521
+ mediators: {
522
+ getAll: (guildId) => `/guilds/${guildId}/mediators`,
523
+ get: (guildId, mediatorId) => `/guilds/${guildId}/mediators/${mediatorId}`,
524
+ create: (guildId) => `/guilds/${guildId}/mediators`,
525
+ update: (guildId, mediatorId) => `/guilds/${guildId}/mediators/${mediatorId}`,
526
+ delete: (guildId, mediatorId) => `/guilds/${guildId}/mediators/${mediatorId}`,
527
+ deleteAll: (guildId) => `/guilds/${guildId}/mediators`,
528
+ resource: (guildId, mediatorId, ...resources) => `/guilds/${guildId}/mediators/${mediatorId}/${resources.join("/")}`
529
+ },
530
+ shop: {
531
+ get: (guildId) => `/guilds/${guildId}/manage/shop`,
532
+ update: (guildId) => `/guilds/${guildId}/manage/shop`,
533
+ delete: (guildId) => `/guilds/${guildId}/manage/shop/ `,
534
+ resource: (guildId, ...resources) => `/guilds/${guildId}/manage/shop/${resources.join("/")}`,
535
+ products: {
536
+ getAll: (guildId) => `/guilds/${guildId}/manage/shop/products`,
537
+ get: (guildId, productId) => `/guilds/${guildId}/manage/shop/${productId}/products`,
538
+ create: (guildId) => `/guilds/${guildId}/manage/shop/products`,
539
+ update: (guildId, productId) => `/guilds/${guildId}/manage/shop/products/${productId}`,
540
+ delete: (guildId, productId) => `/guilds/${guildId}/manage/shop/products/${productId}`,
541
+ deleteAll: (guildId) => `/guilds/${guildId}/products/shop`,
542
+ resource: (guildId, productId, ...resources) => `/guilds/${guildId}/manage/shop/products/${productId}/${resources.join("/")}`
543
+ }
544
+ }
545
+ },
546
+ vipmembers: {
547
+ get: (guildId, memberId) => `/guilds/${guildId}/vipmembers/${memberId}`,
548
+ getAll: (guildId) => `/guilds/${guildId}/vipmembers`,
549
+ deleteAll: (guildId) => `/guilds/${guildId}/vipmembers`,
550
+ create: (guildId) => `/guilds/${guildId}/vipmembers`,
551
+ update: (guildId, memberId) => `/guilds/${guildId}/vipmembers/${memberId}`,
552
+ delete: (guildId, memberId) => `/guilds/${guildId}/vipmembers/${memberId}`
553
+ },
554
+ giveaways: {
555
+ get: (giveawayId) => `/giveaways/${giveawayId}`,
556
+ getAll: () => `/giveaways`,
557
+ deleteAll: () => `/giveaways`,
558
+ create: () => `/giveaways`,
559
+ update: (giveawayId) => `/giveaways/${giveawayId}`,
560
+ delete: (giveawayId) => `/giveaways/${giveawayId}`
561
+ }
562
+ };
563
+
564
+ // src/structures/Collection.ts
565
+ var Collection = class _Collection extends Map {
566
+ constructor(key, data) {
567
+ super();
568
+ __publicField(this, "key");
569
+ this.key = key;
570
+ if (data && Array.isArray(data) && key) {
571
+ if (data.length > 0) return;
572
+ for (let v of data) this.set(key, v);
573
+ }
574
+ }
575
+ at(index) {
576
+ if (index < 0 || index >= this.size) {
577
+ return void 0;
578
+ }
579
+ let i = 0;
580
+ for (let [, value] of this) {
581
+ if (i === index) {
582
+ return value;
583
+ }
584
+ i++;
585
+ }
586
+ }
587
+ has(key) {
588
+ return this.get(key) !== void 0 ? true : false;
589
+ }
590
+ get first() {
591
+ return this.values().next().value;
592
+ }
593
+ get last() {
594
+ return [...this.values()].at(-1);
595
+ }
596
+ get length() {
597
+ return this.toArray().length;
598
+ }
599
+ find(predicate) {
600
+ for (const [key, value] of this) {
601
+ if (predicate(value, key, this)) return value;
602
+ }
603
+ return void 0;
604
+ }
605
+ filter(predicate) {
606
+ const results = new _Collection(this.key, []);
607
+ for (const [key, value] of this) {
608
+ if (predicate(value, key, this)) results.set(key, value);
609
+ }
610
+ return results;
611
+ }
612
+ some(predicate) {
613
+ const results = new _Collection(this.key, []);
614
+ for (const [key, value] of this) {
615
+ if (predicate(value, key, this)) results.set(key, value);
616
+ }
617
+ return results;
618
+ }
619
+ map(callback) {
620
+ return [...this].map(([key, val]) => callback(val, key, this));
621
+ }
622
+ toArray() {
623
+ return [...this.values()];
624
+ }
625
+ toJSON() {
626
+ let obj = {};
627
+ for (let [k, v] of this.entries()) {
628
+ obj[`${k}`] = v;
629
+ }
630
+ return obj;
631
+ }
632
+ sort(compareFunction) {
633
+ const sortedEntries = [...this.entries()].sort((ab, ba) => {
634
+ return compareFunction(ab[1], ba[1], this);
635
+ });
636
+ const coll = new _Collection();
637
+ for (let [k, v] of sortedEntries) coll.set(k, v);
638
+ return coll;
639
+ }
640
+ toString() {
641
+ return `${this.size}`;
642
+ }
643
+ };
644
+
645
+ // src/managers/base.ts
646
+ var BaseManager = class {
647
+ constructor(guild) {
648
+ /** This url of the manager */
649
+ __publicField(this, "base_url");
650
+ /** The rest client */
651
+ __publicField(this, "rest");
652
+ /** The guild of the manager */
653
+ __publicField(this, "guild");
654
+ /** Cache */
655
+ __publicField(this, "cache");
656
+ this.guild = guild;
657
+ this.rest = guild.rest;
658
+ this.cache = new Collection();
659
+ }
660
+ };
661
+
662
+ // src/managers/player/PlayerManager.ts
663
+ var PlayerManager = class extends Collection {
664
+ constructor(structure, base_url) {
665
+ super("players");
666
+ __publicField(this, "base_url");
667
+ __publicField(this, "rest");
668
+ __publicField(this, "guild");
669
+ this.base_url = base_url;
670
+ this.guild = structure.guild;
671
+ this.rest = structure.rest;
672
+ }
673
+ _set(data) {
674
+ this.clear();
675
+ if (Array.isArray(data)) {
676
+ for (let p of data) {
677
+ if (!p.id) continue;
678
+ this.set(p.id, {
679
+ id: p.id,
680
+ createdAt: p.createdAt ? new Date(p.createdAt) : /* @__PURE__ */ new Date(),
681
+ updateAt: p.updateAt ? new Date(p.updateAt) : /* @__PURE__ */ new Date()
93
682
  });
94
- const responseBody = await res.body.json();
95
- const { data, message } = responseBody;
96
- const now = new Date().getTime();
97
- if (!data || res.body.errored) {
98
- if (message)
99
- this.emit("debug", `${FgRed}${message}${Reset}`);
100
- this.emit("debug", `[No data]${FgGreen} ${(now - before) / 1000}${Reset}`);
101
- return "No data available.";
683
+ }
684
+ } else {
685
+ if (!data.id) return;
686
+ this.set(data.id, {
687
+ id: data.id,
688
+ createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
689
+ updateAt: data.updateAt ? new Date(data.updateAt) : /* @__PURE__ */ new Date()
690
+ });
691
+ }
692
+ return this;
693
+ }
694
+ /**
695
+ * Adds a player or an array of players to the structure.
696
+ * @param player A player or an array of players to be added
697
+ * @returns returns a collection of players
698
+ */
699
+ async add(player) {
700
+ let players = [];
701
+ if (Array.isArray(player)) {
702
+ for (let p of player) this.has(p.id) ? null : players.push(p);
703
+ } else this.has(player.id) ? null : players.push(player);
704
+ const payload = { set: players };
705
+ const response = await this.rest.request({
706
+ method: "PATCH",
707
+ payload,
708
+ url: this.base_url
709
+ });
710
+ return this._set(response.players);
711
+ }
712
+ /**
713
+ * Remover a player or an array of players.
714
+ * @param player The player or an array of players to be removed
715
+ * @returns Player manager
716
+ */
717
+ async remove(player) {
718
+ const ids = new Set(Array.isArray(player) ? player.map((p) => p.id) : [player.id]);
719
+ const players = this.toArray().filter((p) => !ids.has(p.id));
720
+ const payload = { set: players };
721
+ const response = await this.rest.request({
722
+ method: "PATCH",
723
+ payload,
724
+ url: this.base_url
725
+ });
726
+ return this._set(response.players);
727
+ }
728
+ };
729
+
730
+ // src/structures/bet/GuildBet.ts
731
+ var GuildBet = class {
732
+ constructor(data, manager) {
733
+ /** The bet's type */
734
+ __publicField(this, "type");
735
+ /** The bet's mode */
736
+ __publicField(this, "mode");
737
+ /** The bet's status */
738
+ __publicField(this, "status");
739
+ /** The bet's maximum size */
740
+ __publicField(this, "maximumSize");
741
+ /** The bet's price */
742
+ __publicField(this, "price");
743
+ /** The bet's players */
744
+ __publicField(this, "players");
745
+ __publicField(this, "teams");
746
+ /** The bet's channel */
747
+ __publicField(this, "channels");
748
+ /** The bet's messages */
749
+ __publicField(this, "messages");
750
+ /** The id of the winner */
751
+ __publicField(this, "winners");
752
+ /** The id of the loser */
753
+ __publicField(this, "losers");
754
+ /** The bet's creator id */
755
+ __publicField(this, "creatorId");
756
+ /** The bet's mediator */
757
+ __publicField(this, "mediatorId");
758
+ /** The bet's confirmers */
759
+ __publicField(this, "confirmed");
760
+ /** Creation Date */
761
+ __publicField(this, "createdAt");
762
+ /** Updated Date */
763
+ __publicField(this, "updatedAt");
764
+ /** Bet's id */
765
+ __publicField(this, "_id");
766
+ __publicField(this, "queues");
767
+ __publicField(this, "guild_id");
768
+ __publicField(this, "rest");
769
+ __publicField(this, "guild");
770
+ __publicField(this, "manager");
771
+ this.manager = manager;
772
+ this.guild = manager.guild;
773
+ this.rest = manager.rest;
774
+ this._id = data?._id;
775
+ this.guild_id = data?.guild_id;
776
+ this.type = data?.type;
777
+ this.mode = data?.mode;
778
+ this.status = data?.status;
779
+ this.maximumSize = data?.maximumSize;
780
+ this.price = data?.price;
781
+ this.teams = data?.teams;
782
+ this.channels = data?.channels;
783
+ this.players = new PlayerManager(this, Routes.guilds.bets.resource(this.guild_id, this._id, "players"));
784
+ this.messages = new MessagesManager(this, Routes.guilds.bets.resource(this.guild_id, this._id, "messages"));
785
+ this.winners = data?.winners;
786
+ this.losers = data?.losers;
787
+ this.creatorId = data?.creatorId;
788
+ this.mediatorId = data?.mediatorId;
789
+ this.confirmed = data?.confirmed;
790
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
791
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
792
+ this.queues = [];
793
+ for (let queue of data.queues ?? []) {
794
+ this.queues.push({
795
+ _id: queue?._id,
796
+ type: queue?.type,
797
+ players: queue?.players,
798
+ updatedAt: queue?.updatedAt ? new Date(queue?.updatedAt) : /* @__PURE__ */ new Date(),
799
+ createdAt: queue?.createdAt ? new Date(queue?.createdAt) : /* @__PURE__ */ new Date()
800
+ });
801
+ }
802
+ if (data?.messages?.length !== 0) this.messages.set(data.messages);
803
+ if (data?.players.length !== 0) this.players._set(data.players);
804
+ }
805
+ toString() {
806
+ return this._id;
807
+ }
808
+ async fetch() {
809
+ const route = Routes.guilds.bets.get(this.guild.id, this._id);
810
+ const response = await this.rest.request({ url: route, method: "GET" });
811
+ return this._updateInternals(response);
812
+ }
813
+ async addPlayer(player, queue_type) {
814
+ if (this.players.length === 2) return this;
815
+ if (this.players.has(player.id)) return this;
816
+ this.players.set(player.id, player);
817
+ if (queue_type) {
818
+ const queue = this.queues.find((q) => q.type === queue_type);
819
+ if (!queue) return this;
820
+ for (const q of this.queues) {
821
+ q.players = q.players.filter((p) => p.id !== player.id);
822
+ }
823
+ if (!queue.players.some((p) => p.id === player.id)) {
824
+ queue.players.push({ id: player.id });
825
+ }
826
+ }
827
+ return await this.update({
828
+ players: this.players.toArray(),
829
+ queues: this.queues
830
+ });
831
+ }
832
+ async removePlayer(player) {
833
+ if (!this.players.some((p) => p.id === player.id)) return this;
834
+ let players = this.players.toArray();
835
+ players = this.players.filter((p) => p.id !== player.id).toArray();
836
+ for (const q of this.queues) {
837
+ q.players = q.players.filter((p) => p.id !== player.id);
838
+ }
839
+ return await this.update({
840
+ players,
841
+ queues: this.queues
842
+ });
843
+ }
844
+ async update(data) {
845
+ const payload = data;
846
+ const route = Routes.guilds.bets.update(this.guild.id, this._id);
847
+ const response = await this.rest.request({ method: "patch", url: route, payload });
848
+ return this._updateInternals(response);
849
+ }
850
+ async delete() {
851
+ const route = Routes.guilds.bets.delete(this.manager.guild.id, this._id);
852
+ const response = await this.rest.request({
853
+ method: "DELETE",
854
+ url: route
855
+ });
856
+ this.rest.emit("betDelete", this);
857
+ this.manager.cache.delete(this._id);
858
+ return response;
859
+ }
860
+ _updateInternals(data) {
861
+ for (let key in data) {
862
+ if (key === "_id" || key === "createdAt") continue;
863
+ if (key === "messages") {
864
+ this.messages.set(data[key]);
865
+ continue;
866
+ }
867
+ if (key === "players") {
868
+ this.players._set(data[key]);
869
+ continue;
870
+ }
871
+ if (key in this) {
872
+ this[key] = data[key];
873
+ }
874
+ }
875
+ if (data?.messages?.length !== 0) {
876
+ if (this?.messages instanceof MessagesManager) this.messages.set(data.messages);
877
+ else {
878
+ this.messages = new MessagesManager(this, Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
879
+ this.messages.set(data.messages);
880
+ }
881
+ }
882
+ this.updatedAt = /* @__PURE__ */ new Date();
883
+ this.createdAt = new Date(data.createdAt);
884
+ this.manager.set(this);
885
+ return this;
886
+ }
887
+ toJSON() {
888
+ let json = {};
889
+ for (const [key, value] of Object.entries(this)) {
890
+ const exclude = ["rest", "guild", "manager"];
891
+ if (exclude.includes(key)) continue;
892
+ if (typeof value !== "function") {
893
+ json[key] = value;
894
+ }
895
+ }
896
+ return {
897
+ ...json,
898
+ messages: this?.messages instanceof MessagesManager ? this.messages?.cache?.toArray() : [],
899
+ players: this.players.toArray()
900
+ };
901
+ }
902
+ };
903
+
904
+ // src/structures/betuser/GuildBetUser.ts
905
+ var GuildBetUser = class _GuildBetUser {
906
+ /**
907
+ * Bet user
908
+ * @param data The user's data
909
+ * @param manager The manager
910
+ * @param rest The rest client
911
+ */
912
+ constructor(data, manager) {
913
+ /** User daily */
914
+ __publicField(this, "daily");
915
+ __publicField(this, "profile");
916
+ /** User's name */
917
+ __publicField(this, "id");
918
+ __publicField(this, "guild_id");
919
+ /** User's credit */
920
+ __publicField(this, "credit");
921
+ /** User's wins */
922
+ __publicField(this, "wins");
923
+ /** User's mvps */
924
+ __publicField(this, "mvps");
925
+ /** User's losses */
926
+ __publicField(this, "losses");
927
+ /** User's games */
928
+ __publicField(this, "games");
929
+ /** User's blacklist */
930
+ __publicField(this, "blacklist");
931
+ /** User's coins */
932
+ __publicField(this, "coins");
933
+ __publicField(this, "spins");
934
+ /** Creation Date */
935
+ __publicField(this, "createdAt");
936
+ /** Updated Date */
937
+ __publicField(this, "updatedAt");
938
+ __publicField(this, "consecutive_wins");
939
+ /** The given manager */
940
+ __publicField(this, "manager");
941
+ /** The rest client */
942
+ __publicField(this, "rest");
943
+ __publicField(this, "guild");
944
+ this.id = data?.id;
945
+ this.guild_id = data?.guild_id;
946
+ this.manager = manager;
947
+ this.rest = manager.rest;
948
+ this.guild = manager.guild;
949
+ this.wins = data?.wins;
950
+ this.coins = data?.coins;
951
+ this.losses = data?.losses;
952
+ this.credit = data?.credit;
953
+ this.spins = data?.spins;
954
+ this.daily = data?.daily;
955
+ this.games = data?.games;
956
+ this.blacklist = data?.blacklist;
957
+ this.consecutive_wins = data?.consecutive_wins;
958
+ this.profile = data?.profile;
959
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
960
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
961
+ }
962
+ /** String representation of this user */
963
+ toString() {
964
+ return `<@${this.id}>`;
965
+ }
966
+ /**
967
+ * Fetches the user
968
+ * @returns New Instance of the user
969
+ */
970
+ async fetch() {
971
+ const route = Routes.guilds.betusers.get(this.manager.guild.id, this.id);
972
+ const response = await this.rest.request({
973
+ method: "get",
974
+ url: route
975
+ });
976
+ const user = new _GuildBetUser(response, this.manager);
977
+ this.manager.cache.set(user.id, user);
978
+ this.rest.betusers.set(user.id, user);
979
+ return user;
980
+ }
981
+ /**
982
+ * Set the user blacklist
983
+ * @param value Value to set to
984
+ * @returns GuildBetUser
985
+ */
986
+ async setBlacklist(value) {
987
+ const route = Routes.guilds.betusers.resource(this.manager.guild.id, this.id, "blacklist");
988
+ const payload = { set: value };
989
+ await this.rest.request({
990
+ method: "patch",
991
+ url: route,
992
+ payload
993
+ });
994
+ this.blacklist = value;
995
+ this.manager.cache.set(this.id, this);
996
+ this.rest.betusers.set(this.id, this);
997
+ return this;
998
+ }
999
+ async reset() {
1000
+ const route = Routes.guilds.betusers.get(this.manager.guild.id, this.id);
1001
+ const payload = { reset: true };
1002
+ const response = await this.rest.request({
1003
+ method: "DELETE",
1004
+ url: route,
1005
+ payload
1006
+ });
1007
+ return this._updateInternals(response);
1008
+ }
1009
+ async updateProfile(data) {
1010
+ const _data = {
1011
+ profile: {
1012
+ avatarUrl: data.avatarUrl || this.profile.avatarUrl || "",
1013
+ bannerUrl: data.bannerUrl || this.profile.bannerUrl || "",
1014
+ bio: data.bio || this.profile.bio || "Melhor da minha aldeia (use !bio para alterar)",
1015
+ name: data.name || this.profile.name || "",
1016
+ textColor: data.textColor || this.profile.textColor || "#ffffff",
1017
+ primaryColor: data.primaryColor || this.profile.primaryColor || "#272727",
1018
+ secondaryColor: data.secondaryColor || this.profile.secondaryColor || "#151515"
1019
+ }
1020
+ };
1021
+ const route = Routes.guilds.betusers.update(this.manager.guild.id, this.id);
1022
+ const response = await this.rest.request({
1023
+ method: "patch",
1024
+ url: route,
1025
+ payload: _data
1026
+ });
1027
+ return this._updateInternals(response);
1028
+ }
1029
+ _updateInternals(data) {
1030
+ for (let key in data) {
1031
+ if (key === "id" || key === "createdAt") continue;
1032
+ if (key in this) {
1033
+ this[key] = data[key];
1034
+ }
1035
+ }
1036
+ this.updatedAt = /* @__PURE__ */ new Date();
1037
+ this.createdAt = new Date(data.createdAt);
1038
+ this.manager.set(this);
1039
+ this.rest.emit("betuserUpdate", this);
1040
+ return this;
1041
+ }
1042
+ /**
1043
+ * Update certain property
1044
+ * @param data The new data to update with
1045
+ * @returns
1046
+ */
1047
+ async update(data) {
1048
+ if (!data?.type) data.type = "add";
1049
+ const route = Routes.guilds.betusers.get(this.manager.guild.id, this.id);
1050
+ let payload = {};
1051
+ const numericFields = ["wins", "credit", "losses", "mvps", "games", "coins", "spins", "consecutive_wins"];
1052
+ const arrayFields = ["items", "original_channels", "adverts", "accessories"];
1053
+ if (data?.type === "add" || data?.type === "remove") {
1054
+ for (const key in data) {
1055
+ if (key === "type") continue;
1056
+ const value = data[key];
1057
+ if (numericFields.includes(key)) {
1058
+ const current = this[key] || 0;
1059
+ const num = value || 0;
1060
+ payload[key] = Math.max(0, data?.type === "add" ? current + num : current - num);
1061
+ } else if (key === "blacklist") {
1062
+ payload["blacklist"] = value;
1063
+ } else if (key === "profile") {
1064
+ payload["profile"] = value;
1065
+ } else if (arrayFields.includes(key)) {
1066
+ const current = this[key];
1067
+ const incoming = value;
1068
+ payload[key] = data?.type === "add" ? [.../* @__PURE__ */ new Set([...current, ...incoming])] : current.filter((x) => !incoming.includes(x));
102
1069
  }
103
- if (message)
104
- this.emit("debug", `${FgRed}${message}${Reset}`);
105
- this.emit("debug", `[Request]${FgGreen} ${(now - before) / 1000}s done.${Reset}`);
106
- return data;
1070
+ }
107
1071
  }
108
- async getStatus() {
109
- return await this.request({ method: "GET", url: "/status" });
1072
+ const response = await this.rest.request({
1073
+ method: "patch",
1074
+ url: route,
1075
+ payload
1076
+ });
1077
+ return this._updateInternals(response);
1078
+ }
1079
+ async _update(data) {
1080
+ const route = Routes.guilds.betusers.get(this.manager.guild.id, this.id);
1081
+ let payload = {};
1082
+ const response = await this.rest.request({
1083
+ method: "put",
1084
+ url: route,
1085
+ payload
1086
+ });
1087
+ return this._updateInternals(response);
1088
+ }
1089
+ async delete() {
1090
+ const route = Routes.guilds.betusers.delete(this.manager.guild.id, this.id);
1091
+ const response = await this.rest.request({
1092
+ method: "DELETE",
1093
+ url: route
1094
+ });
1095
+ this.rest.emit("betuserDelete", this);
1096
+ this.manager.cache.delete(this.id);
1097
+ return response;
1098
+ }
1099
+ toJSON() {
1100
+ let json = {};
1101
+ for (const [key, value] of Object.entries(this)) {
1102
+ const exclude = ["rest", "guilds", "guild", "manager"];
1103
+ if (exclude.includes(key)) continue;
1104
+ if (typeof value !== "function") {
1105
+ json[key] = value;
1106
+ }
1107
+ }
1108
+ return json;
1109
+ }
1110
+ };
1111
+
1112
+ // src/structures/logentry/LogEntry.ts
1113
+ var LogEntry = class {
1114
+ constructor(data, manager) {
1115
+ __publicField(this, "_id");
1116
+ __publicField(this, "guild_id");
1117
+ __publicField(this, "user_id");
1118
+ __publicField(this, "admin_id");
1119
+ __publicField(this, "object_id");
1120
+ __publicField(this, "type");
1121
+ __publicField(this, "description");
1122
+ __publicField(this, "change");
1123
+ __publicField(this, "before");
1124
+ __publicField(this, "after");
1125
+ __publicField(this, "logs_channel_id");
1126
+ __publicField(this, "createdAt");
1127
+ __publicField(this, "updatedAt");
1128
+ __publicField(this, "manager");
1129
+ /** The given guild */
1130
+ __publicField(this, "guild");
1131
+ /** The rest client */
1132
+ __publicField(this, "rest");
1133
+ this.manager = manager;
1134
+ this.guild = manager.guild;
1135
+ this._id = data?._id;
1136
+ this.guild_id = data?.guild_id;
1137
+ this.user_id = data?.user_id;
1138
+ this.admin_id = data?.admin_id;
1139
+ this.object_id = data?.object_id;
1140
+ this.type = data?.type;
1141
+ this.description = data?.description;
1142
+ this.change = data?.change;
1143
+ this.before = data?.before;
1144
+ this.after = data?.after;
1145
+ this.logs_channel_id = data?.logs_channel_id;
1146
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
1147
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
1148
+ }
1149
+ async fetch() {
1150
+ const route = Routes.guilds.resources(this.guild.id, "logs", this._id);
1151
+ const response = await this.rest.request({ url: route, method: "GET" });
1152
+ return this._updateInternals(response);
1153
+ }
1154
+ toJSON() {
1155
+ const json = {};
1156
+ for (const [key, value] of Object.entries(this)) {
1157
+ if (typeof value !== "function") {
1158
+ json[key] = value;
1159
+ }
110
1160
  }
111
- emit(event, ...args // tuple type is spread automatically
112
- ) {
113
- return super.emit(event, ...args);
1161
+ return json;
1162
+ }
1163
+ _updateInternals(data) {
1164
+ for (let key in data) {
1165
+ if (key === "id" || key === "createdAt") continue;
1166
+ if (key in this) {
1167
+ this[key] = data[key];
1168
+ }
114
1169
  }
115
- on(event, listener) {
116
- return super.on(event, listener);
1170
+ this.updatedAt = /* @__PURE__ */ new Date();
1171
+ this.manager.set(this);
1172
+ return this;
1173
+ }
1174
+ };
1175
+
1176
+ // src/structures/match/GuildMatch.ts
1177
+ var GuildMatch = class _GuildMatch {
1178
+ /**
1179
+ * GuildMatch match
1180
+ * @param data The match's data
1181
+ * @param guild The guild
1182
+ * @param rest The rest client
1183
+ */
1184
+ constructor(data, manager) {
1185
+ __publicField(this, "_id");
1186
+ __publicField(this, "selections");
1187
+ /** Match's type */
1188
+ __publicField(this, "type");
1189
+ __publicField(this, "channels");
1190
+ __publicField(this, "guild_id");
1191
+ /** Match's status */
1192
+ __publicField(this, "status");
1193
+ /** Match's challenge */
1194
+ __publicField(this, "challenge");
1195
+ /** Match's players */
1196
+ __publicField(this, "players");
1197
+ __publicField(this, "teams");
1198
+ /** Match's winners */
1199
+ __publicField(this, "winners");
1200
+ /** Match's losers */
1201
+ __publicField(this, "losers");
1202
+ /** Match's maximum size */
1203
+ __publicField(this, "maximumSize");
1204
+ /** Match's kicked out */
1205
+ __publicField(this, "kickedOut");
1206
+ /** Match's confirmed */
1207
+ __publicField(this, "confirmed");
1208
+ /** Match's leaders */
1209
+ __publicField(this, "leaders");
1210
+ /** Match's creator id */
1211
+ __publicField(this, "creatorId");
1212
+ /** Match's room creator id */
1213
+ __publicField(this, "roomCreatorId");
1214
+ /** Creation Date */
1215
+ __publicField(this, "createdAt");
1216
+ /** Updated Date */
1217
+ __publicField(this, "updatedAt");
1218
+ __publicField(this, "messages");
1219
+ /** Match's id */
1220
+ __publicField(this, "mvps");
1221
+ __publicField(this, "manager");
1222
+ __publicField(this, "bet");
1223
+ __publicField(this, "admin_id");
1224
+ /** The given guild */
1225
+ __publicField(this, "guild");
1226
+ /** The rest client */
1227
+ __publicField(this, "rest");
1228
+ __publicField(this, "key");
1229
+ this._id = data?._id;
1230
+ this.guild_id = data?.guild_id;
1231
+ this.manager = manager;
1232
+ this.guild = manager.guild;
1233
+ this.rest = manager.rest;
1234
+ this.admin_id = data?.admin_id;
1235
+ this.challenge = data?.challenge;
1236
+ this.players = data?.players;
1237
+ this.messages = new MessagesManager(this, Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
1238
+ this.channels = data?.channels;
1239
+ this.type = data?.type;
1240
+ this.status = data?.status;
1241
+ this.bet = this.guild.bets.cache.get(data?.bet?._id);
1242
+ this.mvps = data?.mvps;
1243
+ this.winners = data?.winners;
1244
+ this.losers = data?.losers;
1245
+ this.maximumSize = data?.maximumSize;
1246
+ this.kickedOut = data?.kickedOut;
1247
+ this.confirmed = data?.confirmed;
1248
+ this.teams = data?.teams;
1249
+ this.leaders = data?.leaders;
1250
+ this.creatorId = data?.creatorId;
1251
+ this.roomCreatorId = data?.roomCreatorId;
1252
+ this.selections = data?.selections;
1253
+ this.key = "matches";
1254
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
1255
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
1256
+ if (data?.messages?.length !== 0) this.messages.set(data.messages);
1257
+ }
1258
+ /**
1259
+ * Fetches the match
1260
+ * @returns New Instance of the match
1261
+ */
1262
+ async fetch() {
1263
+ const route = Routes.guilds.matches.get(this.guild.id, this._id);
1264
+ const response = await this.rest.request({
1265
+ method: "get",
1266
+ url: route
1267
+ });
1268
+ return await this._updateInternals(response);
1269
+ }
1270
+ async addConfirmed(type, id) {
1271
+ const confirmed = this.confirmed.find((c) => c.type === type);
1272
+ const idsToAdd = Array.isArray(id) ? id : [id];
1273
+ if (!confirmed) {
1274
+ this.confirmed.push({ type, ids: [...idsToAdd], count: idsToAdd.length });
1275
+ } else {
1276
+ const chIndex = this.confirmed.findIndex((ch) => ch.type === type);
1277
+ const mergedIds = [.../* @__PURE__ */ new Set([...confirmed.ids || [], ...idsToAdd])];
1278
+ this.confirmed[chIndex] = { ...confirmed, ids: mergedIds, count: mergedIds.length };
1279
+ }
1280
+ return this.update({ confirmed: this.confirmed });
1281
+ }
1282
+ async setConfirmed(set) {
1283
+ Assertion.assertObject(set);
1284
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "confirmed");
1285
+ const response = await this.rest.request({
1286
+ method: "PATCH",
1287
+ url: route,
1288
+ payload: set
1289
+ });
1290
+ return await this._updateInternals(response);
1291
+ }
1292
+ async setStatus(status) {
1293
+ Assertion.assertString(status);
1294
+ const payload = { set: status.toLowerCase() };
1295
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "status");
1296
+ const response = await this.rest.request({
1297
+ method: "PATCH",
1298
+ url: route,
1299
+ payload
1300
+ });
1301
+ return await this._updateInternals(response);
1302
+ }
1303
+ async setWinners(players) {
1304
+ if (!Array.isArray(players)) players = [players];
1305
+ const payload = { set: players };
1306
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "winners");
1307
+ const response = await this.rest.request({
1308
+ method: "PATCH",
1309
+ url: route,
1310
+ payload
1311
+ });
1312
+ return await this._updateInternals(response);
1313
+ }
1314
+ async setLoser(players) {
1315
+ if (!Array.isArray(players)) players = [players];
1316
+ const payload = { set: players };
1317
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "losers");
1318
+ const response = await this.rest.request({
1319
+ method: "PATCH",
1320
+ url: route,
1321
+ payload
1322
+ });
1323
+ return await this._updateInternals(response);
1324
+ }
1325
+ async setMvps(...usersId) {
1326
+ const payload = { set: usersId };
1327
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "mvps");
1328
+ const response = await this.rest.request({
1329
+ method: "PATCH",
1330
+ url: route,
1331
+ payload
1332
+ });
1333
+ return await this._updateInternals(response);
1334
+ }
1335
+ async setRoomCreatorId(userId) {
1336
+ Assertion.assertString(userId);
1337
+ const payload = { set: userId };
1338
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "roomCreatorId");
1339
+ const response = await this.rest.request({
1340
+ method: "PATCH",
1341
+ url: route,
1342
+ payload
1343
+ });
1344
+ return await this._updateInternals(response);
1345
+ }
1346
+ async setRoomAdminId(userId) {
1347
+ Assertion.assertString(userId);
1348
+ const payload = { set: userId };
1349
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id, "admin_id");
1350
+ const response = await this.rest.request({
1351
+ method: "PATCH",
1352
+ url: route,
1353
+ payload
1354
+ });
1355
+ return await this._updateInternals(response);
1356
+ }
1357
+ async kick(player) {
1358
+ this.players = this.players.filter((p) => p.id !== player.id);
1359
+ this.leaders = this.leaders.filter((p) => p.id !== player.id);
1360
+ const teamIndex = this.teams.findIndex((t) => t.some((p) => p.id === player.id));
1361
+ if (teamIndex !== -1) {
1362
+ let team = this.teams.find((t) => t.some((p) => p.id === player.id));
1363
+ team = team.filter((p) => p.id === player.id);
1364
+ this.teams[teamIndex] = team;
1365
+ }
1366
+ return await this.update(this.toJSON());
1367
+ }
1368
+ async update(data) {
1369
+ const route = Routes.guilds.matches.get(this.guild.id, this._id);
1370
+ if (data?.bet && data?.bet instanceof GuildBet) {
1371
+ data.bet = data.bet.toJSON();
1372
+ }
1373
+ const response = await this.rest.request({
1374
+ method: "patch",
1375
+ url: route,
1376
+ payload: data
1377
+ });
1378
+ this.rest.emit("matchUpdate", this, new _GuildMatch(response, this.manager));
1379
+ return await this._updateInternals(response);
1380
+ }
1381
+ async delete() {
1382
+ const route = Routes.guilds.matches.resource(this.guild.id, this._id);
1383
+ const response = await this.rest.request({
1384
+ method: "DELETE",
1385
+ url: route
1386
+ });
1387
+ this.manager.cache.delete(this?._id);
1388
+ this.rest.matches.delete(this?._id);
1389
+ return response;
1390
+ }
1391
+ toJSON() {
1392
+ let json = {};
1393
+ for (const [key, value] of Object.entries(this)) {
1394
+ const exclude = ["rest", "guilds", "guild", "manager"];
1395
+ if (exclude.includes(key)) continue;
1396
+ if (typeof value !== "function") {
1397
+ json[key] = value;
1398
+ }
1399
+ }
1400
+ return {
1401
+ ...json,
1402
+ messages: this?.messages instanceof MessagesManager ? this.messages?.cache?.toArray() : []
1403
+ };
1404
+ }
1405
+ async _updateInternals(data) {
1406
+ if (!data) return;
1407
+ for (let key in data) {
1408
+ if (key === "id" || key === "createdAt" || key === "messages") continue;
1409
+ if (key in this) {
1410
+ this[key] = data[key];
1411
+ }
1412
+ if (key === "bet") {
1413
+ this.bet = this.guild.bets.set(data.bet);
1414
+ }
1415
+ }
1416
+ if (data?.messages?.length !== 0) {
1417
+ if (this?.messages instanceof MessagesManager) this.messages.set(data.messages);
1418
+ else {
1419
+ this.messages = new MessagesManager(this, Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
1420
+ this.messages.set(data.messages);
1421
+ }
1422
+ }
1423
+ if (!(this.bet instanceof GuildBet) && data?.bet) {
1424
+ this.bet = this.guild.bets.cache.get(data._id) ?? await this.guild.bets.fetch({ betId: data?.bet?._id });
1425
+ }
1426
+ this.updatedAt = /* @__PURE__ */ new Date();
1427
+ this.manager.set(this);
1428
+ return this;
1429
+ }
1430
+ };
1431
+
1432
+ // src/structures/mediator/GuildMediator.ts
1433
+ var GuildMediator = class _GuildMediator {
1434
+ /**
1435
+ * Bet user
1436
+ * @param data The user's data
1437
+ * @param manager The manager
1438
+ * @param rest The rest client
1439
+ */
1440
+ constructor(data, manager) {
1441
+ /** User's name */
1442
+ __publicField(this, "id");
1443
+ __publicField(this, "guild_id");
1444
+ /** User's games */
1445
+ __publicField(this, "games");
1446
+ __publicField(this, "paypal");
1447
+ __publicField(this, "revolut");
1448
+ __publicField(this, "mbway");
1449
+ __publicField(this, "external_links");
1450
+ /** Creation Date */
1451
+ __publicField(this, "createdAt");
1452
+ /** Updated Date */
1453
+ __publicField(this, "updatedAt");
1454
+ /** The given manager */
1455
+ __publicField(this, "manager");
1456
+ /** The rest client */
1457
+ __publicField(this, "rest");
1458
+ __publicField(this, "guild");
1459
+ this.id = data?.id;
1460
+ this.guild_id = data?.guild_id;
1461
+ this.manager = manager;
1462
+ this.rest = manager.rest;
1463
+ this.guild = manager.guild;
1464
+ this.games = data?.games;
1465
+ this.paypal = data?.paypal;
1466
+ this.revolut = data?.revolut;
1467
+ this.mbway = data?.mbway;
1468
+ this.external_links = data?.external_links;
1469
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
1470
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
1471
+ }
1472
+ /** String representation of this user */
1473
+ toString() {
1474
+ return `<@${this.id}>`;
1475
+ }
1476
+ /**
1477
+ * Fetches the user
1478
+ * @returns New Instance of the user
1479
+ */
1480
+ async fetch() {
1481
+ const route = Routes.guilds.mediators.get(this.manager.guild.id, this.id);
1482
+ const response = await this.rest.request({
1483
+ method: "get",
1484
+ url: route
1485
+ });
1486
+ const user = new _GuildMediator(response, this.manager);
1487
+ this.manager.cache.set(user.id, user);
1488
+ this.rest.mediators.set(user.id, user);
1489
+ return user;
1490
+ }
1491
+ async reset() {
1492
+ const route = Routes.guilds.mediators.get(this.manager.guild.id, this.id);
1493
+ const payload = { reset: true };
1494
+ const response = await this.rest.request({
1495
+ method: "DELETE",
1496
+ url: route,
1497
+ payload
1498
+ });
1499
+ return this._updateInternals(response);
1500
+ }
1501
+ _updateInternals(data) {
1502
+ for (let key in data) {
1503
+ if (key === "id" || key === "createdAt") continue;
1504
+ if (key in this) {
1505
+ this[key] = data[key];
1506
+ }
1507
+ }
1508
+ this.updatedAt = /* @__PURE__ */ new Date();
1509
+ this.createdAt = new Date(data.createdAt);
1510
+ this.manager.set(this);
1511
+ return this;
1512
+ }
1513
+ /**
1514
+ * Update certain property
1515
+ * @param data The new data to update with
1516
+ * @returns
1517
+ */
1518
+ async update(data) {
1519
+ const route = Routes.guilds.mediators.get(this.manager.guild.id, this.id);
1520
+ let payload = data;
1521
+ const response = await this.rest.request({
1522
+ method: "patch",
1523
+ url: route,
1524
+ payload
1525
+ });
1526
+ return this._updateInternals(response);
1527
+ }
1528
+ async setPaymentlink(type, link) {
1529
+ const route = Routes.guilds.mediators.get(this.manager.guild.id, this.id);
1530
+ let payload = { [type]: link };
1531
+ const response = await this.rest.request({
1532
+ method: "patch",
1533
+ url: route,
1534
+ payload
1535
+ });
1536
+ return this._updateInternals(response);
1537
+ }
1538
+ async delete() {
1539
+ const route = Routes.guilds.mediators.delete(this.manager.guild.id, this.id);
1540
+ const response = await this.rest.request({
1541
+ method: "DELETE",
1542
+ url: route
1543
+ });
1544
+ this.manager.cache.delete(this.id);
1545
+ return response;
1546
+ }
1547
+ toJSON() {
1548
+ let json = {};
1549
+ for (const [key, value] of Object.entries(this)) {
1550
+ const exclude = ["rest", "guilds", "guild", "manager"];
1551
+ if (exclude.includes(key)) continue;
1552
+ if (typeof value !== "function") {
1553
+ json[key] = value;
1554
+ }
1555
+ }
1556
+ return json;
1557
+ }
1558
+ };
1559
+
1560
+ // src/structures/user/GuildUser.ts
1561
+ var GuildUser = class _GuildUser {
1562
+ /**
1563
+ * Bet user
1564
+ * @param data The user's data
1565
+ * @param manager The manager
1566
+ * @param rest The rest client
1567
+ */
1568
+ constructor(data, manager) {
1569
+ /** User's id */
1570
+ __publicField(this, "id");
1571
+ __publicField(this, "guild_id");
1572
+ /** User's daily */
1573
+ __publicField(this, "daily");
1574
+ /** User's points */
1575
+ __publicField(this, "points");
1576
+ /** User's wins */
1577
+ __publicField(this, "wins");
1578
+ /** User's mvps */
1579
+ __publicField(this, "mvps");
1580
+ /** User's losses */
1581
+ __publicField(this, "losses");
1582
+ /** User's games */
1583
+ __publicField(this, "games");
1584
+ /** If user is blacklisted */
1585
+ __publicField(this, "blacklist");
1586
+ /** User's accessories such as double point */
1587
+ __publicField(this, "accessories");
1588
+ /** User's original channels */
1589
+ __publicField(this, "original_channels");
1590
+ __publicField(this, "profile");
1591
+ __publicField(this, "creations");
1592
+ /** User's items */
1593
+ __publicField(this, "adverts");
1594
+ __publicField(this, "spins");
1595
+ /** Creation Date */
1596
+ __publicField(this, "createdAt");
1597
+ /** Updated Date */
1598
+ __publicField(this, "updatedAt");
1599
+ /** The given manager */
1600
+ __publicField(this, "manager");
1601
+ /** The rest client */
1602
+ __publicField(this, "rest");
1603
+ this.id = data?.id;
1604
+ this.guild_id = data?.guild_id;
1605
+ this.manager = manager;
1606
+ this.rest = manager.rest;
1607
+ this.wins = data?.wins;
1608
+ this.losses = data?.losses;
1609
+ this.mvps = data?.mvps;
1610
+ this.points = data?.points;
1611
+ this.creations = data?.creations;
1612
+ this.spins = data.spins;
1613
+ this.daily = data?.daily;
1614
+ this.games = data?.games;
1615
+ this.blacklist = data?.blacklist;
1616
+ this.accessories = data?.accessories;
1617
+ this.original_channels = data?.original_channels;
1618
+ this.profile = data?.profile;
1619
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
1620
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
1621
+ this.adverts = [];
1622
+ for (let _adv of data?.adverts || []) {
1623
+ this.adverts.push({
1624
+ _id: _adv._id,
1625
+ admin_id: _adv.admin_id,
1626
+ role_id: _adv.role_id,
1627
+ reason: _adv.reason,
1628
+ points_removed: _adv.points_removed,
1629
+ proof: _adv.proof,
1630
+ proof_ext: _adv.proof_ext,
1631
+ createdAt: _adv.createdAt ? new Date(_adv.createdAt) : /* @__PURE__ */ new Date(),
1632
+ updatedAt: _adv.updatedAt ? new Date(_adv.updatedAt) : /* @__PURE__ */ new Date()
1633
+ });
1634
+ }
1635
+ }
1636
+ /** String representation of this user */
1637
+ toString() {
1638
+ return `<@${this.id}>`;
1639
+ }
1640
+ /**
1641
+ * Fetches the user
1642
+ * @returns New Instance of the user
1643
+ */
1644
+ async fetch() {
1645
+ const route = Routes.guilds.users.get(this.manager.guild.id, this.id);
1646
+ const response = await this.rest.request({
1647
+ method: "get",
1648
+ url: route
1649
+ });
1650
+ const user = new _GuildUser(response, this.manager);
1651
+ this.manager.cache.set(user.id, user);
1652
+ this.rest.users.set(user.id, user);
1653
+ return user;
1654
+ }
1655
+ /**
1656
+ * Set the user blacklist
1657
+ * @param value Value to set to
1658
+ * @returns GuildUser
1659
+ */
1660
+ async setBlacklist(value) {
1661
+ const route = Routes.guilds.users.resource(this.manager.guild.id, this.id, "blacklist");
1662
+ const payload = { set: value };
1663
+ await this.rest.request({
1664
+ method: "patch",
1665
+ url: route,
1666
+ payload
1667
+ });
1668
+ this.blacklist = value;
1669
+ this.manager.cache.set(this.id, this);
1670
+ this.rest.users.set(this.id, this);
1671
+ return this;
1672
+ }
1673
+ async reset() {
1674
+ const route = Routes.guilds.users.get(this.manager.guild.id, this.id);
1675
+ const payload = { reset: true };
1676
+ const response = await this.rest.request({
1677
+ method: "DELETE",
1678
+ url: route,
1679
+ payload
1680
+ });
1681
+ this._updateInternals(response);
1682
+ return this;
1683
+ }
1684
+ async updateProfile(data) {
1685
+ const _data = {
1686
+ profile: {
1687
+ avatarUrl: data.avatarUrl || this.profile.avatarUrl || "",
1688
+ bannerUrl: data.bannerUrl || this.profile.bannerUrl || "",
1689
+ bio: data.bio || this.profile.bio || "Melhor da minha aldeia (use !bio para alterar)",
1690
+ name: data.name || this.profile.name || "",
1691
+ textColor: data.textColor || this.profile.textColor || "#ffffff",
1692
+ primaryColor: data.primaryColor || this.profile.primaryColor || "#272727",
1693
+ secondaryColor: data.secondaryColor || this.profile.secondaryColor || "#151515"
1694
+ }
1695
+ };
1696
+ const route = Routes.guilds.users.update(this.manager.guild.id, this.id);
1697
+ const response = await this.rest.request({
1698
+ method: "patch",
1699
+ url: route,
1700
+ payload: _data
1701
+ });
1702
+ this._updateInternals(response);
1703
+ return this;
1704
+ }
1705
+ _updateInternals(data) {
1706
+ for (let key in data) {
1707
+ if (key === "id" || key === "createdAt") continue;
1708
+ if (key in this) {
1709
+ this[key] = data[key];
1710
+ }
1711
+ if (key === "adverts") {
1712
+ this.adverts = [];
1713
+ for (let _adv of data.adverts) {
1714
+ this.adverts.push({
1715
+ _id: _adv._id,
1716
+ admin_id: _adv.admin_id,
1717
+ role_id: _adv.role_id,
1718
+ reason: _adv.reason,
1719
+ points_removed: _adv.points_removed,
1720
+ proof: _adv.proof,
1721
+ proof_ext: _adv.proof_ext,
1722
+ createdAt: _adv.createdAt ? new Date(_adv.createdAt) : /* @__PURE__ */ new Date(),
1723
+ updatedAt: _adv.updatedAt ? new Date(_adv.updatedAt) : /* @__PURE__ */ new Date()
1724
+ });
1725
+ }
1726
+ }
1727
+ }
1728
+ this.updatedAt = /* @__PURE__ */ new Date();
1729
+ this.createdAt = new Date(data.createdAt);
1730
+ this.manager.set(this);
1731
+ this.rest.emit("userUpdate", this);
1732
+ return this;
1733
+ }
1734
+ async addAdvert(data) {
1735
+ const route = Routes.guilds.users.resource(this.manager.guild.id, this.id, "adverts");
1736
+ const payload = data;
1737
+ const response = await this.rest.request({ method: "POST", url: route, payload });
1738
+ return this._updateInternals(response);
1739
+ }
1740
+ async removeAdvert(advertId) {
1741
+ let advs = this.adverts;
1742
+ if (advertId) advs = advs.filter((a) => a._id !== advertId);
1743
+ else advs.pop();
1744
+ const payload = { adverts: advs };
1745
+ const route = Routes.guilds.users.update(this.manager.guild.id, this.id);
1746
+ const response = await this.rest.request({ method: "PATCH", url: route, payload });
1747
+ return this._updateInternals(response);
1748
+ }
1749
+ /**
1750
+ * Update certain property
1751
+ * @param data The new data to update with
1752
+ * @returns
1753
+ */
1754
+ async update(data) {
1755
+ if (!data?.type) data.type = "add";
1756
+ const route = Routes.guilds.users.get(this.manager.guild.id, this.id);
1757
+ let payload = {};
1758
+ const numericFields = ["wins", "points", "losses", "mvps", "games", "creations", "spins"];
1759
+ const arrayFields = ["items", "original_channels", "adverts", "accessories"];
1760
+ if (data?.type === "add" || data?.type === "remove") {
1761
+ for (const key in data) {
1762
+ if (key === "type") continue;
1763
+ const value = data[key];
1764
+ if (numericFields.includes(key)) {
1765
+ const current = this[key] || 0;
1766
+ const num = value || 0;
1767
+ payload[key] = Math.max(0, data?.type === "add" ? current + num : current - num);
1768
+ } else if (key === "blacklist") {
1769
+ payload["blacklist"] = value;
1770
+ } else if (key === "profile") {
1771
+ payload["profile"] = value;
1772
+ } else if (arrayFields.includes(key)) {
1773
+ if (key === "original_channels") {
1774
+ const current2 = this.original_channels;
1775
+ const fromData = data["original_channels"];
1776
+ let channels = [];
1777
+ if (data?.type === "add") {
1778
+ const existingIds = new Set(current2.map((ch) => ch.matchId));
1779
+ channels = [...current2, ...fromData.filter((ch) => !existingIds.has(ch.matchId))];
1780
+ } else if (data?.type === "remove") {
1781
+ const idsToRemove = new Set(fromData.map((ch) => ch.matchId));
1782
+ channels = current2.filter((ch) => !idsToRemove.has(ch.matchId));
1783
+ }
1784
+ payload["original_channels"] = channels;
1785
+ continue;
1786
+ }
1787
+ const current = this[key];
1788
+ const incoming = value;
1789
+ payload[key] = data?.type === "add" ? [.../* @__PURE__ */ new Set([...current, ...incoming])] : current.filter((x) => !incoming.includes(x));
1790
+ }
1791
+ }
1792
+ }
1793
+ const response = await this.rest.request({
1794
+ method: "patch",
1795
+ url: route,
1796
+ payload
1797
+ });
1798
+ this._updateInternals(response);
1799
+ return this;
1800
+ }
1801
+ async delete() {
1802
+ const route = Routes.guilds.users.delete(this.manager.guild.id, this.id);
1803
+ const response = await this.rest.request({
1804
+ method: "DELETE",
1805
+ url: route
1806
+ });
1807
+ this.rest.emit("userDelete", this);
1808
+ this.manager.cache.delete(this.id);
1809
+ return response;
1810
+ }
1811
+ toJSON() {
1812
+ let json = {};
1813
+ for (const [key, value] of Object.entries(this)) {
1814
+ const exclude = ["rest", "guilds", "guild", "manager"];
1815
+ if (exclude.includes(key)) continue;
1816
+ if (typeof value !== "function") {
1817
+ json[key] = value;
1818
+ }
1819
+ }
1820
+ return json;
1821
+ }
1822
+ };
1823
+
1824
+ // src/structures/vipmember/VipMember.ts
1825
+ var _VipMember_instances, updateData_fn;
1826
+ var _VipMember = class _VipMember {
1827
+ /**
1828
+ * Bet member
1829
+ * @param data The member's data
1830
+ * @param manager The manager
1831
+ * @param rest The rest client
1832
+ */
1833
+ constructor(data, manager) {
1834
+ __privateAdd(this, _VipMember_instances);
1835
+ /** member's id */
1836
+ __publicField(this, "id");
1837
+ /** member name */
1838
+ __publicField(this, "name");
1839
+ /** Members's roleId */
1840
+ __publicField(this, "roleId");
1841
+ /** Members's voiceChannelId */
1842
+ __publicField(this, "voiceChannelId");
1843
+ /** Vip's type */
1844
+ __publicField(this, "type");
1845
+ /** Member's Guild Id */
1846
+ __publicField(this, "guild_id");
1847
+ __publicField(this, "duration");
1848
+ __publicField(this, "status");
1849
+ /** member's daily */
1850
+ __publicField(this, "createdAt");
1851
+ /** Updated Date */
1852
+ __publicField(this, "updatedAt");
1853
+ /** The given manager */
1854
+ __publicField(this, "manager");
1855
+ /** The rest client */
1856
+ __publicField(this, "rest");
1857
+ __publicField(this, "guild");
1858
+ this.name = data?.name;
1859
+ this.id = data?.id;
1860
+ this.manager = manager;
1861
+ this.rest = manager.rest;
1862
+ this.guild = manager.guild;
1863
+ this.duration = data?.duration ? new Date(data?.duration) : /* @__PURE__ */ new Date();
1864
+ this.status = data?.status;
1865
+ this.type = data?.type;
1866
+ this.roleId = data?.roleId;
1867
+ this.voiceChannelId = data?.voiceChannelId;
1868
+ this.guild_id = data?.guild_id;
1869
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
1870
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
1871
+ }
1872
+ /** String representation of this member */
1873
+ toString() {
1874
+ return `<@${this.id}>`;
1875
+ }
1876
+ /**
1877
+ * Fetches the member
1878
+ * @returns New Instance of the member
1879
+ */
1880
+ async fetch() {
1881
+ const route = Routes.vipmembers.get(this.guild_id, this.id);
1882
+ const response = await this.rest.request({
1883
+ method: "get",
1884
+ url: route
1885
+ });
1886
+ const member = new _VipMember(response, this.manager);
1887
+ this.manager.cache.set(member.id, member);
1888
+ return member;
1889
+ }
1890
+ async reset() {
1891
+ const route = Routes.vipmembers.get(this.guild_id, this.id);
1892
+ const payload = { reset: true };
1893
+ const response = await this.rest.request({
1894
+ method: "DELETE",
1895
+ url: route,
1896
+ payload
1897
+ });
1898
+ __privateMethod(this, _VipMember_instances, updateData_fn).call(this, response);
1899
+ this.type = response.type;
1900
+ this.manager.set(response);
1901
+ return this;
1902
+ }
1903
+ /**
1904
+ * Update certain property
1905
+ * @param data The new data to update with
1906
+ * @returns
1907
+ */
1908
+ async update(data) {
1909
+ const route = Routes.vipmembers.get(this.guild.id, this.id);
1910
+ const payload = data;
1911
+ const response = await this.rest.request({
1912
+ method: "patch",
1913
+ url: route,
1914
+ payload
1915
+ });
1916
+ for (const k in response) {
1917
+ if (k === "id") continue;
1918
+ if (Object.hasOwn(this, k)) {
1919
+ this[k] = response[k];
1920
+ }
117
1921
  }
118
- once(event, listener) {
119
- return super.once(event, listener);
1922
+ this.updatedAt = response?.updatedAt ? new Date(response?.updatedAt) : /* @__PURE__ */ new Date();
1923
+ this.duration = response?.duration ? new Date(response?.duration) : /* @__PURE__ */ new Date();
1924
+ this.createdAt = response?.createdAt ? new Date(response?.createdAt) : /* @__PURE__ */ new Date();
1925
+ this.type = response.type;
1926
+ this.manager.cache.set(this.id, this);
1927
+ return this;
1928
+ }
1929
+ async delete() {
1930
+ const route = Routes.vipmembers.delete(this.guild_id, this.id);
1931
+ const response = await this.rest.request({
1932
+ method: "DELETE",
1933
+ url: route
1934
+ });
1935
+ this.manager.cache.delete(this.id);
1936
+ return response;
1937
+ }
1938
+ toJSON() {
1939
+ let json;
1940
+ for (const [key, value] of Object.entries(this)) {
1941
+ if (typeof value !== "function") {
1942
+ json[key] = value;
1943
+ }
120
1944
  }
1945
+ return json;
1946
+ }
1947
+ };
1948
+ _VipMember_instances = new WeakSet();
1949
+ updateData_fn = function(data) {
1950
+ for (const k in data) {
1951
+ if (k === "id") continue;
1952
+ if (Object.hasOwn(this, k)) {
1953
+ this[k] = data[k];
1954
+ this.data[k] = data[k];
1955
+ }
1956
+ }
1957
+ };
1958
+ var VipMember = _VipMember;
1959
+
1960
+ // src/structures/ticket/Ticket.ts
1961
+ var GuildTicket = class {
1962
+ constructor(data, manager) {
1963
+ __publicField(this, "_id");
1964
+ __publicField(this, "guild_id");
1965
+ __publicField(this, "type");
1966
+ __publicField(this, "status");
1967
+ __publicField(this, "admin_id");
1968
+ __publicField(this, "channel_id");
1969
+ __publicField(this, "closed_by_id");
1970
+ __publicField(this, "creator_id");
1971
+ __publicField(this, "customer_rating");
1972
+ __publicField(this, "messages");
1973
+ __publicField(this, "createdAt");
1974
+ __publicField(this, "updatedAt");
1975
+ __publicField(this, "rest");
1976
+ __publicField(this, "guild");
1977
+ __publicField(this, "manager");
1978
+ this.manager = manager;
1979
+ this.guild = manager.guild;
1980
+ this.rest = manager.rest;
1981
+ this._id = data?._id;
1982
+ this.type = data?.type;
1983
+ this.admin_id = data?.admin_id;
1984
+ this.guild_id = data?.guild_id;
1985
+ this.channel_id = data?.channel_id;
1986
+ this.creator_id = data?.creator_id;
1987
+ this.status = data?.status;
1988
+ this.customer_rating = data?.customer_rating;
1989
+ this.messages = data?.messages;
1990
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
1991
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
1992
+ }
1993
+ async fetch() {
1994
+ const route = Routes.guilds.tickets.get(this.guild.id, this._id);
1995
+ const response = await this.rest.request({
1996
+ method: "GET",
1997
+ url: route
1998
+ });
1999
+ return this._updateInternals(response);
2000
+ }
2001
+ async setCustomerRating(rating) {
2002
+ const route = Routes.guilds.tickets.resource(this.guild.id, this._id, "customer_rating");
2003
+ const payload = { set: rating };
2004
+ const response = await this.rest.request({
2005
+ method: "PATCH",
2006
+ url: route,
2007
+ payload
2008
+ });
2009
+ return this._updateInternals(response);
2010
+ }
2011
+ async setAdminId(id) {
2012
+ const route = Routes.guilds.tickets.resource(this.guild.id, this._id, "admin_id");
2013
+ const payload = { set: id };
2014
+ const response = await this.rest.request({
2015
+ method: "PATCH",
2016
+ url: route,
2017
+ payload
2018
+ });
2019
+ return this._updateInternals(response);
2020
+ }
2021
+ async setChannelId(id) {
2022
+ const route = Routes.guilds.tickets.resource(this.guild.id, this._id, "channel_id");
2023
+ const payload = { set: id };
2024
+ const response = await this.rest.request({
2025
+ method: "PATCH",
2026
+ url: route,
2027
+ payload
2028
+ });
2029
+ return this._updateInternals(response);
2030
+ }
2031
+ async setClosedById(id) {
2032
+ const route = Routes.guilds.tickets.resource(this.guild.id, this._id, "closed_by_id");
2033
+ const payload = { set: id };
2034
+ const response = await this.rest.request({
2035
+ method: "PATCH",
2036
+ url: route,
2037
+ payload
2038
+ });
2039
+ return this._updateInternals(response);
2040
+ }
2041
+ async setStatus(status) {
2042
+ const route = Routes.guilds.tickets.resource(this.guild.id, this._id, "status");
2043
+ const payload = { set: status };
2044
+ const response = await this.rest.request({
2045
+ method: "PATCH",
2046
+ url: route,
2047
+ payload
2048
+ });
2049
+ return this._updateInternals(response);
2050
+ }
2051
+ async addMessage(message) {
2052
+ const route = Routes.guilds.tickets.resource(this.guild.id, this._id, "messages");
2053
+ const payload = { set: [...this.messages, message] };
2054
+ const response = await this.rest.request({
2055
+ method: "PATCH",
2056
+ url: route,
2057
+ payload
2058
+ });
2059
+ return this._updateInternals(response);
2060
+ }
2061
+ _updateInternals(data) {
2062
+ for (let key in data) {
2063
+ if (key === "id" || key === "createdAt") continue;
2064
+ if (key in this) {
2065
+ this[key] = data[key];
2066
+ }
2067
+ }
2068
+ this.updatedAt = /* @__PURE__ */ new Date();
2069
+ this.createdAt = new Date(data.createdAt);
2070
+ this.manager.set(this);
2071
+ return this;
2072
+ }
2073
+ };
2074
+
2075
+ // src/structures/minesgame/MinesGame.ts
2076
+ var MinesGame = class {
2077
+ constructor(data, manager) {
2078
+ __publicField(this, "guild_id");
2079
+ __publicField(this, "_id");
2080
+ __publicField(this, "creatorId");
2081
+ __publicField(this, "maxMines");
2082
+ __publicField(this, "bombs");
2083
+ __publicField(this, "bombsPosition");
2084
+ __publicField(this, "bet");
2085
+ __publicField(this, "multiplier");
2086
+ __publicField(this, "status");
2087
+ __publicField(this, "createdAt");
2088
+ __publicField(this, "updatedAt");
2089
+ __publicField(this, "rest");
2090
+ __publicField(this, "manager");
2091
+ this.manager = manager;
2092
+ this.rest = manager.rest;
2093
+ this.guild_id = data?.guild_id;
2094
+ this.bombsPosition = data?.bombsPosition;
2095
+ this._id = data?._id;
2096
+ this.multiplier = data?.multiplier;
2097
+ this.creatorId = data?.creatorId;
2098
+ this.maxMines = data?.maxMines;
2099
+ this.bombs = data?.bombs;
2100
+ this.bet = data?.bet;
2101
+ this.status = data?.status;
2102
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
2103
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
2104
+ }
2105
+ async fetch() {
2106
+ const route = `/${Routes.fields("minesgames", this._id)}`;
2107
+ const response = await this.rest.request({
2108
+ method: "GET",
2109
+ url: route
2110
+ });
2111
+ return this._updateInternals(response);
2112
+ }
2113
+ async delete() {
2114
+ const route = `/${Routes.fields("minesgames", this._id)}`;
2115
+ const response = await this.rest.request({
2116
+ method: "delete",
2117
+ url: route
2118
+ });
2119
+ return this._updateInternals(response);
2120
+ }
2121
+ async update(data) {
2122
+ const route = `/${Routes.fields("minesgames", this._id)}`;
2123
+ const response = await this.rest.request({
2124
+ method: "PATCH",
2125
+ url: route,
2126
+ payload: data
2127
+ });
2128
+ return this._updateInternals(response);
2129
+ }
2130
+ _updateInternals(data) {
2131
+ for (let key in data) {
2132
+ if (key === "id" || key === "createdAt") continue;
2133
+ if (key in this) {
2134
+ this[key] = data[key];
2135
+ }
2136
+ }
2137
+ this.updatedAt = /* @__PURE__ */ new Date();
2138
+ this.manager.set(this);
2139
+ return this;
2140
+ }
2141
+ };
2142
+
2143
+ // src/structures/automaticmessage/AutomaticMessage.ts
2144
+ var AutomaticMessage = class {
2145
+ constructor(data, manager) {
2146
+ __publicField(this, "_id");
2147
+ __publicField(this, "id");
2148
+ __publicField(this, "type");
2149
+ __publicField(this, "admin_id");
2150
+ __publicField(this, "channel_ids");
2151
+ __publicField(this, "content");
2152
+ __publicField(this, "embeds");
2153
+ __publicField(this, "components");
2154
+ __publicField(this, "attachments");
2155
+ __publicField(this, "flags");
2156
+ __publicField(this, "interval_ms");
2157
+ __publicField(this, "createdAt");
2158
+ __publicField(this, "updatedAt");
2159
+ __publicField(this, "guild");
2160
+ __publicField(this, "manager");
2161
+ __publicField(this, "rest");
2162
+ this.manager = manager;
2163
+ this.guild = manager.guild;
2164
+ this.rest = manager.rest;
2165
+ this._id = data?._id;
2166
+ this.id = data?.id;
2167
+ this.type = data?.type;
2168
+ this.admin_id = data?.admin_id;
2169
+ this.channel_ids = data?.channel_ids;
2170
+ this.content = data?.content;
2171
+ this.embeds = data?.embeds;
2172
+ this.components = data?.components;
2173
+ this.attachments = data?.attachments;
2174
+ this.flags = data?.flags;
2175
+ this.interval_ms = data?.interval_ms;
2176
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
2177
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
2178
+ }
2179
+ async fetch() {
2180
+ const route = Routes.guilds.resource(this.guild.id, "automatic_messages", this._id);
2181
+ const response = await this.rest.request({
2182
+ method: "get",
2183
+ url: route
2184
+ });
2185
+ return this._updateInternals(response);
2186
+ }
2187
+ async addChannelId(...id) {
2188
+ const ids = [.../* @__PURE__ */ new Set([...this.channel_ids, ...id])];
2189
+ return this.update({ channel_ids: ids });
2190
+ }
2191
+ async removeChannelId(...id) {
2192
+ const remove = new Set(id);
2193
+ const ids = this.channel_ids.filter((i) => !remove.has(i));
2194
+ return this.update({ channel_ids: ids });
2195
+ }
2196
+ async update(data) {
2197
+ const route = Routes.guilds.get(this.guild.id);
2198
+ const response = await this.rest.request({
2199
+ method: "patch",
2200
+ url: route,
2201
+ payload: { automatic_messages: this.manager.cache.toArray() }
2202
+ });
2203
+ return this._updateInternals(response);
2204
+ }
2205
+ async delete() {
2206
+ this.manager.cache.delete(this._id);
2207
+ const route = Routes.guilds.get(this.guild.id);
2208
+ const response = await this.rest.request({
2209
+ method: "patch",
2210
+ url: route,
2211
+ payload: { automatic_messages: this.manager.cache.toArray() }
2212
+ });
2213
+ return this.manager.set(response.automatic_messages);
2214
+ }
2215
+ _updateInternals(data) {
2216
+ for (let key in data) {
2217
+ if (key === "_id" || key === "createdAt") continue;
2218
+ if (key in this) {
2219
+ this[key] = data[key];
2220
+ }
2221
+ }
2222
+ this.updatedAt = /* @__PURE__ */ new Date();
2223
+ this.createdAt = new Date(data.createdAt);
2224
+ this.manager._add(this);
2225
+ return this;
2226
+ }
2227
+ toJSON() {
2228
+ return {
2229
+ _id: this._id,
2230
+ id: this.id,
2231
+ type: this.type,
2232
+ admin_id: this.admin_id,
2233
+ attachments: this.attachments,
2234
+ channel_ids: this.channel_ids,
2235
+ content: this.content,
2236
+ embeds: this.embeds,
2237
+ flags: this.flags,
2238
+ interval_ms: this.interval_ms,
2239
+ components: this.components,
2240
+ createdAt: this.createdAt,
2241
+ updatedAt: this.updatedAt
2242
+ };
2243
+ }
2244
+ };
2245
+
2246
+ // src/utils/randomKeyGenerator.ts
2247
+ var import_crypto = require("crypto");
2248
+ function randomKeyGenerator(max, enconding) {
2249
+ return (0, import_crypto.randomBytes)(24).toString(enconding ?? "base64").slice(0, max || 24).toUpperCase();
121
2250
  }
122
- exports.REST = REST;
2251
+
2252
+ // src/managers/automaticmessage/AutomaticMessageManager.ts
2253
+ var AutomaticMessageManager = class extends BaseManager {
2254
+ constructor(guild) {
2255
+ super(guild);
2256
+ this.guild = guild;
2257
+ this.rest = guild.rest;
2258
+ this.base_url = Routes.guilds.resource(guild.id, "automatic_messages");
2259
+ this.cache = new Collection();
2260
+ if (guild.automatic_messages && guild.automatic_messages.length !== 0) this.set(guild.automatic_messages);
2261
+ else this.guild.automatic_messages = [];
2262
+ }
2263
+ async fetch(messageId) {
2264
+ const route = this.base_url;
2265
+ if (messageId) {
2266
+ const response2 = await this.rest.request({
2267
+ method: "get",
2268
+ url: `${route}`
2269
+ });
2270
+ return this._add(response2).find((m) => m.id === messageId);
2271
+ }
2272
+ const response = await this.rest.request({
2273
+ method: "get",
2274
+ url: route
2275
+ });
2276
+ return this._add(response.automatic_messages);
2277
+ }
2278
+ async create(data) {
2279
+ if (!data.type) throw new Error(`Missing message's type.`);
2280
+ const id = randomKeyGenerator(9).replace(/-/g, "0").replace(/_/g, "Y");
2281
+ const m = { ...data, id };
2282
+ this.guild.automatic_messages.push(m);
2283
+ const route = Routes.guilds.get(this.guild.id);
2284
+ const response = await this.rest.request({
2285
+ method: "patch",
2286
+ url: route,
2287
+ payload: { automatic_messages: this.guild.automatic_messages }
2288
+ });
2289
+ return this._add(response.automatic_messages).find((m2) => m2.id === id);
2290
+ }
2291
+ _add(data) {
2292
+ if (Array.isArray(data)) {
2293
+ for (let _m of data) {
2294
+ if (!_m.id) continue;
2295
+ if (_m instanceof AutomaticMessage) this.cache.set(_m.id, _m);
2296
+ else this.cache.set(_m.id, new AutomaticMessage(_m, this));
2297
+ }
2298
+ } else {
2299
+ if (!data.id) return this.cache;
2300
+ if (data instanceof AutomaticMessage) this.cache.set(data.id, data);
2301
+ else this.cache.set(data.id, new AutomaticMessage(data, this));
2302
+ }
2303
+ return this.cache;
2304
+ }
2305
+ set(data) {
2306
+ this.cache.clear();
2307
+ if (Array.isArray(data)) {
2308
+ for (let _m of data) {
2309
+ if (!_m.id) continue;
2310
+ if (_m instanceof AutomaticMessage) this.cache.set(_m.id, _m);
2311
+ else this.cache.set(_m.id, new AutomaticMessage(_m, this));
2312
+ }
2313
+ } else {
2314
+ if (!data.id) return this.cache;
2315
+ if (data instanceof AutomaticMessage) this.cache.set(data.id, data);
2316
+ else this.cache.set(data.id, new AutomaticMessage(data, this));
2317
+ }
2318
+ return this.cache;
2319
+ }
2320
+ async delete(messageId) {
2321
+ if (messageId) return await this.cache.get(messageId).delete();
2322
+ this.cache.clear();
2323
+ const route = Routes.guilds.get(this.guild.id);
2324
+ const response = await this.rest.request({
2325
+ method: "patch",
2326
+ url: route,
2327
+ payload: { automatic_messages: [] }
2328
+ });
2329
+ return response;
2330
+ }
2331
+ };
2332
+
2333
+ // src/managers/bet/GuildBetManager.ts
2334
+ var GuildBetManager2 = class extends BaseManager {
2335
+ constructor(guild) {
2336
+ super(guild);
2337
+ this.guild = guild;
2338
+ this.rest = guild.rest;
2339
+ this.base_url = Routes.guilds.bets.getAll(guild.id);
2340
+ this.cache = new Collection("bets");
2341
+ }
2342
+ toString() {
2343
+ return this.cache.size;
2344
+ }
2345
+ async fetch(options) {
2346
+ const route = this.base_url;
2347
+ if (options && options.cache) return this.cache;
2348
+ if (options && options.betId) {
2349
+ const response2 = await this.rest.request({ url: `${route}/${options.betId}`, method: "GET" });
2350
+ return this.set(response2);
2351
+ }
2352
+ const response = await this.rest.request({ url: route, method: "GET" });
2353
+ return this.set(response);
2354
+ }
2355
+ async create(data) {
2356
+ const route = Routes.guilds.bets.create(this.guild.id);
2357
+ const response = await this.rest.request({ url: route, method: "POST", payload: data });
2358
+ return this.set(response);
2359
+ }
2360
+ async delete(betId) {
2361
+ const route = Routes.fields(this.base_url, betId);
2362
+ const response = await this.rest.request({ url: route, method: "DELETE" });
2363
+ return this.set(response);
2364
+ }
2365
+ set(data) {
2366
+ if (!data) return;
2367
+ if (Array.isArray(data)) {
2368
+ for (let _bet of data) {
2369
+ if (!_bet._id) continue;
2370
+ const bet = new GuildBet(_bet, this);
2371
+ this.cache.set(bet._id, bet);
2372
+ this.rest.bets.set(bet._id, bet);
2373
+ }
2374
+ } else {
2375
+ if (!data._id) return;
2376
+ if (data instanceof GuildBet) {
2377
+ this.cache.set(data._id, data);
2378
+ return data;
2379
+ }
2380
+ const bet = new GuildBet(data, this);
2381
+ this.cache.set(bet._id, bet);
2382
+ this.rest.bets.set(bet._id, bet);
2383
+ return bet;
2384
+ }
2385
+ }
2386
+ };
2387
+
2388
+ // src/managers/betuser/GuildBetUserManager.ts
2389
+ var GuildBetUserManager = class extends BaseManager {
2390
+ constructor(guild) {
2391
+ super(guild);
2392
+ this.guild = guild;
2393
+ this.rest = guild.rest;
2394
+ this.base_url = Routes.guilds.betusers.getAll(guild.id);
2395
+ this.cache = new Collection("betusers");
2396
+ }
2397
+ async fetch(options) {
2398
+ if (options && options.cache) return this.cache;
2399
+ if (options && options.userId) {
2400
+ const route2 = Routes.fields(this.base_url, options.userId);
2401
+ const response2 = await this.rest.request({
2402
+ method: "GET",
2403
+ url: route2
2404
+ });
2405
+ const user = new GuildBetUser(response2, this);
2406
+ this.set(user);
2407
+ return user;
2408
+ }
2409
+ const route = this.base_url;
2410
+ const response = await this.rest.request({
2411
+ method: "GET",
2412
+ url: route
2413
+ });
2414
+ this.set(response);
2415
+ return this.cache;
2416
+ }
2417
+ async updateMany(...betusers) {
2418
+ const route = this.base_url;
2419
+ const response = await this.rest.request({
2420
+ method: "PATCH",
2421
+ url: route,
2422
+ payload: { betusers }
2423
+ });
2424
+ return this.set(response);
2425
+ }
2426
+ async deleteAll() {
2427
+ const route = this.base_url;
2428
+ await this.rest.request({
2429
+ method: "DELETE",
2430
+ url: route
2431
+ });
2432
+ this.cache.clear();
2433
+ }
2434
+ async resetAll() {
2435
+ const route = this.base_url;
2436
+ const response = await this.rest.request({
2437
+ method: "put",
2438
+ url: route
2439
+ });
2440
+ this.cache.clear();
2441
+ return this.set(response);
2442
+ }
2443
+ set(data) {
2444
+ if (!data) return this.cache;
2445
+ if (Array.isArray(data)) {
2446
+ for (let _user of data) {
2447
+ if (!_user.id) return;
2448
+ const user = new GuildBetUser(_user, this);
2449
+ this.cache.set(user.id, user);
2450
+ this.rest.betusers.set(user.id, user);
2451
+ }
2452
+ return this.cache;
2453
+ } else {
2454
+ if (!data.id) return;
2455
+ const user = new GuildBetUser(data, this);
2456
+ this.cache.set(user.id, user);
2457
+ this.rest.betusers.set(user.id, user);
2458
+ return user;
2459
+ }
2460
+ }
2461
+ };
2462
+
2463
+ // src/managers/buffer/BufferManager.ts
2464
+ var BufferManager = class {
2465
+ constructor(guild) {
2466
+ __publicField(this, "matches");
2467
+ __publicField(this, "tickets");
2468
+ __publicField(this, "guild");
2469
+ this.matches = new Collection("buffer:matches");
2470
+ this.tickets = new Collection("buffer:tickets");
2471
+ this.guild = guild;
2472
+ }
2473
+ async flush(key) {
2474
+ const { rest } = this.guild;
2475
+ const cache = this[key];
2476
+ const { size, clear } = cache;
2477
+ if (size >= 2) {
2478
+ const response = await rest.request({
2479
+ method: "POST",
2480
+ url: Routes.guilds.resources(this.guild.id, key, "bulk"),
2481
+ payload: { [key]: this[key].toArray() }
2482
+ });
2483
+ this.guild[key].set(response);
2484
+ clear();
2485
+ return response;
2486
+ }
2487
+ return;
2488
+ }
2489
+ createMatch(id, data) {
2490
+ this.matches.set(id, data);
2491
+ }
2492
+ createTicket(id, data) {
2493
+ this.tickets.set(id, data);
2494
+ }
2495
+ };
2496
+
2497
+ // src/managers/logs/LogManager.ts
2498
+ var LogManager = class extends BaseManager {
2499
+ constructor(guild) {
2500
+ super(guild);
2501
+ this.guild = guild;
2502
+ this.rest = guild.rest;
2503
+ this.base_url = Routes.fields(Routes.guilds.get(guild.id), "logs");
2504
+ this.cache = new Collection();
2505
+ }
2506
+ async fetch() {
2507
+ const route = this.base_url;
2508
+ const response = await this.rest.request({
2509
+ method: "GET",
2510
+ url: route
2511
+ });
2512
+ return this.set(response);
2513
+ }
2514
+ async create(data) {
2515
+ const route = this.base_url;
2516
+ const payload = { ...data };
2517
+ const response = await this.rest.request({
2518
+ method: "POST",
2519
+ url: route,
2520
+ payload
2521
+ });
2522
+ const logEntry = this.set(response);
2523
+ this.cache.set(data._id, logEntry);
2524
+ this.rest.emit("logEntryCreate", logEntry, this.guild);
2525
+ return logEntry;
2526
+ }
2527
+ /* async createMany(data: Optional<APILogEntry>[]): Promise<APILogEntry[]> {
2528
+ const route = Routes.fields(this.base_url, "bulk");
2529
+ const payload = { ...data };
2530
+ const response = await this.rest.request<APILogEntry[], typeof payload>({
2531
+ method: "POST",
2532
+ url: route,
2533
+ payload,
2534
+ });
2535
+
2536
+ this.set(response);
2537
+ return response;
2538
+ } */
2539
+ set(data) {
2540
+ if (!data) return this.cache;
2541
+ if (Array.isArray(data)) {
2542
+ this.cache.clear();
2543
+ for (let entry of data) {
2544
+ if (!entry._id) continue;
2545
+ const logEntry = new LogEntry(entry, this);
2546
+ this.cache.set(entry._id, logEntry);
2547
+ }
2548
+ return this.cache;
2549
+ } else {
2550
+ const logEntry = new LogEntry(data, this);
2551
+ this.cache.set(data._id, logEntry);
2552
+ return logEntry;
2553
+ }
2554
+ }
2555
+ };
2556
+
2557
+ // src/managers/match/GuildMatchManager.ts
2558
+ var GuildMatchManager2 = class extends BaseManager {
2559
+ /**
2560
+ * Manage users with the given client
2561
+ * @param users An array of users
2562
+ * @param rest The rest client
2563
+ */
2564
+ constructor(guild) {
2565
+ super(guild);
2566
+ this.guild = guild;
2567
+ this.rest = guild.rest;
2568
+ this.base_url = Routes.guilds.matches.getAll(guild.id);
2569
+ this.cache = new Collection("matches");
2570
+ }
2571
+ /**
2572
+ * Fetch a match
2573
+ * @param id Id of the match to fetch
2574
+ * @returns APIBetUser
2575
+ */
2576
+ async fetch(options) {
2577
+ if (options && options.cache) return this.cache;
2578
+ if (options && options.matchId) {
2579
+ const route2 = Routes.guilds.matches.get(this.guild.id, options.matchId);
2580
+ const response2 = await this.rest.request({
2581
+ method: "get",
2582
+ url: route2
2583
+ });
2584
+ return this.set(response2);
2585
+ }
2586
+ const route = Routes.guilds.matches.getAll(this.guild.id);
2587
+ const response = await this.rest.request({
2588
+ method: "get",
2589
+ url: route
2590
+ });
2591
+ if (!response) return this.cache;
2592
+ const coll = new Collection("matches");
2593
+ for (let match of response ?? []) {
2594
+ const guildMatch = new GuildMatch(match, this);
2595
+ coll.set(match._id, guildMatch);
2596
+ this.rest.matches.set(match._id, guildMatch);
2597
+ }
2598
+ this.cache = coll;
2599
+ return coll;
2600
+ }
2601
+ async fetchAll() {
2602
+ const route = Routes.guilds.matches.getAll(this.guild.id);
2603
+ const response = await this.rest.request({
2604
+ method: "get",
2605
+ url: route
2606
+ });
2607
+ if (Array.isArray(response) && response.length === 0) {
2608
+ this.cache.clear();
2609
+ return this.cache;
2610
+ }
2611
+ this.set(response);
2612
+ return this.cache;
2613
+ }
2614
+ set(data) {
2615
+ if (!data) return this.cache;
2616
+ if (Array.isArray(data)) {
2617
+ for (let _match of data) {
2618
+ if (!_match._id) continue;
2619
+ const match = new GuildMatch(_match, this);
2620
+ this.cache.set(match._id, match);
2621
+ }
2622
+ return this.cache;
2623
+ } else {
2624
+ if (!data._id) return this.cache;
2625
+ if (data instanceof GuildMatch) {
2626
+ this.cache.set(data._id, data);
2627
+ return data;
2628
+ }
2629
+ const match = new GuildMatch(data, this);
2630
+ this.cache.set(match._id, match);
2631
+ return match;
2632
+ }
2633
+ }
2634
+ async create(payload) {
2635
+ Assertion.assertObject(payload);
2636
+ const route = Routes.guilds.matches.create(this.guild.id);
2637
+ const response = await this.rest.request({
2638
+ method: "POST",
2639
+ url: route,
2640
+ payload
2641
+ });
2642
+ return this.set(response);
2643
+ }
2644
+ async delete(id) {
2645
+ const route = Routes.fields(this.base_url, id);
2646
+ const response = await this.rest.request({ url: route, method: "DELETE" });
2647
+ return this.set(response);
2648
+ }
2649
+ };
2650
+
2651
+ // src/managers/mediator/GuildMediatorManager.ts
2652
+ var GuildMediatorManager = class extends BaseManager {
2653
+ constructor(guild) {
2654
+ super(guild);
2655
+ this.guild = guild;
2656
+ this.rest = guild.rest;
2657
+ this.base_url = Routes.guilds.mediators.getAll(guild.id);
2658
+ this.cache = new Collection("mediators");
2659
+ }
2660
+ async fetch(options) {
2661
+ if (options && options.cache) return this.cache;
2662
+ if (options && options.mediatorId) {
2663
+ const route2 = Routes.fields(this.base_url, options.mediatorId);
2664
+ const response2 = await this.rest.request({
2665
+ method: "GET",
2666
+ url: route2
2667
+ });
2668
+ return this.set(response2);
2669
+ }
2670
+ const route = this.base_url;
2671
+ const response = await this.rest.request({
2672
+ method: "GET",
2673
+ url: route
2674
+ });
2675
+ this.set(response);
2676
+ return this.cache;
2677
+ }
2678
+ async updateMany(...mediators) {
2679
+ const route = this.base_url;
2680
+ const response = await this.rest.request({
2681
+ method: "PATCH",
2682
+ url: route,
2683
+ payload: { mediators }
2684
+ });
2685
+ return this.set(response);
2686
+ }
2687
+ async create(payload) {
2688
+ const route = Routes.guilds.mediators.create(this.guild.id);
2689
+ const response = await this.rest.request({
2690
+ method: "POST",
2691
+ url: route,
2692
+ payload
2693
+ });
2694
+ return this.set(response);
2695
+ }
2696
+ async deleteAll() {
2697
+ const route = this.base_url;
2698
+ await this.rest.request({
2699
+ method: "DELETE",
2700
+ url: route
2701
+ });
2702
+ this.cache.clear();
2703
+ }
2704
+ async resetAll() {
2705
+ const route = this.base_url;
2706
+ const response = await this.rest.request({
2707
+ method: "put",
2708
+ url: route
2709
+ });
2710
+ this.cache.clear();
2711
+ this.set(response);
2712
+ return this.cache;
2713
+ }
2714
+ set(data) {
2715
+ if (!data) return this.cache;
2716
+ if (Array.isArray(data)) {
2717
+ for (let _mediator of data) {
2718
+ if (!_mediator.id) return;
2719
+ const mediator = new GuildMediator(_mediator, this);
2720
+ this.cache.set(mediator.id, mediator);
2721
+ this.rest.mediators.set(mediator.id, mediator);
2722
+ }
2723
+ return this.cache;
2724
+ } else {
2725
+ if (!data.id) return;
2726
+ const mediator = new GuildMediator(data, this);
2727
+ this.cache.set(mediator.id, mediator);
2728
+ this.rest.mediators.set(mediator.id, mediator);
2729
+ return mediator;
2730
+ }
2731
+ }
2732
+ };
2733
+
2734
+ // src/managers/message/MessagesManager.ts
2735
+ var MessagesManager = class {
2736
+ constructor(structure, base_url) {
2737
+ __publicField(this, "cache");
2738
+ __publicField(this, "base_url");
2739
+ __publicField(this, "rest");
2740
+ __publicField(this, "guild");
2741
+ this.rest = structure.rest;
2742
+ this.guild = structure.guild;
2743
+ this.cache = new Collection("messages");
2744
+ this.base_url = base_url;
2745
+ }
2746
+ async fetch() {
2747
+ const response = await this.rest.request({
2748
+ method: "GET",
2749
+ url: this.base_url,
2750
+ payload: {}
2751
+ });
2752
+ this.cache.set(response._id, response);
2753
+ return response;
2754
+ }
2755
+ async create(data) {
2756
+ const messages = [...this.cache.toArray()];
2757
+ if (Array.isArray(data)) messages.push(...data);
2758
+ else messages.push(data);
2759
+ const response = await this.rest.request({
2760
+ method: "PATCH",
2761
+ url: this.base_url,
2762
+ payload: { set: messages }
2763
+ });
2764
+ return this.set(response.messages);
2765
+ }
2766
+ set(data) {
2767
+ if (!data) return this.cache;
2768
+ if (Array.isArray(data)) {
2769
+ for (let message of data) {
2770
+ if (message && !message._id) continue;
2771
+ this.cache.set(message._id, message);
2772
+ }
2773
+ } else {
2774
+ if (data && !data._id) return this.cache;
2775
+ this.cache.set(data._id, data);
2776
+ }
2777
+ return this.cache;
2778
+ }
2779
+ };
2780
+
2781
+ // src/managers/minesgame/MinesGameManager.ts
2782
+ var MinesGameManager = class {
2783
+ constructor(rest) {
2784
+ __publicField(this, "cache");
2785
+ __publicField(this, "rest");
2786
+ this.cache = new Collection("minesgames");
2787
+ this.rest = rest;
2788
+ }
2789
+ async create(data) {
2790
+ const route = "/minesgames";
2791
+ const response = await this.rest.request({
2792
+ method: "POST",
2793
+ url: route,
2794
+ payload: data
2795
+ });
2796
+ return this.set(response);
2797
+ }
2798
+ async delete(gameId) {
2799
+ const route = `/minesgames/${gameId}`;
2800
+ const response = await this.rest.request({
2801
+ method: "DELETE",
2802
+ url: route
2803
+ });
2804
+ this.cache.delete(gameId);
2805
+ return response;
2806
+ }
2807
+ async fetch(options) {
2808
+ if (options && options.cache) return this.cache;
2809
+ if (options && options.gameId) {
2810
+ const route2 = `/minesgames/${options.gameId}`;
2811
+ const response2 = await this.rest.request({
2812
+ method: "GET",
2813
+ url: route2
2814
+ });
2815
+ const game = new MinesGame(response2, this);
2816
+ this.set(game);
2817
+ return game;
2818
+ }
2819
+ const route = "/minesgames";
2820
+ const response = await this.rest.request({
2821
+ method: "GET",
2822
+ url: route
2823
+ });
2824
+ return this.set(response);
2825
+ }
2826
+ set(data) {
2827
+ if (!data) return this.cache;
2828
+ if (Array.isArray(data)) {
2829
+ for (let _game of data) {
2830
+ const game = new MinesGame(_game, this);
2831
+ this.cache.set(game._id, game);
2832
+ }
2833
+ return this.cache;
2834
+ } else {
2835
+ const game = new MinesGame(data, this);
2836
+ this.cache.set(game._id, game);
2837
+ return game;
2838
+ }
2839
+ }
2840
+ };
2841
+
2842
+ // src/managers/permission/GuildPermissionManager.ts
2843
+ var GuildPermissionManager = class extends BaseManager {
2844
+ constructor(guild) {
2845
+ super(guild);
2846
+ this.guild = guild;
2847
+ this.rest = guild.rest;
2848
+ this.base_url = Routes.guilds.resource(guild.id, "permissions");
2849
+ }
2850
+ async addRole(type, ...ids) {
2851
+ const perm = this.guild.permissions.find((p) => p.type === type) || { ids: [], type };
2852
+ const _ids = [.../* @__PURE__ */ new Set([...perm.ids, ...ids])];
2853
+ const perms = [...this.guild.permissions];
2854
+ let permsIndex = this.guild.permissions.findIndex((p) => p.type === type);
2855
+ if (permsIndex === -1) perms.push({ type, ids: _ids });
2856
+ else perms[permsIndex] = { type, ids: _ids };
2857
+ const payload = { set: perms };
2858
+ const response = await this.rest.request({
2859
+ method: "PATCH",
2860
+ url: this.base_url,
2861
+ payload
2862
+ });
2863
+ this.guild.permissions = response.permissions;
2864
+ this.rest.guilds.cache.set(this.guild.id, this.guild);
2865
+ return response;
2866
+ }
2867
+ async removeRole(type, ...ids) {
2868
+ const perm = this.guild.permissions.find((p) => p.type === type) || { ids: [], type };
2869
+ const _ids = [.../* @__PURE__ */ new Set([...perm.ids.filter((i) => !ids.includes(i))])];
2870
+ const perms = [...this.guild.permissions];
2871
+ let permsIndex = this.guild.permissions.findIndex((p) => p.type === type);
2872
+ if (permsIndex === -1) {
2873
+ perms.push({ type, ids: _ids });
2874
+ } else {
2875
+ perms[permsIndex] = { type, ids: _ids };
2876
+ }
2877
+ const payload = { set: perms };
2878
+ const response = await this.rest.request({
2879
+ method: "PATCH",
2880
+ url: this.base_url,
2881
+ payload
2882
+ });
2883
+ this.guild.permissions = response.permissions;
2884
+ this.rest.guilds.cache.set(this.guild.id, this.guild);
2885
+ return response;
2886
+ }
2887
+ };
2888
+
2889
+ // src/managers/ticket/TicketManager.ts
2890
+ var GuildTicketManager = class {
2891
+ constructor(guild) {
2892
+ __publicField(this, "cache");
2893
+ __publicField(this, "guild");
2894
+ __publicField(this, "rest");
2895
+ this.guild = guild;
2896
+ this.rest = guild.rest;
2897
+ this.cache = new Collection("tickets");
2898
+ }
2899
+ async createTicketCategory(data) {
2900
+ const categories = this.guild.tickets_configuration.categories;
2901
+ let hasCategory = categories.find((c) => c.type === data?.type);
2902
+ if (hasCategory) {
2903
+ hasCategory = data;
2904
+ const index = categories.findIndex((c) => c.type === data?.type);
2905
+ categories[index] = hasCategory;
2906
+ } else {
2907
+ categories.push(data);
2908
+ }
2909
+ const payload = { tickets_configuration: { categories } };
2910
+ const route = Routes.guilds.get(this.guild.id);
2911
+ const response = await this.rest.request({
2912
+ method: "PATCH",
2913
+ url: route,
2914
+ payload
2915
+ });
2916
+ this.guild._updateInternals(response);
2917
+ return response;
2918
+ }
2919
+ async deleteTicketCategory(data) {
2920
+ let categories = this.guild.tickets_configuration.categories;
2921
+ let categoryIndex = categories.findIndex((c) => c.type === data?.type);
2922
+ if (categoryIndex === -1) return this.guild;
2923
+ categories = categories.filter((c) => c.type !== data.type);
2924
+ const payload = { tickets_configuration: { categories } };
2925
+ const route = Routes.guilds.get(this.guild.id);
2926
+ const response = await this.rest.request({
2927
+ method: "PATCH",
2928
+ url: route,
2929
+ payload
2930
+ });
2931
+ this.guild._updateInternals(response);
2932
+ return response;
2933
+ }
2934
+ async fetch(options) {
2935
+ if (options && options.cache) return this.cache;
2936
+ if (options && options.ticketId) {
2937
+ const route2 = Routes.guilds.tickets.get(this.guild.id, options.ticketId);
2938
+ const response2 = await this.rest.request({
2939
+ method: "GET",
2940
+ url: route2
2941
+ });
2942
+ return this.set(response2);
2943
+ }
2944
+ const route = Routes.guilds.tickets.getAll(this.guild.id);
2945
+ const response = await this.rest.request({
2946
+ method: "GET",
2947
+ url: route
2948
+ });
2949
+ return this.set(response);
2950
+ }
2951
+ async create(data) {
2952
+ const route = Routes.guilds.tickets.create(this.guild.id);
2953
+ const response = await this.rest.request({
2954
+ method: "POST",
2955
+ url: route,
2956
+ payload: data
2957
+ });
2958
+ const ticket = this.set(response);
2959
+ this.rest.emit("ticketCreate", ticket);
2960
+ return ticket;
2961
+ }
2962
+ async delete(options) {
2963
+ if (options && options.ticketId) {
2964
+ const route2 = Routes.guilds.tickets.delete(this.guild.id, options.ticketId);
2965
+ await this.rest.request({
2966
+ method: "DELETE",
2967
+ url: route2
2968
+ });
2969
+ this.rest.emit("ticketDelete", this.cache.get(options.ticketId));
2970
+ this.cache.delete(options.ticketId);
2971
+ return true;
2972
+ }
2973
+ const route = Routes.guilds.tickets.deleteAll(this.guild.id);
2974
+ await this.rest.request({
2975
+ method: "DELETE",
2976
+ url: route
2977
+ });
2978
+ this.rest.emit("ticketsDelete", this.cache);
2979
+ this.cache.clear();
2980
+ return true;
2981
+ }
2982
+ set(data) {
2983
+ if (!data) return this.cache;
2984
+ if (Array.isArray(data)) {
2985
+ for (let _ticket of data) {
2986
+ if (!_ticket._id) return;
2987
+ const ticket = new GuildTicket(_ticket, this);
2988
+ this.cache.set(ticket._id, ticket);
2989
+ this.rest.tickets.set(ticket._id, ticket);
2990
+ }
2991
+ return this.cache;
2992
+ } else {
2993
+ if (!data._id) return;
2994
+ const ticket = new GuildTicket(data, this);
2995
+ this.cache.set(ticket._id, ticket);
2996
+ this.rest.tickets.set(ticket._id, ticket);
2997
+ return ticket;
2998
+ }
2999
+ }
3000
+ };
3001
+
3002
+ // src/managers/user/GuildUserManager.ts
3003
+ var GuildUserManager = class extends BaseManager {
3004
+ constructor(guild) {
3005
+ super(guild);
3006
+ this.guild = guild;
3007
+ this.rest = guild.rest;
3008
+ this.base_url = Routes.guilds.users.getAll(guild.id);
3009
+ this.cache = new Collection("users");
3010
+ }
3011
+ async fetch(options) {
3012
+ if (options && options.cache) return this.cache;
3013
+ if (options && options.userId) {
3014
+ const route2 = Routes.fields(this.base_url, options.userId);
3015
+ const response2 = await this.rest.request({
3016
+ method: "GET",
3017
+ url: route2
3018
+ });
3019
+ const user = new GuildUser(response2, this);
3020
+ this.set(user);
3021
+ return user;
3022
+ }
3023
+ const route = this.base_url;
3024
+ const response = await this.rest.request({
3025
+ method: "GET",
3026
+ url: route
3027
+ });
3028
+ this.cache.clear();
3029
+ for (let userData of response) {
3030
+ const user = new GuildUser(userData, this);
3031
+ this.set(user);
3032
+ }
3033
+ return this.cache;
3034
+ }
3035
+ async updateMany(...users) {
3036
+ const route = this.base_url;
3037
+ const response = await this.rest.request({
3038
+ method: "PATCH",
3039
+ url: route,
3040
+ payload: { users }
3041
+ });
3042
+ for (const userData of response) {
3043
+ const user = new GuildUser(userData, this);
3044
+ this.set(user);
3045
+ }
3046
+ return this.cache;
3047
+ }
3048
+ async deleteAll() {
3049
+ const route = this.base_url;
3050
+ await this.rest.request({
3051
+ method: "DELETE",
3052
+ url: route
3053
+ });
3054
+ this.cache.clear();
3055
+ }
3056
+ async resetAll() {
3057
+ const route = this.base_url;
3058
+ const response = await this.rest.request({
3059
+ method: "put",
3060
+ url: route
3061
+ });
3062
+ this.cache.clear();
3063
+ this.set(response);
3064
+ return this.cache;
3065
+ }
3066
+ set(data) {
3067
+ if (!data) return this.cache;
3068
+ if (Array.isArray(data)) {
3069
+ for (let _user of data) {
3070
+ if (!_user.id) return;
3071
+ const user = new GuildUser(_user, this);
3072
+ this.cache.set(user.id, user);
3073
+ this.rest.users.set(user.id, user);
3074
+ }
3075
+ return this.cache;
3076
+ } else {
3077
+ if (!data.id) return;
3078
+ const user = new GuildUser(data, this);
3079
+ this.cache.set(user.id, user);
3080
+ this.rest.users.set(user.id, user);
3081
+ return user;
3082
+ }
3083
+ }
3084
+ };
3085
+
3086
+ // src/managers/vipmember/VipMemberManager.ts
3087
+ var VipMemberManager = class extends BaseManager {
3088
+ /**
3089
+ * Manage vipmembers with the given client
3090
+ * @param vipmembers An array of vipmembers
3091
+ * @param rest The rest client
3092
+ */
3093
+ constructor(guild) {
3094
+ super(guild);
3095
+ this.guild = guild;
3096
+ this.rest = guild.rest;
3097
+ this.base_url = Routes.guilds.resource(guild.id, "vipmembers");
3098
+ this.cache = new Collection("vipmembers");
3099
+ }
3100
+ async create(data) {
3101
+ const route = Routes.vipmembers.create(this.guild.id);
3102
+ const payload = { ...data };
3103
+ const response = await this.rest.request({
3104
+ method: "post",
3105
+ url: route,
3106
+ payload
3107
+ });
3108
+ const member = new VipMember(response, this);
3109
+ this.cache.set(member?.id, member);
3110
+ return member;
3111
+ }
3112
+ /**
3113
+ * Fetch a member
3114
+ * @param id Id of the member to fetch
3115
+ * @returns VipMember
3116
+ */
3117
+ async fetch(options) {
3118
+ if (options && options.cache) return this.cache;
3119
+ if (options && options.memberId) {
3120
+ const route2 = Routes.vipmembers.get(this.guild.id, options.memberId);
3121
+ const payload = { guild_id: this.guild.id };
3122
+ const response2 = await this.rest.request({
3123
+ method: "get",
3124
+ url: route2,
3125
+ payload
3126
+ });
3127
+ if (!response2) return this.cache.get(options.memberId);
3128
+ const member = new VipMember(response2, this);
3129
+ this.cache.set(member?.id, member);
3130
+ return member;
3131
+ }
3132
+ const route = Routes.vipmembers.getAll(this.guild.id);
3133
+ const response = await this.rest.request({
3134
+ method: "get",
3135
+ url: route
3136
+ });
3137
+ if (Array.isArray(response) && response.length === 0) {
3138
+ this.cache.clear();
3139
+ return this.cache;
3140
+ }
3141
+ this.setAll(response);
3142
+ return this.cache;
3143
+ }
3144
+ async updateMember(id, data) {
3145
+ const route = Routes.vipmembers.update(this.guild.id, id);
3146
+ const payload = { ...data, guild_id: this.guild.id };
3147
+ const response = await this.rest.request({
3148
+ method: "patch",
3149
+ url: route,
3150
+ payload
3151
+ });
3152
+ const member = this.set(response);
3153
+ return member;
3154
+ }
3155
+ set(data) {
3156
+ if (!data?.id) return;
3157
+ const member = new VipMember(data, this);
3158
+ this.cache.set(member.id, member);
3159
+ return member;
3160
+ }
3161
+ setAll(data) {
3162
+ if (!data) return this.cache;
3163
+ for (let member of data) this.set(member);
3164
+ return this.cache;
3165
+ }
3166
+ async resetAll() {
3167
+ const route = Routes.vipmembers.getAll(this.guild.id);
3168
+ const response = await this.rest.request({
3169
+ method: "PUT",
3170
+ url: route
3171
+ });
3172
+ this.setAll(response);
3173
+ return this.cache;
3174
+ }
3175
+ async delete(id) {
3176
+ Assertion.assertString(id);
3177
+ Assertion.assertString(this.guild.id);
3178
+ const route = Routes.vipmembers.delete(id, this.guild.id);
3179
+ await this.rest.request({
3180
+ method: "DELETE",
3181
+ url: route
3182
+ });
3183
+ this.cache.delete(id);
3184
+ return this.cache;
3185
+ }
3186
+ async deleteAll() {
3187
+ Assertion.assertString(this.guild.id);
3188
+ const route = Routes.vipmembers.deleteAll(this.guild.id);
3189
+ const value = await this.rest.request({
3190
+ method: "DELETE",
3191
+ url: route
3192
+ });
3193
+ this.cache.clear();
3194
+ return value;
3195
+ }
3196
+ };
3197
+
3198
+ // src/structures/guild/Guild.ts
3199
+ var Guild5 = class {
3200
+ /**
3201
+ * The guild structure
3202
+ * @param data The guild's data
3203
+ * @param rest The rest client
3204
+ */
3205
+ constructor(data, rest) {
3206
+ /** The data of this guild */
3207
+ __publicField(this, "data");
3208
+ /** The rest client */
3209
+ __publicField(this, "rest");
3210
+ /** The guild's id */
3211
+ __publicField(this, "id");
3212
+ __publicField(this, "modes");
3213
+ /** Guild's client key */
3214
+ __publicField(this, "client_key");
3215
+ /** Guild Permissions */
3216
+ __publicField(this, "permissions");
3217
+ /** Guild Ticket */
3218
+ __publicField(this, "tickets");
3219
+ /** Guild Ticket Configuration */
3220
+ __publicField(this, "tickets_configuration");
3221
+ /** Guild Daily Categories */
3222
+ __publicField(this, "daily_categories");
3223
+ /** Guild Scores */
3224
+ __publicField(this, "scores");
3225
+ /** Guild Status */
3226
+ __publicField(this, "status");
3227
+ __publicField(this, "channels");
3228
+ __publicField(this, "roulette_settings");
3229
+ /** Guild Prefix */
3230
+ __publicField(this, "prefix");
3231
+ /** Guild Creation Date */
3232
+ __publicField(this, "createdAt");
3233
+ /** Guild Updated Date */
3234
+ __publicField(this, "updatedAt");
3235
+ /** Guild Matches */
3236
+ __publicField(this, "matches");
3237
+ /** Guild Prices Used */
3238
+ __publicField(this, "prices");
3239
+ __publicField(this, "permissionsManager");
3240
+ __publicField(this, "buffer");
3241
+ __publicField(this, "vipMembers");
3242
+ __publicField(this, "users");
3243
+ __publicField(this, "logEntries");
3244
+ __publicField(this, "shop");
3245
+ __publicField(this, "betusers");
3246
+ __publicField(this, "bets");
3247
+ __publicField(this, "mediators");
3248
+ __publicField(this, "automatic_messages");
3249
+ __publicField(this, "automaticMessagesManager");
3250
+ __publicField(this, "adverts");
3251
+ __publicField(this, "codes");
3252
+ __publicField(this, "coin_symbol");
3253
+ this.data = data;
3254
+ this.rest = rest;
3255
+ this.id = data?.id;
3256
+ this.client_key = data?.client_key;
3257
+ this.daily_categories = data?.daily_categories;
3258
+ this.permissions = data?.permissions;
3259
+ this.modes = data?.modes;
3260
+ this.prices = data?.prices;
3261
+ this.scores = data?.scores;
3262
+ this.codes = data?.codes;
3263
+ this.prefix = data?.prefix;
3264
+ this.status = data?.status;
3265
+ this.tickets_configuration = data?.tickets_configuration;
3266
+ this.automatic_messages = data?.automatic_messages;
3267
+ this.channels = data?.channels;
3268
+ this.shop = data?.shop;
3269
+ this.coin_symbol = data?.coin_symbol;
3270
+ this.roulette_settings = data?.roulette_settings;
3271
+ this.createdAt = data?.createdAt ? new Date(data?.createdAt) : /* @__PURE__ */ new Date();
3272
+ this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : /* @__PURE__ */ new Date();
3273
+ this.permissionsManager = new GuildPermissionManager(this);
3274
+ this.buffer = new BufferManager(this);
3275
+ this.users = new GuildUserManager(this);
3276
+ this.matches = new GuildMatchManager2(this);
3277
+ this.tickets = new GuildTicketManager(this);
3278
+ this.vipMembers = new VipMemberManager(this);
3279
+ this.logEntries = new LogManager(this);
3280
+ this.betusers = new GuildBetUserManager(this);
3281
+ this.bets = new GuildBetManager2(this);
3282
+ this.mediators = new GuildMediatorManager(this);
3283
+ this.automaticMessagesManager = new AutomaticMessageManager(this);
3284
+ this.adverts = [];
3285
+ for (let _adv of data?.adverts || []) {
3286
+ this.adverts.push({
3287
+ _id: _adv._id,
3288
+ admin_id: _adv.admin_id,
3289
+ points_to_remove: _adv.points_to_remove,
3290
+ role_id: _adv.role_id,
3291
+ createdAt: _adv.createdAt ? new Date(_adv.createdAt) : /* @__PURE__ */ new Date(),
3292
+ updatedAt: _adv.updatedAt ? new Date(_adv.updatedAt) : /* @__PURE__ */ new Date()
3293
+ });
3294
+ }
3295
+ this.codes = [];
3296
+ for (let _adv of data?.codes || []) {
3297
+ this.codes.push({
3298
+ _id: _adv._id,
3299
+ admin_id: _adv.admin_id,
3300
+ type: _adv.type,
3301
+ add: _adv.add,
3302
+ code: _adv.code,
3303
+ expire: _adv.expire ? new Date(_adv.expire) : /* @__PURE__ */ new Date(),
3304
+ createdAt: _adv.createdAt ? new Date(_adv.createdAt) : /* @__PURE__ */ new Date(),
3305
+ updatedAt: _adv.updatedAt ? new Date(_adv.updatedAt) : /* @__PURE__ */ new Date()
3306
+ });
3307
+ }
3308
+ }
3309
+ async getChannel(type) {
3310
+ const channel = this.channels.find((c) => c.type === type);
3311
+ if (channel) return channel;
3312
+ else {
3313
+ const channels = [...this.channels, { type, ids: [] }];
3314
+ const route = Routes.guilds.get(this.id);
3315
+ const response = await this.rest.request({
3316
+ method: "PATCH",
3317
+ url: route,
3318
+ payload: { channels }
3319
+ });
3320
+ this._updateInternals(response);
3321
+ return response.channels.find((t) => t.type === type);
3322
+ }
3323
+ }
3324
+ async getPermission(type) {
3325
+ const permission = this.permissions.find((c) => c.type === type);
3326
+ if (permission) return permission;
3327
+ else {
3328
+ const permissions = [...this.permissions, { type, ids: [] }];
3329
+ const route = Routes.guilds.get(this.id);
3330
+ const response = await this.rest.request({
3331
+ method: "PATCH",
3332
+ url: route,
3333
+ payload: { permissions }
3334
+ });
3335
+ this._updateInternals(response);
3336
+ return response.permissions.find((t) => t.type === type);
3337
+ }
3338
+ }
3339
+ async createAdvert(data) {
3340
+ this.adverts.push(data);
3341
+ const route = Routes.guilds.get(this.id);
3342
+ const payload = { adverts: this.adverts };
3343
+ const response = await this.rest.request({ method: "PATCH", url: route, payload });
3344
+ return this._updateInternals(response);
3345
+ }
3346
+ async removeAdvert(advertId) {
3347
+ const route = Routes.guilds.get(this.id);
3348
+ const payload = { adverts: this.adverts.filter((a) => a._id !== advertId) };
3349
+ const response = await this.rest.request({ method: "PATCH", url: route, payload });
3350
+ return this._updateInternals(response);
3351
+ }
3352
+ async createCode(data) {
3353
+ this.codes.push(data);
3354
+ const route = Routes.guilds.get(this.id);
3355
+ const payload = { codes: this.codes };
3356
+ const response = await this.rest.request({ method: "PATCH", url: route, payload });
3357
+ return this._updateInternals(response);
3358
+ }
3359
+ async removeCode(codeId) {
3360
+ const route = Routes.guilds.get(this.id);
3361
+ const payload = { codes: this.codes.filter((a) => a._id !== codeId) };
3362
+ const response = await this.rest.request({ method: "PATCH", url: route, payload });
3363
+ return this._updateInternals(response);
3364
+ }
3365
+ async addIdToChannel(type, id) {
3366
+ const channel = this.channels.find((c) => c.type === type);
3367
+ const idsToAdd = Array.isArray(id) ? id : [id];
3368
+ if (!channel) {
3369
+ this.channels.push({ type, ids: [...idsToAdd] });
3370
+ } else {
3371
+ const chIndex = this.channels.findIndex((ch) => ch.type === type);
3372
+ const mergedIds = [.../* @__PURE__ */ new Set([...channel.ids || [], ...idsToAdd])];
3373
+ this.channels[chIndex] = { ...channel, ids: mergedIds };
3374
+ }
3375
+ const route = Routes.guilds.get(this.id);
3376
+ const payload = { channels: this.channels };
3377
+ const response = await this.rest.request({
3378
+ method: "PATCH",
3379
+ url: route,
3380
+ payload
3381
+ });
3382
+ return this._updateInternals(response);
3383
+ }
3384
+ async setChannelIds(type, ...ids) {
3385
+ const channel = this.channels.find((c) => c.type === type);
3386
+ if (!ids || ids.length === 0) return;
3387
+ if (!channel) {
3388
+ this.channels.push({ type, ids });
3389
+ } else {
3390
+ const chIndex = this.channels.findIndex((ch) => ch.type === type);
3391
+ const mergedIds = [.../* @__PURE__ */ new Set([...ids])];
3392
+ this.channels[chIndex] = { ...channel, ids: mergedIds };
3393
+ }
3394
+ const route = Routes.guilds.get(this.id);
3395
+ const payload = { channels: this.channels };
3396
+ const response = await this.rest.request({
3397
+ method: "PATCH",
3398
+ url: route,
3399
+ payload
3400
+ });
3401
+ return this._updateInternals(response);
3402
+ }
3403
+ async removeIdInChannel(type, id) {
3404
+ const chIndex = this.channels.findIndex((c) => c.type === type);
3405
+ if (chIndex !== -1) {
3406
+ const existing = this.channels[chIndex];
3407
+ const idsToRemove = Array.isArray(id) ? id : [id];
3408
+ existing.ids = existing.ids.filter((i) => !idsToRemove.includes(i));
3409
+ this.channels[chIndex] = existing;
3410
+ } else {
3411
+ this.channels.push({
3412
+ type,
3413
+ ids: []
3414
+ });
3415
+ }
3416
+ const route = Routes.guilds.get(this.id);
3417
+ const payload = { channels: this.channels };
3418
+ const response = await this.rest.request({
3419
+ method: "PATCH",
3420
+ url: route,
3421
+ payload
3422
+ });
3423
+ return this._updateInternals(response);
3424
+ }
3425
+ async updateRouletteSettings(data) {
3426
+ const _data = {
3427
+ roulette_settings: {
3428
+ primary_color: !data.default ? data.primary_color || this.roulette_settings.primary_color || "#161616" : "#161616",
3429
+ secondary_color: !data.default ? data.secondary_color || this.roulette_settings.secondary_color || "#1A1A1A" : "#1A1A1A",
3430
+ tertiary_color: !data.default ? data.tertiary_color || this.roulette_settings.tertiary_color || "#2D2D2D" : "#2D2D2D",
3431
+ text_color: !data.default ? data.text_color || this.roulette_settings.text_color || "#ffffff" : "#ffffff",
3432
+ prizes: data.prizes || this.roulette_settings.prizes || []
3433
+ }
3434
+ };
3435
+ return this.update(_data);
3436
+ }
3437
+ getActive(key) {
3438
+ return this[key].cache.filter((o) => o.status === "created" || o.status === "on");
3439
+ }
3440
+ async addRoulettePrize(prize) {
3441
+ if (!prize.label) {
3442
+ throw new Error("Prize label is required");
3443
+ }
3444
+ const prizes = this.roulette_settings.prizes;
3445
+ const prizeIndex = prize._id ? prizes.findIndex((p) => p._id === prize._id) : prizes.findIndex((p) => p.label === prize.label);
3446
+ const defaultProbability = prizes.length > 0 ? 1 / prizes.length : 0.1;
3447
+ if (prizeIndex !== -1) {
3448
+ const existing = prizes[prizeIndex];
3449
+ prizes[prizeIndex] = {
3450
+ label: prize.label,
3451
+ custom_color: prize.custom_color ?? existing.custom_color,
3452
+ custom_probability: prize.custom_probability ?? existing.custom_probability ?? defaultProbability,
3453
+ _id: existing._id
3454
+ };
3455
+ } else {
3456
+ prizes.push({
3457
+ label: prize.label,
3458
+ custom_color: prize.custom_color ?? "",
3459
+ custom_probability: prize.custom_probability ?? defaultProbability
3460
+ });
3461
+ }
3462
+ await this.updateRouletteSettings({ prizes });
3463
+ return this.roulette_settings.prizes.find((p) => p.label === prize.label);
3464
+ }
3465
+ async removeRoulettePrize(id) {
3466
+ let prizes = this.roulette_settings.prizes;
3467
+ if (!prizes.find((p) => p._id === id)) return this;
3468
+ prizes = prizes.filter((p) => p._id !== id);
3469
+ return this.updateRouletteSettings({ prizes });
3470
+ }
3471
+ async _start() {
3472
+ await Promise.all([
3473
+ this.users.fetch(),
3474
+ this.matches.fetch(),
3475
+ this.tickets.fetch(),
3476
+ this.vipMembers.fetch(),
3477
+ this.logEntries.fetch(),
3478
+ this.betusers.fetch(),
3479
+ this.bets.fetch(),
3480
+ this.mediators.fetch()
3481
+ ]);
3482
+ return this;
3483
+ }
3484
+ _updateInternals(data) {
3485
+ for (let key in data) {
3486
+ if (key === "id" || key === "createdAt") continue;
3487
+ if (key in this) {
3488
+ this[key] = data[key];
3489
+ }
3490
+ if (key === "adverts") {
3491
+ this.adverts = [];
3492
+ for (let _adv of data.adverts) {
3493
+ this.adverts.push({
3494
+ _id: _adv._id,
3495
+ admin_id: _adv.admin_id,
3496
+ points_to_remove: _adv.points_to_remove,
3497
+ role_id: _adv.role_id,
3498
+ createdAt: _adv.createdAt ? new Date(_adv.createdAt) : /* @__PURE__ */ new Date(),
3499
+ updatedAt: _adv.updatedAt ? new Date(_adv.updatedAt) : /* @__PURE__ */ new Date()
3500
+ });
3501
+ }
3502
+ }
3503
+ if (key === "code") {
3504
+ this.codes = [];
3505
+ for (let _adv of data.codes) {
3506
+ this.codes.push({
3507
+ _id: _adv._id,
3508
+ admin_id: _adv.admin_id,
3509
+ type: _adv.type,
3510
+ add: _adv.add,
3511
+ code: _adv.code,
3512
+ expire: _adv.expire ? new Date(_adv.expire) : /* @__PURE__ */ new Date(),
3513
+ createdAt: _adv.createdAt ? new Date(_adv.createdAt) : /* @__PURE__ */ new Date(),
3514
+ updatedAt: _adv.updatedAt ? new Date(_adv.updatedAt) : /* @__PURE__ */ new Date()
3515
+ });
3516
+ }
3517
+ }
3518
+ }
3519
+ this.automaticMessagesManager.set(this.automatic_messages);
3520
+ this.updatedAt = /* @__PURE__ */ new Date();
3521
+ this.rest.guilds.cache.set(this.id, this);
3522
+ this.rest.emit("guildUpdate", this);
3523
+ return this;
3524
+ }
3525
+ async fetch() {
3526
+ const route = Routes.guilds.get(this.id);
3527
+ const response = await this.rest.request({
3528
+ method: "get",
3529
+ url: route
3530
+ });
3531
+ return this._updateInternals(response);
3532
+ }
3533
+ async update(data) {
3534
+ const route = Routes.guilds.get(this.id);
3535
+ const response = await this.rest.request({
3536
+ method: "patch",
3537
+ url: route,
3538
+ payload: data
3539
+ });
3540
+ for (const k in response) {
3541
+ if (k === "id" || k == "createdAt") continue;
3542
+ if (k in this) {
3543
+ this[k] = response[k];
3544
+ }
3545
+ }
3546
+ this.updatedAt = /* @__PURE__ */ new Date();
3547
+ this.rest.guilds.cache.set(this.id, this);
3548
+ this.rest.emit("guildUpdate", this);
3549
+ return this;
3550
+ }
3551
+ async setStatus(key, status) {
3552
+ Assertion.assertString(key);
3553
+ this.status[key] = status;
3554
+ const route = Routes.guilds.resource(this.id, "status");
3555
+ const payload = { set: this.status };
3556
+ const response = await this.rest.request({
3557
+ method: "PATCH",
3558
+ url: route,
3559
+ payload
3560
+ });
3561
+ this.status = response.status;
3562
+ this.rest.guilds.cache.set(this.id, this);
3563
+ this.rest.emit("guildUpdate", this);
3564
+ return this;
3565
+ }
3566
+ async togglePrice(price) {
3567
+ Assertion.assertNumber(price);
3568
+ const includesPrice = this.prices.includes(price);
3569
+ if (includesPrice) this.prices = this.prices.filter((p) => p !== price);
3570
+ else this.prices.push(price);
3571
+ await this.update({ prices: this.prices });
3572
+ return this;
3573
+ }
3574
+ async setPrefix(prefix) {
3575
+ Assertion.assertString(prefix);
3576
+ const route = Routes.fields(Routes.guilds.resource(this.id, "prefix"));
3577
+ const payload = { set: prefix };
3578
+ const response = await this.rest.request({
3579
+ method: "PATCH",
3580
+ url: route,
3581
+ payload
3582
+ });
3583
+ this._updateInternals(response);
3584
+ return this;
3585
+ }
3586
+ async toggleDailyCategory(category) {
3587
+ Assertion.assertString(category);
3588
+ let categories = this.daily_categories;
3589
+ const returnCategories = () => {
3590
+ const isCategoryOn = categories.includes(category);
3591
+ if (isCategoryOn) categories = categories.filter((m) => m !== category);
3592
+ else categories = [...categories, category];
3593
+ return categories;
3594
+ };
3595
+ const _categories = returnCategories();
3596
+ const payload = { daily_categories: _categories };
3597
+ const route = Routes.guilds.get(this.id);
3598
+ const response = await this.rest.request({
3599
+ method: "patch",
3600
+ url: route,
3601
+ payload
3602
+ });
3603
+ this._updateInternals(response);
3604
+ return this;
3605
+ }
3606
+ async setScores(name, amount) {
3607
+ const route = Routes.guilds.get(this.id);
3608
+ let scores = this.scores;
3609
+ scores[name] = amount;
3610
+ const payload = { scores };
3611
+ const response = await this.rest.request({
3612
+ method: "patch",
3613
+ url: route,
3614
+ payload
3615
+ });
3616
+ this._updateInternals(response);
3617
+ return this;
3618
+ }
3619
+ async toggleMode(mode) {
3620
+ const route = Routes.guilds.get(this.id);
3621
+ let modes = this.modes;
3622
+ const returnModes = () => {
3623
+ const isModeOn = modes.on.includes(mode);
3624
+ if (isModeOn) {
3625
+ modes.on = modes.on.filter((m) => m !== mode);
3626
+ modes.off.push(mode);
3627
+ return modes;
3628
+ } else {
3629
+ modes.off = modes.off.filter((m) => m !== mode);
3630
+ modes.on.push(mode);
3631
+ return modes;
3632
+ }
3633
+ };
3634
+ const md = returnModes();
3635
+ const payload = { modes: md };
3636
+ const response = await this.rest.request({
3637
+ method: "patch",
3638
+ url: route,
3639
+ payload
3640
+ });
3641
+ this._updateInternals(response);
3642
+ return this;
3643
+ }
3644
+ };
3645
+
3646
+ // src/managers/guild/GuildManager.ts
3647
+ var GuildManager = class {
3648
+ /**
3649
+ * Manage guilds with the given client
3650
+ * @param guilds An array of guilds
3651
+ * @param rest The rest client
3652
+ */
3653
+ constructor(rest) {
3654
+ /** A cache of guilds */
3655
+ __publicField(this, "cache");
3656
+ /** The rest client */
3657
+ __publicField(this, "rest");
3658
+ this.cache = new Collection("guilds");
3659
+ this.rest = rest;
3660
+ }
3661
+ /**
3662
+ * Fetch a guild
3663
+ * @param id Id of the guild to fetch
3664
+ * @returns APIGuild
3665
+ */
3666
+ async fetch(options) {
3667
+ if (options && options.cache) return this.cache;
3668
+ if (options && options.guildId) {
3669
+ const route2 = Routes.guilds.get(options.guildId);
3670
+ const response2 = await this.rest.request({
3671
+ method: "get",
3672
+ url: route2
3673
+ });
3674
+ const guild = new Guild5(response2, this.rest);
3675
+ await guild._start().then((g) => {
3676
+ this.cache.set(g.id, g);
3677
+ });
3678
+ this.cache.set(guild.id, guild);
3679
+ return guild;
3680
+ }
3681
+ const route = Routes.guilds.getAll();
3682
+ const response = await this.rest.request({
3683
+ method: "get",
3684
+ url: route
3685
+ });
3686
+ for (let _guild of response) {
3687
+ if (!_guild.id) continue;
3688
+ const guild = new Guild5(_guild, this.rest);
3689
+ await guild._start().then((g) => {
3690
+ this.cache.set(g.id, g);
3691
+ });
3692
+ }
3693
+ return this.cache;
3694
+ }
3695
+ async delete(options) {
3696
+ if (options && options.guildId) {
3697
+ Assertion.assertString(options.guildId);
3698
+ const route2 = Routes.guilds.delete(options.guildId);
3699
+ const guild = this.cache.get(options.guildId);
3700
+ this.rest.emit("guildDelete", guild);
3701
+ await this.rest.request({
3702
+ method: "DELETE",
3703
+ url: route2
3704
+ });
3705
+ this.cache.delete(options.guildId);
3706
+ return this.cache;
3707
+ }
3708
+ const route = Routes.guilds.deleteAll();
3709
+ this.rest.emit("guildsDelete", this.cache);
3710
+ const value = await this.rest.request({
3711
+ method: "DELETE",
3712
+ url: route
3713
+ });
3714
+ this.cache.clear();
3715
+ return value;
3716
+ }
3717
+ set(data) {
3718
+ if (!data) return this.cache;
3719
+ if (Array.isArray(data)) {
3720
+ for (let _guild of data) {
3721
+ const guild = new Guild5(_guild, this.rest);
3722
+ this.cache.set(guild.id, guild);
3723
+ }
3724
+ return this.cache;
3725
+ } else {
3726
+ const guild = new Guild5(data, this.rest);
3727
+ this.cache.set(guild.id, guild);
3728
+ return guild;
3729
+ }
3730
+ }
3731
+ };
3732
+
3733
+ // src/rest/REST.ts
3734
+ import_dotenv.default.config();
3735
+ var Reset = "\x1B[0m";
3736
+ var FgGreen = "\x1B[32m";
3737
+ var FgRed = "\x1B[31m";
3738
+ var FgBlue = "\x1B[34m";
3739
+ var FgCyan = "\x1B[36m";
3740
+ var REST8 = class extends import_events.default {
3741
+ /**
3742
+ *
3743
+ * @param key The unique key for he client
3744
+ */
3745
+ constructor(options) {
3746
+ super({ captureRejections: true });
3747
+ /**
3748
+ * The unique key for client
3749
+ */
3750
+ __publicField(this, "clientKey");
3751
+ __publicField(this, "authKey");
3752
+ __publicField(this, "guildId");
3753
+ /** The guild manager */
3754
+ __publicField(this, "guilds");
3755
+ __publicField(this, "minesGames");
3756
+ __publicField(this, "users");
3757
+ __publicField(this, "betusers");
3758
+ __publicField(this, "matches");
3759
+ __publicField(this, "bets");
3760
+ __publicField(this, "tickets");
3761
+ __publicField(this, "vipmembers");
3762
+ __publicField(this, "mediators");
3763
+ this.clientKey = options.clientKey ?? "";
3764
+ this.authKey = options.authKey ?? "";
3765
+ this.guildId = options.guildId ?? "";
3766
+ this.guilds = new GuildManager(this);
3767
+ this.minesGames = new MinesGameManager(this);
3768
+ this.users = new Collection("rest:users");
3769
+ this.matches = new Collection("rest:matches");
3770
+ this.bets = new Collection("rest:bets");
3771
+ this.betusers = new Collection("rest:betusers");
3772
+ this.tickets = new Collection("rest:tickets");
3773
+ this.vipmembers = new Collection("rest:vipmembers");
3774
+ this.mediators = new Collection("rest:mediators");
3775
+ this.setMaxListeners(999);
3776
+ }
3777
+ /** Initialize the caching sistem */
3778
+ async init() {
3779
+ if (!this.clientKey || !this.authKey || !this.guildId)
3780
+ throw new Error("Client key, auth key, and guildId is necessary");
3781
+ await Promise.all([this.guilds.fetch({ guildId: this.guildId }), this.minesGames.fetch()]);
3782
+ return this;
3783
+ }
3784
+ formatUrl(url) {
3785
+ return (url.endsWith("/") ? url.slice(0, url.length - 1) : url) ?? "/status";
3786
+ }
3787
+ /**
3788
+ * Request Data from a certain url
3789
+ * @param options
3790
+ * @returns
3791
+ */
3792
+ async request(options) {
3793
+ let { method, url, payload } = options;
3794
+ Assertion.assertString(method);
3795
+ Assertion.assertString(this.clientKey);
3796
+ Assertion.assertString(url);
3797
+ url = this.formatUrl(Routes.base + url);
3798
+ const headers = new import_undici.Headers();
3799
+ headers.append("authorization", this.authKey);
3800
+ headers.append("client_key", this.clientKey);
3801
+ headers.append("Content-Type", "application/json");
3802
+ const before = Date.now();
3803
+ this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
3804
+ const body = { ...payload };
3805
+ const res = await (0, import_undici.request)(url, {
3806
+ method: method.toUpperCase(),
3807
+ headers,
3808
+ body: JSON.stringify(body)
3809
+ });
3810
+ const responseBody = await res.body.json();
3811
+ const { data, message } = responseBody;
3812
+ const now = (/* @__PURE__ */ new Date()).getTime();
3813
+ if (!data || res.body.errored) {
3814
+ if (message) this.emit("debug", `${FgRed}${message}${Reset}`);
3815
+ this.emit("debug", `[No data]${FgGreen} ${(now - before) / 1e3}${Reset}`);
3816
+ return "No data available.";
3817
+ }
3818
+ if (message) this.emit("debug", `${FgRed}${message}${Reset}`);
3819
+ this.emit("debug", `[Request]${FgGreen} ${(now - before) / 1e3}s done.${Reset}`);
3820
+ return data;
3821
+ }
3822
+ async getStatus() {
3823
+ return await this.request({ method: "GET", url: "/status" });
3824
+ }
3825
+ emit(event, ...args) {
3826
+ return super.emit(event, ...args);
3827
+ }
3828
+ on(event, listener) {
3829
+ return super.on(event, listener);
3830
+ }
3831
+ once(event, listener) {
3832
+ return super.once(event, listener);
3833
+ }
3834
+ };
3835
+ // Annotate the CommonJS export names for ESM import in node:
3836
+ 0 && (module.exports = {
3837
+ REST
3838
+ });