@duque.edits/sdk 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/{v1/index.ts → dist/index.d.ts} +27 -30
  2. package/dist/index.js +43 -0
  3. package/dist/managers/bet/GuildBetManager.d.ts +32 -0
  4. package/dist/managers/bet/GuildBetManager.js +107 -0
  5. package/dist/managers/betuser/GuildBetUserManager.d.ts +30 -0
  6. package/dist/managers/betuser/GuildBetUserManager.js +94 -0
  7. package/dist/managers/channel/ChannelManager.d.ts +39 -0
  8. package/dist/managers/channel/ChannelManager.js +147 -0
  9. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +34 -0
  10. package/dist/managers/groupedchannel/GroupedChannelManager.js +92 -0
  11. package/dist/managers/guild/GuildManager.d.ts +24 -0
  12. package/dist/managers/guild/GuildManager.js +75 -0
  13. package/dist/managers/match/GuildMatchManager.d.ts +32 -0
  14. package/dist/managers/match/GuildMatchManager.js +103 -0
  15. package/dist/managers/mediator/GuildMediatorManager.d.ts +32 -0
  16. package/dist/managers/mediator/GuildMediatorManager.js +97 -0
  17. package/dist/managers/messages/MessagesManager.d.ts +32 -0
  18. package/dist/managers/messages/MessagesManager.js +82 -0
  19. package/dist/managers/permission/GuildPermissionManager.d.ts +26 -0
  20. package/dist/managers/permission/GuildPermissionManager.js +70 -0
  21. package/dist/managers/product/GuildProductManager.d.ts +32 -0
  22. package/dist/managers/product/GuildProductManager.js +102 -0
  23. package/dist/managers/ticket/GuildTicketManager.d.ts +32 -0
  24. package/dist/managers/ticket/GuildTicketManager.js +99 -0
  25. package/dist/managers/user/GuildUserManager.d.ts +32 -0
  26. package/dist/managers/user/GuildUserManager.js +106 -0
  27. package/dist/rest/APIEndpoints.d.ts +11 -0
  28. package/dist/rest/APIEndpoints.js +12 -0
  29. package/dist/rest/REST.d.ts +51 -0
  30. package/dist/rest/REST.js +96 -0
  31. package/dist/rest/Routes.d.ts +84 -0
  32. package/dist/rest/Routes.js +89 -0
  33. package/dist/structures/Collection.d.ts +17 -0
  34. package/dist/structures/Collection.js +87 -0
  35. package/dist/structures/bet/GuildBet.d.ts +86 -0
  36. package/dist/structures/bet/GuildBet.js +276 -0
  37. package/dist/structures/betuser/GuildBetUser.d.ts +82 -0
  38. package/dist/structures/betuser/GuildBetUser.js +194 -0
  39. package/dist/structures/channel/Channel.d.ts +31 -0
  40. package/dist/structures/channel/Channel.js +57 -0
  41. package/dist/structures/groupedchannel/GroupedChannel.d.ts +34 -0
  42. package/dist/structures/groupedchannel/GroupedChannel.js +121 -0
  43. package/dist/structures/guild/Guild.d.ts +89 -0
  44. package/dist/structures/guild/Guild.js +223 -0
  45. package/dist/structures/match/GuildMatch.d.ts +84 -0
  46. package/dist/structures/match/GuildMatch.js +327 -0
  47. package/dist/structures/mediator/GuildMediator.d.ts +41 -0
  48. package/dist/structures/mediator/GuildMediator.js +131 -0
  49. package/dist/structures/product/GuildProduct.d.ts +52 -0
  50. package/dist/structures/product/GuildProduct.js +175 -0
  51. package/dist/structures/shop/GuildShop.d.ts +34 -0
  52. package/dist/structures/shop/GuildShop.js +80 -0
  53. package/dist/structures/ticket/GuildTicket.d.ts +51 -0
  54. package/dist/structures/ticket/GuildTicket.js +170 -0
  55. package/dist/structures/user/GuildUser.d.ts +82 -0
  56. package/dist/structures/user/GuildUser.js +209 -0
  57. package/dist/types/api/APIBaseChannel.d.ts +10 -0
  58. package/dist/types/api/APIBaseChannel.js +2 -0
  59. package/dist/types/api/APIBetChannel.d.ts +10 -0
  60. package/dist/types/api/APIBetChannel.js +2 -0
  61. package/dist/types/api/APIBetMessage.d.ts +10 -0
  62. package/dist/types/api/APIBetMessage.js +2 -0
  63. package/dist/types/api/APIGuild.d.ts +92 -0
  64. package/dist/types/api/APIGuild.js +2 -0
  65. package/dist/types/api/APIGuildBet.d.ts +48 -0
  66. package/dist/types/api/APIGuildBet.js +2 -0
  67. package/dist/types/api/APIGuildBetUser.d.ts +32 -0
  68. package/dist/types/api/APIGuildBetUser.js +2 -0
  69. package/dist/types/api/APIGuildChannel.d.ts +10 -0
  70. package/dist/types/api/APIGuildChannel.js +2 -0
  71. package/dist/types/api/APIGuildEmoji.d.ts +12 -0
  72. package/dist/types/api/APIGuildEmoji.js +2 -0
  73. package/dist/types/api/APIGuildGroupedChannel.d.ts +10 -0
  74. package/dist/types/api/APIGuildGroupedChannel.js +2 -0
  75. package/dist/types/api/APIGuildMatch.d.ts +46 -0
  76. package/dist/types/api/APIGuildMatch.js +2 -0
  77. package/dist/types/api/APIGuildMediator.d.ts +13 -0
  78. package/dist/types/api/APIGuildMediator.js +3 -0
  79. package/dist/types/api/APIGuildMessage.d.ts +10 -0
  80. package/dist/types/api/APIGuildMessage.js +2 -0
  81. package/dist/types/api/APIGuildPermissions.d.ts +6 -0
  82. package/dist/types/api/APIGuildPermissions.js +2 -0
  83. package/dist/types/api/APIGuildRole.d.ts +10 -0
  84. package/dist/types/api/APIGuildRole.js +2 -0
  85. package/dist/types/api/APIGuildShop.d.ts +11 -0
  86. package/dist/types/api/APIGuildShop.js +2 -0
  87. package/dist/types/api/APIGuildTicket.d.ts +25 -0
  88. package/dist/types/api/APIGuildTicket.js +3 -0
  89. package/dist/types/api/APIGuildUser.d.ts +31 -0
  90. package/dist/types/api/APIGuildUser.js +2 -0
  91. package/dist/types/api/APIMessage.d.ts +12 -0
  92. package/dist/types/api/APIMessage.js +2 -0
  93. package/dist/types/api/APIPlayer.d.ts +10 -0
  94. package/dist/types/api/APIPlayer.js +2 -0
  95. package/dist/types/api/APIProduct.d.ts +19 -0
  96. package/dist/types/api/APIProduct.js +3 -0
  97. package/dist/types/api/index.d.ts +130 -0
  98. package/dist/types/api/index.js +35 -0
  99. package/{v1/types/index.ts → dist/types/index.d.ts} +21 -24
  100. package/dist/types/index.js +37 -0
  101. package/dist/utils/Assertion.d.ts +32 -0
  102. package/dist/utils/Assertion.js +60 -0
  103. package/package.json +5 -1
  104. package/.gitattributes +0 -2
  105. package/tests/index.ts +0 -86
  106. package/tsconfig.json +0 -15
  107. package/v1/managers/bet/GuildBetManager.ts +0 -117
  108. package/v1/managers/betuser/GuildBetUserManager.ts +0 -103
  109. package/v1/managers/channel/ChannelManager.ts +0 -168
  110. package/v1/managers/groupedchannel/GroupedChannelManager.ts +0 -117
  111. package/v1/managers/guild/GuildManager.ts +0 -84
  112. package/v1/managers/match/GuildMatchManager.ts +0 -115
  113. package/v1/managers/mediator/GuildMediatorManager.ts +0 -111
  114. package/v1/managers/messages/MessagesManager.ts +0 -95
  115. package/v1/managers/permission/GuildPermissionManager.ts +0 -88
  116. package/v1/managers/product/GuildProductManager.ts +0 -115
  117. package/v1/managers/ticket/GuildTicketManager.ts +0 -112
  118. package/v1/managers/user/GuildUserManager.ts +0 -116
  119. package/v1/rest/APIEndpoints.ts +0 -11
  120. package/v1/rest/REST.ts +0 -126
  121. package/v1/rest/Routes.ts +0 -143
  122. package/v1/structures/Collection.ts +0 -85
  123. package/v1/structures/bet/GuildBet.ts +0 -332
  124. package/v1/structures/betuser/GuildBetUser.ts +0 -247
  125. package/v1/structures/channel/Channel.ts +0 -78
  126. package/v1/structures/groupedchannel/GroupedChannel.ts +0 -165
  127. package/v1/structures/guild/Guild.ts +0 -302
  128. package/v1/structures/match/GuildMatch.ts +0 -385
  129. package/v1/structures/mediator/GuildMediator.ts +0 -175
  130. package/v1/structures/product/GuildProduct.ts +0 -217
  131. package/v1/structures/shop/GuildShop.ts +0 -98
  132. package/v1/structures/ticket/GuildTicket.ts +0 -227
  133. package/v1/structures/user/GuildUser.ts +0 -248
  134. package/v1/types/api/APIBaseChannel.ts +0 -13
  135. package/v1/types/api/APIBetChannel.ts +0 -13
  136. package/v1/types/api/APIBetMessage.ts +0 -13
  137. package/v1/types/api/APIGuild.ts +0 -123
  138. package/v1/types/api/APIGuildBet.ts +0 -69
  139. package/v1/types/api/APIGuildBetUser.ts +0 -46
  140. package/v1/types/api/APIGuildChannel.ts +0 -13
  141. package/v1/types/api/APIGuildEmoji.ts +0 -16
  142. package/v1/types/api/APIGuildGroupedChannel.ts +0 -13
  143. package/v1/types/api/APIGuildMatch.ts +0 -67
  144. package/v1/types/api/APIGuildMediator.ts +0 -18
  145. package/v1/types/api/APIGuildMessage.ts +0 -13
  146. package/v1/types/api/APIGuildPermissions.ts +0 -7
  147. package/v1/types/api/APIGuildRole.ts +0 -13
  148. package/v1/types/api/APIGuildShop.ts +0 -15
  149. package/v1/types/api/APIGuildTicket.ts +0 -36
  150. package/v1/types/api/APIGuildUser.ts +0 -45
  151. package/v1/types/api/APIMessage.ts +0 -16
  152. package/v1/types/api/APIPlayer.ts +0 -13
  153. package/v1/types/api/APIProduct.ts +0 -27
  154. package/v1/types/api/index.ts +0 -180
  155. package/v1/utils/Assertion.ts +0 -56
@@ -1,175 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Guild } from "../guild/Guild";
4
- import { APIGuildMediator } from "../../types/api/APIGuildMediator";
5
- import { Optional } from "../../types/api";
6
- import { Assertion } from "../../utils/Assertion";
7
- import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
8
-
9
- export class GuildMediator {
10
- /** Mediator's id */
11
- id: string;
12
-
13
- /** Mediator's name */
14
- name: string;
15
-
16
- /** Mediator's links */
17
- paymentLinks: string[];
18
-
19
- /** Creation Date */
20
- createdAt: Date;
21
-
22
- /** Updated Date */
23
- updatedAt: Date;
24
-
25
- /** The given guild */
26
- readonly guild: Guild;
27
-
28
- /** The rest client */
29
- readonly rest: REST;
30
- readonly manager: GuildMediatorManager;
31
-
32
- /**
33
- * GuildMediator mediator
34
- * @param data The mediator's data
35
- * @param guild The guild
36
- * @param rest The rest client
37
- */
38
- constructor(
39
- data: APIGuildMediator,
40
- guild: Guild,
41
- manager: GuildMediatorManager,
42
- rest: REST
43
- ) {
44
- this.id = data.id;
45
- this.name = data.name;
46
- this.paymentLinks = data.paymentLinks;
47
-
48
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
49
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
50
-
51
- this.guild = guild;
52
- this.rest = rest;
53
- this.manager = manager;
54
- }
55
- /** String representation of this mediator */
56
- toString() {
57
- return `<@${this.id}>`;
58
- }
59
- /**
60
- * Fetches the mediator
61
- * @returns New Instance of the mediator
62
- */
63
- async fetch() {
64
- const route = Routes.guilds.mediators.get(this.guild.id, this.id);
65
- const response = await this.rest.request<APIGuildMediator, {}>({
66
- method: "get",
67
- url: route,
68
- });
69
-
70
- const med = new GuildMediator(
71
- response,
72
- this.guild,
73
- this.manager,
74
- this.rest
75
- );
76
- this.manager.cache.set(med.id, med);
77
- this.rest.mediators.set(med.id, med);
78
- return med;
79
- }
80
-
81
- async update(data: Optional<APIGuildMediator>) {
82
- const route = Routes.guilds.mediators.get(this.guild.id, this.id);
83
- const payload = data;
84
-
85
- const response = await this.rest.request<APIGuildMediator, typeof payload>({
86
- method: "patch",
87
- url: route,
88
- payload,
89
- });
90
- const med = new GuildMediator(
91
- response,
92
- this.guild,
93
- this.manager,
94
- this.rest
95
- );
96
- this.rest.emit("mediatorUpdate", this);
97
- for (const k in response) {
98
- if (k === "id") continue;
99
-
100
- if (Object.hasOwn(this, k)) {
101
- (this as any)[k] = response[k as keyof APIGuildMediator];
102
- }
103
- }
104
- this.manager.cache.set(med.id, med);
105
- this.rest.emit("mediatorUpdate", this, med);
106
- return this;
107
- }
108
-
109
- async delete() {
110
- const route = Routes.guilds.mediators.delete(this.guild.id, this.id);
111
- const response = await this.rest.request<boolean, {}>({
112
- method: "DELETE",
113
- url: route,
114
- });
115
-
116
- this.manager.cache.delete(this.id);
117
- this.rest.mediators.delete(this.id);
118
- this.rest.emit("mediatorUpdate", this);
119
- return response;
120
- }
121
- async setLinks(link: string) {
122
- Assertion.assertString(link);
123
-
124
- const route = Routes.guilds.mediators.resource(
125
- this.guild.id,
126
- this.id,
127
- "links"
128
- );
129
- const payload = { paymentLinks: [link], set: true };
130
- const response = await this.rest.request<APIGuildMediator, {}>({
131
- method: "PATCH",
132
- url: route,
133
- payload,
134
- });
135
-
136
- this.paymentLinks = response.paymentLinks;
137
- this.manager.cache.set(this.id, this);
138
- this.rest.mediators.set(this.id, this);
139
- this.rest.emit("mediatorUpdate", this);
140
- return this.paymentLinks;
141
- }
142
- async removeLink(link: string) {
143
- Assertion.assertString(link);
144
-
145
- const route = Routes.guilds.mediators.resource(
146
- this.guild.id,
147
- this.id,
148
- "links"
149
- );
150
-
151
- const payload = {
152
- paymentLinks: this.paymentLinks.filter((lm) => lm !== link),
153
- };
154
- const response = await this.rest.request<APIGuildMediator, {}>({
155
- method: "PATCH",
156
- url: route,
157
- payload,
158
- });
159
-
160
- this.paymentLinks = response.paymentLinks;
161
- this.manager.cache.set(this.id, this);
162
- this.rest.mediators.set(this.id, this);
163
- this.rest.emit("mediatorUpdate", this);
164
- return this.paymentLinks;
165
- }
166
- toJSON() {
167
- const json: Record<string, unknown> = {};
168
- for (const [key, value] of Object.entries(this)) {
169
- if (typeof value !== "function") {
170
- json[key] = value;
171
- }
172
- }
173
- return json;
174
- }
175
- }
@@ -1,217 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Items, Optional } from "../../types/api";
4
- import { APIProduct } from "../../types/api/APIProduct";
5
- import { APIPlayer } from "../../types/api/APIPlayer";
6
- import { Assertion } from "../../utils/Assertion";
7
- import { GuildProductManager } from "../../managers/product/GuildProductManager";
8
-
9
- export class GuildProduct implements APIProduct {
10
- /** Product's name */
11
- name: string;
12
-
13
- /** Product's description */
14
- description: string;
15
-
16
- /** Product's id */
17
- id: string;
18
-
19
- /** Product's price */
20
- price: number;
21
-
22
- /** Product's buyers */
23
- buyers: APIPlayer[];
24
-
25
- /** Product's emoji */
26
- emoji: string;
27
-
28
- /** Creation Date */
29
- createdAt: Date;
30
-
31
- /** Updated Date */
32
- updatedAt: Date;
33
-
34
- /** The given manager */
35
- readonly manager: GuildProductManager;
36
-
37
- /** The rest client */
38
- readonly rest: REST;
39
-
40
- /**
41
- * Bet product
42
- * @param data The product's data
43
- * @param manager The manager
44
- * @param rest The rest client
45
- */
46
- constructor(data: APIProduct, manager: GuildProductManager, rest: REST) {
47
- this.name = data?.name;
48
- this.id = data?.id;
49
- this.price = data?.price;
50
- this.buyers = data?.buyers;
51
- this.emoji = data?.emoji;
52
- this.description = data?.description;
53
-
54
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
55
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
56
-
57
- this.manager = manager;
58
- this.rest = rest;
59
- }
60
- /** String representation of this product */
61
- toString() {
62
- return `<@${this.id}>`;
63
- }
64
- /**
65
- * Fetches the product
66
- * @returns New Instance of the product
67
- */
68
- async fetch() {
69
- const route = Routes.guilds.shop.products.get(
70
- this.manager.guild.id,
71
- this.id
72
- );
73
- const response = await this.rest.request<APIProduct, {}>({
74
- method: "get",
75
- url: route,
76
- });
77
- const product = new GuildProduct(response, this.manager, this.rest);
78
- this.manager.cache.set(product.id, product);
79
- return product;
80
- }
81
- async setPrice(price: number) {
82
- Assertion.assertNumber(price);
83
-
84
- const route = Routes.guilds.shop.products.resource(
85
- this.id,
86
- this.manager.guild.id,
87
- "price"
88
- );
89
- const payload = { price };
90
- const response = await this.rest.request<APIProduct, typeof payload>({
91
- method: "PATCH",
92
- url: route,
93
- });
94
- this.price = response.price;
95
- this.manager.cache.set(this.id, this);
96
- return this;
97
- }
98
- async addBuyer(id: string, name: string, type: string) {
99
- Assertion.assertString(id);
100
- Assertion.assertString(name);
101
- Assertion.assertString(type);
102
-
103
- const payload = { id, name, type };
104
- const route = Routes.guilds.shop.products.resource(
105
- this.id,
106
- this.manager.guild.id,
107
- "buyers"
108
- );
109
- const response = await this.rest.request<APIProduct, typeof payload>({
110
- method: "POST",
111
- url: route,
112
- payload,
113
- });
114
-
115
- let user;
116
- if (type == "bet") {
117
- user = this.manager.guild.betUsers.cache.get(id);
118
- user.items = [...new Set([...user.items, this.id])] as Items;
119
- this.manager.guild.betUsers.cache.set(user.id, user);
120
- this.rest.betUsers.set(user.id, user);
121
- } else if (type == "match") {
122
- user = this.manager.guild.users.cache.get(id);
123
- user.items = [...new Set([...user.items, this.id])] as Items;
124
- this.manager.guild.users.cache.set(user.id, user);
125
- this.rest.users.set(user.id, user);
126
- }
127
- this.buyers = response.buyers;
128
- this.manager.cache.set(this.id, this);
129
-
130
- return this;
131
- }
132
- async removeBuyer(id: string, name: string, type: string) {
133
- Assertion.assertString(id);
134
- Assertion.assertString(name);
135
- Assertion.assertString(type);
136
-
137
- const payload = { id, name, type };
138
- const route = Routes.guilds.shop.products.resource(
139
- this.id,
140
- this.manager.guild.id,
141
- "buyers",
142
- id
143
- );
144
- const response = await this.rest.request<APIProduct, {}>({
145
- method: "DELETE",
146
- url: route,
147
- payload,
148
- });
149
-
150
- let user;
151
- if (type == "bet") {
152
- user = this.manager.guild.betUsers.cache.get(id);
153
- user.items = [
154
- ...new Set(user.items.filter((item) => item != this.id)),
155
- ] as Items;
156
- this.manager.guild.betUsers.cache.set(user.id, user);
157
- } else if (type == "match") {
158
- user = this.manager.guild.users.cache.get(id);
159
- user.items = [
160
- ...new Set(user.items.filter((item) => item != this.id)),
161
- ] as Items;
162
- this.manager.guild.users.cache.set(user.id, user);
163
- }
164
-
165
- this.buyers = response.buyers;
166
- this.manager.cache.set(this.id, this);
167
- return this;
168
- }
169
- /**
170
- * Update certain property
171
- * @param data The new data to update with
172
- * @returns
173
- */
174
- async update(payload: Optional<APIProduct>) {
175
- const route = Routes.guilds.shop.products.get(
176
- this.manager.guild.id,
177
- this.id
178
- );
179
- const response = await this.rest.request<APIProduct, typeof payload>({
180
- method: "patch",
181
- url: route,
182
- payload,
183
- });
184
-
185
- for (const k in response) {
186
- if (k === "id") continue;
187
- if (Object.hasOwn(this, k)) {
188
- (this as any)[k] = response[k as keyof APIProduct];
189
- }
190
- }
191
- this.manager.cache.set(this.id, this);
192
- return this;
193
- }
194
- async delete() {
195
- const route = Routes.guilds.shop.products.delete(
196
- this.manager.guild.id,
197
- this.id
198
- );
199
- const response = await this.rest.request<boolean, {}>({
200
- method: "DELETE",
201
- url: route,
202
- });
203
-
204
- this.rest.emit("betproductDelete", this);
205
- this.manager.cache.delete(this.id);
206
- return response;
207
- }
208
- toJSON() {
209
- const json: Record<string, unknown> = {};
210
- for (const [key, value] of Object.entries(this)) {
211
- if (typeof value !== "function") {
212
- json[key] = value;
213
- }
214
- }
215
- return json;
216
- }
217
- }
@@ -1,98 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Guild } from "../guild/Guild";
4
- import { Optional } from "../../types/api";
5
- import { Assertion } from "../../utils/Assertion";
6
- import { APIProduct } from "../../types/api/APIProduct";
7
- import { APIGuildShop } from "../../types/api/APIGuildShop";
8
- import { GuildProductManager } from "../../managers/product/GuildProductManager";
9
-
10
- export class GuildShop {
11
- /**shop's product */
12
- products: GuildProductManager;
13
-
14
- /** Bought count */
15
- boughtCount: number;
16
-
17
- /** Creation Date */
18
- createdAt: Date;
19
-
20
- /** Updated Date */
21
- updatedAt: Date;
22
-
23
- /** The given guild */
24
- readonly guild: Guild;
25
-
26
- /** The rest client */
27
- readonly rest: REST;
28
-
29
- /**
30
- * GuildShopshop
31
- * @param data Theshop's data
32
- * @param guild The guild
33
- * @param rest The rest client
34
- */
35
- constructor(data: APIGuildShop, guild: Guild, rest: REST) {
36
- this.boughtCount = data?.boughtCount;
37
- this.products = new GuildProductManager(guild, rest);
38
-
39
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
40
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
41
-
42
- this.guild = guild;
43
- this.rest = rest;
44
-
45
- this.products.setAll(data?.products);
46
- }
47
- toString() {
48
- return this.boughtCount.toString();
49
- }
50
- /**
51
- * Fetches theshop
52
- * @returns New Instance of theshop
53
- */
54
- async fetch() {
55
- const route = Routes.guilds.shop.get(this.guild.id);
56
- const response = await this.rest.request<APIGuildShop, {}>({
57
- method: "get",
58
- url: route,
59
- });
60
- const shp = new GuildShop(response, this.guild, this.rest);
61
- this.guild.shop = shp;
62
- return shp;
63
- }
64
-
65
- async update(data: Optional<APIGuildShop>) {
66
- const route = Routes.guilds.shop.get(this.guild.id);
67
- const payload = data;
68
-
69
- const response = await this.rest.request<APIGuildShop, typeof payload>({
70
- method: "patch",
71
- url: route,
72
- payload,
73
- });
74
- this.rest.emit(
75
- "shopUpdate",
76
- this,
77
- new GuildShop(response, this.guild, this.rest)
78
- );
79
- for (const k in response) {
80
- if (k === "id") continue;
81
-
82
- if (Object.hasOwn(this, k)) {
83
- (this as any)[k] = response[k as keyof APIGuildShop];
84
- }
85
- }
86
- this.guild.shop = this;
87
- return this;
88
- }
89
- toJSON() {
90
- const json: Record<string, unknown> = {};
91
- for (const [key, value] of Object.entries(this)) {
92
- if (typeof value !== "function") {
93
- json[key] = value;
94
- }
95
- }
96
- return json;
97
- }
98
- }
@@ -1,227 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Guild } from "../guild/Guild";
4
- import { APIGuildTicket } from "../../types/api/APIGuildTicket";
5
- import { Optional } from "../../types/api";
6
- import { Assertion } from "../../utils/Assertion";
7
- import { GuildTicketManager } from "../../managers/ticket/GuildTicketManager";
8
- import { APIMessage } from "../../types/api/APIMessage";
9
- import { MessagesManager } from "../../managers/messages/MessagesManager";
10
-
11
- export class GuildTicket {
12
- /** Ticket's id */
13
- id: string;
14
-
15
- /** Ticket's creator id */
16
- creatorId: string;
17
-
18
- /** Ticket's admin id */
19
- adminId: string;
20
-
21
- /** Ticket's rating that customer gave */
22
- customerRating: number;
23
-
24
- /** Ticket's channel id */
25
- channelId: string;
26
-
27
- /** Ticket's closed by who */
28
- closedById: string;
29
-
30
- /** Ticket's type */
31
- type: string;
32
-
33
- /** Ticket's status */
34
- status: "on" | "off";
35
-
36
- /** Ticket's messages */
37
- messages: MessagesManager;
38
-
39
- /** Creation Date */
40
- createdAt: Date;
41
-
42
- /** Updated Date */
43
- updatedAt: Date;
44
-
45
- /** The given guild */
46
- readonly guild: Guild;
47
-
48
- /** The rest client */
49
- readonly rest: REST;
50
- readonly manager: GuildTicketManager;
51
-
52
- /**
53
- * GuildMediator mediator
54
- * @param data The mediator's data
55
- * @param guild The guild
56
- * @param rest The rest client
57
- */
58
- constructor(
59
- data: APIGuildTicket,
60
- guild: Guild,
61
- manager: GuildTicketManager,
62
- rest: REST
63
- ) {
64
- this.id = data?.id.toString();
65
- this.creatorId = data?.creatorId;
66
- this.adminId = data?.adminId;
67
- this.customerRating = data.customerRating;
68
- this.closedById = data?.closedById;
69
- this.type = data?.type;
70
- this.status = data?.status;
71
- this.channelId = data?.channelId;
72
- this.messages = new MessagesManager(this.guild, this.id, rest);
73
- this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
74
- this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
75
-
76
- this.guild = guild;
77
- this.rest = rest;
78
- this.manager = manager;
79
-
80
- this.messages.setAll(data?.messages);
81
- }
82
- async fetch(): Promise<GuildTicket> {
83
- const route = Routes.guilds.tickets.get(this.id, this.guild.id);
84
- const response = await this.rest.request<APIGuildTicket, {}>({
85
- method: "DELETE",
86
- url: route,
87
- });
88
- const ticket = new GuildTicket(
89
- response,
90
- this.guild,
91
- this.manager,
92
- this.rest
93
- );
94
- this.manager.cache.set(response.id, ticket);
95
- return ticket;
96
- }
97
- async setChannelId(id: string) {
98
- Assertion.assertString(id);
99
-
100
- const route = Routes.guilds.tickets.resource(
101
- this.guild.id,
102
- this.id,
103
- "channelId"
104
- );
105
- const payload = { channelId: id };
106
- const response = await this.rest.request<APIGuildTicket, typeof payload>({
107
- method: "PATCH",
108
- url: route,
109
- payload,
110
- });
111
-
112
- this.channelId = response.channelId;
113
- this.manager.cache.set(this.id, this);
114
- return this;
115
- }
116
- async setAdminId(id: string) {
117
- Assertion.assertString(id);
118
- const route = Routes.guilds.tickets.resource(
119
- this.guild.id,
120
- this.id,
121
- "adminId"
122
- );
123
- const payload = { adminId: id };
124
- const response = await this.rest.request<APIGuildTicket, typeof payload>({
125
- method: "PATCH",
126
- url: route,
127
- payload,
128
- });
129
- this.adminId = response.adminId;
130
- this.manager.cache.set(this.id, this);
131
-
132
- return this;
133
- }
134
- async setClosedById(id: string) {
135
- Assertion.assertString(id);
136
- const route = Routes.guilds.tickets.resource(
137
- this.guild.id,
138
- this.id,
139
- "closedById"
140
- );
141
- const payload = { closedById: id };
142
-
143
- const response = await this.rest.request<APIGuildTicket, typeof payload>({
144
- method: "PATCH",
145
- url: route,
146
- payload,
147
- });
148
- this.closedById = response.closedById;
149
- this.manager.cache.set(this.id, this);
150
- return this;
151
- }
152
- async setCustomerRating(rating: string) {
153
- Assertion.assertString(rating);
154
- const route = Routes.guilds.tickets.resource(
155
- this.guild.id,
156
- this.id,
157
- "customerRating"
158
- );
159
- const payload = {
160
- customerRating: rating,
161
- };
162
- const response = await this.rest.request<APIGuildTicket, typeof payload>({
163
- method: "PATCH",
164
- url: route,
165
- });
166
- this.customerRating = response.customerRating;
167
- this.manager.cache.set(this.id, this);
168
- return this;
169
- }
170
- async setType(type: string) {
171
- Assertion.assertString(type);
172
- const route = Routes.guilds.tickets.resource(
173
- this.guild.id,
174
- this.id,
175
- "type"
176
- );
177
- const payload = { type };
178
- const response = await this.rest.request<APIGuildTicket, typeof payload>({
179
- method: "PATCH",
180
- url: route,
181
- payload,
182
- });
183
- this.type = response.type;
184
- this.manager.cache.set(this.id, this);
185
- return this;
186
- }
187
- async setStatus(status: string) {
188
- Assertion.assertString(status);
189
- const route = Routes.guilds.tickets.resource(
190
- this.guild.id,
191
- this.id,
192
- "status"
193
- );
194
- const payload = { status };
195
- const response = await this.rest.request<APIGuildTicket, typeof payload>({
196
- method: "PATCH",
197
- url: route,
198
- payload,
199
- });
200
- this.status = response.status;
201
- this.manager.cache.set(this.id, this);
202
- return this;
203
- }
204
- async delete(): Promise<boolean> {
205
- const route = Routes.guilds.tickets.delete(this.id, this.guild.id);
206
- const response = await this.rest.request<boolean, {}>({
207
- method: "DELETE",
208
- url: route,
209
- });
210
-
211
- this.manager.cache.set(this.id, this);
212
- this.manager.cache.delete(this.id);
213
- return response;
214
- }
215
- toJSON() {
216
- const json: Record<string, unknown> = {};
217
- for (const [key, value] of Object.entries(this)) {
218
- if (typeof value !== "function") {
219
- json[key] = value;
220
- }
221
- }
222
- return json;
223
- }
224
- toString() {
225
- return this.id || "1";
226
- }
227
- }