@duque.edits/sdk 0.0.1

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 (57) hide show
  1. package/.gitattributes +2 -0
  2. package/LICENSE +21 -0
  3. package/README.md +16 -0
  4. package/package.json +46 -0
  5. package/src/index.ts +30 -0
  6. package/src/managers/bet/GuildBetManager.ts +117 -0
  7. package/src/managers/betuser/GuildBetUserManager.ts +103 -0
  8. package/src/managers/channel/ChannelManager.ts +168 -0
  9. package/src/managers/groupedchannel/GroupedChannelManager.ts +117 -0
  10. package/src/managers/guild/GuildManager.ts +84 -0
  11. package/src/managers/match/GuildMatchManager.ts +115 -0
  12. package/src/managers/mediator/GuildMediatorManager.ts +111 -0
  13. package/src/managers/messages/MessagesManager.ts +95 -0
  14. package/src/managers/permission/GuildPermissionManager.ts +88 -0
  15. package/src/managers/product/GuildProductManager.ts +115 -0
  16. package/src/managers/ticket/GuildTicketManager.ts +112 -0
  17. package/src/managers/user/GuildUserManager.ts +116 -0
  18. package/src/rest/APIEndpoints.ts +11 -0
  19. package/src/rest/REST.ts +126 -0
  20. package/src/rest/Routes.ts +143 -0
  21. package/src/structures/Collection.ts +85 -0
  22. package/src/structures/bet/GuildBet.ts +332 -0
  23. package/src/structures/betuser/GuildBetUser.ts +247 -0
  24. package/src/structures/channel/Channel.ts +78 -0
  25. package/src/structures/groupedchannel/GroupedChannel.ts +165 -0
  26. package/src/structures/guild/Guild.ts +302 -0
  27. package/src/structures/match/GuildMatch.ts +385 -0
  28. package/src/structures/mediator/GuildMediator.ts +175 -0
  29. package/src/structures/product/GuildProduct.ts +217 -0
  30. package/src/structures/shop/GuildShop.ts +98 -0
  31. package/src/structures/ticket/GuildTicket.ts +227 -0
  32. package/src/structures/user/GuildUser.ts +248 -0
  33. package/src/types/api/APIBaseChannel.ts +13 -0
  34. package/src/types/api/APIBetChannel.ts +13 -0
  35. package/src/types/api/APIBetMessage.ts +13 -0
  36. package/src/types/api/APIGuild.ts +123 -0
  37. package/src/types/api/APIGuildBet.ts +69 -0
  38. package/src/types/api/APIGuildBetUser.ts +46 -0
  39. package/src/types/api/APIGuildChannel.ts +13 -0
  40. package/src/types/api/APIGuildEmoji.ts +16 -0
  41. package/src/types/api/APIGuildGroupedChannel.ts +13 -0
  42. package/src/types/api/APIGuildMatch.ts +67 -0
  43. package/src/types/api/APIGuildMediator.ts +18 -0
  44. package/src/types/api/APIGuildMessage.ts +13 -0
  45. package/src/types/api/APIGuildPermissions.ts +7 -0
  46. package/src/types/api/APIGuildRole.ts +13 -0
  47. package/src/types/api/APIGuildShop.ts +15 -0
  48. package/src/types/api/APIGuildTicket.ts +36 -0
  49. package/src/types/api/APIGuildUser.ts +45 -0
  50. package/src/types/api/APIMessage.ts +16 -0
  51. package/src/types/api/APIPlayer.ts +13 -0
  52. package/src/types/api/APIProduct.ts +27 -0
  53. package/src/types/api/index.ts +180 -0
  54. package/src/types/index.ts +24 -0
  55. package/src/utils/Assertion.ts +56 -0
  56. package/tests/index.ts +86 -0
  57. package/tsconfig.json +15 -0
@@ -0,0 +1,84 @@
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
+ }
@@ -0,0 +1,115 @@
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
+ }
@@ -0,0 +1,111 @@
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
+ }
@@ -0,0 +1,95 @@
1
+ import { REST } from "../../rest/REST";
2
+ import { Routes } from "../../rest/Routes";
3
+ import { GuildBet } from "../../structures/bet/GuildBet";
4
+ import { Collection } from "../../structures/Collection";
5
+ import { Guild } from "../../structures/guild/Guild";
6
+ import { GuildMatch } from "../../structures/match/GuildMatch";
7
+ import { GuildTicket } from "../../structures/ticket/GuildTicket";
8
+ import { Optional } from "../../types/api";
9
+ import { APIMessage } from "../../types/api/APIMessage";
10
+ import { Assertion } from "../../utils/Assertion";
11
+
12
+ export class MessagesManager {
13
+ /** A cache of messages */
14
+ cache: Collection<string, APIMessage>;
15
+
16
+ /** Key */
17
+ key: string;
18
+
19
+ baseUrl: string;
20
+
21
+ /** The rest client */
22
+ rest: REST;
23
+
24
+ /** APIMessage message guild */
25
+ guild: Guild;
26
+ /**
27
+ * Manage messages with the given client
28
+ * @param messages An array of messages
29
+ * @param rest The rest client
30
+ */
31
+ constructor(guild: Guild, key: string, rest: REST) {
32
+ this.guild = guild;
33
+
34
+ this.key = key;
35
+ this.baseUrl = Routes.fields(Routes.guilds.get(guild?.id), key, "messages");
36
+
37
+ this.cache = new Collection<string, APIMessage>(`${key}-messages`);
38
+
39
+ this.rest = rest;
40
+ }
41
+ async create(payload: Optional<APIMessage>): Promise<APIMessage> {
42
+ Assertion.assertObject(payload);
43
+
44
+ const route = this.baseUrl;
45
+ const response = await this.rest.request<APIMessage, typeof payload>({
46
+ method: "POST",
47
+ url: route,
48
+ payload,
49
+ });
50
+ const message = this.set(response);
51
+ return message;
52
+ }
53
+
54
+ /**
55
+ * Fetch a message
56
+ * @param id Id of the message to fetch
57
+ * @returns APIgroupedChannelUser
58
+ */
59
+ async fetch(type: string) {
60
+ const route = Routes.fields(this.baseUrl, type);
61
+ const response = await this.rest.request<APIMessage, {}>({
62
+ method: "get",
63
+ url: route,
64
+ });
65
+ const channel = this.set(response);
66
+ this.cache.set(channel.type, channel);
67
+
68
+ return channel;
69
+ }
70
+
71
+ async fetchAll() {
72
+ const route = this.baseUrl;
73
+ const response = await this.rest.request<APIMessage[], {}>({
74
+ method: "get",
75
+ url: route,
76
+ });
77
+
78
+ for (let data of response) {
79
+ if (!data.type) continue;
80
+ this.cache.set(data?.type, data);
81
+ }
82
+ return this.cache;
83
+ }
84
+
85
+ set(data: APIMessage): APIMessage {
86
+ if (!data?.type) return;
87
+ this.cache.set(data?.type, data);
88
+ return data;
89
+ }
90
+ setAll(data: APIMessage[]) {
91
+ if (!data) return this.cache;
92
+ for (let message of data) this.set(message);
93
+ return this.cache;
94
+ }
95
+ }
@@ -0,0 +1,88 @@
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 { Optional } from "../../types/api";
6
+ import { APIGuild } from "../../types/api/APIGuild";
7
+ import { APIGuildPermissions } from "../../types/api/APIGuildPermissions";
8
+ import { Assertion } from "../../utils/Assertion";
9
+
10
+ export class GuildPermissionManager {
11
+ /** The rest client */
12
+ rest: REST;
13
+
14
+ /** GuildBet bet guild */
15
+ guild: Guild;
16
+
17
+ permissions: APIGuildPermissions;
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
+
28
+ /**
29
+ * Fetch a bet
30
+ * @param id Id of the bet to fetch
31
+ * @returns APIBetUser
32
+ */
33
+ async fetch() {
34
+ const route = Routes.guilds.resource(this.guild.id, "permissions");
35
+ const response = await this.rest.request<APIGuildPermissions, {}>({
36
+ method: "get",
37
+ url: route,
38
+ });
39
+ this.setAll(response);
40
+ }
41
+ async addId(permissionId: keyof APIGuildPermissions, roleId: string) {
42
+ const route = Routes.guilds.resources(
43
+ this.guild.id,
44
+ "permissions",
45
+ permissionId,
46
+ "ids"
47
+ );
48
+ const payload = { id: roleId };
49
+ const response = await this.rest.request<string[], typeof payload>({
50
+ method: "post",
51
+ url: route,
52
+ payload,
53
+ });
54
+ this.permissions[permissionId] = response;
55
+ return response;
56
+ }
57
+ async removeId(permissionId: keyof APIGuildPermissions, roleId: string) {
58
+ const route = Routes.guilds.resources(
59
+ this.guild.id,
60
+ "permissions",
61
+ permissionId,
62
+ "ids",
63
+ roleId
64
+ );
65
+ const payload = { id: roleId };
66
+ const response = await this.rest.request<string[], typeof payload>({
67
+ method: "delete",
68
+ url: route,
69
+ payload,
70
+ });
71
+
72
+ this.permissions[permissionId] = response;
73
+ return response;
74
+ }
75
+ setAll(data: APIGuildPermissions) {
76
+ if (!data) return this.permissions;
77
+ this.permissions = data;
78
+ }
79
+ toJSON() {
80
+ const json: Record<string, unknown> = {};
81
+ for (const [key, value] of Object.entries(this)) {
82
+ if (typeof value !== "function") {
83
+ json[key] = value;
84
+ }
85
+ }
86
+ return json;
87
+ }
88
+ }
@@ -0,0 +1,115 @@
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 { GuildProduct } from "../../structures/product/GuildProduct";
6
+ import { Optional } from "../../types/api";
7
+ import { APIProduct } from "../../types/api/APIProduct";
8
+ import { Assertion } from "../../utils/Assertion";
9
+
10
+ export class GuildProductManager {
11
+ /** A cache of users */
12
+ cache: Collection<string, GuildProduct>;
13
+
14
+ /** The rest client */
15
+ rest: REST;
16
+
17
+ /** GuildProduct product 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, GuildProduct>("products");
29
+ }
30
+
31
+ async create(payload: Optional<APIProduct>): Promise<GuildProduct> {
32
+ Assertion.assertObject(payload);
33
+
34
+ const route = Routes.guilds.shop.products.create(this.guild.id);
35
+ const response = await this.rest.request<APIProduct, typeof payload>({
36
+ method: "POST",
37
+ url: route,
38
+ });
39
+ const product = this.set(response);
40
+ return product;
41
+ }
42
+
43
+ /**
44
+ * Fetch a product
45
+ * @param id Id of the product to fetch
46
+ * @returns APIBetUser
47
+ */
48
+ async fetch(id: string) {
49
+ const route = Routes.guilds.shop.products.get(this.guild.id, id);
50
+ const response = await this.rest.request<APIProduct, {}>({
51
+ method: "get",
52
+ url: route,
53
+ });
54
+ const product = new GuildProduct(response, this, this.rest);
55
+ this.cache.set(product.id, product);
56
+
57
+ return product;
58
+ }
59
+
60
+ async fetchAll() {
61
+ const route = Routes.guilds.shop.products.getAll(this.guild.id);
62
+ const response = await this.rest.request<APIProduct[], {}>({
63
+ method: "get",
64
+ url: route,
65
+ });
66
+
67
+ for (let betData of response) {
68
+ const product = new GuildProduct(betData, this, this.rest);
69
+ this.cache.set(product.id, product);
70
+ }
71
+ return this.cache;
72
+ }
73
+
74
+ set(data: APIProduct): GuildProduct {
75
+ if (!data.id) return;
76
+ const product = new GuildProduct(data, this, this.rest);
77
+ this.cache.set(data.id, product);
78
+ return product;
79
+ }
80
+ setAll(data: APIProduct[]) {
81
+ if (!data) return this.cache;
82
+ for (let product of data) this.set(product);
83
+ return this.cache;
84
+ }
85
+
86
+ async delete(id: string, type: string) {
87
+ Assertion.assertString(id);
88
+ Assertion.assertString(type);
89
+
90
+ const route = Routes.guilds.shop.products.delete(id, this.guild.id);
91
+ const payload = { type };
92
+ const product = this.cache.get(id);
93
+ this.rest.emit("productsDelete", product);
94
+
95
+ await this.rest.request({
96
+ method: "DELETE",
97
+ url: route,
98
+ payload,
99
+ });
100
+
101
+ this.cache.delete(id);
102
+ return this.cache;
103
+ }
104
+ async deleteAll() {
105
+ const route = Routes.guilds.shop.products.deleteAll(this.guild.id);
106
+ this.rest.emit("productsDelete", 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
+ }