@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,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupedChannelManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const GroupedChannel_1 = require("../../structures/groupedchannel/GroupedChannel");
6
+ const Collection_1 = require("../../structures/Collection");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GroupedChannelManager {
9
+ /** A cache of channels */
10
+ cache;
11
+ /** Key */
12
+ key;
13
+ baseUrl;
14
+ /** The rest client */
15
+ rest;
16
+ /** GroupedChannel groupedChannel guild */
17
+ guild;
18
+ /**
19
+ * Manage channels with the given client
20
+ * @param channels An array of channels
21
+ * @param rest The rest client
22
+ */
23
+ constructor(guild, key, rest) {
24
+ this.key = key;
25
+ this.baseUrl = Routes_1.Routes.fields(Routes_1.Routes.guilds.get(guild?.id), key);
26
+ this.cache = new Collection_1.Collection("groupedChannels");
27
+ this.guild = guild;
28
+ this.rest = rest;
29
+ }
30
+ async delete(type) {
31
+ const route = Routes_1.Routes.fields(this.baseUrl, type);
32
+ const response = await this.rest.request({
33
+ method: "delete",
34
+ url: route,
35
+ });
36
+ this.cache.delete(type);
37
+ return response;
38
+ }
39
+ async create(payload) {
40
+ Assertion_1.Assertion.assertObject(payload);
41
+ const route = this.baseUrl;
42
+ const response = await this.rest.request({
43
+ method: "POST",
44
+ url: route,
45
+ payload,
46
+ });
47
+ const groupedChannel = this.set(response);
48
+ return groupedChannel;
49
+ }
50
+ /**
51
+ * Fetch a groupedChannel
52
+ * @param id Id of the groupedChannel to fetch
53
+ * @returns APIgroupedChannelUser
54
+ */
55
+ async fetch(type) {
56
+ const route = Routes_1.Routes.fields(this.baseUrl, type);
57
+ const response = await this.rest.request({
58
+ method: "get",
59
+ url: route,
60
+ });
61
+ const channel = this.set(response);
62
+ this.cache.set(channel.type, channel);
63
+ return channel;
64
+ }
65
+ async fetchAll() {
66
+ const route = this.baseUrl;
67
+ const response = await this.rest.request({
68
+ method: "get",
69
+ url: route,
70
+ });
71
+ for (let groupedChannelData of response) {
72
+ const groupedChannel = new GroupedChannel_1.GroupedChannel(groupedChannelData, this.guild, this, this.rest);
73
+ this.cache.set(groupedChannel.type, groupedChannel);
74
+ }
75
+ return this.cache;
76
+ }
77
+ setAll(data) {
78
+ if (!data)
79
+ return this.cache;
80
+ for (let groupedChannel of data)
81
+ this.set(groupedChannel);
82
+ return this.cache;
83
+ }
84
+ set(data) {
85
+ if (!data?.type)
86
+ return;
87
+ const groupedChannel = new GroupedChannel_1.GroupedChannel(data, this.guild, this, this.rest);
88
+ this.cache.set(data.type, groupedChannel);
89
+ return groupedChannel;
90
+ }
91
+ }
92
+ exports.GroupedChannelManager = GroupedChannelManager;
@@ -0,0 +1,24 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { Collection } from "../../structures/Collection";
3
+ import { Guild } from "../../structures/guild/Guild";
4
+ export declare class GuildManager {
5
+ /** A cache of guilds */
6
+ cache: Collection<string, Guild>;
7
+ /** The rest client */
8
+ rest: REST;
9
+ /**
10
+ * Manage guilds with the given client
11
+ * @param guilds An array of guilds
12
+ * @param rest The rest client
13
+ */
14
+ constructor(rest: REST);
15
+ /**
16
+ * Fetch a guild
17
+ * @param id Id of the guild to fetch
18
+ * @returns APIGuild
19
+ */
20
+ fetch(id: string): Promise<Guild>;
21
+ fetchAll(): Promise<Collection<string, Guild>>;
22
+ delete(id: string): Promise<Collection<string, Guild>>;
23
+ deleteAll(): Promise<boolean>;
24
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const Collection_1 = require("../../structures/Collection");
6
+ const Guild_1 = require("../../structures/guild/Guild");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GuildManager {
9
+ /** A cache of guilds */
10
+ cache;
11
+ /** The rest client */
12
+ rest;
13
+ /**
14
+ * Manage guilds with the given client
15
+ * @param guilds An array of guilds
16
+ * @param rest The rest client
17
+ */
18
+ constructor(rest) {
19
+ this.cache = new Collection_1.Collection("guilds");
20
+ this.rest = rest;
21
+ }
22
+ /**
23
+ * Fetch a guild
24
+ * @param id Id of the guild to fetch
25
+ * @returns APIGuild
26
+ */
27
+ async fetch(id) {
28
+ const route = Routes_1.Routes.guilds.get(id);
29
+ const response = await this.rest.request({
30
+ method: "get",
31
+ url: route,
32
+ });
33
+ const guild = new Guild_1.Guild(response, this.rest);
34
+ this.cache.set(guild.id, guild);
35
+ return guild;
36
+ }
37
+ async fetchAll() {
38
+ const route = Routes_1.Routes.guilds.getAll();
39
+ const response = await this.rest.request({
40
+ method: "get",
41
+ url: route,
42
+ });
43
+ for (let guildData of response) {
44
+ if (!guildData.id)
45
+ continue;
46
+ const guild = new Guild_1.Guild(guildData, this.rest);
47
+ this.cache.set(guild.id, guild);
48
+ this.rest.guilds.cache.set(guild.id, guild);
49
+ }
50
+ return this.cache;
51
+ }
52
+ async delete(id) {
53
+ Assertion_1.Assertion.assertString(id);
54
+ const route = Routes_1.Routes.guilds.delete(id);
55
+ const guild = this.cache.get(id);
56
+ this.rest.emit("guildDelete", guild);
57
+ await this.rest.request({
58
+ method: "DELETE",
59
+ url: route,
60
+ });
61
+ this.cache.delete(id);
62
+ return this.cache;
63
+ }
64
+ async deleteAll() {
65
+ const route = Routes_1.Routes.guilds.deleteAll();
66
+ this.rest.emit("guildsDelete", this.cache);
67
+ const value = await this.rest.request({
68
+ method: "DELETE",
69
+ url: route,
70
+ });
71
+ this.cache.clear();
72
+ return value;
73
+ }
74
+ }
75
+ exports.GuildManager = GuildManager;
@@ -0,0 +1,32 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { GuildMatch } from "../../structures/match/GuildMatch";
3
+ import { Collection } from "../../structures/Collection";
4
+ import { Guild } from "../../structures/guild/Guild";
5
+ import { APIGuildMatch } from "../../types/api/APIGuildMatch";
6
+ import { Optional } from "../../types/api";
7
+ export declare class GuildMatchManager {
8
+ /** A cache of users */
9
+ cache: Collection<string, GuildMatch>;
10
+ /** The rest client */
11
+ rest: REST;
12
+ /** GuildMatch match 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 match
22
+ * @param id Id of the match to fetch
23
+ * @returns APIBetUser
24
+ */
25
+ fetch(id: string): Promise<GuildMatch>;
26
+ fetchAll(): Promise<Collection<string, GuildMatch>>;
27
+ set(data: APIGuildMatch): GuildMatch;
28
+ setAll(data: APIGuildMatch[]): Collection<string, GuildMatch>;
29
+ create(payload: Optional<APIGuildMatch>): Promise<GuildMatch>;
30
+ delete(id: string): Promise<Collection<string, GuildMatch>>;
31
+ deleteAll(): Promise<boolean>;
32
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildMatchManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const GuildMatch_1 = require("../../structures/match/GuildMatch");
6
+ const Collection_1 = require("../../structures/Collection");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GuildMatchManager {
9
+ /** A cache of users */
10
+ cache;
11
+ /** The rest client */
12
+ rest;
13
+ /** GuildMatch match 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.cache = new Collection_1.Collection("matches");
23
+ this.rest = rest;
24
+ }
25
+ /**
26
+ * Fetch a match
27
+ * @param id Id of the match to fetch
28
+ * @returns APIBetUser
29
+ */
30
+ async fetch(id) {
31
+ const route = Routes_1.Routes.guilds.matches.get(this.guild.id, id);
32
+ const response = await this.rest.request({
33
+ method: "get",
34
+ url: route,
35
+ });
36
+ const match = new GuildMatch_1.GuildMatch(response, this.guild, this, this.rest);
37
+ this.cache.set(match._id, match);
38
+ this.rest.matches.set(match._id, match);
39
+ return match;
40
+ }
41
+ async fetchAll() {
42
+ const route = Routes_1.Routes.guilds.matches.getAll(this.guild.id);
43
+ const response = await this.rest.request({
44
+ method: "get",
45
+ url: route,
46
+ });
47
+ if (Array.isArray(response) && response.length === 0) {
48
+ this.cache.clear();
49
+ return this.cache;
50
+ }
51
+ this.setAll(response);
52
+ return this.cache;
53
+ }
54
+ set(data) {
55
+ if (!data?._id)
56
+ return;
57
+ const match = new GuildMatch_1.GuildMatch(data, this?.guild, this, this.rest);
58
+ this.cache.set(data?._id, match);
59
+ this.rest.matches.set(data?._id, match);
60
+ return match;
61
+ }
62
+ setAll(data) {
63
+ if (!data)
64
+ return this.cache;
65
+ for (let match of data || [])
66
+ this.set(match);
67
+ return this.cache;
68
+ }
69
+ async create(payload) {
70
+ Assertion_1.Assertion.assertObject(payload);
71
+ const route = Routes_1.Routes.guilds.matches.create(this.guild.id);
72
+ const response = await this.rest.request({
73
+ method: "POST",
74
+ url: route,
75
+ payload,
76
+ });
77
+ const match = this.set(response);
78
+ return match;
79
+ }
80
+ async delete(id) {
81
+ Assertion_1.Assertion.assertString(id);
82
+ const route = Routes_1.Routes.guilds.matches.delete(id, this.guild.id);
83
+ const match = this.cache.get(id);
84
+ this.rest.emit("matchDelete", match);
85
+ await this.rest.request({
86
+ method: "DELETE",
87
+ url: route,
88
+ });
89
+ this.cache.delete(id);
90
+ return this.cache;
91
+ }
92
+ async deleteAll() {
93
+ const route = Routes_1.Routes.guilds.matches.deleteAll(this.guild.id);
94
+ this.rest.emit("matchesDelete", this.cache);
95
+ const value = await this.rest.request({
96
+ method: "DELETE",
97
+ url: route,
98
+ });
99
+ this.cache.clear();
100
+ return value;
101
+ }
102
+ }
103
+ exports.GuildMatchManager = GuildMatchManager;
@@ -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 { GuildMediator } from "../../structures/mediator/GuildMediator";
5
+ import { Optional } from "../../types/api";
6
+ import { APIGuildMediator } from "../../types/api/APIGuildMediator";
7
+ export declare class GuildMediatorManager {
8
+ /** A cache of users */
9
+ cache: Collection<string, GuildMediator>;
10
+ /** The rest client */
11
+ rest: REST;
12
+ /** GuildMediator mediator 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<APIGuildMediator>): Promise<GuildMediator>;
21
+ /**
22
+ * Fetch a mediator
23
+ * @param id Id of the mediator to fetch
24
+ * @returns APImediatorUser
25
+ */
26
+ fetch(id: string): Promise<GuildMediator>;
27
+ fetchAll(): Promise<Collection<string, GuildMediator>>;
28
+ set(data: APIGuildMediator): GuildMediator;
29
+ setAll(data: APIGuildMediator[]): Collection<string, GuildMediator>;
30
+ delete(id: string): Promise<Collection<string, GuildMediator>>;
31
+ deleteAll(): Promise<boolean>;
32
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildMediatorManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const Collection_1 = require("../../structures/Collection");
6
+ const GuildMediator_1 = require("../../structures/mediator/GuildMediator");
7
+ const Assertion_1 = require("../../utils/Assertion");
8
+ class GuildMediatorManager {
9
+ /** A cache of users */
10
+ cache;
11
+ /** The rest client */
12
+ rest;
13
+ /** GuildMediator mediator 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("mediators");
24
+ }
25
+ async create(payload) {
26
+ Assertion_1.Assertion.assertObject(payload);
27
+ const route = Routes_1.Routes.guilds.mediators.create(this.guild.id);
28
+ const response = await this.rest.request({
29
+ method: "POST",
30
+ url: route,
31
+ });
32
+ const mediator = this.set(response);
33
+ return mediator;
34
+ }
35
+ /**
36
+ * Fetch a mediator
37
+ * @param id Id of the mediator to fetch
38
+ * @returns APImediatorUser
39
+ */
40
+ async fetch(id) {
41
+ const route = Routes_1.Routes.guilds.mediators.get(this.guild.id, id);
42
+ const response = await this.rest.request({
43
+ method: "get",
44
+ url: route,
45
+ });
46
+ const mediator = new GuildMediator_1.GuildMediator(response, this.guild, this, this.rest);
47
+ this.cache.set(mediator.id, mediator);
48
+ return mediator;
49
+ }
50
+ async fetchAll() {
51
+ const route = Routes_1.Routes.guilds.mediators.getAll(this.guild.id);
52
+ const response = await this.rest.request({
53
+ method: "get",
54
+ url: route,
55
+ });
56
+ this.setAll(response);
57
+ return this.cache;
58
+ }
59
+ set(data) {
60
+ if (!data.id)
61
+ return;
62
+ const mediator = new GuildMediator_1.GuildMediator(data, this.guild, this, this.rest);
63
+ this.cache.set(data.id, mediator);
64
+ this.rest.mediators.set(mediator.id, mediator);
65
+ return mediator;
66
+ }
67
+ setAll(data) {
68
+ if (!data)
69
+ return this.cache;
70
+ for (let mediator of data)
71
+ this.set(mediator);
72
+ return this.cache;
73
+ }
74
+ async delete(id) {
75
+ Assertion_1.Assertion.assertString(id);
76
+ const route = Routes_1.Routes.guilds.mediators.delete(id, this.guild.id);
77
+ const mediator = this.cache.get(id);
78
+ this.rest.emit("mediatorDelete", mediator);
79
+ await this.rest.request({
80
+ method: "DELETE",
81
+ url: route,
82
+ });
83
+ this.cache.delete(id);
84
+ return this.cache;
85
+ }
86
+ async deleteAll() {
87
+ const route = Routes_1.Routes.guilds.mediators.deleteAll(this.guild.id);
88
+ this.rest.emit("mediatorsDelete", this.cache);
89
+ const value = await this.rest.request({
90
+ method: "DELETE",
91
+ url: route,
92
+ });
93
+ this.cache.clear();
94
+ return value;
95
+ }
96
+ }
97
+ exports.GuildMediatorManager = GuildMediatorManager;
@@ -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 { Optional } from "../../types/api";
5
+ import { APIMessage } from "../../types/api/APIMessage";
6
+ export declare class MessagesManager {
7
+ /** A cache of messages */
8
+ cache: Collection<string, APIMessage>;
9
+ /** Key */
10
+ key: string;
11
+ baseUrl: string;
12
+ /** The rest client */
13
+ rest: REST;
14
+ /** APIMessage message guild */
15
+ guild: Guild;
16
+ /**
17
+ * Manage messages with the given client
18
+ * @param messages An array of messages
19
+ * @param rest The rest client
20
+ */
21
+ constructor(guild: Guild, key: string, rest: REST);
22
+ create(payload: Optional<APIMessage>): Promise<APIMessage>;
23
+ /**
24
+ * Fetch a message
25
+ * @param id Id of the message to fetch
26
+ * @returns APIgroupedChannelUser
27
+ */
28
+ fetch(type: string): Promise<APIMessage>;
29
+ fetchAll(): Promise<Collection<string, APIMessage>>;
30
+ set(data: APIMessage): APIMessage;
31
+ setAll(data: APIMessage[]): Collection<string, APIMessage>;
32
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessagesManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ const Collection_1 = require("../../structures/Collection");
6
+ const Assertion_1 = require("../../utils/Assertion");
7
+ class MessagesManager {
8
+ /** A cache of messages */
9
+ cache;
10
+ /** Key */
11
+ key;
12
+ baseUrl;
13
+ /** The rest client */
14
+ rest;
15
+ /** APIMessage message guild */
16
+ guild;
17
+ /**
18
+ * Manage messages with the given client
19
+ * @param messages An array of messages
20
+ * @param rest The rest client
21
+ */
22
+ constructor(guild, key, rest) {
23
+ this.guild = guild;
24
+ this.key = key;
25
+ this.baseUrl = Routes_1.Routes.fields(Routes_1.Routes.guilds.get(guild?.id), key, "messages");
26
+ this.cache = new Collection_1.Collection(`${key}-messages`);
27
+ this.rest = rest;
28
+ }
29
+ async create(payload) {
30
+ Assertion_1.Assertion.assertObject(payload);
31
+ const route = this.baseUrl;
32
+ const response = await this.rest.request({
33
+ method: "POST",
34
+ url: route,
35
+ payload,
36
+ });
37
+ const message = this.set(response);
38
+ return message;
39
+ }
40
+ /**
41
+ * Fetch a message
42
+ * @param id Id of the message to fetch
43
+ * @returns APIgroupedChannelUser
44
+ */
45
+ async fetch(type) {
46
+ const route = Routes_1.Routes.fields(this.baseUrl, type);
47
+ const response = await this.rest.request({
48
+ method: "get",
49
+ url: route,
50
+ });
51
+ const channel = this.set(response);
52
+ this.cache.set(channel.type, channel);
53
+ return channel;
54
+ }
55
+ async fetchAll() {
56
+ const route = this.baseUrl;
57
+ const response = await this.rest.request({
58
+ method: "get",
59
+ url: route,
60
+ });
61
+ for (let data of response) {
62
+ if (!data.type)
63
+ continue;
64
+ this.cache.set(data?.type, data);
65
+ }
66
+ return this.cache;
67
+ }
68
+ set(data) {
69
+ if (!data?.type)
70
+ return;
71
+ this.cache.set(data?.type, data);
72
+ return data;
73
+ }
74
+ setAll(data) {
75
+ if (!data)
76
+ return this.cache;
77
+ for (let message of data)
78
+ this.set(message);
79
+ return this.cache;
80
+ }
81
+ }
82
+ exports.MessagesManager = MessagesManager;
@@ -0,0 +1,26 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { Guild } from "../../structures/guild/Guild";
3
+ import { APIGuildPermissions } from "../../types/api/APIGuildPermissions";
4
+ export declare class GuildPermissionManager {
5
+ /** The rest client */
6
+ rest: REST;
7
+ /** GuildBet bet guild */
8
+ guild: Guild;
9
+ permissions: APIGuildPermissions;
10
+ /**
11
+ * Manage users with the given client
12
+ * @param users An array of users
13
+ * @param rest The rest client
14
+ */
15
+ constructor(guild: Guild, rest: REST);
16
+ /**
17
+ * Fetch a bet
18
+ * @param id Id of the bet to fetch
19
+ * @returns APIBetUser
20
+ */
21
+ fetch(): Promise<void>;
22
+ addId(permissionId: keyof APIGuildPermissions, roleId: string): Promise<string[]>;
23
+ removeId(permissionId: keyof APIGuildPermissions, roleId: string): Promise<string[]>;
24
+ setAll(data: APIGuildPermissions): APIGuildPermissions;
25
+ toJSON(): Record<string, unknown>;
26
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildPermissionManager = void 0;
4
+ const Routes_1 = require("../../rest/Routes");
5
+ class GuildPermissionManager {
6
+ /** The rest client */
7
+ rest;
8
+ /** GuildBet bet guild */
9
+ guild;
10
+ permissions;
11
+ /**
12
+ * Manage users with the given client
13
+ * @param users An array of users
14
+ * @param rest The rest client
15
+ */
16
+ constructor(guild, rest) {
17
+ this.guild = guild;
18
+ this.rest = rest;
19
+ }
20
+ /**
21
+ * Fetch a bet
22
+ * @param id Id of the bet to fetch
23
+ * @returns APIBetUser
24
+ */
25
+ async fetch() {
26
+ const route = Routes_1.Routes.guilds.resource(this.guild.id, "permissions");
27
+ const response = await this.rest.request({
28
+ method: "get",
29
+ url: route,
30
+ });
31
+ this.setAll(response);
32
+ }
33
+ async addId(permissionId, roleId) {
34
+ const route = Routes_1.Routes.guilds.resources(this.guild.id, "permissions", permissionId, "ids");
35
+ const payload = { id: roleId };
36
+ const response = await this.rest.request({
37
+ method: "post",
38
+ url: route,
39
+ payload,
40
+ });
41
+ this.permissions[permissionId] = response;
42
+ return response;
43
+ }
44
+ async removeId(permissionId, roleId) {
45
+ const route = Routes_1.Routes.guilds.resources(this.guild.id, "permissions", permissionId, "ids", roleId);
46
+ const payload = { id: roleId };
47
+ const response = await this.rest.request({
48
+ method: "delete",
49
+ url: route,
50
+ payload,
51
+ });
52
+ this.permissions[permissionId] = response;
53
+ return response;
54
+ }
55
+ setAll(data) {
56
+ if (!data)
57
+ return this.permissions;
58
+ this.permissions = data;
59
+ }
60
+ toJSON() {
61
+ const json = {};
62
+ for (const [key, value] of Object.entries(this)) {
63
+ if (typeof value !== "function") {
64
+ json[key] = value;
65
+ }
66
+ }
67
+ return json;
68
+ }
69
+ }
70
+ exports.GuildPermissionManager = GuildPermissionManager;