@duque.edits/sdk 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/{src/index.ts → dist/index.d.ts} +27 -30
  2. package/dist/index.js +43 -0
  3. package/dist/managers/bet/GuildBetManager.d.ts +32 -0
  4. package/dist/managers/bet/GuildBetManager.js +107 -0
  5. package/dist/managers/betuser/GuildBetUserManager.d.ts +30 -0
  6. package/dist/managers/betuser/GuildBetUserManager.js +94 -0
  7. package/dist/managers/channel/ChannelManager.d.ts +39 -0
  8. package/dist/managers/channel/ChannelManager.js +147 -0
  9. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +34 -0
  10. package/dist/managers/groupedchannel/GroupedChannelManager.js +92 -0
  11. package/dist/managers/guild/GuildManager.d.ts +24 -0
  12. package/dist/managers/guild/GuildManager.js +75 -0
  13. package/dist/managers/match/GuildMatchManager.d.ts +32 -0
  14. package/dist/managers/match/GuildMatchManager.js +103 -0
  15. package/dist/managers/mediator/GuildMediatorManager.d.ts +32 -0
  16. package/dist/managers/mediator/GuildMediatorManager.js +97 -0
  17. package/dist/managers/messages/MessagesManager.d.ts +32 -0
  18. package/dist/managers/messages/MessagesManager.js +82 -0
  19. package/dist/managers/permission/GuildPermissionManager.d.ts +26 -0
  20. package/dist/managers/permission/GuildPermissionManager.js +70 -0
  21. package/dist/managers/product/GuildProductManager.d.ts +32 -0
  22. package/dist/managers/product/GuildProductManager.js +102 -0
  23. package/dist/managers/ticket/GuildTicketManager.d.ts +32 -0
  24. package/dist/managers/ticket/GuildTicketManager.js +99 -0
  25. package/dist/managers/user/GuildUserManager.d.ts +32 -0
  26. package/dist/managers/user/GuildUserManager.js +106 -0
  27. package/dist/rest/APIEndpoints.d.ts +11 -0
  28. package/dist/rest/APIEndpoints.js +12 -0
  29. package/dist/rest/REST.d.ts +51 -0
  30. package/dist/rest/REST.js +96 -0
  31. package/dist/rest/Routes.d.ts +84 -0
  32. package/dist/rest/Routes.js +89 -0
  33. package/dist/structures/Collection.d.ts +17 -0
  34. package/dist/structures/Collection.js +87 -0
  35. package/dist/structures/bet/GuildBet.d.ts +86 -0
  36. package/dist/structures/bet/GuildBet.js +276 -0
  37. package/dist/structures/betuser/GuildBetUser.d.ts +82 -0
  38. package/dist/structures/betuser/GuildBetUser.js +194 -0
  39. package/dist/structures/channel/Channel.d.ts +31 -0
  40. package/dist/structures/channel/Channel.js +57 -0
  41. package/dist/structures/groupedchannel/GroupedChannel.d.ts +34 -0
  42. package/dist/structures/groupedchannel/GroupedChannel.js +121 -0
  43. package/dist/structures/guild/Guild.d.ts +89 -0
  44. package/dist/structures/guild/Guild.js +223 -0
  45. package/dist/structures/match/GuildMatch.d.ts +84 -0
  46. package/dist/structures/match/GuildMatch.js +327 -0
  47. package/dist/structures/mediator/GuildMediator.d.ts +41 -0
  48. package/dist/structures/mediator/GuildMediator.js +131 -0
  49. package/dist/structures/product/GuildProduct.d.ts +52 -0
  50. package/dist/structures/product/GuildProduct.js +175 -0
  51. package/dist/structures/shop/GuildShop.d.ts +34 -0
  52. package/dist/structures/shop/GuildShop.js +80 -0
  53. package/dist/structures/ticket/GuildTicket.d.ts +51 -0
  54. package/dist/structures/ticket/GuildTicket.js +170 -0
  55. package/dist/structures/user/GuildUser.d.ts +82 -0
  56. package/dist/structures/user/GuildUser.js +209 -0
  57. package/dist/types/api/APIBaseChannel.d.ts +10 -0
  58. package/dist/types/api/APIBaseChannel.js +2 -0
  59. package/dist/types/api/APIBetChannel.d.ts +10 -0
  60. package/dist/types/api/APIBetChannel.js +2 -0
  61. package/dist/types/api/APIBetMessage.d.ts +10 -0
  62. package/dist/types/api/APIBetMessage.js +2 -0
  63. package/dist/types/api/APIGuild.d.ts +92 -0
  64. package/dist/types/api/APIGuild.js +2 -0
  65. package/dist/types/api/APIGuildBet.d.ts +48 -0
  66. package/dist/types/api/APIGuildBet.js +2 -0
  67. package/dist/types/api/APIGuildBetUser.d.ts +32 -0
  68. package/dist/types/api/APIGuildBetUser.js +2 -0
  69. package/dist/types/api/APIGuildChannel.d.ts +10 -0
  70. package/dist/types/api/APIGuildChannel.js +2 -0
  71. package/dist/types/api/APIGuildEmoji.d.ts +12 -0
  72. package/dist/types/api/APIGuildEmoji.js +2 -0
  73. package/dist/types/api/APIGuildGroupedChannel.d.ts +10 -0
  74. package/dist/types/api/APIGuildGroupedChannel.js +2 -0
  75. package/dist/types/api/APIGuildMatch.d.ts +46 -0
  76. package/dist/types/api/APIGuildMatch.js +2 -0
  77. package/dist/types/api/APIGuildMediator.d.ts +13 -0
  78. package/dist/types/api/APIGuildMediator.js +3 -0
  79. package/dist/types/api/APIGuildMessage.d.ts +10 -0
  80. package/dist/types/api/APIGuildMessage.js +2 -0
  81. package/dist/types/api/APIGuildPermissions.d.ts +6 -0
  82. package/dist/types/api/APIGuildPermissions.js +2 -0
  83. package/dist/types/api/APIGuildRole.d.ts +10 -0
  84. package/dist/types/api/APIGuildRole.js +2 -0
  85. package/dist/types/api/APIGuildShop.d.ts +11 -0
  86. package/dist/types/api/APIGuildShop.js +2 -0
  87. package/dist/types/api/APIGuildTicket.d.ts +25 -0
  88. package/dist/types/api/APIGuildTicket.js +3 -0
  89. package/dist/types/api/APIGuildUser.d.ts +31 -0
  90. package/dist/types/api/APIGuildUser.js +2 -0
  91. package/dist/types/api/APIMessage.d.ts +12 -0
  92. package/dist/types/api/APIMessage.js +2 -0
  93. package/dist/types/api/APIPlayer.d.ts +10 -0
  94. package/dist/types/api/APIPlayer.js +2 -0
  95. package/dist/types/api/APIProduct.d.ts +19 -0
  96. package/dist/types/api/APIProduct.js +3 -0
  97. package/dist/types/api/index.d.ts +130 -0
  98. package/dist/types/api/index.js +35 -0
  99. package/{src/types/index.ts → dist/types/index.d.ts} +21 -24
  100. package/dist/types/index.js +37 -0
  101. package/dist/utils/Assertion.d.ts +32 -0
  102. package/dist/utils/Assertion.js +60 -0
  103. package/package.json +5 -1
  104. package/.gitattributes +0 -2
  105. package/src/managers/bet/GuildBetManager.ts +0 -117
  106. package/src/managers/betuser/GuildBetUserManager.ts +0 -103
  107. package/src/managers/channel/ChannelManager.ts +0 -168
  108. package/src/managers/groupedchannel/GroupedChannelManager.ts +0 -117
  109. package/src/managers/guild/GuildManager.ts +0 -84
  110. package/src/managers/match/GuildMatchManager.ts +0 -115
  111. package/src/managers/mediator/GuildMediatorManager.ts +0 -111
  112. package/src/managers/messages/MessagesManager.ts +0 -95
  113. package/src/managers/permission/GuildPermissionManager.ts +0 -88
  114. package/src/managers/product/GuildProductManager.ts +0 -115
  115. package/src/managers/ticket/GuildTicketManager.ts +0 -112
  116. package/src/managers/user/GuildUserManager.ts +0 -116
  117. package/src/rest/APIEndpoints.ts +0 -11
  118. package/src/rest/REST.ts +0 -126
  119. package/src/rest/Routes.ts +0 -143
  120. package/src/structures/Collection.ts +0 -85
  121. package/src/structures/bet/GuildBet.ts +0 -332
  122. package/src/structures/betuser/GuildBetUser.ts +0 -247
  123. package/src/structures/channel/Channel.ts +0 -78
  124. package/src/structures/groupedchannel/GroupedChannel.ts +0 -165
  125. package/src/structures/guild/Guild.ts +0 -302
  126. package/src/structures/match/GuildMatch.ts +0 -385
  127. package/src/structures/mediator/GuildMediator.ts +0 -175
  128. package/src/structures/product/GuildProduct.ts +0 -217
  129. package/src/structures/shop/GuildShop.ts +0 -98
  130. package/src/structures/ticket/GuildTicket.ts +0 -227
  131. package/src/structures/user/GuildUser.ts +0 -248
  132. package/src/types/api/APIBaseChannel.ts +0 -13
  133. package/src/types/api/APIBetChannel.ts +0 -13
  134. package/src/types/api/APIBetMessage.ts +0 -13
  135. package/src/types/api/APIGuild.ts +0 -123
  136. package/src/types/api/APIGuildBet.ts +0 -69
  137. package/src/types/api/APIGuildBetUser.ts +0 -46
  138. package/src/types/api/APIGuildChannel.ts +0 -13
  139. package/src/types/api/APIGuildEmoji.ts +0 -16
  140. package/src/types/api/APIGuildGroupedChannel.ts +0 -13
  141. package/src/types/api/APIGuildMatch.ts +0 -67
  142. package/src/types/api/APIGuildMediator.ts +0 -18
  143. package/src/types/api/APIGuildMessage.ts +0 -13
  144. package/src/types/api/APIGuildPermissions.ts +0 -7
  145. package/src/types/api/APIGuildRole.ts +0 -13
  146. package/src/types/api/APIGuildShop.ts +0 -15
  147. package/src/types/api/APIGuildTicket.ts +0 -36
  148. package/src/types/api/APIGuildUser.ts +0 -45
  149. package/src/types/api/APIMessage.ts +0 -16
  150. package/src/types/api/APIPlayer.ts +0 -13
  151. package/src/types/api/APIProduct.ts +0 -27
  152. package/src/types/api/index.ts +0 -180
  153. package/src/utils/Assertion.ts +0 -56
  154. package/src/v1/managers/channel/ChannelManager.ts +0 -167
  155. package/src/v1/managers/match/GuildMatchManager.ts +0 -114
  156. package/tests/index.ts +0 -86
  157. package/tsconfig.json +0 -15
@@ -1,103 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { GuildBetUser } from "../../structures/betuser/GuildBetUser";
4
- import { Collection } from "../../structures/Collection";
5
- import { Guild } from "../../structures/guild/Guild";
6
- import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
7
- import { Assertion } from "../../utils/Assertion";
8
-
9
- export class GuildBetUserManager {
10
- /** A cache of users */
11
- cache: Collection<string, GuildBetUser>;
12
-
13
- /** The rest client */
14
- rest: REST;
15
-
16
- /** Bet user guild */
17
- guild: Guild;
18
- /**
19
- * Manage users with the given client
20
- * @param users An array of users
21
- * @param rest The rest client
22
- */
23
- constructor(guild: Guild, rest: REST) {
24
- this.guild = guild;
25
- this.rest = rest;
26
-
27
- this.cache = new Collection<string, GuildBetUser>("betUsers");
28
- }
29
- set(data: APIGuildBetUser): Collection<string, GuildBetUser> {
30
- if (!data.id) return;
31
- const user = new GuildBetUser(data, this, this.rest);
32
- this.rest.betUsers.set(user.id, user);
33
- return this.cache.set(user.id, user);
34
- }
35
- setAll(data: APIGuildBetUser[]): Collection<string, GuildBetUser> {
36
- if (!data) return this.cache;
37
- for (let user of data) this.set(user);
38
- return this.cache;
39
- }
40
- /**
41
- * Fetch a user
42
- * @param id Id of the user to fetch
43
- * @returns GuildBetUser
44
- */
45
- async fetch(id: string, name: string): Promise<GuildBetUser> {
46
- const route = Routes.guilds.betUsers.get(this.guild.id, id);
47
- const response = await this.rest.request<APIGuildBetUser, { name: string }>(
48
- {
49
- method: "get",
50
- url: route,
51
- payload: { name },
52
- }
53
- );
54
- if (!response) return this.cache.get(id);
55
-
56
- const user = new GuildBetUser(response, this, this.rest);
57
- this.cache.set(user?.id, user);
58
- this.rest.betUsers.set(user?.id, user);
59
-
60
- return user;
61
- }
62
-
63
- async fetchAll(): Promise<Collection<string, GuildBetUser>> {
64
- const route = Routes.guilds.betUsers.getAll(this.guild.id);
65
- const response = await this.rest.request<APIGuildBetUser[], {}>({
66
- method: "get",
67
- url: route,
68
- });
69
- if (Array.isArray(response) && response.length === 0) {
70
- this.cache.clear();
71
- return this.cache;
72
- }
73
- this.setAll(response);
74
- return this.cache;
75
- }
76
-
77
- async delete(id: string) {
78
- Assertion.assertString(id);
79
-
80
- const route = Routes.guilds.betUsers.delete(id, this.guild.id);
81
- const betUser = this.cache.get(id);
82
- this.rest.emit("betDelete", betUser);
83
-
84
- await this.rest.request<boolean, {}>({
85
- method: "DELETE",
86
- url: route,
87
- });
88
-
89
- this.cache.delete(id);
90
- return this.cache;
91
- }
92
- async deleteAll() {
93
- const route = Routes.guilds.betUsers.deleteAll(this.guild.id);
94
- this.rest.emit("betsDelete", this.cache);
95
-
96
- const value = await this.rest.request<boolean, {}>({
97
- method: "DELETE",
98
- url: route,
99
- });
100
- this.cache.clear();
101
- return value;
102
- }
103
- }
@@ -1,168 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Route, Routes } from "../../rest/Routes";
3
- import { GuildBet } from "../../structures/bet/GuildBet";
4
- import { Channel } from "../../structures/channel/Channel";
5
- import { Collection } from "../../structures/Collection";
6
- import { Guild } from "../../structures/guild/Guild";
7
- import { GuildMatch } from "../../structures/match/GuildMatch";
8
- import { Optional } from "../../types/api";
9
- import { APIBaseChannel } from "../../types/api/APIBaseChannel";
10
-
11
- import { Assertion } from "../../utils/Assertion";
12
- type Channels = Optional<APIBaseChannel>;
13
-
14
- export class ChannelManager<Structure extends GuildBet | GuildMatch> {
15
- /** A cache of bet channels */
16
- cache: Collection<string, Channel<Structure>>;
17
-
18
- /** The rest client */
19
- rest: REST;
20
-
21
- /** GuildBet user guild */
22
- guild: Guild;
23
-
24
- /** The bet */
25
- structure: Structure;
26
-
27
- /** Base Url */
28
- baseUrl: string;
29
-
30
- /**
31
- * Manage channels of a bet
32
- * @param guild The guild at hand
33
- * @param bet The bet at hand
34
- * @param rest The rest client
35
- */
36
- constructor(guild: Guild, structure: Structure, rest: REST) {
37
- this.structure = structure;
38
- this.rest = rest;
39
- this.guild = guild;
40
- this.cache = new Collection<string, Channel<Structure>>("channels");
41
- this.baseUrl = Routes.guilds[structure.key as "bets"].resource(guild.id, structure._id, "channels");
42
- }
43
- async create(id: string, type: string): Promise<Channel<Structure>> {
44
- Assertion.assertString(id);
45
- Assertion.assertString(type);
46
-
47
- const route = this.baseUrl;
48
- const payload = { id, type };
49
- const response = await this.rest.request<APIBaseChannel, typeof payload>({
50
- method: "POST",
51
- url: route,
52
- payload,
53
- });
54
- const channel = this.set(response);
55
-
56
- this.rest.emit("channelCreate", channel);
57
- return channel;
58
- }
59
- async createMany(...channels: Channels[]) {
60
- Assertion.assertArray(channels);
61
- const route = Routes.fields(this.baseUrl, "bulk");
62
- const payload = { channels };
63
- const response = await this.rest.request<APIBaseChannel[], typeof payload>({
64
- method: "POST",
65
- url: route,
66
- payload,
67
- });
68
-
69
- this.rest.emit("channelBulkCreate", response);
70
- return this.setAll(response);
71
- }
72
- async deleteMany(...channels: Optional<APIBaseChannel>[]) {
73
- Assertion.assertArray(channels);
74
-
75
- const route = Routes.fields(this.baseUrl, "bulk");
76
- const payload = { channels };
77
- const response = await this.rest.request<APIBaseChannel[], typeof payload>({
78
- method: "DELETE",
79
- url: route,
80
- payload,
81
- });
82
- const channel = this.setAll(response);
83
-
84
- this.rest.emit("channelBulkDelete", channel);
85
- return channel;
86
- }
87
- setAll(data: APIBaseChannel[]): Collection<string, Channel<Structure>> {
88
- if (!data) return this.cache;
89
- for (let channelData of data) this.set(channelData);
90
- return this.cache;
91
- }
92
- set(data: APIBaseChannel): Channel<Structure> {
93
- if (!data.type) return;
94
- const channel = new Channel(
95
- {
96
- baseUrl: Routes.guilds[this.structure.key as "bets"].resource(this.guild.id, this.structure._id, "channels"),
97
- data: data,
98
- guild: this.guild,
99
- manager: this,
100
- },
101
- this.rest
102
- );
103
- this.cache.set(data.type, channel);
104
- return channel;
105
- }
106
- async update(type: string, payload: Optional<APIBaseChannel>): Promise<Channel<Structure>> {
107
- Assertion.assertString(type);
108
- Assertion.assertObject(payload);
109
-
110
- const route = Routes.fields(this.baseUrl, type);
111
- const response = await this.rest.request<APIBaseChannel, {}>({
112
- method: "PATCH",
113
- url: route,
114
- payload,
115
- });
116
- const channel = this.set(response);
117
- this.rest.emit("betUpdate", this.structure, this.structure);
118
- return channel;
119
- }
120
- async fetch(type: string): Promise<Channel<Structure>> {
121
- Assertion.assertString(type);
122
-
123
- const route = Routes.fields(this.baseUrl, type);
124
- const response = await this.rest.request<APIBaseChannel, {}>({
125
- method: "GET",
126
- url: route,
127
- });
128
-
129
- const channel = this.set(response);
130
- this.cache.set(channel.type, channel);
131
-
132
- return channel;
133
- }
134
- async fetchAll() {
135
- const response = await this.rest.request<APIBaseChannel[], {}>({
136
- method: "GET",
137
- url: this.baseUrl,
138
- });
139
- if (Array.isArray(response) && response.length === 0) {
140
- this.cache.clear();
141
- return this.cache;
142
- }
143
- for (let channelData of response) this.set(channelData);
144
- return this.cache;
145
- }
146
-
147
- async delete(type: string): Promise<Collection<string, Channel<Structure>>> {
148
- Assertion.assertString(type);
149
-
150
- const route = this.baseUrl;
151
- const response = await this.rest.request<APIBaseChannel[], {}>({
152
- method: "DELETE",
153
- url: Routes.fields(route, type),
154
- });
155
- this.cache.delete(type);
156
- return this.cache;
157
- }
158
-
159
- async deleteAll(): Promise<boolean> {
160
- const route = this.baseUrl;
161
- const value = await this.rest.request<boolean, {}>({
162
- method: "DELETE",
163
- url: route,
164
- });
165
- this.cache.clear();
166
- return value;
167
- }
168
- }
@@ -1,117 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { GroupedChannel } from "../../structures/groupedchannel/GroupedChannel";
4
- import { Collection } from "../../structures/Collection";
5
- import { Guild } from "../../structures/guild/Guild";
6
- import { Optional } from "../../types/api";
7
- import { APIGuildGroupedChannel } from "../../types/api/APIGuildGroupedChannel";
8
- import { Assertion } from "../../utils/Assertion";
9
-
10
- export class GroupedChannelManager {
11
- /** A cache of channels */
12
- cache: Collection<string, GroupedChannel>;
13
-
14
- /** Key */
15
- key: string;
16
-
17
- baseUrl: string;
18
-
19
- /** The rest client */
20
- rest: REST;
21
-
22
- /** GroupedChannel groupedChannel guild */
23
- guild: Guild;
24
- /**
25
- * Manage channels with the given client
26
- * @param channels An array of channels
27
- * @param rest The rest client
28
- */
29
- constructor(guild: Guild, key: string, rest: REST) {
30
- this.key = key;
31
- this.baseUrl = Routes.fields(Routes.guilds.get(guild?.id), key);
32
-
33
- this.cache = new Collection<string, GroupedChannel>("groupedChannels");
34
-
35
- this.guild = guild;
36
- this.rest = rest;
37
- }
38
- async delete(type: string) {
39
- const route = Routes.fields(this.baseUrl, type);
40
- const response = await this.rest.request<boolean, {}>({
41
- method: "delete",
42
- url: route,
43
- });
44
- this.cache.delete(type);
45
- return response;
46
- }
47
- async create(
48
- payload: Optional<APIGuildGroupedChannel>
49
- ): Promise<GroupedChannel> {
50
- Assertion.assertObject(payload);
51
-
52
- const route = this.baseUrl;
53
- const response = await this.rest.request<
54
- APIGuildGroupedChannel,
55
- typeof payload
56
- >({
57
- method: "POST",
58
- url: route,
59
- payload,
60
- });
61
- const groupedChannel = this.set(response);
62
- return groupedChannel;
63
- }
64
-
65
- /**
66
- * Fetch a groupedChannel
67
- * @param id Id of the groupedChannel to fetch
68
- * @returns APIgroupedChannelUser
69
- */
70
- async fetch(type: string) {
71
- const route = Routes.fields(this.baseUrl, type);
72
- const response = await this.rest.request<APIGuildGroupedChannel, {}>({
73
- method: "get",
74
- url: route,
75
- });
76
- const channel = this.set(response);
77
- this.cache.set(channel.type, channel);
78
-
79
- return channel;
80
- }
81
-
82
- async fetchAll() {
83
- const route = this.baseUrl;
84
- const response = await this.rest.request<APIGuildGroupedChannel[], {}>({
85
- method: "get",
86
- url: route,
87
- });
88
-
89
- for (let groupedChannelData of response) {
90
- const groupedChannel = new GroupedChannel(
91
- groupedChannelData,
92
- this.guild,
93
- this,
94
- this.rest
95
- );
96
- this.cache.set(groupedChannel.type, groupedChannel);
97
- }
98
- return this.cache;
99
- }
100
- setAll(data: APIGuildGroupedChannel[]) {
101
- if (!data) return this.cache;
102
- for (let groupedChannel of data) this.set(groupedChannel);
103
- return this.cache;
104
- }
105
-
106
- set(data: APIGuildGroupedChannel): GroupedChannel {
107
- if (!data?.type) return;
108
- const groupedChannel = new GroupedChannel(
109
- data,
110
- this.guild,
111
- this,
112
- this.rest
113
- );
114
- this.cache.set(data.type, groupedChannel);
115
- return groupedChannel;
116
- }
117
- }
@@ -1,84 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Collection } from "../../structures/Collection";
4
- import { Guild } from "../../structures/guild/Guild";
5
- import { APIGuild } from "../../types/api/APIGuild";
6
- import { Assertion } from "../../utils/Assertion";
7
-
8
- export class GuildManager {
9
- /** A cache of guilds */
10
- cache: Collection<string, Guild>;
11
-
12
- /** The rest client */
13
- rest: REST;
14
-
15
- /**
16
- * Manage guilds with the given client
17
- * @param guilds An array of guilds
18
- * @param rest The rest client
19
- */
20
- constructor(rest: REST) {
21
- this.cache = new Collection<string, Guild>("guilds");
22
- this.rest = rest;
23
- }
24
-
25
- /**
26
- * Fetch a guild
27
- * @param id Id of the guild to fetch
28
- * @returns APIGuild
29
- */
30
- async fetch(id: string): Promise<Guild> {
31
- const route = Routes.guilds.get(id);
32
- const response = await this.rest.request<APIGuild, {}>({
33
- method: "get",
34
- url: route,
35
- });
36
- const guild = new Guild(response, this.rest);
37
- this.cache.set(guild.id, guild);
38
- return guild;
39
- }
40
-
41
- async fetchAll() {
42
- const route = Routes.guilds.getAll();
43
- const response = await this.rest.request<APIGuild[], {}>({
44
- method: "get",
45
- url: route,
46
- });
47
-
48
- for (let guildData of response) {
49
- if (!guildData.id) continue;
50
- const guild = new Guild(guildData, this.rest);
51
-
52
- this.cache.set(guild.id, guild);
53
- this.rest.guilds.cache.set(guild.id, guild);
54
- }
55
- return this.cache;
56
- }
57
-
58
- async delete(id: string) {
59
- Assertion.assertString(id);
60
-
61
- const route = Routes.guilds.delete(id);
62
- const guild = this.cache.get(id);
63
- this.rest.emit("guildDelete", guild);
64
-
65
- await this.rest.request<boolean, {}>({
66
- method: "DELETE",
67
- url: route,
68
- });
69
-
70
- this.cache.delete(id);
71
- return this.cache;
72
- }
73
- async deleteAll() {
74
- const route = Routes.guilds.deleteAll();
75
- this.rest.emit("guildsDelete", this.cache);
76
-
77
- const value = await this.rest.request<boolean, {}>({
78
- method: "DELETE",
79
- url: route,
80
- });
81
- this.cache.clear();
82
- return value;
83
- }
84
- }
@@ -1,115 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { GuildMatch } from "../../structures/match/GuildMatch";
4
- import { Collection } from "../../structures/Collection";
5
- import { Guild } from "../../structures/guild/Guild";
6
- import { APIGuildMatch } from "../../types/api/APIGuildMatch";
7
- import { Optional } from "../../types/api";
8
- import { Assertion } from "../../utils/Assertion";
9
-
10
- export class GuildMatchManager {
11
- /** A cache of users */
12
- cache: Collection<string, GuildMatch>;
13
-
14
- /** The rest client */
15
- rest: REST;
16
-
17
- /** GuildMatch match guild */
18
- guild: Guild;
19
- /**
20
- * Manage users with the given client
21
- * @param users An array of users
22
- * @param rest The rest client
23
- */
24
- constructor(guild: Guild, rest: REST) {
25
- this.guild = guild;
26
-
27
- this.cache = new Collection<string, GuildMatch>("matches");
28
- this.rest = rest;
29
- }
30
-
31
- /**
32
- * Fetch a match
33
- * @param id Id of the match to fetch
34
- * @returns APIBetUser
35
- */
36
- async fetch(id: string) {
37
- const route = Routes.guilds.matches.get(this.guild.id, id);
38
- const response = await this.rest.request<APIGuildMatch, {}>({
39
- method: "get",
40
- url: route,
41
- });
42
- const match = new GuildMatch(response, this.guild, this, this.rest);
43
- this.cache.set(match._id, match);
44
- this.rest.matches.set(match._id, match);
45
-
46
- return match;
47
- }
48
-
49
- async fetchAll() {
50
- const route = Routes.guilds.matches.getAll(this.guild.id);
51
- const response = await this.rest.request<APIGuildMatch[], {}>({
52
- method: "get",
53
- url: route,
54
- });
55
- if (Array.isArray(response) && response.length === 0) {
56
- this.cache.clear();
57
- return this.cache;
58
- }
59
- this.setAll(response);
60
- return this.cache;
61
- }
62
- set(data: APIGuildMatch): GuildMatch {
63
- if (!data?._id) return;
64
- const match = new GuildMatch(data, this?.guild, this, this.rest);
65
-
66
- this.cache.set(data?._id, match);
67
- this.rest.matches.set(data?._id, match);
68
- return match;
69
- }
70
- setAll(data: APIGuildMatch[]) {
71
- if (!data) return this.cache;
72
- for (let match of data || []) this.set(match);
73
- return this.cache;
74
- }
75
-
76
- async create(payload: Optional<APIGuildMatch>): Promise<GuildMatch> {
77
- Assertion.assertObject(payload);
78
-
79
- const route = Routes.guilds.matches.create(this.guild.id);
80
- const response = await this.rest.request<APIGuildMatch, typeof payload>({
81
- method: "POST",
82
- url: route,
83
- payload,
84
- });
85
- const match = this.set(response);
86
- return match;
87
- }
88
-
89
- async delete(id: string) {
90
- Assertion.assertString(id);
91
-
92
- const route = Routes.guilds.matches.delete(id, this.guild.id);
93
- const match = this.cache.get(id);
94
- this.rest.emit("matchDelete", match);
95
-
96
- await this.rest.request<boolean, {}>({
97
- method: "DELETE",
98
- url: route,
99
- });
100
-
101
- this.cache.delete(id);
102
- return this.cache;
103
- }
104
- async deleteAll() {
105
- const route = Routes.guilds.matches.deleteAll(this.guild.id);
106
- this.rest.emit("matchesDelete", this.cache);
107
-
108
- const value = await this.rest.request<boolean, {}>({
109
- method: "DELETE",
110
- url: route,
111
- });
112
- this.cache.clear();
113
- return value;
114
- }
115
- }
@@ -1,111 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Routes } from "../../rest/Routes";
3
- import { Collection } from "../../structures/Collection";
4
- import { Guild } from "../../structures/guild/Guild";
5
- import { GuildMediator } from "../../structures/mediator/GuildMediator";
6
- import { Optional } from "../../types/api";
7
- import { APIGuildMediator } from "../../types/api/APIGuildMediator";
8
- import { Assertion } from "../../utils/Assertion";
9
-
10
- export class GuildMediatorManager {
11
- /** A cache of users */
12
- cache: Collection<string, GuildMediator>;
13
-
14
- /** The rest client */
15
- rest: REST;
16
-
17
- /** GuildMediator mediator guild */
18
- guild: Guild;
19
- /**
20
- * Manage users with the given client
21
- * @param users An array of users
22
- * @param rest The rest client
23
- */
24
- constructor(guild: Guild, rest: REST) {
25
- this.guild = guild;
26
- this.rest = rest;
27
-
28
- this.cache = new Collection<string, GuildMediator>("mediators");
29
- }
30
-
31
- async create(payload: Optional<APIGuildMediator>): Promise<GuildMediator> {
32
- Assertion.assertObject(payload);
33
-
34
- const route = Routes.guilds.mediators.create(this.guild.id);
35
- const response = await this.rest.request<APIGuildMediator, typeof payload>({
36
- method: "POST",
37
- url: route,
38
- });
39
- const mediator = this.set(response);
40
- return mediator;
41
- }
42
-
43
- /**
44
- * Fetch a mediator
45
- * @param id Id of the mediator to fetch
46
- * @returns APImediatorUser
47
- */
48
- async fetch(id: string) {
49
- const route = Routes.guilds.mediators.get(this.guild.id, id);
50
- const response = await this.rest.request<APIGuildMediator, {}>({
51
- method: "get",
52
- url: route,
53
- });
54
-
55
- const mediator = new GuildMediator(response, this.guild, this, this.rest);
56
- this.cache.set(mediator.id, mediator);
57
-
58
- return mediator;
59
- }
60
-
61
- async fetchAll() {
62
- const route = Routes.guilds.mediators.getAll(this.guild.id);
63
- const response = await this.rest.request<APIGuildMediator[], {}>({
64
- method: "get",
65
- url: route,
66
- });
67
-
68
- this.setAll(response);
69
- return this.cache;
70
- }
71
-
72
- set(data: APIGuildMediator): GuildMediator {
73
- if (!data.id) return;
74
- const mediator = new GuildMediator(data, this.guild, this, this.rest);
75
- this.cache.set(data.id, mediator);
76
- this.rest.mediators.set(mediator.id, mediator);
77
- return mediator;
78
- }
79
- setAll(data: APIGuildMediator[]) {
80
- if (!data) return this.cache;
81
- for (let mediator of data) this.set(mediator);
82
- return this.cache;
83
- }
84
-
85
- async delete(id: string) {
86
- Assertion.assertString(id);
87
-
88
- const route = Routes.guilds.mediators.delete(id, this.guild.id);
89
- const mediator = this.cache.get(id);
90
- this.rest.emit("mediatorDelete", mediator);
91
-
92
- await this.rest.request<boolean, {}>({
93
- method: "DELETE",
94
- url: route,
95
- });
96
-
97
- this.cache.delete(id);
98
- return this.cache;
99
- }
100
- async deleteAll() {
101
- const route = Routes.guilds.mediators.deleteAll(this.guild.id);
102
- this.rest.emit("mediatorsDelete", this.cache);
103
-
104
- const value = await this.rest.request<boolean, {}>({
105
- method: "DELETE",
106
- url: route,
107
- });
108
- this.cache.clear();
109
- return value;
110
- }
111
- }