@duque.edits/sdk 0.0.4 → 0.0.6
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 +90 -0
- package/dist/structures/guild/Guild.js +254 -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 +208 -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 +93 -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 +15 -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duque.edits/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"SDK",
|
|
13
13
|
"DuqueEdits"
|
|
14
14
|
],
|
|
15
|
+
"files": [
|
|
16
|
+
"./dist",
|
|
17
|
+
"./package.json"
|
|
18
|
+
],
|
|
15
19
|
"scripts": {
|
|
16
20
|
"test": "ts-node tests/index.ts"
|
|
17
21
|
},
|
|
@@ -38,6 +42,16 @@
|
|
|
38
42
|
"ts-node": "^10.9.2",
|
|
39
43
|
"typescript": "^5.8.3"
|
|
40
44
|
},
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"require": "./dist/index.js",
|
|
48
|
+
"types": "./dist/index.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./v1": {
|
|
51
|
+
"require": "./dist/v1",
|
|
52
|
+
"types": "./dist/index.d.ts"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
41
55
|
"publishConfig": {
|
|
42
56
|
"access": "public"
|
|
43
57
|
},
|
package/.gitattributes
DELETED
package/tests/index.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { after } from "node:test";
|
|
2
|
-
import { REST } from "../src/rest/REST";
|
|
3
|
-
const client = new REST("877598927149490186");
|
|
4
|
-
const Reset = "\x1b[0m";
|
|
5
|
-
const FgGreen = "\x1b[32m";
|
|
6
|
-
const FgRed = "\x1b[31m";
|
|
7
|
-
const FgBlue = "\x1b[34m";
|
|
8
|
-
const FgCyan = "\x1b[36m";
|
|
9
|
-
|
|
10
|
-
client.on("debug", console.log);
|
|
11
|
-
|
|
12
|
-
client.init().then(async () => {
|
|
13
|
-
const guilds = client.guilds;
|
|
14
|
-
const guild = client.guilds.cache.get("1341399030282059776")!;
|
|
15
|
-
|
|
16
|
-
const users = guild?.users?.cache;
|
|
17
|
-
|
|
18
|
-
const me = users?.get("877598927149490186")!;
|
|
19
|
-
/* const matches = guild?.matches;
|
|
20
|
-
let match = await matches.create({
|
|
21
|
-
creatorId: "12",
|
|
22
|
-
type: "1v1",
|
|
23
|
-
maximumSize: 2,
|
|
24
|
-
});
|
|
25
|
-
await match.channels.createMany(
|
|
26
|
-
{
|
|
27
|
-
type: "dqwdqdwqdqwdqwd",
|
|
28
|
-
id: "1111111111111111111111111",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
type: "duque",
|
|
32
|
-
id: "2333",
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
console.log({ chs: match?.channels?.cache });
|
|
36
|
-
|
|
37
|
-
await match.setMvp("2333");
|
|
38
|
-
console.log({ chs: match?.channels?.cache });
|
|
39
|
-
|
|
40
|
-
await match.setRoomCreatorId("2333");
|
|
41
|
-
console.log({ chs: match?.channels?.cache });
|
|
42
|
-
|
|
43
|
-
await match.setWinners({
|
|
44
|
-
id: "que",
|
|
45
|
-
name: "22e2e",
|
|
46
|
-
});
|
|
47
|
-
match = await match.fetch();
|
|
48
|
-
|
|
49
|
-
console.log({ chs: match?.channels?.cache }); */
|
|
50
|
-
/*
|
|
51
|
-
const channels = guild?.channels;
|
|
52
|
-
const categories = guild?.categories;
|
|
53
|
-
|
|
54
|
-
/* await me.update({
|
|
55
|
-
originalChannels: [
|
|
56
|
-
{
|
|
57
|
-
type: "dqwdqdwqdqwdqwd",
|
|
58
|
-
id: "1111111111111111111111111",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
type: "dqwdqdwqdqwdqwd",
|
|
62
|
-
id: "2333",
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
type: "add",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
await me.update({
|
|
69
|
-
originalChannels: [
|
|
70
|
-
{
|
|
71
|
-
type: "3333",
|
|
72
|
-
id: "33333",
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
type: "313",
|
|
76
|
-
id: "074534535",
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
type: "add",
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
console.log({ mecj: me.originalChannels }); */
|
|
83
|
-
|
|
84
|
-
await me.update({ wins: 10020, type: "add" });
|
|
85
|
-
console.log({ me })
|
|
86
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"skipDefaultLibCheck": true,
|
|
11
|
-
"removeComments": false,
|
|
12
|
-
"strictNullChecks": false,
|
|
13
|
-
},
|
|
14
|
-
"include": ["v1"]
|
|
15
|
-
}
|
|
@@ -1,117 +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 { Optional } from "../../types/api";
|
|
7
|
-
import { APIGuildBet } from "../../types/api/APIGuildBet";
|
|
8
|
-
import { Assertion } from "../../utils/Assertion";
|
|
9
|
-
|
|
10
|
-
export class GuildBetManager {
|
|
11
|
-
/** A cache of users */
|
|
12
|
-
cache: Collection<string, GuildBet>;
|
|
13
|
-
|
|
14
|
-
/** The rest client */
|
|
15
|
-
rest: REST;
|
|
16
|
-
|
|
17
|
-
/** GuildBet bet 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, GuildBet>("bets");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async create(payload: Optional<APIGuildBet>): Promise<GuildBet> {
|
|
32
|
-
Assertion.assertObject(payload);
|
|
33
|
-
|
|
34
|
-
const route = Routes.guilds.bets.create(this.guild.id);
|
|
35
|
-
const response = await this.rest.request<APIGuildBet, typeof payload>({
|
|
36
|
-
method: "POST",
|
|
37
|
-
url: route,
|
|
38
|
-
});
|
|
39
|
-
const bet = this.set(response);
|
|
40
|
-
return bet;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Fetch a bet
|
|
45
|
-
* @param id Id of the bet to fetch
|
|
46
|
-
* @returns APIBetUser
|
|
47
|
-
*/
|
|
48
|
-
async fetch(id: string) {
|
|
49
|
-
const route = Routes.guilds.bets.get(this.guild.id, id);
|
|
50
|
-
const response = await this.rest.request<APIGuildBet, {}>({
|
|
51
|
-
method: "get",
|
|
52
|
-
url: route,
|
|
53
|
-
});
|
|
54
|
-
const bet = new GuildBet(response, this.guild, this, this.rest);
|
|
55
|
-
this.cache.set(bet._id, bet);
|
|
56
|
-
this.rest.bets.set(bet._id, bet);
|
|
57
|
-
|
|
58
|
-
return bet;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async fetchAll() {
|
|
62
|
-
const route = Routes.guilds.bets.getAll(this.guild.id);
|
|
63
|
-
const response = await this.rest.request<APIGuildBet[], {}>({
|
|
64
|
-
method: "get",
|
|
65
|
-
url: route,
|
|
66
|
-
});
|
|
67
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
68
|
-
this.cache.clear();
|
|
69
|
-
return this.cache;
|
|
70
|
-
}
|
|
71
|
-
for (let betData of response) {
|
|
72
|
-
const bet = new GuildBet(betData, this.guild, this, this.rest);
|
|
73
|
-
this.cache.set(bet._id, bet);
|
|
74
|
-
}
|
|
75
|
-
return this.cache;
|
|
76
|
-
}
|
|
77
|
-
set(data: APIGuildBet): GuildBet {
|
|
78
|
-
if (!data._id) return;
|
|
79
|
-
const bet = new GuildBet(data, this.guild, this, this.rest);
|
|
80
|
-
this.cache.set(bet._id, bet);
|
|
81
|
-
this.rest.bets.set(bet._id, bet);
|
|
82
|
-
|
|
83
|
-
return bet;
|
|
84
|
-
}
|
|
85
|
-
setAll(data: APIGuildBet[]) {
|
|
86
|
-
if (!data) return this.cache;
|
|
87
|
-
for (let bet of data) this.set(bet);
|
|
88
|
-
return this.cache;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
async delete(id: string) {
|
|
92
|
-
Assertion.assertString(id);
|
|
93
|
-
|
|
94
|
-
const route = Routes.guilds.bets.delete(id, this.guild.id);
|
|
95
|
-
const bet = this.cache.get(id);
|
|
96
|
-
this.rest.emit("betDelete", bet);
|
|
97
|
-
|
|
98
|
-
await this.rest.request<boolean, {}>({
|
|
99
|
-
method: "DELETE",
|
|
100
|
-
url: route,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
this.cache.delete(id);
|
|
104
|
-
return this.cache;
|
|
105
|
-
}
|
|
106
|
-
async deleteAll() {
|
|
107
|
-
const route = Routes.guilds.bets.deleteAll(this.guild.id);
|
|
108
|
-
this.rest.emit("betsDelete", this.cache);
|
|
109
|
-
|
|
110
|
-
const value = await this.rest.request<boolean, {}>({
|
|
111
|
-
method: "DELETE",
|
|
112
|
-
url: route,
|
|
113
|
-
});
|
|
114
|
-
this.cache.clear();
|
|
115
|
-
return value;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { REST } from "../../rest/REST";
|
|
2
|
-
import { Routes } from "../../rest/Routes";
|
|
3
|
-
import { GuildBetUser } from "../../structures/betuser/GuildBetUser";
|
|
4
|
-
import { Collection } from "../../structures/Collection";
|
|
5
|
-
import { Guild } from "../../structures/guild/Guild";
|
|
6
|
-
import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
|
|
7
|
-
import { Assertion } from "../../utils/Assertion";
|
|
8
|
-
|
|
9
|
-
export class GuildBetUserManager {
|
|
10
|
-
/** A cache of users */
|
|
11
|
-
cache: Collection<string, GuildBetUser>;
|
|
12
|
-
|
|
13
|
-
/** The rest client */
|
|
14
|
-
rest: REST;
|
|
15
|
-
|
|
16
|
-
/** Bet user guild */
|
|
17
|
-
guild: Guild;
|
|
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
|
-
this.cache = new Collection<string, GuildBetUser>("betUsers");
|
|
28
|
-
}
|
|
29
|
-
set(data: APIGuildBetUser): Collection<string, GuildBetUser> {
|
|
30
|
-
if (!data.id) return;
|
|
31
|
-
const user = new GuildBetUser(data, this, this.rest);
|
|
32
|
-
this.rest.betUsers.set(user.id, user);
|
|
33
|
-
return this.cache.set(user.id, user);
|
|
34
|
-
}
|
|
35
|
-
setAll(data: APIGuildBetUser[]): Collection<string, GuildBetUser> {
|
|
36
|
-
if (!data) return this.cache;
|
|
37
|
-
for (let user of data) this.set(user);
|
|
38
|
-
return this.cache;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Fetch a user
|
|
42
|
-
* @param id Id of the user to fetch
|
|
43
|
-
* @returns GuildBetUser
|
|
44
|
-
*/
|
|
45
|
-
async fetch(id: string, name: string): Promise<GuildBetUser> {
|
|
46
|
-
const route = Routes.guilds.betUsers.get(this.guild.id, id);
|
|
47
|
-
const response = await this.rest.request<APIGuildBetUser, { name: string }>(
|
|
48
|
-
{
|
|
49
|
-
method: "get",
|
|
50
|
-
url: route,
|
|
51
|
-
payload: { name },
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
if (!response) return this.cache.get(id);
|
|
55
|
-
|
|
56
|
-
const user = new GuildBetUser(response, this, this.rest);
|
|
57
|
-
this.cache.set(user?.id, user);
|
|
58
|
-
this.rest.betUsers.set(user?.id, user);
|
|
59
|
-
|
|
60
|
-
return user;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async fetchAll(): Promise<Collection<string, GuildBetUser>> {
|
|
64
|
-
const route = Routes.guilds.betUsers.getAll(this.guild.id);
|
|
65
|
-
const response = await this.rest.request<APIGuildBetUser[], {}>({
|
|
66
|
-
method: "get",
|
|
67
|
-
url: route,
|
|
68
|
-
});
|
|
69
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
70
|
-
this.cache.clear();
|
|
71
|
-
return this.cache;
|
|
72
|
-
}
|
|
73
|
-
this.setAll(response);
|
|
74
|
-
return this.cache;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async delete(id: string) {
|
|
78
|
-
Assertion.assertString(id);
|
|
79
|
-
|
|
80
|
-
const route = Routes.guilds.betUsers.delete(id, this.guild.id);
|
|
81
|
-
const betUser = this.cache.get(id);
|
|
82
|
-
this.rest.emit("betDelete", betUser);
|
|
83
|
-
|
|
84
|
-
await this.rest.request<boolean, {}>({
|
|
85
|
-
method: "DELETE",
|
|
86
|
-
url: route,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
this.cache.delete(id);
|
|
90
|
-
return this.cache;
|
|
91
|
-
}
|
|
92
|
-
async deleteAll() {
|
|
93
|
-
const route = Routes.guilds.betUsers.deleteAll(this.guild.id);
|
|
94
|
-
this.rest.emit("betsDelete", this.cache);
|
|
95
|
-
|
|
96
|
-
const value = await this.rest.request<boolean, {}>({
|
|
97
|
-
method: "DELETE",
|
|
98
|
-
url: route,
|
|
99
|
-
});
|
|
100
|
-
this.cache.clear();
|
|
101
|
-
return value;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { REST } from "../../rest/REST";
|
|
2
|
-
import { Route, Routes } from "../../rest/Routes";
|
|
3
|
-
import { GuildBet } from "../../structures/bet/GuildBet";
|
|
4
|
-
import { Channel } from "../../structures/channel/Channel";
|
|
5
|
-
import { Collection } from "../../structures/Collection";
|
|
6
|
-
import { Guild } from "../../structures/guild/Guild";
|
|
7
|
-
import { GuildMatch } from "../../structures/match/GuildMatch";
|
|
8
|
-
import { Optional } from "../../types/api";
|
|
9
|
-
import { APIBaseChannel } from "../../types/api/APIBaseChannel";
|
|
10
|
-
|
|
11
|
-
import { Assertion } from "../../utils/Assertion";
|
|
12
|
-
type Channels = Optional<APIBaseChannel>;
|
|
13
|
-
|
|
14
|
-
export class ChannelManager<Structure extends GuildBet | GuildMatch> {
|
|
15
|
-
/** A cache of bet channels */
|
|
16
|
-
cache: Collection<string, Channel<Structure>>;
|
|
17
|
-
|
|
18
|
-
/** The rest client */
|
|
19
|
-
rest: REST;
|
|
20
|
-
|
|
21
|
-
/** GuildBet user guild */
|
|
22
|
-
guild: Guild;
|
|
23
|
-
|
|
24
|
-
/** The bet */
|
|
25
|
-
structure: Structure;
|
|
26
|
-
|
|
27
|
-
/** Base Url */
|
|
28
|
-
baseUrl: string;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Manage channels of a bet
|
|
32
|
-
* @param guild The guild at hand
|
|
33
|
-
* @param bet The bet at hand
|
|
34
|
-
* @param rest The rest client
|
|
35
|
-
*/
|
|
36
|
-
constructor(guild: Guild, structure: Structure, rest: REST) {
|
|
37
|
-
this.structure = structure;
|
|
38
|
-
this.rest = rest;
|
|
39
|
-
this.guild = guild;
|
|
40
|
-
this.cache = new Collection<string, Channel<Structure>>("channels");
|
|
41
|
-
this.baseUrl = Routes.guilds[structure.key as "bets"].resource(guild.id, structure._id, "channels");
|
|
42
|
-
}
|
|
43
|
-
async create(id: string, type: string): Promise<Channel<Structure>> {
|
|
44
|
-
Assertion.assertString(id);
|
|
45
|
-
Assertion.assertString(type);
|
|
46
|
-
|
|
47
|
-
const route = this.baseUrl;
|
|
48
|
-
const payload = { id, type };
|
|
49
|
-
const response = await this.rest.request<APIBaseChannel, typeof payload>({
|
|
50
|
-
method: "POST",
|
|
51
|
-
url: route,
|
|
52
|
-
payload,
|
|
53
|
-
});
|
|
54
|
-
const channel = this.set(response);
|
|
55
|
-
|
|
56
|
-
this.rest.emit("channelCreate", channel);
|
|
57
|
-
return channel;
|
|
58
|
-
}
|
|
59
|
-
async createMany(...channels: Channels[]) {
|
|
60
|
-
Assertion.assertArray(channels);
|
|
61
|
-
const route = Routes.fields(this.baseUrl, "bulk");
|
|
62
|
-
const payload = { channels };
|
|
63
|
-
const response = await this.rest.request<APIBaseChannel[], typeof payload>({
|
|
64
|
-
method: "POST",
|
|
65
|
-
url: route,
|
|
66
|
-
payload,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
this.rest.emit("channelBulkCreate", response);
|
|
70
|
-
return this.setAll(response);
|
|
71
|
-
}
|
|
72
|
-
async deleteMany(...channels: Optional<APIBaseChannel>[]) {
|
|
73
|
-
Assertion.assertArray(channels);
|
|
74
|
-
|
|
75
|
-
const route = Routes.fields(this.baseUrl, "bulk");
|
|
76
|
-
const payload = { channels };
|
|
77
|
-
const response = await this.rest.request<APIBaseChannel[], typeof payload>({
|
|
78
|
-
method: "DELETE",
|
|
79
|
-
url: route,
|
|
80
|
-
payload,
|
|
81
|
-
});
|
|
82
|
-
const channel = this.setAll(response);
|
|
83
|
-
|
|
84
|
-
this.rest.emit("channelBulkDelete", channel);
|
|
85
|
-
return channel;
|
|
86
|
-
}
|
|
87
|
-
setAll(data: APIBaseChannel[]): Collection<string, Channel<Structure>> {
|
|
88
|
-
if (!data) return this.cache;
|
|
89
|
-
for (let channelData of data) this.set(channelData);
|
|
90
|
-
return this.cache;
|
|
91
|
-
}
|
|
92
|
-
set(data: APIBaseChannel): Channel<Structure> {
|
|
93
|
-
if (!data.type) return;
|
|
94
|
-
const channel = new Channel(
|
|
95
|
-
{
|
|
96
|
-
baseUrl: Routes.guilds[this.structure.key as "bets"].resource(this.guild.id, this.structure._id, "channels"),
|
|
97
|
-
data: data,
|
|
98
|
-
guild: this.guild,
|
|
99
|
-
manager: this,
|
|
100
|
-
},
|
|
101
|
-
this.rest
|
|
102
|
-
);
|
|
103
|
-
this.cache.set(data.type, channel);
|
|
104
|
-
return channel;
|
|
105
|
-
}
|
|
106
|
-
async update(type: string, payload: Optional<APIBaseChannel>): Promise<Channel<Structure>> {
|
|
107
|
-
Assertion.assertString(type);
|
|
108
|
-
Assertion.assertObject(payload);
|
|
109
|
-
|
|
110
|
-
const route = Routes.fields(this.baseUrl, type);
|
|
111
|
-
const response = await this.rest.request<APIBaseChannel, {}>({
|
|
112
|
-
method: "PATCH",
|
|
113
|
-
url: route,
|
|
114
|
-
payload,
|
|
115
|
-
});
|
|
116
|
-
const channel = this.set(response);
|
|
117
|
-
this.rest.emit("betUpdate", this.structure, this.structure);
|
|
118
|
-
return channel;
|
|
119
|
-
}
|
|
120
|
-
async fetch(type: string): Promise<Channel<Structure>> {
|
|
121
|
-
Assertion.assertString(type);
|
|
122
|
-
|
|
123
|
-
const route = Routes.fields(this.baseUrl, type);
|
|
124
|
-
const response = await this.rest.request<APIBaseChannel, {}>({
|
|
125
|
-
method: "GET",
|
|
126
|
-
url: route,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const channel = this.set(response);
|
|
130
|
-
this.cache.set(channel.type, channel);
|
|
131
|
-
|
|
132
|
-
return channel;
|
|
133
|
-
}
|
|
134
|
-
async fetchAll() {
|
|
135
|
-
const response = await this.rest.request<APIBaseChannel[], {}>({
|
|
136
|
-
method: "GET",
|
|
137
|
-
url: this.baseUrl,
|
|
138
|
-
});
|
|
139
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
140
|
-
this.cache.clear();
|
|
141
|
-
return this.cache;
|
|
142
|
-
}
|
|
143
|
-
for (let channelData of response) this.set(channelData);
|
|
144
|
-
return this.cache;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async delete(type: string): Promise<Collection<string, Channel<Structure>>> {
|
|
148
|
-
Assertion.assertString(type);
|
|
149
|
-
|
|
150
|
-
const route = this.baseUrl;
|
|
151
|
-
const response = await this.rest.request<APIBaseChannel[], {}>({
|
|
152
|
-
method: "DELETE",
|
|
153
|
-
url: Routes.fields(route, type),
|
|
154
|
-
});
|
|
155
|
-
this.cache.delete(type);
|
|
156
|
-
return this.cache;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async deleteAll(): Promise<boolean> {
|
|
160
|
-
const route = this.baseUrl;
|
|
161
|
-
const value = await this.rest.request<boolean, {}>({
|
|
162
|
-
method: "DELETE",
|
|
163
|
-
url: route,
|
|
164
|
-
});
|
|
165
|
-
this.cache.clear();
|
|
166
|
-
return value;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { REST } from "../../rest/REST";
|
|
2
|
-
import { Routes } from "../../rest/Routes";
|
|
3
|
-
import { GroupedChannel } from "../../structures/groupedchannel/GroupedChannel";
|
|
4
|
-
import { Collection } from "../../structures/Collection";
|
|
5
|
-
import { Guild } from "../../structures/guild/Guild";
|
|
6
|
-
import { Optional } from "../../types/api";
|
|
7
|
-
import { APIGuildGroupedChannel } from "../../types/api/APIGuildGroupedChannel";
|
|
8
|
-
import { Assertion } from "../../utils/Assertion";
|
|
9
|
-
|
|
10
|
-
export class GroupedChannelManager {
|
|
11
|
-
/** A cache of channels */
|
|
12
|
-
cache: Collection<string, GroupedChannel>;
|
|
13
|
-
|
|
14
|
-
/** Key */
|
|
15
|
-
key: string;
|
|
16
|
-
|
|
17
|
-
baseUrl: string;
|
|
18
|
-
|
|
19
|
-
/** The rest client */
|
|
20
|
-
rest: REST;
|
|
21
|
-
|
|
22
|
-
/** GroupedChannel groupedChannel guild */
|
|
23
|
-
guild: Guild;
|
|
24
|
-
/**
|
|
25
|
-
* Manage channels with the given client
|
|
26
|
-
* @param channels An array of channels
|
|
27
|
-
* @param rest The rest client
|
|
28
|
-
*/
|
|
29
|
-
constructor(guild: Guild, key: string, rest: REST) {
|
|
30
|
-
this.key = key;
|
|
31
|
-
this.baseUrl = Routes.fields(Routes.guilds.get(guild?.id), key);
|
|
32
|
-
|
|
33
|
-
this.cache = new Collection<string, GroupedChannel>("groupedChannels");
|
|
34
|
-
|
|
35
|
-
this.guild = guild;
|
|
36
|
-
this.rest = rest;
|
|
37
|
-
}
|
|
38
|
-
async delete(type: string) {
|
|
39
|
-
const route = Routes.fields(this.baseUrl, type);
|
|
40
|
-
const response = await this.rest.request<boolean, {}>({
|
|
41
|
-
method: "delete",
|
|
42
|
-
url: route,
|
|
43
|
-
});
|
|
44
|
-
this.cache.delete(type);
|
|
45
|
-
return response;
|
|
46
|
-
}
|
|
47
|
-
async create(
|
|
48
|
-
payload: Optional<APIGuildGroupedChannel>
|
|
49
|
-
): Promise<GroupedChannel> {
|
|
50
|
-
Assertion.assertObject(payload);
|
|
51
|
-
|
|
52
|
-
const route = this.baseUrl;
|
|
53
|
-
const response = await this.rest.request<
|
|
54
|
-
APIGuildGroupedChannel,
|
|
55
|
-
typeof payload
|
|
56
|
-
>({
|
|
57
|
-
method: "POST",
|
|
58
|
-
url: route,
|
|
59
|
-
payload,
|
|
60
|
-
});
|
|
61
|
-
const groupedChannel = this.set(response);
|
|
62
|
-
return groupedChannel;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Fetch a groupedChannel
|
|
67
|
-
* @param id Id of the groupedChannel to fetch
|
|
68
|
-
* @returns APIgroupedChannelUser
|
|
69
|
-
*/
|
|
70
|
-
async fetch(type: string) {
|
|
71
|
-
const route = Routes.fields(this.baseUrl, type);
|
|
72
|
-
const response = await this.rest.request<APIGuildGroupedChannel, {}>({
|
|
73
|
-
method: "get",
|
|
74
|
-
url: route,
|
|
75
|
-
});
|
|
76
|
-
const channel = this.set(response);
|
|
77
|
-
this.cache.set(channel.type, channel);
|
|
78
|
-
|
|
79
|
-
return channel;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async fetchAll() {
|
|
83
|
-
const route = this.baseUrl;
|
|
84
|
-
const response = await this.rest.request<APIGuildGroupedChannel[], {}>({
|
|
85
|
-
method: "get",
|
|
86
|
-
url: route,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
for (let groupedChannelData of response) {
|
|
90
|
-
const groupedChannel = new GroupedChannel(
|
|
91
|
-
groupedChannelData,
|
|
92
|
-
this.guild,
|
|
93
|
-
this,
|
|
94
|
-
this.rest
|
|
95
|
-
);
|
|
96
|
-
this.cache.set(groupedChannel.type, groupedChannel);
|
|
97
|
-
}
|
|
98
|
-
return this.cache;
|
|
99
|
-
}
|
|
100
|
-
setAll(data: APIGuildGroupedChannel[]) {
|
|
101
|
-
if (!data) return this.cache;
|
|
102
|
-
for (let groupedChannel of data) this.set(groupedChannel);
|
|
103
|
-
return this.cache;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
set(data: APIGuildGroupedChannel): GroupedChannel {
|
|
107
|
-
if (!data?.type) return;
|
|
108
|
-
const groupedChannel = new GroupedChannel(
|
|
109
|
-
data,
|
|
110
|
-
this.guild,
|
|
111
|
-
this,
|
|
112
|
-
this.rest
|
|
113
|
-
);
|
|
114
|
-
this.cache.set(data.type, groupedChannel);
|
|
115
|
-
return groupedChannel;
|
|
116
|
-
}
|
|
117
|
-
}
|