@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.
- package/{src/index.ts → dist/index.d.ts} +27 -30
- package/dist/index.js +43 -0
- package/dist/managers/bet/GuildBetManager.d.ts +32 -0
- package/dist/managers/bet/GuildBetManager.js +107 -0
- package/dist/managers/betuser/GuildBetUserManager.d.ts +30 -0
- package/dist/managers/betuser/GuildBetUserManager.js +94 -0
- package/dist/managers/channel/ChannelManager.d.ts +39 -0
- package/dist/managers/channel/ChannelManager.js +147 -0
- package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +34 -0
- package/dist/managers/groupedchannel/GroupedChannelManager.js +92 -0
- package/dist/managers/guild/GuildManager.d.ts +24 -0
- package/dist/managers/guild/GuildManager.js +75 -0
- package/dist/managers/match/GuildMatchManager.d.ts +32 -0
- package/dist/managers/match/GuildMatchManager.js +103 -0
- package/dist/managers/mediator/GuildMediatorManager.d.ts +32 -0
- package/dist/managers/mediator/GuildMediatorManager.js +97 -0
- package/dist/managers/messages/MessagesManager.d.ts +32 -0
- package/dist/managers/messages/MessagesManager.js +82 -0
- package/dist/managers/permission/GuildPermissionManager.d.ts +26 -0
- package/dist/managers/permission/GuildPermissionManager.js +70 -0
- package/dist/managers/product/GuildProductManager.d.ts +32 -0
- package/dist/managers/product/GuildProductManager.js +102 -0
- package/dist/managers/ticket/GuildTicketManager.d.ts +32 -0
- package/dist/managers/ticket/GuildTicketManager.js +99 -0
- package/dist/managers/user/GuildUserManager.d.ts +32 -0
- package/dist/managers/user/GuildUserManager.js +106 -0
- package/dist/rest/APIEndpoints.d.ts +11 -0
- package/dist/rest/APIEndpoints.js +12 -0
- package/dist/rest/REST.d.ts +51 -0
- package/dist/rest/REST.js +96 -0
- package/dist/rest/Routes.d.ts +84 -0
- package/dist/rest/Routes.js +89 -0
- package/dist/structures/Collection.d.ts +17 -0
- package/dist/structures/Collection.js +87 -0
- package/dist/structures/bet/GuildBet.d.ts +86 -0
- package/dist/structures/bet/GuildBet.js +276 -0
- package/dist/structures/betuser/GuildBetUser.d.ts +82 -0
- package/dist/structures/betuser/GuildBetUser.js +194 -0
- package/dist/structures/channel/Channel.d.ts +31 -0
- package/dist/structures/channel/Channel.js +57 -0
- package/dist/structures/groupedchannel/GroupedChannel.d.ts +34 -0
- package/dist/structures/groupedchannel/GroupedChannel.js +121 -0
- package/dist/structures/guild/Guild.d.ts +89 -0
- package/dist/structures/guild/Guild.js +223 -0
- package/dist/structures/match/GuildMatch.d.ts +84 -0
- package/dist/structures/match/GuildMatch.js +327 -0
- package/dist/structures/mediator/GuildMediator.d.ts +41 -0
- package/dist/structures/mediator/GuildMediator.js +131 -0
- package/dist/structures/product/GuildProduct.d.ts +52 -0
- package/dist/structures/product/GuildProduct.js +175 -0
- package/dist/structures/shop/GuildShop.d.ts +34 -0
- package/dist/structures/shop/GuildShop.js +80 -0
- package/dist/structures/ticket/GuildTicket.d.ts +51 -0
- package/dist/structures/ticket/GuildTicket.js +170 -0
- package/dist/structures/user/GuildUser.d.ts +82 -0
- package/dist/structures/user/GuildUser.js +209 -0
- package/dist/types/api/APIBaseChannel.d.ts +10 -0
- package/dist/types/api/APIBaseChannel.js +2 -0
- package/dist/types/api/APIBetChannel.d.ts +10 -0
- package/dist/types/api/APIBetChannel.js +2 -0
- package/dist/types/api/APIBetMessage.d.ts +10 -0
- package/dist/types/api/APIBetMessage.js +2 -0
- package/dist/types/api/APIGuild.d.ts +92 -0
- package/dist/types/api/APIGuild.js +2 -0
- package/dist/types/api/APIGuildBet.d.ts +48 -0
- package/dist/types/api/APIGuildBet.js +2 -0
- package/dist/types/api/APIGuildBetUser.d.ts +32 -0
- package/dist/types/api/APIGuildBetUser.js +2 -0
- package/dist/types/api/APIGuildChannel.d.ts +10 -0
- package/dist/types/api/APIGuildChannel.js +2 -0
- package/dist/types/api/APIGuildEmoji.d.ts +12 -0
- package/dist/types/api/APIGuildEmoji.js +2 -0
- package/dist/types/api/APIGuildGroupedChannel.d.ts +10 -0
- package/dist/types/api/APIGuildGroupedChannel.js +2 -0
- package/dist/types/api/APIGuildMatch.d.ts +46 -0
- package/dist/types/api/APIGuildMatch.js +2 -0
- package/dist/types/api/APIGuildMediator.d.ts +13 -0
- package/dist/types/api/APIGuildMediator.js +3 -0
- package/dist/types/api/APIGuildMessage.d.ts +10 -0
- package/dist/types/api/APIGuildMessage.js +2 -0
- package/dist/types/api/APIGuildPermissions.d.ts +6 -0
- package/dist/types/api/APIGuildPermissions.js +2 -0
- package/dist/types/api/APIGuildRole.d.ts +10 -0
- package/dist/types/api/APIGuildRole.js +2 -0
- package/dist/types/api/APIGuildShop.d.ts +11 -0
- package/dist/types/api/APIGuildShop.js +2 -0
- package/dist/types/api/APIGuildTicket.d.ts +25 -0
- package/dist/types/api/APIGuildTicket.js +3 -0
- package/dist/types/api/APIGuildUser.d.ts +31 -0
- package/dist/types/api/APIGuildUser.js +2 -0
- package/dist/types/api/APIMessage.d.ts +12 -0
- package/dist/types/api/APIMessage.js +2 -0
- package/dist/types/api/APIPlayer.d.ts +10 -0
- package/dist/types/api/APIPlayer.js +2 -0
- package/dist/types/api/APIProduct.d.ts +19 -0
- package/dist/types/api/APIProduct.js +3 -0
- package/dist/types/api/index.d.ts +130 -0
- package/dist/types/api/index.js +35 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +21 -24
- package/dist/types/index.js +37 -0
- package/dist/utils/Assertion.d.ts +32 -0
- package/dist/utils/Assertion.js +60 -0
- package/package.json +5 -1
- package/.gitattributes +0 -2
- package/src/managers/bet/GuildBetManager.ts +0 -117
- package/src/managers/betuser/GuildBetUserManager.ts +0 -103
- package/src/managers/channel/ChannelManager.ts +0 -168
- package/src/managers/groupedchannel/GroupedChannelManager.ts +0 -117
- package/src/managers/guild/GuildManager.ts +0 -84
- package/src/managers/match/GuildMatchManager.ts +0 -115
- package/src/managers/mediator/GuildMediatorManager.ts +0 -111
- package/src/managers/messages/MessagesManager.ts +0 -95
- package/src/managers/permission/GuildPermissionManager.ts +0 -88
- package/src/managers/product/GuildProductManager.ts +0 -115
- package/src/managers/ticket/GuildTicketManager.ts +0 -112
- package/src/managers/user/GuildUserManager.ts +0 -116
- package/src/rest/APIEndpoints.ts +0 -11
- package/src/rest/REST.ts +0 -126
- package/src/rest/Routes.ts +0 -143
- package/src/structures/Collection.ts +0 -85
- package/src/structures/bet/GuildBet.ts +0 -332
- package/src/structures/betuser/GuildBetUser.ts +0 -247
- package/src/structures/channel/Channel.ts +0 -78
- package/src/structures/groupedchannel/GroupedChannel.ts +0 -165
- package/src/structures/guild/Guild.ts +0 -302
- package/src/structures/match/GuildMatch.ts +0 -385
- package/src/structures/mediator/GuildMediator.ts +0 -175
- package/src/structures/product/GuildProduct.ts +0 -217
- package/src/structures/shop/GuildShop.ts +0 -98
- package/src/structures/ticket/GuildTicket.ts +0 -227
- package/src/structures/user/GuildUser.ts +0 -248
- package/src/types/api/APIBaseChannel.ts +0 -13
- package/src/types/api/APIBetChannel.ts +0 -13
- package/src/types/api/APIBetMessage.ts +0 -13
- package/src/types/api/APIGuild.ts +0 -123
- package/src/types/api/APIGuildBet.ts +0 -69
- package/src/types/api/APIGuildBetUser.ts +0 -46
- package/src/types/api/APIGuildChannel.ts +0 -13
- package/src/types/api/APIGuildEmoji.ts +0 -16
- package/src/types/api/APIGuildGroupedChannel.ts +0 -13
- package/src/types/api/APIGuildMatch.ts +0 -67
- package/src/types/api/APIGuildMediator.ts +0 -18
- package/src/types/api/APIGuildMessage.ts +0 -13
- package/src/types/api/APIGuildPermissions.ts +0 -7
- package/src/types/api/APIGuildRole.ts +0 -13
- package/src/types/api/APIGuildShop.ts +0 -15
- package/src/types/api/APIGuildTicket.ts +0 -36
- package/src/types/api/APIGuildUser.ts +0 -45
- package/src/types/api/APIMessage.ts +0 -16
- package/src/types/api/APIPlayer.ts +0 -13
- package/src/types/api/APIProduct.ts +0 -27
- package/src/types/api/index.ts +0 -180
- package/src/utils/Assertion.ts +0 -56
- package/src/v1/managers/channel/ChannelManager.ts +0 -167
- package/src/v1/managers/match/GuildMatchManager.ts +0 -114
- package/tests/index.ts +0 -86
- package/tsconfig.json +0 -15
|
@@ -1,95 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,88 +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 { 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
|
-
}
|
|
@@ -1,115 +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 { 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
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { REST } from "../../rest/REST";
|
|
2
|
-
import { Routes } from "../../rest/Routes";
|
|
3
|
-
import { GuildTicket } from "../../structures/ticket/GuildTicket";
|
|
4
|
-
import { Collection } from "../../structures/Collection";
|
|
5
|
-
import { Guild } from "../../structures/guild/Guild";
|
|
6
|
-
import { Optional } from "../../types/api";
|
|
7
|
-
import { APIGuildTicket } from "../../types/api/APIGuildTicket";
|
|
8
|
-
import { Assertion } from "../../utils/Assertion";
|
|
9
|
-
|
|
10
|
-
export class GuildTicketManager {
|
|
11
|
-
/** A cache of users */
|
|
12
|
-
cache: Collection<string, GuildTicket>;
|
|
13
|
-
|
|
14
|
-
/** The rest client */
|
|
15
|
-
rest: REST;
|
|
16
|
-
|
|
17
|
-
/** GuildTicket ticket 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, GuildTicket>("tickets");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async create(payload: Optional<APIGuildTicket>): Promise<GuildTicket> {
|
|
32
|
-
Assertion.assertObject(payload);
|
|
33
|
-
|
|
34
|
-
const route = Routes.guilds.tickets.create(this.guild.id);
|
|
35
|
-
const response = await this.rest.request<APIGuildTicket, typeof payload>({
|
|
36
|
-
method: "POST",
|
|
37
|
-
url: route,
|
|
38
|
-
});
|
|
39
|
-
const ticket = this.set(response);
|
|
40
|
-
return ticket;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Fetch a ticket
|
|
45
|
-
* @param id Id of the ticket to fetch
|
|
46
|
-
* @returns APIticketUser
|
|
47
|
-
*/
|
|
48
|
-
async fetch(id: string) {
|
|
49
|
-
const route = Routes.guilds.tickets.get(this.guild.id, id);
|
|
50
|
-
const response = await this.rest.request<APIGuildTicket, {}>({
|
|
51
|
-
method: "get",
|
|
52
|
-
url: route,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const ticket = new GuildTicket(response, this.guild, this, this.rest);
|
|
56
|
-
this.cache.set(ticket.id, ticket);
|
|
57
|
-
|
|
58
|
-
return ticket;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async fetchAll() {
|
|
62
|
-
const route = Routes.guilds.tickets.getAll(this.guild.id);
|
|
63
|
-
const response = await this.rest.request<APIGuildTicket[], {}>({
|
|
64
|
-
method: "get",
|
|
65
|
-
url: route,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
for (let ticketData of response) {
|
|
69
|
-
const ticket = new GuildTicket(ticketData, this.guild, this, this.rest);
|
|
70
|
-
this.cache.set(ticket.id, ticket);
|
|
71
|
-
}
|
|
72
|
-
return this.cache;
|
|
73
|
-
}
|
|
74
|
-
set(data: APIGuildTicket): GuildTicket {
|
|
75
|
-
if (!data.id) return;
|
|
76
|
-
const ticket = new GuildTicket(data, this.guild, this, this.rest);
|
|
77
|
-
this.cache.set(data.id.toString(), ticket);
|
|
78
|
-
return ticket;
|
|
79
|
-
}
|
|
80
|
-
setAll(data: APIGuildTicket[]) {
|
|
81
|
-
if (!data) return this.cache;
|
|
82
|
-
for (let ticket of data) this.set(ticket);
|
|
83
|
-
return this.cache;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async delete(id: string) {
|
|
87
|
-
Assertion.assertString(id);
|
|
88
|
-
|
|
89
|
-
const route = Routes.guilds.tickets.delete(id, this.guild.id);
|
|
90
|
-
const ticket = this.cache.get(id);
|
|
91
|
-
this.rest.emit("ticketDelete", ticket);
|
|
92
|
-
|
|
93
|
-
await this.rest.request<boolean, {}>({
|
|
94
|
-
method: "DELETE",
|
|
95
|
-
url: route,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
this.cache.delete(id);
|
|
99
|
-
return this.cache;
|
|
100
|
-
}
|
|
101
|
-
async deleteAll() {
|
|
102
|
-
const route = Routes.guilds.tickets.deleteAll(this.guild.id);
|
|
103
|
-
this.rest.emit("ticketsDelete", this.cache);
|
|
104
|
-
|
|
105
|
-
const value = await this.rest.request<boolean, {}>({
|
|
106
|
-
method: "DELETE",
|
|
107
|
-
url: route,
|
|
108
|
-
});
|
|
109
|
-
this.cache.clear();
|
|
110
|
-
return value;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { REST } from "../../rest/REST";
|
|
2
|
-
import { Routes } from "../../rest/Routes";
|
|
3
|
-
import { GuildUser } from "../../structures/user/GuildUser";
|
|
4
|
-
import { Collection } from "../../structures/Collection";
|
|
5
|
-
import { Guild } from "../../structures/guild/Guild";
|
|
6
|
-
import { APIGuildUser } from "../../types/api/APIGuildUser";
|
|
7
|
-
import { Assertion } from "../../utils/Assertion";
|
|
8
|
-
import { Optional } from "../../types";
|
|
9
|
-
|
|
10
|
-
export class GuildUserManager {
|
|
11
|
-
/** A cache of users */
|
|
12
|
-
cache: Collection<string, GuildUser>;
|
|
13
|
-
|
|
14
|
-
/** The rest client */
|
|
15
|
-
rest: REST;
|
|
16
|
-
|
|
17
|
-
/** Bet user 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, GuildUser>("users");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Fetch a user
|
|
33
|
-
* @param id Id of the user to fetch
|
|
34
|
-
* @returns GuildUser
|
|
35
|
-
*/
|
|
36
|
-
async fetch(id: string, name: string): Promise<GuildUser> {
|
|
37
|
-
const route = Routes.guilds.users.get(this.guild.id, id);
|
|
38
|
-
const response = await this.rest.request<APIGuildUser, { name: string }>({
|
|
39
|
-
method: "get",
|
|
40
|
-
url: route,
|
|
41
|
-
payload: { name },
|
|
42
|
-
});
|
|
43
|
-
if (!response) return this.cache.get(id);
|
|
44
|
-
|
|
45
|
-
const user = new GuildUser(response, this, this.rest);
|
|
46
|
-
this.cache.set(user?.id, user);
|
|
47
|
-
this.rest.users.set(user?.id, user);
|
|
48
|
-
|
|
49
|
-
return user;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async fetchAll(): Promise<Collection<string, GuildUser>> {
|
|
53
|
-
const route = Routes.guilds.users.getAll(this.guild.id);
|
|
54
|
-
const response = await this.rest.request<APIGuildUser[], {}>({
|
|
55
|
-
method: "get",
|
|
56
|
-
url: route,
|
|
57
|
-
});
|
|
58
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
59
|
-
this.cache.clear();
|
|
60
|
-
return this.cache;
|
|
61
|
-
}
|
|
62
|
-
this.setAll(response);
|
|
63
|
-
return this.cache;
|
|
64
|
-
}
|
|
65
|
-
async updateUser(id: string, name: string, data: Optional<APIGuildUser>) {
|
|
66
|
-
const route = Routes.guilds.users.update(this.guild.id, id);
|
|
67
|
-
const payload = { ...data, name };
|
|
68
|
-
const response = await this.rest.request<APIGuildUser, typeof payload>({
|
|
69
|
-
method: "Patch",
|
|
70
|
-
url: route,
|
|
71
|
-
payload,
|
|
72
|
-
});
|
|
73
|
-
const user = this.set(response);
|
|
74
|
-
return user;
|
|
75
|
-
}
|
|
76
|
-
set(data: APIGuildUser): GuildUser {
|
|
77
|
-
if (!data.id) return;
|
|
78
|
-
const user = new GuildUser(data, this, this.rest);
|
|
79
|
-
this.cache.set(user?.id, user);
|
|
80
|
-
this.rest.users.set(user?.id, user);
|
|
81
|
-
|
|
82
|
-
return user;
|
|
83
|
-
}
|
|
84
|
-
setAll(data: APIGuildUser[]): Collection<string, GuildUser> {
|
|
85
|
-
if (!data) return this.cache;
|
|
86
|
-
for (let user of data) this.set(user);
|
|
87
|
-
return this.cache;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async delete(id: string) {
|
|
91
|
-
Assertion.assertString(id);
|
|
92
|
-
|
|
93
|
-
const route = Routes.guilds.users.delete(id, this.guild.id);
|
|
94
|
-
const user = this.cache.get(id);
|
|
95
|
-
this.rest.emit("userDelete", user);
|
|
96
|
-
|
|
97
|
-
await this.rest.request<boolean, {}>({
|
|
98
|
-
method: "DELETE",
|
|
99
|
-
url: route,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this.cache.delete(id);
|
|
103
|
-
return this.cache;
|
|
104
|
-
}
|
|
105
|
-
async deleteAll() {
|
|
106
|
-
const route = Routes.guilds.users.deleteAll(this.guild.id);
|
|
107
|
-
this.rest.emit("usersDelete", this.cache);
|
|
108
|
-
|
|
109
|
-
const value = await this.rest.request<boolean, {}>({
|
|
110
|
-
method: "DELETE",
|
|
111
|
-
url: route,
|
|
112
|
-
});
|
|
113
|
-
this.cache.clear();
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
}
|
package/src/rest/APIEndpoints.ts
DELETED
package/src/rest/REST.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "events";
|
|
2
|
-
import { Assertion } from "../utils/Assertion";
|
|
3
|
-
import { request, Headers } from "undici";
|
|
4
|
-
import { Routes } from "./Routes";
|
|
5
|
-
import env from "dotenv";
|
|
6
|
-
import { GuildManager } from "../managers/guild/GuildManager";
|
|
7
|
-
import { GuildBet } from "../structures/bet/GuildBet";
|
|
8
|
-
import { Collection } from "../structures/Collection";
|
|
9
|
-
import { GuildBetUser } from "../structures/betuser/GuildBetUser";
|
|
10
|
-
import { GuildMatch } from "../structures/match/GuildMatch";
|
|
11
|
-
import { GuildMediator } from "../structures/mediator/GuildMediator";
|
|
12
|
-
import { GuildUser } from "../structures/user/GuildUser";
|
|
13
|
-
env.config();
|
|
14
|
-
|
|
15
|
-
const Reset = "\x1b[0m";
|
|
16
|
-
const FgGreen = "\x1b[32m";
|
|
17
|
-
const FgRed = "\x1b[31m";
|
|
18
|
-
const FgBlue = "\x1b[34m";
|
|
19
|
-
const FgCyan = "\x1b[36m";
|
|
20
|
-
|
|
21
|
-
interface RequestOptions<Payload> {
|
|
22
|
-
/** The request's method */
|
|
23
|
-
method: string;
|
|
24
|
-
|
|
25
|
-
/** The request's url */
|
|
26
|
-
url: string;
|
|
27
|
-
|
|
28
|
-
/** The request payload */
|
|
29
|
-
payload?: Payload;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The main class of this package
|
|
34
|
-
*/
|
|
35
|
-
export class REST extends EventEmitter {
|
|
36
|
-
/**
|
|
37
|
-
* The unique key for client
|
|
38
|
-
*/
|
|
39
|
-
key: string;
|
|
40
|
-
|
|
41
|
-
/** The guild manager */
|
|
42
|
-
guilds: GuildManager;
|
|
43
|
-
|
|
44
|
-
bets: Collection<string, GuildBet>;
|
|
45
|
-
matches: Collection<string, GuildMatch>;
|
|
46
|
-
betUsers: Collection<string, GuildBetUser>;
|
|
47
|
-
users: Collection<string, GuildUser>;
|
|
48
|
-
mediators: Collection<string, GuildMediator>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
* @param key The unique key for he client
|
|
53
|
-
*/
|
|
54
|
-
constructor(key?: string) {
|
|
55
|
-
super({ captureRejections: true });
|
|
56
|
-
|
|
57
|
-
if (key) {
|
|
58
|
-
Assertion.assertString(key);
|
|
59
|
-
this.key = key;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.guilds = new GuildManager(this);
|
|
63
|
-
this.bets = new Collection<string, GuildBet>("bets");
|
|
64
|
-
this.matches = new Collection<string, GuildMatch>("matches");
|
|
65
|
-
this.betUsers = new Collection<string, GuildBetUser>("betUsers");
|
|
66
|
-
this.users = new Collection<string, GuildUser>("users");
|
|
67
|
-
this.mediators = new Collection<string, GuildMediator>("mediators");
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Set the api key
|
|
71
|
-
* @param key The unique key of the client
|
|
72
|
-
*/
|
|
73
|
-
setKey(key: string) {
|
|
74
|
-
this.key = key;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Initialize the caching sistem */
|
|
78
|
-
async init() {
|
|
79
|
-
await this.guilds.fetchAll();
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Request Data from a certain url
|
|
85
|
-
* @param options
|
|
86
|
-
* @returns
|
|
87
|
-
*/
|
|
88
|
-
async request<Expecting, Payload>(options: RequestOptions<Payload>) {
|
|
89
|
-
let { method, url, payload } = options;
|
|
90
|
-
Assertion.assertString(method);
|
|
91
|
-
Assertion.assertString(this.key);
|
|
92
|
-
Assertion.assertString(url);
|
|
93
|
-
|
|
94
|
-
method = method.toUpperCase();
|
|
95
|
-
url = Routes.base + url;
|
|
96
|
-
|
|
97
|
-
const headers = new Headers();
|
|
98
|
-
headers.append("duque-auth", process.env.AUTH);
|
|
99
|
-
headers.append("Content-Type", "application/json");
|
|
100
|
-
headers.append("duque-client-key", this.key);
|
|
101
|
-
|
|
102
|
-
const before = Date.now();
|
|
103
|
-
this.emit(
|
|
104
|
-
"debug",
|
|
105
|
-
[`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n")
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const res = await request(url, {
|
|
109
|
-
method,
|
|
110
|
-
headers,
|
|
111
|
-
body: payload !== undefined ? JSON.stringify(payload) : undefined,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const body = await res.body.json();
|
|
115
|
-
const { data, message } = body as Record<string, unknown>;
|
|
116
|
-
const now = new Date().getTime();
|
|
117
|
-
|
|
118
|
-
if (message) this.emit("debug", `${FgRed}${message}${Reset}`);
|
|
119
|
-
this.emit(
|
|
120
|
-
"debug",
|
|
121
|
-
`[Request]${FgGreen} ${(now - before) / 1000}s done.${Reset}`
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
return data as Expecting;
|
|
125
|
-
}
|
|
126
|
-
}
|