@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,15 +0,0 @@
|
|
|
1
|
-
import { APIProduct } from "./APIProduct";
|
|
2
|
-
|
|
3
|
-
export interface APIGuildShop {
|
|
4
|
-
/** Shop's product */
|
|
5
|
-
products: APIProduct[];
|
|
6
|
-
|
|
7
|
-
/** Bought count */
|
|
8
|
-
boughtCount: number;
|
|
9
|
-
|
|
10
|
-
/** Creation Date */
|
|
11
|
-
createdAt: Date;
|
|
12
|
-
|
|
13
|
-
/** Updated Date */
|
|
14
|
-
updatedAt: Date;
|
|
15
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { APIMessage } from "./APIMessage";
|
|
2
|
-
|
|
3
|
-
export interface APIGuildTicket {
|
|
4
|
-
/** Ticket's id */
|
|
5
|
-
id: string;
|
|
6
|
-
|
|
7
|
-
/** Ticket's creator id */
|
|
8
|
-
creatorId: string;
|
|
9
|
-
|
|
10
|
-
/** Ticket's admin id */
|
|
11
|
-
adminId: string;
|
|
12
|
-
|
|
13
|
-
/** Ticket's rating that customer gave */
|
|
14
|
-
customerRating: number;
|
|
15
|
-
|
|
16
|
-
/** Ticket's channel id */
|
|
17
|
-
channelId: string;
|
|
18
|
-
|
|
19
|
-
/** Ticket's closed by who */
|
|
20
|
-
closedById: string;
|
|
21
|
-
|
|
22
|
-
/** Ticket's type */
|
|
23
|
-
type: string;
|
|
24
|
-
|
|
25
|
-
/** Ticket's status */
|
|
26
|
-
status: "on" | "off";
|
|
27
|
-
|
|
28
|
-
/** Ticket's messages */
|
|
29
|
-
messages: APIMessage[];
|
|
30
|
-
|
|
31
|
-
/** Creation Date */
|
|
32
|
-
createdAt: Date;
|
|
33
|
-
|
|
34
|
-
/** Updated Date */
|
|
35
|
-
updatedAt: Date;
|
|
36
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Accessory, Daily, Items, OriginalChannels } from ".";
|
|
2
|
-
|
|
3
|
-
export interface APIGuildUser {
|
|
4
|
-
/** User's id */
|
|
5
|
-
id: string;
|
|
6
|
-
|
|
7
|
-
/** User name */
|
|
8
|
-
name: string;
|
|
9
|
-
|
|
10
|
-
/** User's daily */
|
|
11
|
-
daily: Omit<Daily, "credit">;
|
|
12
|
-
|
|
13
|
-
/** User's points */
|
|
14
|
-
points: number;
|
|
15
|
-
|
|
16
|
-
/** User's wins */
|
|
17
|
-
wins: number;
|
|
18
|
-
|
|
19
|
-
/** User's mvps */
|
|
20
|
-
mvps: number;
|
|
21
|
-
|
|
22
|
-
/** User's losses */
|
|
23
|
-
losses: number;
|
|
24
|
-
|
|
25
|
-
/** User's games */
|
|
26
|
-
games: number;
|
|
27
|
-
|
|
28
|
-
/** If user is blacklisted */
|
|
29
|
-
blacklist: boolean;
|
|
30
|
-
|
|
31
|
-
/** User's accessories such as double point */
|
|
32
|
-
accessories: Accessory[];
|
|
33
|
-
|
|
34
|
-
/** User's original channels */
|
|
35
|
-
originalChannels: OriginalChannels;
|
|
36
|
-
|
|
37
|
-
/** User's items */
|
|
38
|
-
items: Items;
|
|
39
|
-
|
|
40
|
-
/** Creation Date */
|
|
41
|
-
createdAt: Date;
|
|
42
|
-
|
|
43
|
-
/** Updated Date */
|
|
44
|
-
updatedAt: Date;
|
|
45
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface APIMessage {
|
|
2
|
-
/** Message's content */
|
|
3
|
-
content: string | object;
|
|
4
|
-
|
|
5
|
-
/** Message's creator id */
|
|
6
|
-
userId: string;
|
|
7
|
-
|
|
8
|
-
/** Message's type */
|
|
9
|
-
type: "text" | "img" | ".png" | ".gif" | ".jpg";
|
|
10
|
-
|
|
11
|
-
/** Creation Date */
|
|
12
|
-
createdAt: Date;
|
|
13
|
-
|
|
14
|
-
/** Updated Date */
|
|
15
|
-
updatedAt: Date;
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { APIPlayer } from "./APIPlayer";
|
|
2
|
-
|
|
3
|
-
export interface APIProduct {
|
|
4
|
-
/** Product's name */
|
|
5
|
-
name: string;
|
|
6
|
-
|
|
7
|
-
/** Product's description */
|
|
8
|
-
description: string;
|
|
9
|
-
|
|
10
|
-
/** Product's id */
|
|
11
|
-
id: string;
|
|
12
|
-
|
|
13
|
-
/** Product's price */
|
|
14
|
-
price: number;
|
|
15
|
-
|
|
16
|
-
/** Product's buyers */
|
|
17
|
-
buyers: APIPlayer[];
|
|
18
|
-
|
|
19
|
-
/** Product's emoji */
|
|
20
|
-
emoji: string;
|
|
21
|
-
|
|
22
|
-
/** Creation Date */
|
|
23
|
-
createdAt: Date;
|
|
24
|
-
|
|
25
|
-
/** Updated Date */
|
|
26
|
-
updatedAt: Date;
|
|
27
|
-
};
|
package/src/types/api/index.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
export interface APITicketCategory {
|
|
2
|
-
/** Category's type */
|
|
3
|
-
type: string;
|
|
4
|
-
|
|
5
|
-
/** Category's emoji */
|
|
6
|
-
emoji: string;
|
|
7
|
-
|
|
8
|
-
/** Category's description */
|
|
9
|
-
description: string;
|
|
10
|
-
|
|
11
|
-
/** Category's alias */
|
|
12
|
-
alias: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Blacklisted {
|
|
16
|
-
/** Blacklist's id */
|
|
17
|
-
id: string;
|
|
18
|
-
|
|
19
|
-
/** Blacklist added by */
|
|
20
|
-
addedBy: string;
|
|
21
|
-
|
|
22
|
-
/** Guild Creation Date */
|
|
23
|
-
createdAt: Date;
|
|
24
|
-
|
|
25
|
-
/** Guild Updated Date */
|
|
26
|
-
updatedAt: Date;
|
|
27
|
-
}
|
|
28
|
-
export type GuildBlacklist = Blacklisted[];
|
|
29
|
-
|
|
30
|
-
export interface LogMessage {
|
|
31
|
-
/** The message's content */
|
|
32
|
-
content: string | Buffer<any>;
|
|
33
|
-
|
|
34
|
-
/** The message's sender */
|
|
35
|
-
userId: string;
|
|
36
|
-
|
|
37
|
-
/** The message's type */
|
|
38
|
-
type: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Base match modes */
|
|
42
|
-
export type BaseMatchModes =
|
|
43
|
-
| "1x1"
|
|
44
|
-
| "2x2"
|
|
45
|
-
| "3x3"
|
|
46
|
-
| "4x4"
|
|
47
|
-
| "5x5"
|
|
48
|
-
| "6x6"
|
|
49
|
-
| "1v1"
|
|
50
|
-
| "2v2"
|
|
51
|
-
| "3v3"
|
|
52
|
-
| "4v4"
|
|
53
|
-
| "5v5"
|
|
54
|
-
| "6v6";
|
|
55
|
-
|
|
56
|
-
/** Base match status */
|
|
57
|
-
export type BaseMatchStatus = "on" | "created" | "off" | "shutted";
|
|
58
|
-
|
|
59
|
-
/** The logs of the structure */
|
|
60
|
-
export interface Logs {
|
|
61
|
-
/** The messages of the structure */
|
|
62
|
-
messages: LogMessage[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Original Channel */
|
|
66
|
-
export type OriginalChannel = {
|
|
67
|
-
/** Channel id */
|
|
68
|
-
channelId: string;
|
|
69
|
-
|
|
70
|
-
/** Match id */
|
|
71
|
-
matchId: string;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/** Items */
|
|
75
|
-
export type Items = string[];
|
|
76
|
-
|
|
77
|
-
/** Original Channels */
|
|
78
|
-
export type OriginalChannels = OriginalChannel[];
|
|
79
|
-
|
|
80
|
-
/** Accessories */
|
|
81
|
-
export type Accessory = {
|
|
82
|
-
/** Accessory type */
|
|
83
|
-
type: "point_protect" | "immunity" | "double_points";
|
|
84
|
-
|
|
85
|
-
/** Accessory longevity */
|
|
86
|
-
longevity: string;
|
|
87
|
-
|
|
88
|
-
/** Accessory adder */
|
|
89
|
-
addedBy: string;
|
|
90
|
-
|
|
91
|
-
/** When accessory added */
|
|
92
|
-
when: Date;
|
|
93
|
-
|
|
94
|
-
/** If accessory has expired */
|
|
95
|
-
expired: boolean;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/** Daily information */
|
|
99
|
-
export type Daily = {
|
|
100
|
-
/** Wins */
|
|
101
|
-
wins: number;
|
|
102
|
-
|
|
103
|
-
/** Coins */
|
|
104
|
-
coins: number;
|
|
105
|
-
|
|
106
|
-
/** Points */
|
|
107
|
-
points: number;
|
|
108
|
-
|
|
109
|
-
/** Credit */
|
|
110
|
-
credit: number;
|
|
111
|
-
|
|
112
|
-
/** Losses */
|
|
113
|
-
losses: number;
|
|
114
|
-
|
|
115
|
-
/** Mvps */
|
|
116
|
-
mvps: number;
|
|
117
|
-
|
|
118
|
-
/** Date of the daily */
|
|
119
|
-
date: Date;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export interface Banner {
|
|
123
|
-
/** Equipped banner */
|
|
124
|
-
equipped: number;
|
|
125
|
-
|
|
126
|
-
/** Bought banners */
|
|
127
|
-
allowed: number[];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface ProfileCard {
|
|
131
|
-
/** Profile's description */
|
|
132
|
-
description: string;
|
|
133
|
-
|
|
134
|
-
/** Profile's banner */
|
|
135
|
-
banner: Banner;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export interface Confirm {
|
|
139
|
-
/** Confirm's type */
|
|
140
|
-
type: string;
|
|
141
|
-
|
|
142
|
-
/** Confirm's id */
|
|
143
|
-
ids: string[];
|
|
144
|
-
|
|
145
|
-
/** Confirm's counts */
|
|
146
|
-
count: number;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export type Optional<T> = { [K in keyof T]?: T[K] };
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
export enum MATCHTYPES {
|
|
153
|
-
OneVOne = "1v1",
|
|
154
|
-
TwoVTwo = "2v2",
|
|
155
|
-
ThreeVThree = "3v3",
|
|
156
|
-
FourVFour = "4v4",
|
|
157
|
-
FiveVFive = "5v5",
|
|
158
|
-
SixVSix = "6v6",
|
|
159
|
-
}
|
|
160
|
-
export enum MATCHSTATUS {
|
|
161
|
-
ON = "on",
|
|
162
|
-
OFF = "off",
|
|
163
|
-
CREATED = "created",
|
|
164
|
-
SHUTTED = "shutted",
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export enum BETSTATUS {
|
|
168
|
-
ON = "on",
|
|
169
|
-
OFF = "off",
|
|
170
|
-
CREATED = "created",
|
|
171
|
-
SHUTTED = "shutted",
|
|
172
|
-
WAITING = "waiting",
|
|
173
|
-
}
|
|
174
|
-
export enum STATES {
|
|
175
|
-
ON = "on",
|
|
176
|
-
OFF = "off",
|
|
177
|
-
CREATED = "created",
|
|
178
|
-
SHUTTED = "shutted",
|
|
179
|
-
WAITING = "waiting",
|
|
180
|
-
}
|
package/src/utils/Assertion.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Class used to assert types in the sdk
|
|
3
|
-
*/
|
|
4
|
-
export class Assertion {
|
|
5
|
-
constructor() {}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Tests if given key is a string
|
|
9
|
-
* @param key Key to test
|
|
10
|
-
*/
|
|
11
|
-
static assertString(key: unknown): key is string {
|
|
12
|
-
if (typeof key !== "string") throw new Error(`${key} must be a string`);
|
|
13
|
-
if (!key || key === "") throw new Error(`${key} must be a string`);
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Tests if given key is a number
|
|
19
|
-
* @param key Key to test
|
|
20
|
-
*/
|
|
21
|
-
static assertNumber(key: unknown): key is number {
|
|
22
|
-
if (typeof key !== "number") throw new Error(`${key} must be a number`);
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Tests if given key is a boolean
|
|
28
|
-
* @param key Key to test
|
|
29
|
-
*/
|
|
30
|
-
static assertBoolean(key: unknown): key is boolean {
|
|
31
|
-
if (typeof key !== "boolean") throw new Error(`${key} must be a boolean`);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Tests if given key is an array
|
|
37
|
-
* @param key Key to test
|
|
38
|
-
*/
|
|
39
|
-
static assertArray(key: unknown): key is object {
|
|
40
|
-
if (!Array.isArray(key)) throw new Error(`${key} must be an array`);
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Tests if given key is an object
|
|
46
|
-
* @param key Key to test
|
|
47
|
-
*/
|
|
48
|
-
static assertObject(key: unknown): key is object {
|
|
49
|
-
if (typeof key !== "object") throw new Error(`${key} must be an object`);
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
toString() {
|
|
54
|
-
return 'string, number, boolean, array, object';
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { REST } from "../../../rest/REST";
|
|
2
|
-
import { 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 { APIBaseChannel, Optional } from "../../../types";
|
|
9
|
-
import { Assertion } from "../../../utils/Assertion";
|
|
10
|
-
|
|
11
|
-
type Channels = Optional<APIBaseChannel>;
|
|
12
|
-
|
|
13
|
-
export class ChannelManager<Structure extends GuildBet | GuildMatch> {
|
|
14
|
-
/** A cache of bet channels */
|
|
15
|
-
cache: Collection<string, Channel<Structure>>;
|
|
16
|
-
|
|
17
|
-
/** The rest client */
|
|
18
|
-
rest: REST;
|
|
19
|
-
|
|
20
|
-
/** GuildBet user guild */
|
|
21
|
-
guild: Guild;
|
|
22
|
-
|
|
23
|
-
/** The bet */
|
|
24
|
-
structure: Structure;
|
|
25
|
-
|
|
26
|
-
/** Base Url */
|
|
27
|
-
baseUrl: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Manage channels of a bet
|
|
31
|
-
* @param guild The guild at hand
|
|
32
|
-
* @param bet The bet at hand
|
|
33
|
-
* @param rest The rest client
|
|
34
|
-
*/
|
|
35
|
-
constructor(guild: Guild, structure: Structure, rest: REST) {
|
|
36
|
-
this.structure = structure;
|
|
37
|
-
this.rest = rest;
|
|
38
|
-
this.guild = guild;
|
|
39
|
-
this.cache = new Collection<string, Channel<Structure>>("channels");
|
|
40
|
-
this.baseUrl = Routes.guilds[structure.key as "bets"].resource(guild.id, structure._id, "channels");
|
|
41
|
-
}
|
|
42
|
-
async create(id: string, type: string): Promise<Channel<Structure>> {
|
|
43
|
-
Assertion.assertString(id);
|
|
44
|
-
Assertion.assertString(type);
|
|
45
|
-
|
|
46
|
-
const route = this.baseUrl;
|
|
47
|
-
const payload = { id, type };
|
|
48
|
-
const response = await this.rest.request<APIBaseChannel, typeof payload>({
|
|
49
|
-
method: "POST",
|
|
50
|
-
url: route,
|
|
51
|
-
payload,
|
|
52
|
-
});
|
|
53
|
-
const channel = this.set(response);
|
|
54
|
-
|
|
55
|
-
this.rest.emit("channelCreate", channel);
|
|
56
|
-
return channel;
|
|
57
|
-
}
|
|
58
|
-
async createMany(...channels: Channels[]) {
|
|
59
|
-
Assertion.assertArray(channels);
|
|
60
|
-
const route = Routes.fields(this.baseUrl, "bulk");
|
|
61
|
-
const payload = { channels };
|
|
62
|
-
const response = await this.rest.request<APIBaseChannel[], typeof payload>({
|
|
63
|
-
method: "POST",
|
|
64
|
-
url: route,
|
|
65
|
-
payload,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
this.rest.emit("channelBulkCreate", response);
|
|
69
|
-
return this.setAll(response);
|
|
70
|
-
}
|
|
71
|
-
async deleteMany(...channels: Optional<APIBaseChannel>[]) {
|
|
72
|
-
Assertion.assertArray(channels);
|
|
73
|
-
|
|
74
|
-
const route = Routes.fields(this.baseUrl, "bulk");
|
|
75
|
-
const payload = { channels };
|
|
76
|
-
const response = await this.rest.request<APIBaseChannel[], typeof payload>({
|
|
77
|
-
method: "DELETE",
|
|
78
|
-
url: route,
|
|
79
|
-
payload,
|
|
80
|
-
});
|
|
81
|
-
const channel = this.setAll(response);
|
|
82
|
-
|
|
83
|
-
this.rest.emit("channelBulkDelete", channel);
|
|
84
|
-
return channel;
|
|
85
|
-
}
|
|
86
|
-
setAll(data: APIBaseChannel[]): Collection<string, Channel<Structure>> {
|
|
87
|
-
if (!data) return this.cache;
|
|
88
|
-
for (let channelData of data) this.set(channelData);
|
|
89
|
-
return this.cache;
|
|
90
|
-
}
|
|
91
|
-
set(data: APIBaseChannel): Channel<Structure> {
|
|
92
|
-
if (!data.type) return;
|
|
93
|
-
const channel = new Channel(
|
|
94
|
-
{
|
|
95
|
-
baseUrl: Routes.guilds[this.structure.key as "bets"].resource(this.guild.id, this.structure._id, "channels"),
|
|
96
|
-
data: data,
|
|
97
|
-
guild: this.guild,
|
|
98
|
-
manager: this,
|
|
99
|
-
},
|
|
100
|
-
this.rest
|
|
101
|
-
);
|
|
102
|
-
this.cache.set(data.type, channel);
|
|
103
|
-
return channel;
|
|
104
|
-
}
|
|
105
|
-
async update(type: string, payload: Optional<APIBaseChannel>): Promise<Channel<Structure>> {
|
|
106
|
-
Assertion.assertString(type);
|
|
107
|
-
Assertion.assertObject(payload);
|
|
108
|
-
|
|
109
|
-
const route = Routes.fields(this.baseUrl, type);
|
|
110
|
-
const response = await this.rest.request<APIBaseChannel, {}>({
|
|
111
|
-
method: "PATCH",
|
|
112
|
-
url: route,
|
|
113
|
-
payload,
|
|
114
|
-
});
|
|
115
|
-
const channel = this.set(response);
|
|
116
|
-
this.rest.emit("betUpdate", this.structure, this.structure);
|
|
117
|
-
return channel;
|
|
118
|
-
}
|
|
119
|
-
async fetch(type: string): Promise<Channel<Structure>> {
|
|
120
|
-
Assertion.assertString(type);
|
|
121
|
-
|
|
122
|
-
const route = Routes.fields(this.baseUrl, type);
|
|
123
|
-
const response = await this.rest.request<APIBaseChannel, {}>({
|
|
124
|
-
method: "GET",
|
|
125
|
-
url: route,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const channel = this.set(response);
|
|
129
|
-
this.cache.set(channel.type, channel);
|
|
130
|
-
|
|
131
|
-
return channel;
|
|
132
|
-
}
|
|
133
|
-
async fetchAll() {
|
|
134
|
-
const response = await this.rest.request<APIBaseChannel[], {}>({
|
|
135
|
-
method: "GET",
|
|
136
|
-
url: this.baseUrl,
|
|
137
|
-
});
|
|
138
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
139
|
-
this.cache.clear();
|
|
140
|
-
return this.cache;
|
|
141
|
-
}
|
|
142
|
-
for (let channelData of response) this.set(channelData);
|
|
143
|
-
return this.cache;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async delete(type: string): Promise<Collection<string, Channel<Structure>>> {
|
|
147
|
-
Assertion.assertString(type);
|
|
148
|
-
|
|
149
|
-
const route = this.baseUrl;
|
|
150
|
-
const response = await this.rest.request<APIBaseChannel[], {}>({
|
|
151
|
-
method: "DELETE",
|
|
152
|
-
url: Routes.fields(route, type),
|
|
153
|
-
});
|
|
154
|
-
this.cache.delete(type);
|
|
155
|
-
return this.cache;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async deleteAll(): Promise<boolean> {
|
|
159
|
-
const route = this.baseUrl;
|
|
160
|
-
const value = await this.rest.request<boolean, {}>({
|
|
161
|
-
method: "DELETE",
|
|
162
|
-
url: route,
|
|
163
|
-
});
|
|
164
|
-
this.cache.clear();
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -1,114 +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 { GuildMatch } from "../../../structures/match/GuildMatch";
|
|
6
|
-
import { APIGuildMatch, Optional } from "../../../types";
|
|
7
|
-
import { Assertion } from "../../../utils/Assertion";
|
|
8
|
-
|
|
9
|
-
export class GuildMatchManager {
|
|
10
|
-
/** A cache of users */
|
|
11
|
-
cache: Collection<string, GuildMatch>;
|
|
12
|
-
|
|
13
|
-
/** The rest client */
|
|
14
|
-
rest: REST;
|
|
15
|
-
|
|
16
|
-
/** GuildMatch match 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
|
-
|
|
26
|
-
this.cache = new Collection<string, GuildMatch>("matches");
|
|
27
|
-
this.rest = rest;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Fetch a match
|
|
32
|
-
* @param id Id of the match to fetch
|
|
33
|
-
* @returns APIBetUser
|
|
34
|
-
*/
|
|
35
|
-
async fetch(id: string) {
|
|
36
|
-
const route = Routes.guilds.matches.get(this.guild.id, id);
|
|
37
|
-
const response = await this.rest.request<APIGuildMatch, {}>({
|
|
38
|
-
method: "get",
|
|
39
|
-
url: route,
|
|
40
|
-
});
|
|
41
|
-
const match = new GuildMatch(response, this.guild, this, this.rest);
|
|
42
|
-
this.cache.set(match._id, match);
|
|
43
|
-
this.rest.matches.set(match._id, match);
|
|
44
|
-
|
|
45
|
-
return match;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async fetchAll() {
|
|
49
|
-
const route = Routes.guilds.matches.getAll(this.guild.id);
|
|
50
|
-
const response = await this.rest.request<APIGuildMatch[], {}>({
|
|
51
|
-
method: "get",
|
|
52
|
-
url: route,
|
|
53
|
-
});
|
|
54
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
55
|
-
this.cache.clear();
|
|
56
|
-
return this.cache;
|
|
57
|
-
}
|
|
58
|
-
this.setAll(response);
|
|
59
|
-
return this.cache;
|
|
60
|
-
}
|
|
61
|
-
set(data: APIGuildMatch): GuildMatch {
|
|
62
|
-
if (!data?._id) return;
|
|
63
|
-
const match = new GuildMatch(data, this?.guild, this, this.rest);
|
|
64
|
-
|
|
65
|
-
this.cache.set(data?._id, match);
|
|
66
|
-
this.rest.matches.set(data?._id, match);
|
|
67
|
-
return match;
|
|
68
|
-
}
|
|
69
|
-
setAll(data: APIGuildMatch[]) {
|
|
70
|
-
if (!data) return this.cache;
|
|
71
|
-
for (let match of data || []) this.set(match);
|
|
72
|
-
return this.cache;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async create(payload: Optional<APIGuildMatch>): Promise<GuildMatch> {
|
|
76
|
-
Assertion.assertObject(payload);
|
|
77
|
-
|
|
78
|
-
const route = Routes.guilds.matches.create(this.guild.id);
|
|
79
|
-
const response = await this.rest.request<APIGuildMatch, typeof payload>({
|
|
80
|
-
method: "POST",
|
|
81
|
-
url: route,
|
|
82
|
-
payload,
|
|
83
|
-
});
|
|
84
|
-
const match = this.set(response);
|
|
85
|
-
return match;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async delete(id: string) {
|
|
89
|
-
Assertion.assertString(id);
|
|
90
|
-
|
|
91
|
-
const route = Routes.guilds.matches.delete(id, this.guild.id);
|
|
92
|
-
const match = this.cache.get(id);
|
|
93
|
-
this.rest.emit("matchDelete", match);
|
|
94
|
-
|
|
95
|
-
await this.rest.request<boolean, {}>({
|
|
96
|
-
method: "DELETE",
|
|
97
|
-
url: route,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
this.cache.delete(id);
|
|
101
|
-
return this.cache;
|
|
102
|
-
}
|
|
103
|
-
async deleteAll() {
|
|
104
|
-
const route = Routes.guilds.matches.deleteAll(this.guild.id);
|
|
105
|
-
this.rest.emit("matchesDelete", this.cache);
|
|
106
|
-
|
|
107
|
-
const value = await this.rest.request<boolean, {}>({
|
|
108
|
-
method: "DELETE",
|
|
109
|
-
url: route,
|
|
110
|
-
});
|
|
111
|
-
this.cache.clear();
|
|
112
|
-
return value;
|
|
113
|
-
}
|
|
114
|
-
}
|