@duque.edits/sdk 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{v1/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/{v1/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/tests/index.ts +0 -86
- package/tsconfig.json +0 -15
- package/v1/managers/bet/GuildBetManager.ts +0 -117
- package/v1/managers/betuser/GuildBetUserManager.ts +0 -103
- package/v1/managers/channel/ChannelManager.ts +0 -168
- package/v1/managers/groupedchannel/GroupedChannelManager.ts +0 -117
- package/v1/managers/guild/GuildManager.ts +0 -84
- package/v1/managers/match/GuildMatchManager.ts +0 -115
- package/v1/managers/mediator/GuildMediatorManager.ts +0 -111
- package/v1/managers/messages/MessagesManager.ts +0 -95
- package/v1/managers/permission/GuildPermissionManager.ts +0 -88
- package/v1/managers/product/GuildProductManager.ts +0 -115
- package/v1/managers/ticket/GuildTicketManager.ts +0 -112
- package/v1/managers/user/GuildUserManager.ts +0 -116
- package/v1/rest/APIEndpoints.ts +0 -11
- package/v1/rest/REST.ts +0 -126
- package/v1/rest/Routes.ts +0 -143
- package/v1/structures/Collection.ts +0 -85
- package/v1/structures/bet/GuildBet.ts +0 -332
- package/v1/structures/betuser/GuildBetUser.ts +0 -247
- package/v1/structures/channel/Channel.ts +0 -78
- package/v1/structures/groupedchannel/GroupedChannel.ts +0 -165
- package/v1/structures/guild/Guild.ts +0 -302
- package/v1/structures/match/GuildMatch.ts +0 -385
- package/v1/structures/mediator/GuildMediator.ts +0 -175
- package/v1/structures/product/GuildProduct.ts +0 -217
- package/v1/structures/shop/GuildShop.ts +0 -98
- package/v1/structures/ticket/GuildTicket.ts +0 -227
- package/v1/structures/user/GuildUser.ts +0 -248
- package/v1/types/api/APIBaseChannel.ts +0 -13
- package/v1/types/api/APIBetChannel.ts +0 -13
- package/v1/types/api/APIBetMessage.ts +0 -13
- package/v1/types/api/APIGuild.ts +0 -123
- package/v1/types/api/APIGuildBet.ts +0 -69
- package/v1/types/api/APIGuildBetUser.ts +0 -46
- package/v1/types/api/APIGuildChannel.ts +0 -13
- package/v1/types/api/APIGuildEmoji.ts +0 -16
- package/v1/types/api/APIGuildGroupedChannel.ts +0 -13
- package/v1/types/api/APIGuildMatch.ts +0 -67
- package/v1/types/api/APIGuildMediator.ts +0 -18
- package/v1/types/api/APIGuildMessage.ts +0 -13
- package/v1/types/api/APIGuildPermissions.ts +0 -7
- package/v1/types/api/APIGuildRole.ts +0 -13
- package/v1/types/api/APIGuildShop.ts +0 -15
- package/v1/types/api/APIGuildTicket.ts +0 -36
- package/v1/types/api/APIGuildUser.ts +0 -45
- package/v1/types/api/APIMessage.ts +0 -16
- package/v1/types/api/APIPlayer.ts +0 -13
- package/v1/types/api/APIProduct.ts +0 -27
- package/v1/types/api/index.ts +0 -180
- package/v1/utils/Assertion.ts +0 -56
|
@@ -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 { GuildProduct } from "../../structures/product/GuildProduct";
|
|
5
|
+
import { Optional } from "../../types/api";
|
|
6
|
+
import { APIProduct } from "../../types/api/APIProduct";
|
|
7
|
+
export declare class GuildProductManager {
|
|
8
|
+
/** A cache of users */
|
|
9
|
+
cache: Collection<string, GuildProduct>;
|
|
10
|
+
/** The rest client */
|
|
11
|
+
rest: REST;
|
|
12
|
+
/** GuildProduct product 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<APIProduct>): Promise<GuildProduct>;
|
|
21
|
+
/**
|
|
22
|
+
* Fetch a product
|
|
23
|
+
* @param id Id of the product to fetch
|
|
24
|
+
* @returns APIBetUser
|
|
25
|
+
*/
|
|
26
|
+
fetch(id: string): Promise<GuildProduct>;
|
|
27
|
+
fetchAll(): Promise<Collection<string, GuildProduct>>;
|
|
28
|
+
set(data: APIProduct): GuildProduct;
|
|
29
|
+
setAll(data: APIProduct[]): Collection<string, GuildProduct>;
|
|
30
|
+
delete(id: string, type: string): Promise<Collection<string, GuildProduct>>;
|
|
31
|
+
deleteAll(): Promise<boolean>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildProductManager = void 0;
|
|
4
|
+
const Routes_1 = require("../../rest/Routes");
|
|
5
|
+
const Collection_1 = require("../../structures/Collection");
|
|
6
|
+
const GuildProduct_1 = require("../../structures/product/GuildProduct");
|
|
7
|
+
const Assertion_1 = require("../../utils/Assertion");
|
|
8
|
+
class GuildProductManager {
|
|
9
|
+
/** A cache of users */
|
|
10
|
+
cache;
|
|
11
|
+
/** The rest client */
|
|
12
|
+
rest;
|
|
13
|
+
/** GuildProduct product 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("products");
|
|
24
|
+
}
|
|
25
|
+
async create(payload) {
|
|
26
|
+
Assertion_1.Assertion.assertObject(payload);
|
|
27
|
+
const route = Routes_1.Routes.guilds.shop.products.create(this.guild.id);
|
|
28
|
+
const response = await this.rest.request({
|
|
29
|
+
method: "POST",
|
|
30
|
+
url: route,
|
|
31
|
+
});
|
|
32
|
+
const product = this.set(response);
|
|
33
|
+
return product;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fetch a product
|
|
37
|
+
* @param id Id of the product to fetch
|
|
38
|
+
* @returns APIBetUser
|
|
39
|
+
*/
|
|
40
|
+
async fetch(id) {
|
|
41
|
+
const route = Routes_1.Routes.guilds.shop.products.get(this.guild.id, id);
|
|
42
|
+
const response = await this.rest.request({
|
|
43
|
+
method: "get",
|
|
44
|
+
url: route,
|
|
45
|
+
});
|
|
46
|
+
const product = new GuildProduct_1.GuildProduct(response, this, this.rest);
|
|
47
|
+
this.cache.set(product.id, product);
|
|
48
|
+
return product;
|
|
49
|
+
}
|
|
50
|
+
async fetchAll() {
|
|
51
|
+
const route = Routes_1.Routes.guilds.shop.products.getAll(this.guild.id);
|
|
52
|
+
const response = await this.rest.request({
|
|
53
|
+
method: "get",
|
|
54
|
+
url: route,
|
|
55
|
+
});
|
|
56
|
+
for (let betData of response) {
|
|
57
|
+
const product = new GuildProduct_1.GuildProduct(betData, this, this.rest);
|
|
58
|
+
this.cache.set(product.id, product);
|
|
59
|
+
}
|
|
60
|
+
return this.cache;
|
|
61
|
+
}
|
|
62
|
+
set(data) {
|
|
63
|
+
if (!data.id)
|
|
64
|
+
return;
|
|
65
|
+
const product = new GuildProduct_1.GuildProduct(data, this, this.rest);
|
|
66
|
+
this.cache.set(data.id, product);
|
|
67
|
+
return product;
|
|
68
|
+
}
|
|
69
|
+
setAll(data) {
|
|
70
|
+
if (!data)
|
|
71
|
+
return this.cache;
|
|
72
|
+
for (let product of data)
|
|
73
|
+
this.set(product);
|
|
74
|
+
return this.cache;
|
|
75
|
+
}
|
|
76
|
+
async delete(id, type) {
|
|
77
|
+
Assertion_1.Assertion.assertString(id);
|
|
78
|
+
Assertion_1.Assertion.assertString(type);
|
|
79
|
+
const route = Routes_1.Routes.guilds.shop.products.delete(id, this.guild.id);
|
|
80
|
+
const payload = { type };
|
|
81
|
+
const product = this.cache.get(id);
|
|
82
|
+
this.rest.emit("productsDelete", product);
|
|
83
|
+
await this.rest.request({
|
|
84
|
+
method: "DELETE",
|
|
85
|
+
url: route,
|
|
86
|
+
payload,
|
|
87
|
+
});
|
|
88
|
+
this.cache.delete(id);
|
|
89
|
+
return this.cache;
|
|
90
|
+
}
|
|
91
|
+
async deleteAll() {
|
|
92
|
+
const route = Routes_1.Routes.guilds.shop.products.deleteAll(this.guild.id);
|
|
93
|
+
this.rest.emit("productsDelete", this.cache);
|
|
94
|
+
const value = await this.rest.request({
|
|
95
|
+
method: "DELETE",
|
|
96
|
+
url: route,
|
|
97
|
+
});
|
|
98
|
+
this.cache.clear();
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.GuildProductManager = GuildProductManager;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { REST } from "../../rest/REST";
|
|
2
|
+
import { GuildTicket } from "../../structures/ticket/GuildTicket";
|
|
3
|
+
import { Collection } from "../../structures/Collection";
|
|
4
|
+
import { Guild } from "../../structures/guild/Guild";
|
|
5
|
+
import { Optional } from "../../types/api";
|
|
6
|
+
import { APIGuildTicket } from "../../types/api/APIGuildTicket";
|
|
7
|
+
export declare class GuildTicketManager {
|
|
8
|
+
/** A cache of users */
|
|
9
|
+
cache: Collection<string, GuildTicket>;
|
|
10
|
+
/** The rest client */
|
|
11
|
+
rest: REST;
|
|
12
|
+
/** GuildTicket ticket 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<APIGuildTicket>): Promise<GuildTicket>;
|
|
21
|
+
/**
|
|
22
|
+
* Fetch a ticket
|
|
23
|
+
* @param id Id of the ticket to fetch
|
|
24
|
+
* @returns APIticketUser
|
|
25
|
+
*/
|
|
26
|
+
fetch(id: string): Promise<GuildTicket>;
|
|
27
|
+
fetchAll(): Promise<Collection<string, GuildTicket>>;
|
|
28
|
+
set(data: APIGuildTicket): GuildTicket;
|
|
29
|
+
setAll(data: APIGuildTicket[]): Collection<string, GuildTicket>;
|
|
30
|
+
delete(id: string): Promise<Collection<string, GuildTicket>>;
|
|
31
|
+
deleteAll(): Promise<boolean>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildTicketManager = void 0;
|
|
4
|
+
const Routes_1 = require("../../rest/Routes");
|
|
5
|
+
const GuildTicket_1 = require("../../structures/ticket/GuildTicket");
|
|
6
|
+
const Collection_1 = require("../../structures/Collection");
|
|
7
|
+
const Assertion_1 = require("../../utils/Assertion");
|
|
8
|
+
class GuildTicketManager {
|
|
9
|
+
/** A cache of users */
|
|
10
|
+
cache;
|
|
11
|
+
/** The rest client */
|
|
12
|
+
rest;
|
|
13
|
+
/** GuildTicket ticket 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("tickets");
|
|
24
|
+
}
|
|
25
|
+
async create(payload) {
|
|
26
|
+
Assertion_1.Assertion.assertObject(payload);
|
|
27
|
+
const route = Routes_1.Routes.guilds.tickets.create(this.guild.id);
|
|
28
|
+
const response = await this.rest.request({
|
|
29
|
+
method: "POST",
|
|
30
|
+
url: route,
|
|
31
|
+
});
|
|
32
|
+
const ticket = this.set(response);
|
|
33
|
+
return ticket;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fetch a ticket
|
|
37
|
+
* @param id Id of the ticket to fetch
|
|
38
|
+
* @returns APIticketUser
|
|
39
|
+
*/
|
|
40
|
+
async fetch(id) {
|
|
41
|
+
const route = Routes_1.Routes.guilds.tickets.get(this.guild.id, id);
|
|
42
|
+
const response = await this.rest.request({
|
|
43
|
+
method: "get",
|
|
44
|
+
url: route,
|
|
45
|
+
});
|
|
46
|
+
const ticket = new GuildTicket_1.GuildTicket(response, this.guild, this, this.rest);
|
|
47
|
+
this.cache.set(ticket.id, ticket);
|
|
48
|
+
return ticket;
|
|
49
|
+
}
|
|
50
|
+
async fetchAll() {
|
|
51
|
+
const route = Routes_1.Routes.guilds.tickets.getAll(this.guild.id);
|
|
52
|
+
const response = await this.rest.request({
|
|
53
|
+
method: "get",
|
|
54
|
+
url: route,
|
|
55
|
+
});
|
|
56
|
+
for (let ticketData of response) {
|
|
57
|
+
const ticket = new GuildTicket_1.GuildTicket(ticketData, this.guild, this, this.rest);
|
|
58
|
+
this.cache.set(ticket.id, ticket);
|
|
59
|
+
}
|
|
60
|
+
return this.cache;
|
|
61
|
+
}
|
|
62
|
+
set(data) {
|
|
63
|
+
if (!data.id)
|
|
64
|
+
return;
|
|
65
|
+
const ticket = new GuildTicket_1.GuildTicket(data, this.guild, this, this.rest);
|
|
66
|
+
this.cache.set(data.id.toString(), ticket);
|
|
67
|
+
return ticket;
|
|
68
|
+
}
|
|
69
|
+
setAll(data) {
|
|
70
|
+
if (!data)
|
|
71
|
+
return this.cache;
|
|
72
|
+
for (let ticket of data)
|
|
73
|
+
this.set(ticket);
|
|
74
|
+
return this.cache;
|
|
75
|
+
}
|
|
76
|
+
async delete(id) {
|
|
77
|
+
Assertion_1.Assertion.assertString(id);
|
|
78
|
+
const route = Routes_1.Routes.guilds.tickets.delete(id, this.guild.id);
|
|
79
|
+
const ticket = this.cache.get(id);
|
|
80
|
+
this.rest.emit("ticketDelete", ticket);
|
|
81
|
+
await this.rest.request({
|
|
82
|
+
method: "DELETE",
|
|
83
|
+
url: route,
|
|
84
|
+
});
|
|
85
|
+
this.cache.delete(id);
|
|
86
|
+
return this.cache;
|
|
87
|
+
}
|
|
88
|
+
async deleteAll() {
|
|
89
|
+
const route = Routes_1.Routes.guilds.tickets.deleteAll(this.guild.id);
|
|
90
|
+
this.rest.emit("ticketsDelete", this.cache);
|
|
91
|
+
const value = await this.rest.request({
|
|
92
|
+
method: "DELETE",
|
|
93
|
+
url: route,
|
|
94
|
+
});
|
|
95
|
+
this.cache.clear();
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.GuildTicketManager = GuildTicketManager;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { REST } from "../../rest/REST";
|
|
2
|
+
import { GuildUser } from "../../structures/user/GuildUser";
|
|
3
|
+
import { Collection } from "../../structures/Collection";
|
|
4
|
+
import { Guild } from "../../structures/guild/Guild";
|
|
5
|
+
import { APIGuildUser } from "../../types/api/APIGuildUser";
|
|
6
|
+
import { Optional } from "../../types";
|
|
7
|
+
export declare class GuildUserManager {
|
|
8
|
+
/** A cache of users */
|
|
9
|
+
cache: Collection<string, GuildUser>;
|
|
10
|
+
/** The rest client */
|
|
11
|
+
rest: REST;
|
|
12
|
+
/** Bet user 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 user
|
|
22
|
+
* @param id Id of the user to fetch
|
|
23
|
+
* @returns GuildUser
|
|
24
|
+
*/
|
|
25
|
+
fetch(id: string, name: string): Promise<GuildUser>;
|
|
26
|
+
fetchAll(): Promise<Collection<string, GuildUser>>;
|
|
27
|
+
updateUser(id: string, name: string, data: Optional<APIGuildUser>): Promise<GuildUser>;
|
|
28
|
+
set(data: APIGuildUser): GuildUser;
|
|
29
|
+
setAll(data: APIGuildUser[]): Collection<string, GuildUser>;
|
|
30
|
+
delete(id: string): Promise<Collection<string, GuildUser>>;
|
|
31
|
+
deleteAll(): Promise<boolean>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildUserManager = void 0;
|
|
4
|
+
const Routes_1 = require("../../rest/Routes");
|
|
5
|
+
const GuildUser_1 = require("../../structures/user/GuildUser");
|
|
6
|
+
const Collection_1 = require("../../structures/Collection");
|
|
7
|
+
const Assertion_1 = require("../../utils/Assertion");
|
|
8
|
+
class GuildUserManager {
|
|
9
|
+
/** A cache of users */
|
|
10
|
+
cache;
|
|
11
|
+
/** The rest client */
|
|
12
|
+
rest;
|
|
13
|
+
/** Bet user 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("users");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch a user
|
|
27
|
+
* @param id Id of the user to fetch
|
|
28
|
+
* @returns GuildUser
|
|
29
|
+
*/
|
|
30
|
+
async fetch(id, name) {
|
|
31
|
+
const route = Routes_1.Routes.guilds.users.get(this.guild.id, id);
|
|
32
|
+
const response = await this.rest.request({
|
|
33
|
+
method: "get",
|
|
34
|
+
url: route,
|
|
35
|
+
payload: { name },
|
|
36
|
+
});
|
|
37
|
+
if (!response)
|
|
38
|
+
return this.cache.get(id);
|
|
39
|
+
const user = new GuildUser_1.GuildUser(response, this, this.rest);
|
|
40
|
+
this.cache.set(user?.id, user);
|
|
41
|
+
this.rest.users.set(user?.id, user);
|
|
42
|
+
return user;
|
|
43
|
+
}
|
|
44
|
+
async fetchAll() {
|
|
45
|
+
const route = Routes_1.Routes.guilds.users.getAll(this.guild.id);
|
|
46
|
+
const response = await this.rest.request({
|
|
47
|
+
method: "get",
|
|
48
|
+
url: route,
|
|
49
|
+
});
|
|
50
|
+
if (Array.isArray(response) && response.length === 0) {
|
|
51
|
+
this.cache.clear();
|
|
52
|
+
return this.cache;
|
|
53
|
+
}
|
|
54
|
+
this.setAll(response);
|
|
55
|
+
return this.cache;
|
|
56
|
+
}
|
|
57
|
+
async updateUser(id, name, data) {
|
|
58
|
+
const route = Routes_1.Routes.guilds.users.update(this.guild.id, id);
|
|
59
|
+
const payload = { ...data, name };
|
|
60
|
+
const response = await this.rest.request({
|
|
61
|
+
method: "Patch",
|
|
62
|
+
url: route,
|
|
63
|
+
payload,
|
|
64
|
+
});
|
|
65
|
+
const user = this.set(response);
|
|
66
|
+
return user;
|
|
67
|
+
}
|
|
68
|
+
set(data) {
|
|
69
|
+
if (!data.id)
|
|
70
|
+
return;
|
|
71
|
+
const user = new GuildUser_1.GuildUser(data, this, this.rest);
|
|
72
|
+
this.cache.set(user?.id, user);
|
|
73
|
+
this.rest.users.set(user?.id, user);
|
|
74
|
+
return user;
|
|
75
|
+
}
|
|
76
|
+
setAll(data) {
|
|
77
|
+
if (!data)
|
|
78
|
+
return this.cache;
|
|
79
|
+
for (let user of data)
|
|
80
|
+
this.set(user);
|
|
81
|
+
return this.cache;
|
|
82
|
+
}
|
|
83
|
+
async delete(id) {
|
|
84
|
+
Assertion_1.Assertion.assertString(id);
|
|
85
|
+
const route = Routes_1.Routes.guilds.users.delete(id, this.guild.id);
|
|
86
|
+
const user = this.cache.get(id);
|
|
87
|
+
this.rest.emit("userDelete", user);
|
|
88
|
+
await this.rest.request({
|
|
89
|
+
method: "DELETE",
|
|
90
|
+
url: route,
|
|
91
|
+
});
|
|
92
|
+
this.cache.delete(id);
|
|
93
|
+
return this.cache;
|
|
94
|
+
}
|
|
95
|
+
async deleteAll() {
|
|
96
|
+
const route = Routes_1.Routes.guilds.users.deleteAll(this.guild.id);
|
|
97
|
+
this.rest.emit("usersDelete", this.cache);
|
|
98
|
+
const value = await this.rest.request({
|
|
99
|
+
method: "DELETE",
|
|
100
|
+
url: route,
|
|
101
|
+
});
|
|
102
|
+
this.cache.clear();
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.GuildUserManager = GuildUserManager;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { GuildManager } from "../managers/guild/GuildManager";
|
|
3
|
+
import { GuildBet } from "../structures/bet/GuildBet";
|
|
4
|
+
import { Collection } from "../structures/Collection";
|
|
5
|
+
import { GuildBetUser } from "../structures/betuser/GuildBetUser";
|
|
6
|
+
import { GuildMatch } from "../structures/match/GuildMatch";
|
|
7
|
+
import { GuildMediator } from "../structures/mediator/GuildMediator";
|
|
8
|
+
import { GuildUser } from "../structures/user/GuildUser";
|
|
9
|
+
interface RequestOptions<Payload> {
|
|
10
|
+
/** The request's method */
|
|
11
|
+
method: string;
|
|
12
|
+
/** The request's url */
|
|
13
|
+
url: string;
|
|
14
|
+
/** The request payload */
|
|
15
|
+
payload?: Payload;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The main class of this package
|
|
19
|
+
*/
|
|
20
|
+
export declare class REST extends EventEmitter {
|
|
21
|
+
/**
|
|
22
|
+
* The unique key for client
|
|
23
|
+
*/
|
|
24
|
+
key: string;
|
|
25
|
+
/** The guild manager */
|
|
26
|
+
guilds: GuildManager;
|
|
27
|
+
bets: Collection<string, GuildBet>;
|
|
28
|
+
matches: Collection<string, GuildMatch>;
|
|
29
|
+
betUsers: Collection<string, GuildBetUser>;
|
|
30
|
+
users: Collection<string, GuildUser>;
|
|
31
|
+
mediators: Collection<string, GuildMediator>;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param key The unique key for he client
|
|
35
|
+
*/
|
|
36
|
+
constructor(key?: string);
|
|
37
|
+
/**
|
|
38
|
+
* Set the api key
|
|
39
|
+
* @param key The unique key of the client
|
|
40
|
+
*/
|
|
41
|
+
setKey(key: string): void;
|
|
42
|
+
/** Initialize the caching sistem */
|
|
43
|
+
init(): Promise<this>;
|
|
44
|
+
/**
|
|
45
|
+
* Request Data from a certain url
|
|
46
|
+
* @param options
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
request<Expecting, Payload>(options: RequestOptions<Payload>): Promise<Expecting>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.REST = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const Assertion_1 = require("../utils/Assertion");
|
|
9
|
+
const undici_1 = require("undici");
|
|
10
|
+
const Routes_1 = require("./Routes");
|
|
11
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
12
|
+
const GuildManager_1 = require("../managers/guild/GuildManager");
|
|
13
|
+
const Collection_1 = require("../structures/Collection");
|
|
14
|
+
dotenv_1.default.config();
|
|
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
|
+
* The main class of this package
|
|
22
|
+
*/
|
|
23
|
+
class REST extends events_1.default {
|
|
24
|
+
/**
|
|
25
|
+
* The unique key for client
|
|
26
|
+
*/
|
|
27
|
+
key;
|
|
28
|
+
/** The guild manager */
|
|
29
|
+
guilds;
|
|
30
|
+
bets;
|
|
31
|
+
matches;
|
|
32
|
+
betUsers;
|
|
33
|
+
users;
|
|
34
|
+
mediators;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param key The unique key for he client
|
|
38
|
+
*/
|
|
39
|
+
constructor(key) {
|
|
40
|
+
super({ captureRejections: true });
|
|
41
|
+
if (key) {
|
|
42
|
+
Assertion_1.Assertion.assertString(key);
|
|
43
|
+
this.key = key;
|
|
44
|
+
}
|
|
45
|
+
this.guilds = new GuildManager_1.GuildManager(this);
|
|
46
|
+
this.bets = new Collection_1.Collection("bets");
|
|
47
|
+
this.matches = new Collection_1.Collection("matches");
|
|
48
|
+
this.betUsers = new Collection_1.Collection("betUsers");
|
|
49
|
+
this.users = new Collection_1.Collection("users");
|
|
50
|
+
this.mediators = new Collection_1.Collection("mediators");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set the api key
|
|
54
|
+
* @param key The unique key of the client
|
|
55
|
+
*/
|
|
56
|
+
setKey(key) {
|
|
57
|
+
this.key = key;
|
|
58
|
+
}
|
|
59
|
+
/** Initialize the caching sistem */
|
|
60
|
+
async init() {
|
|
61
|
+
await this.guilds.fetchAll();
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Request Data from a certain url
|
|
66
|
+
* @param options
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
async request(options) {
|
|
70
|
+
let { method, url, payload } = options;
|
|
71
|
+
Assertion_1.Assertion.assertString(method);
|
|
72
|
+
Assertion_1.Assertion.assertString(this.key);
|
|
73
|
+
Assertion_1.Assertion.assertString(url);
|
|
74
|
+
method = method.toUpperCase();
|
|
75
|
+
url = Routes_1.Routes.base + url;
|
|
76
|
+
const headers = new undici_1.Headers();
|
|
77
|
+
headers.append("duque-auth", process.env.AUTH);
|
|
78
|
+
headers.append("Content-Type", "application/json");
|
|
79
|
+
headers.append("duque-client-key", this.key);
|
|
80
|
+
const before = Date.now();
|
|
81
|
+
this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
|
|
82
|
+
const res = await (0, undici_1.request)(url, {
|
|
83
|
+
method,
|
|
84
|
+
headers,
|
|
85
|
+
body: payload !== undefined ? JSON.stringify(payload) : undefined,
|
|
86
|
+
});
|
|
87
|
+
const body = await res.body.json();
|
|
88
|
+
const { data, message } = body;
|
|
89
|
+
const now = new Date().getTime();
|
|
90
|
+
if (message)
|
|
91
|
+
this.emit("debug", `${FgRed}${message}${Reset}`);
|
|
92
|
+
this.emit("debug", `[Request]${FgGreen} ${(now - before) / 1000}s done.${Reset}`);
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.REST = REST;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const Route: <K>(route: string) => string;
|
|
2
|
+
export declare const Routes: {
|
|
3
|
+
base: string;
|
|
4
|
+
field: (field: string) => string;
|
|
5
|
+
fields: (...fields: string[]) => string;
|
|
6
|
+
guilds: {
|
|
7
|
+
create: () => string;
|
|
8
|
+
get: (guildId: string) => string;
|
|
9
|
+
getAll: () => string;
|
|
10
|
+
delete: (guildId: string) => string;
|
|
11
|
+
deleteAll: () => string;
|
|
12
|
+
resource: (guildId: string, resource: string) => string;
|
|
13
|
+
resources: (guildId: string, ...resourcess: string[]) => string;
|
|
14
|
+
users: {
|
|
15
|
+
create: (guildId: string) => string;
|
|
16
|
+
update: (guildId: string, userId: string) => string;
|
|
17
|
+
getAll: (guildId: string) => string;
|
|
18
|
+
get: (guildId: string, userId: string) => string;
|
|
19
|
+
delete: (guildId: string, userId: string) => string;
|
|
20
|
+
deleteAll: (guildId: string) => string;
|
|
21
|
+
resource: (guildId: string, userId: string, resource: string) => string;
|
|
22
|
+
};
|
|
23
|
+
betUsers: {
|
|
24
|
+
getAll: (guildId: string) => string;
|
|
25
|
+
get: (guildId: string, userId: string) => string;
|
|
26
|
+
create: (guildId: string) => string;
|
|
27
|
+
update: (guildId: string, userId: string) => string;
|
|
28
|
+
delete: (guildId: string, userId: string) => string;
|
|
29
|
+
deleteAll: (guildId: string) => string;
|
|
30
|
+
resource: (guildId: string, userId: string, resourceName: string) => string;
|
|
31
|
+
};
|
|
32
|
+
matches: {
|
|
33
|
+
getAll: (guildId: string) => string;
|
|
34
|
+
get: (guildId: string, matchId: string) => string;
|
|
35
|
+
create: (guildId: string) => string;
|
|
36
|
+
update: (guildId: string, matchId: string) => string;
|
|
37
|
+
delete: (guildId: string, matchId: string) => string;
|
|
38
|
+
deleteAll: (guildId: string) => string;
|
|
39
|
+
resource: (guildId: string, matchId: string, ...resources: string[]) => string;
|
|
40
|
+
};
|
|
41
|
+
bets: {
|
|
42
|
+
getAll: (guildId: string) => string;
|
|
43
|
+
get: (guildId: string, betId: string) => string;
|
|
44
|
+
create: (guildId: string) => string;
|
|
45
|
+
update: (guildId: string, betId: string) => string;
|
|
46
|
+
delete: (guildId: string, betId: string) => string;
|
|
47
|
+
deleteAll: (guildId: string) => string;
|
|
48
|
+
resource: (guildId: string, betId: string, ...resources: string[]) => string;
|
|
49
|
+
};
|
|
50
|
+
tickets: {
|
|
51
|
+
getAll: (guildId: string) => string;
|
|
52
|
+
get: (guildId: string, ticketId: string) => string;
|
|
53
|
+
create: (guildId: string) => string;
|
|
54
|
+
update: (guildId: string, ticketId: string) => string;
|
|
55
|
+
delete: (guildId: string, ticketId: string) => string;
|
|
56
|
+
deleteAll: (guildId: string) => string;
|
|
57
|
+
resource: (guildId: string, ticketId: string, ...resources: string[]) => string;
|
|
58
|
+
};
|
|
59
|
+
mediators: {
|
|
60
|
+
getAll: (guildId: string) => string;
|
|
61
|
+
get: (guildId: string, mediatorId: string) => string;
|
|
62
|
+
create: (guildId: string) => string;
|
|
63
|
+
update: (guildId: string, mediatorId: string) => string;
|
|
64
|
+
delete: (guildId: string, mediatorId: string) => string;
|
|
65
|
+
deleteAll: (guildId: string) => string;
|
|
66
|
+
resource: (guildId: string, mediatorId: string, ...resources: string[]) => string;
|
|
67
|
+
};
|
|
68
|
+
shop: {
|
|
69
|
+
get: (guildId: string) => string;
|
|
70
|
+
update: (guildId: string) => string;
|
|
71
|
+
delete: (guildId: string) => string;
|
|
72
|
+
resource: (guildId: string, ...resources: string[]) => string;
|
|
73
|
+
products: {
|
|
74
|
+
getAll: (guildId: string) => string;
|
|
75
|
+
get: (guildId: string, productId: string) => string;
|
|
76
|
+
create: (guildId: string) => string;
|
|
77
|
+
update: (guildId: string, productId: string) => string;
|
|
78
|
+
delete: (guildId: string, productId: string) => string;
|
|
79
|
+
deleteAll: (guildId: string) => string;
|
|
80
|
+
resource: (guildId: string, productId: string, ...resources: string[]) => string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|