@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.
- package/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/package.json +46 -0
- package/src/index.ts +30 -0
- package/src/managers/bet/GuildBetManager.ts +117 -0
- package/src/managers/betuser/GuildBetUserManager.ts +103 -0
- package/src/managers/channel/ChannelManager.ts +168 -0
- package/src/managers/groupedchannel/GroupedChannelManager.ts +117 -0
- package/src/managers/guild/GuildManager.ts +84 -0
- package/src/managers/match/GuildMatchManager.ts +115 -0
- package/src/managers/mediator/GuildMediatorManager.ts +111 -0
- package/src/managers/messages/MessagesManager.ts +95 -0
- package/src/managers/permission/GuildPermissionManager.ts +88 -0
- package/src/managers/product/GuildProductManager.ts +115 -0
- package/src/managers/ticket/GuildTicketManager.ts +112 -0
- package/src/managers/user/GuildUserManager.ts +116 -0
- package/src/rest/APIEndpoints.ts +11 -0
- package/src/rest/REST.ts +126 -0
- package/src/rest/Routes.ts +143 -0
- package/src/structures/Collection.ts +85 -0
- package/src/structures/bet/GuildBet.ts +332 -0
- package/src/structures/betuser/GuildBetUser.ts +247 -0
- package/src/structures/channel/Channel.ts +78 -0
- package/src/structures/groupedchannel/GroupedChannel.ts +165 -0
- package/src/structures/guild/Guild.ts +302 -0
- package/src/structures/match/GuildMatch.ts +385 -0
- package/src/structures/mediator/GuildMediator.ts +175 -0
- package/src/structures/product/GuildProduct.ts +217 -0
- package/src/structures/shop/GuildShop.ts +98 -0
- package/src/structures/ticket/GuildTicket.ts +227 -0
- package/src/structures/user/GuildUser.ts +248 -0
- package/src/types/api/APIBaseChannel.ts +13 -0
- package/src/types/api/APIBetChannel.ts +13 -0
- package/src/types/api/APIBetMessage.ts +13 -0
- package/src/types/api/APIGuild.ts +123 -0
- package/src/types/api/APIGuildBet.ts +69 -0
- package/src/types/api/APIGuildBetUser.ts +46 -0
- package/src/types/api/APIGuildChannel.ts +13 -0
- package/src/types/api/APIGuildEmoji.ts +16 -0
- package/src/types/api/APIGuildGroupedChannel.ts +13 -0
- package/src/types/api/APIGuildMatch.ts +67 -0
- package/src/types/api/APIGuildMediator.ts +18 -0
- package/src/types/api/APIGuildMessage.ts +13 -0
- package/src/types/api/APIGuildPermissions.ts +7 -0
- package/src/types/api/APIGuildRole.ts +13 -0
- package/src/types/api/APIGuildShop.ts +15 -0
- package/src/types/api/APIGuildTicket.ts +36 -0
- package/src/types/api/APIGuildUser.ts +45 -0
- package/src/types/api/APIMessage.ts +16 -0
- package/src/types/api/APIPlayer.ts +13 -0
- package/src/types/api/APIProduct.ts +27 -0
- package/src/types/api/index.ts +180 -0
- package/src/types/index.ts +24 -0
- package/src/utils/Assertion.ts +56 -0
- package/tests/index.ts +86 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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/REST.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { APIEndpoints } from "./APIEndpoints";
|
|
2
|
+
export const Route = <K>(route: string) => route;
|
|
3
|
+
|
|
4
|
+
export const Routes = {
|
|
5
|
+
base: "http://localhost:3000/api/v1",
|
|
6
|
+
//base: "https://duquedev.up.railway.app/api/v1",
|
|
7
|
+
|
|
8
|
+
field: (field: string) => `${field}`,
|
|
9
|
+
fields: (...fields: string[]) => `${fields.join("/")}`,
|
|
10
|
+
|
|
11
|
+
guilds: {
|
|
12
|
+
create: () => `/guilds`,
|
|
13
|
+
|
|
14
|
+
get: (guildId: string) => `/guilds/${guildId}`,
|
|
15
|
+
getAll: () => `/guilds`,
|
|
16
|
+
delete: (guildId: string) => `/guilds/${guildId}`,
|
|
17
|
+
deleteAll: () => `/guilds`,
|
|
18
|
+
resource: (guildId: string, resource: string) =>
|
|
19
|
+
`/guilds/${guildId}/${resource}`,
|
|
20
|
+
resources: (guildId: string, ...resourcess: string[]) =>
|
|
21
|
+
`/guilds/${guildId}/${resourcess.join("/")}`,
|
|
22
|
+
|
|
23
|
+
users: {
|
|
24
|
+
create: (guildId: string) => `/guilds/${guildId}/users`,
|
|
25
|
+
update: (guildId: string, userId: string) =>
|
|
26
|
+
`/guilds/${guildId}/users/${userId}`,
|
|
27
|
+
|
|
28
|
+
getAll: (guildId: string) => `/guilds/${guildId}/users`,
|
|
29
|
+
get: (guildId: string, userId: string) =>
|
|
30
|
+
`/guilds/${guildId}/users/${userId}`,
|
|
31
|
+
|
|
32
|
+
delete: (guildId: string, userId: string) =>
|
|
33
|
+
`/guilds/${guildId}/users/${userId}`,
|
|
34
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/users`,
|
|
35
|
+
|
|
36
|
+
resource: (guildId: string, userId: string, resource: string) =>
|
|
37
|
+
`/guilds/${guildId}/users/${userId}/${resource}`,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
betUsers: {
|
|
41
|
+
getAll: (guildId: string) => `/guilds/${guildId}/betusers`,
|
|
42
|
+
get: (guildId: string, userId: string) =>
|
|
43
|
+
`/guilds/${guildId}/betusers/${userId}`,
|
|
44
|
+
|
|
45
|
+
create: (guildId: string) => `/guilds/${guildId}/betusers`,
|
|
46
|
+
update: (guildId: string, userId: string) =>
|
|
47
|
+
`/guilds/${guildId}/betusers/${userId}`,
|
|
48
|
+
|
|
49
|
+
delete: (guildId: string, userId: string) =>
|
|
50
|
+
`/guilds/${guildId}/betusers/${userId}`,
|
|
51
|
+
|
|
52
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/betusers`,
|
|
53
|
+
resource: (guildId: string, userId: string, resourceName: string) =>
|
|
54
|
+
`/guilds/${guildId}/betusers/${userId}/${resourceName}`,
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
matches: {
|
|
58
|
+
getAll: (guildId: string) => `/guilds/${guildId}/matches`,
|
|
59
|
+
get: (guildId: string, matchId: string) =>
|
|
60
|
+
`/guilds/${guildId}/matches/${matchId}`,
|
|
61
|
+
|
|
62
|
+
create: (guildId: string) => `/guilds/${guildId}/matches`,
|
|
63
|
+
update: (guildId: string, matchId: string) =>
|
|
64
|
+
`/guilds/${guildId}/matches/${matchId}`,
|
|
65
|
+
|
|
66
|
+
delete: (guildId: string, matchId: string) =>
|
|
67
|
+
`/guilds/${guildId}/matches/${matchId}`,
|
|
68
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/matches`,
|
|
69
|
+
resource: (guildId: string, matchId: string, ...resources: string[]) =>
|
|
70
|
+
`/guilds/${guildId}/matches/${matchId}/${resources.join("/")}`,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
bets: {
|
|
74
|
+
getAll: (guildId: string) => `/guilds/${guildId}/bets`,
|
|
75
|
+
get: (guildId: string, betId: string) =>
|
|
76
|
+
`/guilds/${guildId}/bets/${betId}`,
|
|
77
|
+
create: (guildId: string) => `/guilds/${guildId}/bets`,
|
|
78
|
+
update: (guildId: string, betId: string) =>
|
|
79
|
+
`/guilds/${guildId}/bets/${betId}`,
|
|
80
|
+
delete: (guildId: string, betId: string) =>
|
|
81
|
+
`/guilds/${guildId}/bets/${betId}`,
|
|
82
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/bets`,
|
|
83
|
+
resource: (guildId: string, betId: string, ...resources: string[]) =>
|
|
84
|
+
`/guilds/${guildId}/bets/${betId}/${resources.join("/")}`,
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
tickets: {
|
|
88
|
+
getAll: (guildId: string) => `/guilds/${guildId}/tickets`,
|
|
89
|
+
get: (guildId: string, ticketId: string) =>
|
|
90
|
+
`/guilds/${guildId}/tickets/${ticketId}`,
|
|
91
|
+
create: (guildId: string) => `/guilds/${guildId}/tickets`,
|
|
92
|
+
update: (guildId: string, ticketId: string) =>
|
|
93
|
+
`/guilds/${guildId}/tickets/${ticketId}`,
|
|
94
|
+
delete: (guildId: string, ticketId: string) =>
|
|
95
|
+
`/guilds/${guildId}/tickets/${ticketId}`,
|
|
96
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/tickets`,
|
|
97
|
+
resource: (guildId: string, ticketId: string, ...resources: string[]) =>
|
|
98
|
+
`/guilds/${guildId}/tickets/${ticketId}/${resources.join("/")}`,
|
|
99
|
+
},
|
|
100
|
+
mediators: {
|
|
101
|
+
getAll: (guildId: string) => `/guilds/${guildId}/mediators`,
|
|
102
|
+
get: (guildId: string, mediatorId: string) =>
|
|
103
|
+
`/guilds/${guildId}/mediators/${mediatorId}`,
|
|
104
|
+
create: (guildId: string) => `/guilds/${guildId}/mediators`,
|
|
105
|
+
update: (guildId: string, mediatorId: string) =>
|
|
106
|
+
`/guilds/${guildId}/mediators/${mediatorId}`,
|
|
107
|
+
delete: (guildId: string, mediatorId: string) =>
|
|
108
|
+
`/guilds/${guildId}/mediators/${mediatorId}`,
|
|
109
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/mediators`,
|
|
110
|
+
resource: (guildId: string, mediatorId: string, ...resources: string[]) =>
|
|
111
|
+
`/guilds/${guildId}/mediators/${mediatorId}/${resources.join("/")}`,
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
shop: {
|
|
115
|
+
get: (guildId: string) => `/guilds/${guildId}/shop`,
|
|
116
|
+
|
|
117
|
+
update: (guildId: string) => `/guilds/${guildId}/shop`,
|
|
118
|
+
delete: (guildId: string) => `/guilds/${guildId}/shop/ `,
|
|
119
|
+
resource: (guildId: string, ...resources: string[]) =>
|
|
120
|
+
`/guilds/${guildId}/shop/${resources.join("/")}`,
|
|
121
|
+
|
|
122
|
+
products: {
|
|
123
|
+
getAll: (guildId: string) => `/guilds/${guildId}/shop/products`,
|
|
124
|
+
get: (guildId: string, productId: string) =>
|
|
125
|
+
`/guilds/${guildId}/shop/${productId}/products`,
|
|
126
|
+
create: (guildId: string) => `/guilds/${guildId}/shop/products`,
|
|
127
|
+
update: (guildId: string, productId: string) =>
|
|
128
|
+
`/guilds/${guildId}/shop/products/${productId}`,
|
|
129
|
+
delete: (guildId: string, productId: string) =>
|
|
130
|
+
`/guilds/${guildId}/shop/products/${productId}`,
|
|
131
|
+
deleteAll: (guildId: string) => `/guilds/${guildId}/products/shop`,
|
|
132
|
+
resource: (
|
|
133
|
+
guildId: string,
|
|
134
|
+
productId: string,
|
|
135
|
+
...resources: string[]
|
|
136
|
+
) =>
|
|
137
|
+
`/guilds/${guildId}/shop/products/${productId}/${resources.join(
|
|
138
|
+
"/"
|
|
139
|
+
)}`,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
type Predicate = (x: unknown) => boolean;
|
|
2
|
+
type Optional<T> = { [K in keyof T]?: T[K] };
|
|
3
|
+
|
|
4
|
+
export class Collection<K, V> extends Map<K, V> {
|
|
5
|
+
key: string;
|
|
6
|
+
|
|
7
|
+
constructor(key?: string, data?: Iterable<V>) {
|
|
8
|
+
super();
|
|
9
|
+
this.key = key;
|
|
10
|
+
|
|
11
|
+
if (data && Array.isArray(data) && key) {
|
|
12
|
+
if (data.length > 0) return;
|
|
13
|
+
for (let v of data) this.set(key as K, v);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
at(index: number) {
|
|
17
|
+
if (index < 0 || index >= this.size) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
let i = 0;
|
|
21
|
+
for (let [key, value] of this) {
|
|
22
|
+
if (i === index) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
i++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
has(key: K) {
|
|
29
|
+
return this.get(key) !== undefined ? true : false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get first() {
|
|
33
|
+
return this.values().next().value;
|
|
34
|
+
}
|
|
35
|
+
get last() {
|
|
36
|
+
return [...this.values()].at(-1);
|
|
37
|
+
}
|
|
38
|
+
get length() {
|
|
39
|
+
return this.toArray().length;
|
|
40
|
+
}
|
|
41
|
+
find(predicate: (value: V, key: K, Collection: this) => any) {
|
|
42
|
+
for (const [key, value] of this) {
|
|
43
|
+
if (predicate(value, key, this)) return value;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
filter(predicate: (value: V, key: K, Collection: this) => any) {
|
|
48
|
+
const results = new Collection<K, V>("", []);
|
|
49
|
+
for (const [key, value] of this) {
|
|
50
|
+
if (predicate(value, key, this)) results.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
some(predicate: (value: V, key: K, Collection: this) => any) {
|
|
55
|
+
const results = new Collection("", []);
|
|
56
|
+
for (const [key, value] of this) {
|
|
57
|
+
if (predicate(value, key, this)) results.set(key, value);
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
61
|
+
map(callback: (value: V, key: K, Collection: this) => any) {
|
|
62
|
+
return [...this].map(([key, val]) => callback(val, key, this));
|
|
63
|
+
}
|
|
64
|
+
toArray() {
|
|
65
|
+
return [...this.values()];
|
|
66
|
+
}
|
|
67
|
+
toJSON() {
|
|
68
|
+
let obj: Record<string, unknown> = {};
|
|
69
|
+
for (let [k, v] of this.entries()) {
|
|
70
|
+
obj[`${k}`] = v;
|
|
71
|
+
}
|
|
72
|
+
return obj;
|
|
73
|
+
}
|
|
74
|
+
sort(compareFunction: (a: V, b: V, Collection: this) => any) {
|
|
75
|
+
const sortedEntries = [...this.entries()].sort((ab, ba) => {
|
|
76
|
+
return compareFunction(ab[1], ba[1], this);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return new Collection(this.key, sortedEntries);
|
|
80
|
+
}
|
|
81
|
+
toString() {
|
|
82
|
+
return `${this.size}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
module.exports = { Collection };
|