@duque.edits/sdk 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/{src/index.ts → dist/index.d.ts} +27 -30
  2. package/dist/index.js +43 -0
  3. package/dist/managers/bet/GuildBetManager.d.ts +32 -0
  4. package/dist/managers/bet/GuildBetManager.js +107 -0
  5. package/dist/managers/betuser/GuildBetUserManager.d.ts +30 -0
  6. package/dist/managers/betuser/GuildBetUserManager.js +94 -0
  7. package/dist/managers/channel/ChannelManager.d.ts +39 -0
  8. package/dist/managers/channel/ChannelManager.js +147 -0
  9. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +34 -0
  10. package/dist/managers/groupedchannel/GroupedChannelManager.js +92 -0
  11. package/dist/managers/guild/GuildManager.d.ts +24 -0
  12. package/dist/managers/guild/GuildManager.js +75 -0
  13. package/dist/managers/match/GuildMatchManager.d.ts +32 -0
  14. package/dist/managers/match/GuildMatchManager.js +103 -0
  15. package/dist/managers/mediator/GuildMediatorManager.d.ts +32 -0
  16. package/dist/managers/mediator/GuildMediatorManager.js +97 -0
  17. package/dist/managers/messages/MessagesManager.d.ts +32 -0
  18. package/dist/managers/messages/MessagesManager.js +82 -0
  19. package/dist/managers/permission/GuildPermissionManager.d.ts +26 -0
  20. package/dist/managers/permission/GuildPermissionManager.js +70 -0
  21. package/dist/managers/product/GuildProductManager.d.ts +32 -0
  22. package/dist/managers/product/GuildProductManager.js +102 -0
  23. package/dist/managers/ticket/GuildTicketManager.d.ts +32 -0
  24. package/dist/managers/ticket/GuildTicketManager.js +99 -0
  25. package/dist/managers/user/GuildUserManager.d.ts +32 -0
  26. package/dist/managers/user/GuildUserManager.js +106 -0
  27. package/dist/rest/APIEndpoints.d.ts +11 -0
  28. package/dist/rest/APIEndpoints.js +12 -0
  29. package/dist/rest/REST.d.ts +51 -0
  30. package/dist/rest/REST.js +96 -0
  31. package/dist/rest/Routes.d.ts +84 -0
  32. package/dist/rest/Routes.js +89 -0
  33. package/dist/structures/Collection.d.ts +17 -0
  34. package/dist/structures/Collection.js +87 -0
  35. package/dist/structures/bet/GuildBet.d.ts +86 -0
  36. package/dist/structures/bet/GuildBet.js +276 -0
  37. package/dist/structures/betuser/GuildBetUser.d.ts +82 -0
  38. package/dist/structures/betuser/GuildBetUser.js +194 -0
  39. package/dist/structures/channel/Channel.d.ts +31 -0
  40. package/dist/structures/channel/Channel.js +57 -0
  41. package/dist/structures/groupedchannel/GroupedChannel.d.ts +34 -0
  42. package/dist/structures/groupedchannel/GroupedChannel.js +121 -0
  43. package/dist/structures/guild/Guild.d.ts +89 -0
  44. package/dist/structures/guild/Guild.js +223 -0
  45. package/dist/structures/match/GuildMatch.d.ts +84 -0
  46. package/dist/structures/match/GuildMatch.js +327 -0
  47. package/dist/structures/mediator/GuildMediator.d.ts +41 -0
  48. package/dist/structures/mediator/GuildMediator.js +131 -0
  49. package/dist/structures/product/GuildProduct.d.ts +52 -0
  50. package/dist/structures/product/GuildProduct.js +175 -0
  51. package/dist/structures/shop/GuildShop.d.ts +34 -0
  52. package/dist/structures/shop/GuildShop.js +80 -0
  53. package/dist/structures/ticket/GuildTicket.d.ts +51 -0
  54. package/dist/structures/ticket/GuildTicket.js +170 -0
  55. package/dist/structures/user/GuildUser.d.ts +82 -0
  56. package/dist/structures/user/GuildUser.js +209 -0
  57. package/dist/types/api/APIBaseChannel.d.ts +10 -0
  58. package/dist/types/api/APIBaseChannel.js +2 -0
  59. package/dist/types/api/APIBetChannel.d.ts +10 -0
  60. package/dist/types/api/APIBetChannel.js +2 -0
  61. package/dist/types/api/APIBetMessage.d.ts +10 -0
  62. package/dist/types/api/APIBetMessage.js +2 -0
  63. package/dist/types/api/APIGuild.d.ts +92 -0
  64. package/dist/types/api/APIGuild.js +2 -0
  65. package/dist/types/api/APIGuildBet.d.ts +48 -0
  66. package/dist/types/api/APIGuildBet.js +2 -0
  67. package/dist/types/api/APIGuildBetUser.d.ts +32 -0
  68. package/dist/types/api/APIGuildBetUser.js +2 -0
  69. package/dist/types/api/APIGuildChannel.d.ts +10 -0
  70. package/dist/types/api/APIGuildChannel.js +2 -0
  71. package/dist/types/api/APIGuildEmoji.d.ts +12 -0
  72. package/dist/types/api/APIGuildEmoji.js +2 -0
  73. package/dist/types/api/APIGuildGroupedChannel.d.ts +10 -0
  74. package/dist/types/api/APIGuildGroupedChannel.js +2 -0
  75. package/dist/types/api/APIGuildMatch.d.ts +46 -0
  76. package/dist/types/api/APIGuildMatch.js +2 -0
  77. package/dist/types/api/APIGuildMediator.d.ts +13 -0
  78. package/dist/types/api/APIGuildMediator.js +3 -0
  79. package/dist/types/api/APIGuildMessage.d.ts +10 -0
  80. package/dist/types/api/APIGuildMessage.js +2 -0
  81. package/dist/types/api/APIGuildPermissions.d.ts +6 -0
  82. package/dist/types/api/APIGuildPermissions.js +2 -0
  83. package/dist/types/api/APIGuildRole.d.ts +10 -0
  84. package/dist/types/api/APIGuildRole.js +2 -0
  85. package/dist/types/api/APIGuildShop.d.ts +11 -0
  86. package/dist/types/api/APIGuildShop.js +2 -0
  87. package/dist/types/api/APIGuildTicket.d.ts +25 -0
  88. package/dist/types/api/APIGuildTicket.js +3 -0
  89. package/dist/types/api/APIGuildUser.d.ts +31 -0
  90. package/dist/types/api/APIGuildUser.js +2 -0
  91. package/dist/types/api/APIMessage.d.ts +12 -0
  92. package/dist/types/api/APIMessage.js +2 -0
  93. package/dist/types/api/APIPlayer.d.ts +10 -0
  94. package/dist/types/api/APIPlayer.js +2 -0
  95. package/dist/types/api/APIProduct.d.ts +19 -0
  96. package/dist/types/api/APIProduct.js +3 -0
  97. package/dist/types/api/index.d.ts +130 -0
  98. package/dist/types/api/index.js +35 -0
  99. package/{src/types/index.ts → dist/types/index.d.ts} +21 -24
  100. package/dist/types/index.js +37 -0
  101. package/dist/utils/Assertion.d.ts +32 -0
  102. package/dist/utils/Assertion.js +60 -0
  103. package/package.json +5 -1
  104. package/.gitattributes +0 -2
  105. package/src/managers/bet/GuildBetManager.ts +0 -117
  106. package/src/managers/betuser/GuildBetUserManager.ts +0 -103
  107. package/src/managers/channel/ChannelManager.ts +0 -168
  108. package/src/managers/groupedchannel/GroupedChannelManager.ts +0 -117
  109. package/src/managers/guild/GuildManager.ts +0 -84
  110. package/src/managers/match/GuildMatchManager.ts +0 -115
  111. package/src/managers/mediator/GuildMediatorManager.ts +0 -111
  112. package/src/managers/messages/MessagesManager.ts +0 -95
  113. package/src/managers/permission/GuildPermissionManager.ts +0 -88
  114. package/src/managers/product/GuildProductManager.ts +0 -115
  115. package/src/managers/ticket/GuildTicketManager.ts +0 -112
  116. package/src/managers/user/GuildUserManager.ts +0 -116
  117. package/src/rest/APIEndpoints.ts +0 -11
  118. package/src/rest/REST.ts +0 -126
  119. package/src/rest/Routes.ts +0 -143
  120. package/src/structures/Collection.ts +0 -85
  121. package/src/structures/bet/GuildBet.ts +0 -332
  122. package/src/structures/betuser/GuildBetUser.ts +0 -247
  123. package/src/structures/channel/Channel.ts +0 -78
  124. package/src/structures/groupedchannel/GroupedChannel.ts +0 -165
  125. package/src/structures/guild/Guild.ts +0 -302
  126. package/src/structures/match/GuildMatch.ts +0 -385
  127. package/src/structures/mediator/GuildMediator.ts +0 -175
  128. package/src/structures/product/GuildProduct.ts +0 -217
  129. package/src/structures/shop/GuildShop.ts +0 -98
  130. package/src/structures/ticket/GuildTicket.ts +0 -227
  131. package/src/structures/user/GuildUser.ts +0 -248
  132. package/src/types/api/APIBaseChannel.ts +0 -13
  133. package/src/types/api/APIBetChannel.ts +0 -13
  134. package/src/types/api/APIBetMessage.ts +0 -13
  135. package/src/types/api/APIGuild.ts +0 -123
  136. package/src/types/api/APIGuildBet.ts +0 -69
  137. package/src/types/api/APIGuildBetUser.ts +0 -46
  138. package/src/types/api/APIGuildChannel.ts +0 -13
  139. package/src/types/api/APIGuildEmoji.ts +0 -16
  140. package/src/types/api/APIGuildGroupedChannel.ts +0 -13
  141. package/src/types/api/APIGuildMatch.ts +0 -67
  142. package/src/types/api/APIGuildMediator.ts +0 -18
  143. package/src/types/api/APIGuildMessage.ts +0 -13
  144. package/src/types/api/APIGuildPermissions.ts +0 -7
  145. package/src/types/api/APIGuildRole.ts +0 -13
  146. package/src/types/api/APIGuildShop.ts +0 -15
  147. package/src/types/api/APIGuildTicket.ts +0 -36
  148. package/src/types/api/APIGuildUser.ts +0 -45
  149. package/src/types/api/APIMessage.ts +0 -16
  150. package/src/types/api/APIPlayer.ts +0 -13
  151. package/src/types/api/APIProduct.ts +0 -27
  152. package/src/types/api/index.ts +0 -180
  153. package/src/utils/Assertion.ts +0 -56
  154. package/src/v1/managers/channel/ChannelManager.ts +0 -167
  155. package/src/v1/managers/match/GuildMatchManager.ts +0 -114
  156. package/tests/index.ts +0 -86
  157. package/tsconfig.json +0 -15
@@ -0,0 +1,32 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { Collection } from "../../structures/Collection";
3
+ import { Guild } from "../../structures/guild/Guild";
4
+ import { GuildProduct } from "../../structures/product/GuildProduct";
5
+ import { Optional } from "../../types/api";
6
+ import { APIProduct } from "../../types/api/APIProduct";
7
+ export declare class GuildProductManager {
8
+ /** A cache of users */
9
+ cache: Collection<string, GuildProduct>;
10
+ /** The rest client */
11
+ rest: REST;
12
+ /** GuildProduct product guild */
13
+ guild: Guild;
14
+ /**
15
+ * Manage users with the given client
16
+ * @param users An array of users
17
+ * @param rest The rest client
18
+ */
19
+ constructor(guild: Guild, rest: REST);
20
+ create(payload: Optional<APIProduct>): Promise<GuildProduct>;
21
+ /**
22
+ * Fetch a product
23
+ * @param id Id of the product to fetch
24
+ * @returns APIBetUser
25
+ */
26
+ fetch(id: string): Promise<GuildProduct>;
27
+ fetchAll(): Promise<Collection<string, GuildProduct>>;
28
+ set(data: APIProduct): GuildProduct;
29
+ setAll(data: APIProduct[]): Collection<string, GuildProduct>;
30
+ delete(id: string, type: string): Promise<Collection<string, GuildProduct>>;
31
+ deleteAll(): Promise<boolean>;
32
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildProductManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const Collection_1 = require("../../structures/Collection");
6
+ const GuildProduct_1 = require("../../structures/product/GuildProduct");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GuildProductManager {
9
+ /** A cache of users */
10
+ cache;
11
+ /** The rest client */
12
+ rest;
13
+ /** GuildProduct product guild */
14
+ guild;
15
+ /**
16
+ * Manage users with the given client
17
+ * @param users An array of users
18
+ * @param rest The rest client
19
+ */
20
+ constructor(guild, rest) {
21
+ this.guild = guild;
22
+ this.rest = rest;
23
+ this.cache = new Collection_1.Collection("products");
24
+ }
25
+ async create(payload) {
26
+ Assertion_1.Assertion.assertObject(payload);
27
+ const route = Routes_1.Routes.guilds.shop.products.create(this.guild.id);
28
+ const response = await this.rest.request({
29
+ method: "POST",
30
+ url: route,
31
+ });
32
+ const product = this.set(response);
33
+ return product;
34
+ }
35
+ /**
36
+ * Fetch a product
37
+ * @param id Id of the product to fetch
38
+ * @returns APIBetUser
39
+ */
40
+ async fetch(id) {
41
+ const route = Routes_1.Routes.guilds.shop.products.get(this.guild.id, id);
42
+ const response = await this.rest.request({
43
+ method: "get",
44
+ url: route,
45
+ });
46
+ const product = new GuildProduct_1.GuildProduct(response, this, this.rest);
47
+ this.cache.set(product.id, product);
48
+ return product;
49
+ }
50
+ async fetchAll() {
51
+ const route = Routes_1.Routes.guilds.shop.products.getAll(this.guild.id);
52
+ const response = await this.rest.request({
53
+ method: "get",
54
+ url: route,
55
+ });
56
+ for (let betData of response) {
57
+ const product = new GuildProduct_1.GuildProduct(betData, this, this.rest);
58
+ this.cache.set(product.id, product);
59
+ }
60
+ return this.cache;
61
+ }
62
+ set(data) {
63
+ if (!data.id)
64
+ return;
65
+ const product = new GuildProduct_1.GuildProduct(data, this, this.rest);
66
+ this.cache.set(data.id, product);
67
+ return product;
68
+ }
69
+ setAll(data) {
70
+ if (!data)
71
+ return this.cache;
72
+ for (let product of data)
73
+ this.set(product);
74
+ return this.cache;
75
+ }
76
+ async delete(id, type) {
77
+ Assertion_1.Assertion.assertString(id);
78
+ Assertion_1.Assertion.assertString(type);
79
+ const route = Routes_1.Routes.guilds.shop.products.delete(id, this.guild.id);
80
+ const payload = { type };
81
+ const product = this.cache.get(id);
82
+ this.rest.emit("productsDelete", product);
83
+ await this.rest.request({
84
+ method: "DELETE",
85
+ url: route,
86
+ payload,
87
+ });
88
+ this.cache.delete(id);
89
+ return this.cache;
90
+ }
91
+ async deleteAll() {
92
+ const route = Routes_1.Routes.guilds.shop.products.deleteAll(this.guild.id);
93
+ this.rest.emit("productsDelete", this.cache);
94
+ const value = await this.rest.request({
95
+ method: "DELETE",
96
+ url: route,
97
+ });
98
+ this.cache.clear();
99
+ return value;
100
+ }
101
+ }
102
+ exports.GuildProductManager = GuildProductManager;
@@ -0,0 +1,32 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { GuildTicket } from "../../structures/ticket/GuildTicket";
3
+ import { Collection } from "../../structures/Collection";
4
+ import { Guild } from "../../structures/guild/Guild";
5
+ import { Optional } from "../../types/api";
6
+ import { APIGuildTicket } from "../../types/api/APIGuildTicket";
7
+ export declare class GuildTicketManager {
8
+ /** A cache of users */
9
+ cache: Collection<string, GuildTicket>;
10
+ /** The rest client */
11
+ rest: REST;
12
+ /** GuildTicket ticket guild */
13
+ guild: Guild;
14
+ /**
15
+ * Manage users with the given client
16
+ * @param users An array of users
17
+ * @param rest The rest client
18
+ */
19
+ constructor(guild: Guild, rest: REST);
20
+ create(payload: Optional<APIGuildTicket>): Promise<GuildTicket>;
21
+ /**
22
+ * Fetch a ticket
23
+ * @param id Id of the ticket to fetch
24
+ * @returns APIticketUser
25
+ */
26
+ fetch(id: string): Promise<GuildTicket>;
27
+ fetchAll(): Promise<Collection<string, GuildTicket>>;
28
+ set(data: APIGuildTicket): GuildTicket;
29
+ setAll(data: APIGuildTicket[]): Collection<string, GuildTicket>;
30
+ delete(id: string): Promise<Collection<string, GuildTicket>>;
31
+ deleteAll(): Promise<boolean>;
32
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildTicketManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const GuildTicket_1 = require("../../structures/ticket/GuildTicket");
6
+ const Collection_1 = require("../../structures/Collection");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GuildTicketManager {
9
+ /** A cache of users */
10
+ cache;
11
+ /** The rest client */
12
+ rest;
13
+ /** GuildTicket ticket guild */
14
+ guild;
15
+ /**
16
+ * Manage users with the given client
17
+ * @param users An array of users
18
+ * @param rest The rest client
19
+ */
20
+ constructor(guild, rest) {
21
+ this.guild = guild;
22
+ this.rest = rest;
23
+ this.cache = new Collection_1.Collection("tickets");
24
+ }
25
+ async create(payload) {
26
+ Assertion_1.Assertion.assertObject(payload);
27
+ const route = Routes_1.Routes.guilds.tickets.create(this.guild.id);
28
+ const response = await this.rest.request({
29
+ method: "POST",
30
+ url: route,
31
+ });
32
+ const ticket = this.set(response);
33
+ return ticket;
34
+ }
35
+ /**
36
+ * Fetch a ticket
37
+ * @param id Id of the ticket to fetch
38
+ * @returns APIticketUser
39
+ */
40
+ async fetch(id) {
41
+ const route = Routes_1.Routes.guilds.tickets.get(this.guild.id, id);
42
+ const response = await this.rest.request({
43
+ method: "get",
44
+ url: route,
45
+ });
46
+ const ticket = new GuildTicket_1.GuildTicket(response, this.guild, this, this.rest);
47
+ this.cache.set(ticket.id, ticket);
48
+ return ticket;
49
+ }
50
+ async fetchAll() {
51
+ const route = Routes_1.Routes.guilds.tickets.getAll(this.guild.id);
52
+ const response = await this.rest.request({
53
+ method: "get",
54
+ url: route,
55
+ });
56
+ for (let ticketData of response) {
57
+ const ticket = new GuildTicket_1.GuildTicket(ticketData, this.guild, this, this.rest);
58
+ this.cache.set(ticket.id, ticket);
59
+ }
60
+ return this.cache;
61
+ }
62
+ set(data) {
63
+ if (!data.id)
64
+ return;
65
+ const ticket = new GuildTicket_1.GuildTicket(data, this.guild, this, this.rest);
66
+ this.cache.set(data.id.toString(), ticket);
67
+ return ticket;
68
+ }
69
+ setAll(data) {
70
+ if (!data)
71
+ return this.cache;
72
+ for (let ticket of data)
73
+ this.set(ticket);
74
+ return this.cache;
75
+ }
76
+ async delete(id) {
77
+ Assertion_1.Assertion.assertString(id);
78
+ const route = Routes_1.Routes.guilds.tickets.delete(id, this.guild.id);
79
+ const ticket = this.cache.get(id);
80
+ this.rest.emit("ticketDelete", ticket);
81
+ await this.rest.request({
82
+ method: "DELETE",
83
+ url: route,
84
+ });
85
+ this.cache.delete(id);
86
+ return this.cache;
87
+ }
88
+ async deleteAll() {
89
+ const route = Routes_1.Routes.guilds.tickets.deleteAll(this.guild.id);
90
+ this.rest.emit("ticketsDelete", this.cache);
91
+ const value = await this.rest.request({
92
+ method: "DELETE",
93
+ url: route,
94
+ });
95
+ this.cache.clear();
96
+ return value;
97
+ }
98
+ }
99
+ exports.GuildTicketManager = GuildTicketManager;
@@ -0,0 +1,32 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { GuildUser } from "../../structures/user/GuildUser";
3
+ import { Collection } from "../../structures/Collection";
4
+ import { Guild } from "../../structures/guild/Guild";
5
+ import { APIGuildUser } from "../../types/api/APIGuildUser";
6
+ import { Optional } from "../../types";
7
+ export declare class GuildUserManager {
8
+ /** A cache of users */
9
+ cache: Collection<string, GuildUser>;
10
+ /** The rest client */
11
+ rest: REST;
12
+ /** Bet user guild */
13
+ guild: Guild;
14
+ /**
15
+ * Manage users with the given client
16
+ * @param users An array of users
17
+ * @param rest The rest client
18
+ */
19
+ constructor(guild: Guild, rest: REST);
20
+ /**
21
+ * Fetch a user
22
+ * @param id Id of the user to fetch
23
+ * @returns GuildUser
24
+ */
25
+ fetch(id: string, name: string): Promise<GuildUser>;
26
+ fetchAll(): Promise<Collection<string, GuildUser>>;
27
+ updateUser(id: string, name: string, data: Optional<APIGuildUser>): Promise<GuildUser>;
28
+ set(data: APIGuildUser): GuildUser;
29
+ setAll(data: APIGuildUser[]): Collection<string, GuildUser>;
30
+ delete(id: string): Promise<Collection<string, GuildUser>>;
31
+ deleteAll(): Promise<boolean>;
32
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildUserManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const GuildUser_1 = require("../../structures/user/GuildUser");
6
+ const Collection_1 = require("../../structures/Collection");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GuildUserManager {
9
+ /** A cache of users */
10
+ cache;
11
+ /** The rest client */
12
+ rest;
13
+ /** Bet user guild */
14
+ guild;
15
+ /**
16
+ * Manage users with the given client
17
+ * @param users An array of users
18
+ * @param rest The rest client
19
+ */
20
+ constructor(guild, rest) {
21
+ this.guild = guild;
22
+ this.rest = rest;
23
+ this.cache = new Collection_1.Collection("users");
24
+ }
25
+ /**
26
+ * Fetch a user
27
+ * @param id Id of the user to fetch
28
+ * @returns GuildUser
29
+ */
30
+ async fetch(id, name) {
31
+ const route = Routes_1.Routes.guilds.users.get(this.guild.id, id);
32
+ const response = await this.rest.request({
33
+ method: "get",
34
+ url: route,
35
+ payload: { name },
36
+ });
37
+ if (!response)
38
+ return this.cache.get(id);
39
+ const user = new GuildUser_1.GuildUser(response, this, this.rest);
40
+ this.cache.set(user?.id, user);
41
+ this.rest.users.set(user?.id, user);
42
+ return user;
43
+ }
44
+ async fetchAll() {
45
+ const route = Routes_1.Routes.guilds.users.getAll(this.guild.id);
46
+ const response = await this.rest.request({
47
+ method: "get",
48
+ url: route,
49
+ });
50
+ if (Array.isArray(response) && response.length === 0) {
51
+ this.cache.clear();
52
+ return this.cache;
53
+ }
54
+ this.setAll(response);
55
+ return this.cache;
56
+ }
57
+ async updateUser(id, name, data) {
58
+ const route = Routes_1.Routes.guilds.users.update(this.guild.id, id);
59
+ const payload = { ...data, name };
60
+ const response = await this.rest.request({
61
+ method: "Patch",
62
+ url: route,
63
+ payload,
64
+ });
65
+ const user = this.set(response);
66
+ return user;
67
+ }
68
+ set(data) {
69
+ if (!data.id)
70
+ return;
71
+ const user = new GuildUser_1.GuildUser(data, this, this.rest);
72
+ this.cache.set(user?.id, user);
73
+ this.rest.users.set(user?.id, user);
74
+ return user;
75
+ }
76
+ setAll(data) {
77
+ if (!data)
78
+ return this.cache;
79
+ for (let user of data)
80
+ this.set(user);
81
+ return this.cache;
82
+ }
83
+ async delete(id) {
84
+ Assertion_1.Assertion.assertString(id);
85
+ const route = Routes_1.Routes.guilds.users.delete(id, this.guild.id);
86
+ const user = this.cache.get(id);
87
+ this.rest.emit("userDelete", user);
88
+ await this.rest.request({
89
+ method: "DELETE",
90
+ url: route,
91
+ });
92
+ this.cache.delete(id);
93
+ return this.cache;
94
+ }
95
+ async deleteAll() {
96
+ const route = Routes_1.Routes.guilds.users.deleteAll(this.guild.id);
97
+ this.rest.emit("usersDelete", this.cache);
98
+ const value = await this.rest.request({
99
+ method: "DELETE",
100
+ url: route,
101
+ });
102
+ this.cache.clear();
103
+ return value;
104
+ }
105
+ }
106
+ exports.GuildUserManager = GuildUserManager;
@@ -0,0 +1,11 @@
1
+ declare class Guild {
2
+ id: string;
3
+ tickets: [];
4
+ }
5
+ export declare const APIEndpoints: {
6
+ "guilds/get": {
7
+ response: typeof Guild;
8
+ };
9
+ };
10
+ export type APIEndpoint = keyof string;
11
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIEndpoints = void 0;
4
+ class Guild {
5
+ id;
6
+ tickets;
7
+ }
8
+ exports.APIEndpoints = {
9
+ "guilds/get": {
10
+ response: Guild,
11
+ },
12
+ };
@@ -0,0 +1,51 @@
1
+ import EventEmitter from "events";
2
+ import { GuildManager } from "../managers/guild/GuildManager";
3
+ import { GuildBet } from "../structures/bet/GuildBet";
4
+ import { Collection } from "../structures/Collection";
5
+ import { GuildBetUser } from "../structures/betuser/GuildBetUser";
6
+ import { GuildMatch } from "../structures/match/GuildMatch";
7
+ import { GuildMediator } from "../structures/mediator/GuildMediator";
8
+ import { GuildUser } from "../structures/user/GuildUser";
9
+ interface RequestOptions<Payload> {
10
+ /** The request's method */
11
+ method: string;
12
+ /** The request's url */
13
+ url: string;
14
+ /** The request payload */
15
+ payload?: Payload;
16
+ }
17
+ /**
18
+ * The main class of this package
19
+ */
20
+ export declare class REST extends EventEmitter {
21
+ /**
22
+ * The unique key for client
23
+ */
24
+ key: string;
25
+ /** The guild manager */
26
+ guilds: GuildManager;
27
+ bets: Collection<string, GuildBet>;
28
+ matches: Collection<string, GuildMatch>;
29
+ betUsers: Collection<string, GuildBetUser>;
30
+ users: Collection<string, GuildUser>;
31
+ mediators: Collection<string, GuildMediator>;
32
+ /**
33
+ *
34
+ * @param key The unique key for he client
35
+ */
36
+ constructor(key?: string);
37
+ /**
38
+ * Set the api key
39
+ * @param key The unique key of the client
40
+ */
41
+ setKey(key: string): void;
42
+ /** Initialize the caching sistem */
43
+ init(): Promise<this>;
44
+ /**
45
+ * Request Data from a certain url
46
+ * @param options
47
+ * @returns
48
+ */
49
+ request<Expecting, Payload>(options: RequestOptions<Payload>): Promise<Expecting>;
50
+ }
51
+ export {};
@@ -0,0 +1,96 @@
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 events_1 = __importDefault(require("events"));
8
+ const Assertion_1 = require("../utils/Assertion");
9
+ const undici_1 = require("undici");
10
+ const Routes_1 = require("./Routes");
11
+ const dotenv_1 = __importDefault(require("dotenv"));
12
+ const GuildManager_1 = require("../managers/guild/GuildManager");
13
+ const Collection_1 = require("../structures/Collection");
14
+ dotenv_1.default.config();
15
+ const Reset = "\x1b[0m";
16
+ const FgGreen = "\x1b[32m";
17
+ const FgRed = "\x1b[31m";
18
+ const FgBlue = "\x1b[34m";
19
+ const FgCyan = "\x1b[36m";
20
+ /**
21
+ * The main class of this package
22
+ */
23
+ class REST extends events_1.default {
24
+ /**
25
+ * The unique key for client
26
+ */
27
+ key;
28
+ /** The guild manager */
29
+ guilds;
30
+ bets;
31
+ matches;
32
+ betUsers;
33
+ users;
34
+ mediators;
35
+ /**
36
+ *
37
+ * @param key The unique key for he client
38
+ */
39
+ constructor(key) {
40
+ super({ captureRejections: true });
41
+ if (key) {
42
+ Assertion_1.Assertion.assertString(key);
43
+ this.key = key;
44
+ }
45
+ this.guilds = new GuildManager_1.GuildManager(this);
46
+ this.bets = new Collection_1.Collection("bets");
47
+ this.matches = new Collection_1.Collection("matches");
48
+ this.betUsers = new Collection_1.Collection("betUsers");
49
+ this.users = new Collection_1.Collection("users");
50
+ this.mediators = new Collection_1.Collection("mediators");
51
+ }
52
+ /**
53
+ * Set the api key
54
+ * @param key The unique key of the client
55
+ */
56
+ setKey(key) {
57
+ this.key = key;
58
+ }
59
+ /** Initialize the caching sistem */
60
+ async init() {
61
+ await this.guilds.fetchAll();
62
+ return this;
63
+ }
64
+ /**
65
+ * Request Data from a certain url
66
+ * @param options
67
+ * @returns
68
+ */
69
+ async request(options) {
70
+ let { method, url, payload } = options;
71
+ Assertion_1.Assertion.assertString(method);
72
+ Assertion_1.Assertion.assertString(this.key);
73
+ Assertion_1.Assertion.assertString(url);
74
+ method = method.toUpperCase();
75
+ url = Routes_1.Routes.base + url;
76
+ const headers = new undici_1.Headers();
77
+ headers.append("duque-auth", process.env.AUTH);
78
+ headers.append("Content-Type", "application/json");
79
+ headers.append("duque-client-key", this.key);
80
+ const before = Date.now();
81
+ this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
82
+ const res = await (0, undici_1.request)(url, {
83
+ method,
84
+ headers,
85
+ body: payload !== undefined ? JSON.stringify(payload) : undefined,
86
+ });
87
+ const body = await res.body.json();
88
+ const { data, message } = body;
89
+ const now = new Date().getTime();
90
+ if (message)
91
+ this.emit("debug", `${FgRed}${message}${Reset}`);
92
+ this.emit("debug", `[Request]${FgGreen} ${(now - before) / 1000}s done.${Reset}`);
93
+ return data;
94
+ }
95
+ }
96
+ exports.REST = REST;
@@ -0,0 +1,84 @@
1
+ export declare const Route: <K>(route: string) => string;
2
+ export declare const Routes: {
3
+ base: string;
4
+ field: (field: string) => string;
5
+ fields: (...fields: string[]) => string;
6
+ guilds: {
7
+ create: () => string;
8
+ get: (guildId: string) => string;
9
+ getAll: () => string;
10
+ delete: (guildId: string) => string;
11
+ deleteAll: () => string;
12
+ resource: (guildId: string, resource: string) => string;
13
+ resources: (guildId: string, ...resourcess: string[]) => string;
14
+ users: {
15
+ create: (guildId: string) => string;
16
+ update: (guildId: string, userId: string) => string;
17
+ getAll: (guildId: string) => string;
18
+ get: (guildId: string, userId: string) => string;
19
+ delete: (guildId: string, userId: string) => string;
20
+ deleteAll: (guildId: string) => string;
21
+ resource: (guildId: string, userId: string, resource: string) => string;
22
+ };
23
+ betUsers: {
24
+ getAll: (guildId: string) => string;
25
+ get: (guildId: string, userId: string) => string;
26
+ create: (guildId: string) => string;
27
+ update: (guildId: string, userId: string) => string;
28
+ delete: (guildId: string, userId: string) => string;
29
+ deleteAll: (guildId: string) => string;
30
+ resource: (guildId: string, userId: string, resourceName: string) => string;
31
+ };
32
+ matches: {
33
+ getAll: (guildId: string) => string;
34
+ get: (guildId: string, matchId: string) => string;
35
+ create: (guildId: string) => string;
36
+ update: (guildId: string, matchId: string) => string;
37
+ delete: (guildId: string, matchId: string) => string;
38
+ deleteAll: (guildId: string) => string;
39
+ resource: (guildId: string, matchId: string, ...resources: string[]) => string;
40
+ };
41
+ bets: {
42
+ getAll: (guildId: string) => string;
43
+ get: (guildId: string, betId: string) => string;
44
+ create: (guildId: string) => string;
45
+ update: (guildId: string, betId: string) => string;
46
+ delete: (guildId: string, betId: string) => string;
47
+ deleteAll: (guildId: string) => string;
48
+ resource: (guildId: string, betId: string, ...resources: string[]) => string;
49
+ };
50
+ tickets: {
51
+ getAll: (guildId: string) => string;
52
+ get: (guildId: string, ticketId: string) => string;
53
+ create: (guildId: string) => string;
54
+ update: (guildId: string, ticketId: string) => string;
55
+ delete: (guildId: string, ticketId: string) => string;
56
+ deleteAll: (guildId: string) => string;
57
+ resource: (guildId: string, ticketId: string, ...resources: string[]) => string;
58
+ };
59
+ mediators: {
60
+ getAll: (guildId: string) => string;
61
+ get: (guildId: string, mediatorId: string) => string;
62
+ create: (guildId: string) => string;
63
+ update: (guildId: string, mediatorId: string) => string;
64
+ delete: (guildId: string, mediatorId: string) => string;
65
+ deleteAll: (guildId: string) => string;
66
+ resource: (guildId: string, mediatorId: string, ...resources: string[]) => string;
67
+ };
68
+ shop: {
69
+ get: (guildId: string) => string;
70
+ update: (guildId: string) => string;
71
+ delete: (guildId: string) => string;
72
+ resource: (guildId: string, ...resources: string[]) => string;
73
+ products: {
74
+ getAll: (guildId: string) => string;
75
+ get: (guildId: string, productId: string) => string;
76
+ create: (guildId: string) => string;
77
+ update: (guildId: string, productId: string) => string;
78
+ delete: (guildId: string, productId: string) => string;
79
+ deleteAll: (guildId: string) => string;
80
+ resource: (guildId: string, productId: string, ...resources: string[]) => string;
81
+ };
82
+ };
83
+ };
84
+ };