@duque.edits/sdk 0.0.7 → 0.0.8
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/dist/managers/bet/GuildBetManager.d.ts +3 -0
- package/dist/managers/bet/GuildBetManager.js +21 -3
- package/dist/managers/betuser/GuildBetUserManager.d.ts +6 -0
- package/dist/managers/betuser/GuildBetUserManager.js +57 -0
- package/dist/managers/buffer/BufferManager.d.ts +14 -0
- package/dist/managers/buffer/BufferManager.js +32 -0
- package/dist/managers/channel/ChannelManager.d.ts +1 -1
- package/dist/managers/channel/ChannelManager.js +2 -1
- package/dist/managers/mediator/GuildMediatorManager.js +2 -2
- package/dist/managers/user/GuildUserManager.d.ts +1 -0
- package/dist/managers/user/GuildUserManager.js +9 -0
- package/dist/rest/Routes.js +2 -2
- package/dist/structures/bet/GuildBet.d.ts +3 -2
- package/dist/structures/bet/GuildBet.js +34 -28
- package/dist/structures/betuser/GuildBetUser.d.ts +3 -0
- package/dist/structures/betuser/GuildBetUser.js +39 -21
- package/dist/structures/guild/Guild.d.ts +2 -0
- package/dist/structures/guild/Guild.js +14 -12
- package/dist/structures/match/GuildMatch.d.ts +1 -1
- package/dist/structures/match/GuildMatch.js +2 -2
- package/dist/structures/user/GuildUser.d.ts +2 -0
- package/dist/structures/user/GuildUser.js +21 -0
- package/dist/types/api/APIGuildBetUser.d.ts +2 -0
- package/dist/types/api/index.d.ts +4 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { Collection } from "../../structures/Collection";
|
|
|
4
4
|
import { Guild } from "../../structures/guild/Guild";
|
|
5
5
|
import { Optional } from "../../types/api";
|
|
6
6
|
import { APIGuildBet } from "../../types/api/APIGuildBet";
|
|
7
|
+
type OptionalGuildBet = Optional<APIGuildBet>;
|
|
7
8
|
export declare class GuildBetManager {
|
|
8
9
|
/** A cache of users */
|
|
9
10
|
cache: Collection<string, GuildBet>;
|
|
@@ -18,6 +19,7 @@ export declare class GuildBetManager {
|
|
|
18
19
|
*/
|
|
19
20
|
constructor(guild: Guild, rest: REST);
|
|
20
21
|
create(payload: Optional<APIGuildBet>): Promise<GuildBet>;
|
|
22
|
+
createMany(bets: OptionalGuildBet[]): Promise<Collection<string, GuildBet>>;
|
|
21
23
|
/**
|
|
22
24
|
* Fetch a bet
|
|
23
25
|
* @param id Id of the bet to fetch
|
|
@@ -30,3 +32,4 @@ export declare class GuildBetManager {
|
|
|
30
32
|
delete(id: string): Promise<Collection<string, GuildBet>>;
|
|
31
33
|
deleteAll(): Promise<boolean>;
|
|
32
34
|
}
|
|
35
|
+
export {};
|
|
@@ -28,11 +28,29 @@ class GuildBetManager {
|
|
|
28
28
|
const response = await this.rest.request({
|
|
29
29
|
method: "POST",
|
|
30
30
|
url: route,
|
|
31
|
-
payload
|
|
31
|
+
payload,
|
|
32
32
|
});
|
|
33
33
|
const bet = this.set(response);
|
|
34
34
|
return bet;
|
|
35
35
|
}
|
|
36
|
+
async createMany(bets) {
|
|
37
|
+
Assertion_1.Assertion.assertArray(bets);
|
|
38
|
+
const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, "bulk");
|
|
39
|
+
const payload = { bets };
|
|
40
|
+
const response = await this.rest.request({
|
|
41
|
+
method: "POST",
|
|
42
|
+
url: route,
|
|
43
|
+
payload,
|
|
44
|
+
});
|
|
45
|
+
this.rest.emit("betBulkCreate", response);
|
|
46
|
+
this.setAll(response);
|
|
47
|
+
const coll = new Collection_1.Collection();
|
|
48
|
+
for (let bt of response) {
|
|
49
|
+
const bet = new GuildBet_1.GuildBet(bt, this.guild, this, this.rest);
|
|
50
|
+
coll.set(bt._id, bet);
|
|
51
|
+
}
|
|
52
|
+
return coll;
|
|
53
|
+
}
|
|
36
54
|
/**
|
|
37
55
|
* Fetch a bet
|
|
38
56
|
* @param id Id of the bet to fetch
|
|
@@ -68,6 +86,8 @@ class GuildBetManager {
|
|
|
68
86
|
set(data) {
|
|
69
87
|
if (!data?._id)
|
|
70
88
|
return;
|
|
89
|
+
if (!this.guild)
|
|
90
|
+
return;
|
|
71
91
|
const bet = new GuildBet_1.GuildBet(data, this.guild, this, this.rest);
|
|
72
92
|
this.cache.set(bet._id, bet);
|
|
73
93
|
this.rest.bets.set(bet._id, bet);
|
|
@@ -80,7 +100,6 @@ class GuildBetManager {
|
|
|
80
100
|
this.set(bet);
|
|
81
101
|
return this.cache;
|
|
82
102
|
}
|
|
83
|
-
;
|
|
84
103
|
async delete(id) {
|
|
85
104
|
Assertion_1.Assertion.assertString(id);
|
|
86
105
|
const route = Routes_1.Routes.guilds.bets.delete(id, this.guild.id);
|
|
@@ -105,4 +124,3 @@ class GuildBetManager {
|
|
|
105
124
|
}
|
|
106
125
|
}
|
|
107
126
|
exports.GuildBetManager = GuildBetManager;
|
|
108
|
-
;
|
|
@@ -2,6 +2,7 @@ import { REST } from "../../rest/REST";
|
|
|
2
2
|
import { GuildBetUser } from "../../structures/betuser/GuildBetUser";
|
|
3
3
|
import { Collection } from "../../structures/Collection";
|
|
4
4
|
import { Guild } from "../../structures/guild/Guild";
|
|
5
|
+
import { APIPlayer, Optional } from "../../types";
|
|
5
6
|
import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
|
|
6
7
|
export declare class GuildBetUserManager {
|
|
7
8
|
/** A cache of users */
|
|
@@ -16,8 +17,13 @@ export declare class GuildBetUserManager {
|
|
|
16
17
|
* @param rest The rest client
|
|
17
18
|
*/
|
|
18
19
|
constructor(guild: Guild, rest: REST);
|
|
20
|
+
updateMany(data: Optional<APIPlayer>[]): Promise<Collection<string, GuildBetUser>>;
|
|
21
|
+
update(id: string, data: Optional<APIGuildBetUser> & {
|
|
22
|
+
type: "add" | "remove";
|
|
23
|
+
}): Promise<GuildBetUser>;
|
|
19
24
|
set(data: APIGuildBetUser): Collection<string, GuildBetUser>;
|
|
20
25
|
setAll(data: APIGuildBetUser[]): Collection<string, GuildBetUser>;
|
|
26
|
+
resetAll(): Promise<Collection<string, GuildBetUser>>;
|
|
21
27
|
/**
|
|
22
28
|
* Fetch a user
|
|
23
29
|
* @param id Id of the user to fetch
|
|
@@ -22,6 +22,54 @@ class GuildBetUserManager {
|
|
|
22
22
|
this.rest = rest;
|
|
23
23
|
this.cache = new Collection_1.Collection("betUsers");
|
|
24
24
|
}
|
|
25
|
+
async updateMany(data) {
|
|
26
|
+
const route = Routes_1.Routes.guilds.resources(this.guild.id, "betUsers", "bulk");
|
|
27
|
+
const payload = { betUsers: data };
|
|
28
|
+
const response = await this.rest.request({
|
|
29
|
+
method: "PATCH",
|
|
30
|
+
url: route,
|
|
31
|
+
payload,
|
|
32
|
+
});
|
|
33
|
+
this.setAll(response);
|
|
34
|
+
return this.cache;
|
|
35
|
+
}
|
|
36
|
+
async update(id, data) {
|
|
37
|
+
const route = Routes_1.Routes.guilds.betUsers.update(this.guild.id, id);
|
|
38
|
+
const payload = {};
|
|
39
|
+
const numericFields = ["coins", "wins", "credit", "losses", "mvps", "games"];
|
|
40
|
+
const arrayFields = ["items", "betsPlayed"];
|
|
41
|
+
if (data.type === "add" || data.type === "remove") {
|
|
42
|
+
for (const key in data) {
|
|
43
|
+
if (key === "type")
|
|
44
|
+
continue;
|
|
45
|
+
const value = data[key];
|
|
46
|
+
if (numericFields.includes(key)) {
|
|
47
|
+
const current = this[key];
|
|
48
|
+
const num = value;
|
|
49
|
+
payload[key] = Math.max(0, data.type === "add" ? current + num : num - current);
|
|
50
|
+
}
|
|
51
|
+
else if (key === "blacklist") {
|
|
52
|
+
payload["blacklist"] = value;
|
|
53
|
+
}
|
|
54
|
+
else if (arrayFields.includes(key)) {
|
|
55
|
+
const current = this[key];
|
|
56
|
+
const incoming = value;
|
|
57
|
+
payload[key] =
|
|
58
|
+
data.type === "add"
|
|
59
|
+
? [...new Set([...current, ...incoming])]
|
|
60
|
+
: current.filter((x) => !incoming.includes(x));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const response = await this.rest.request({
|
|
65
|
+
method: "patch",
|
|
66
|
+
url: route,
|
|
67
|
+
payload,
|
|
68
|
+
});
|
|
69
|
+
const user = new GuildBetUser_1.GuildBetUser(response, this, this.rest);
|
|
70
|
+
this.cache.set(user.id, user);
|
|
71
|
+
return user;
|
|
72
|
+
}
|
|
25
73
|
set(data) {
|
|
26
74
|
if (!data?.id)
|
|
27
75
|
return;
|
|
@@ -36,6 +84,15 @@ class GuildBetUserManager {
|
|
|
36
84
|
this.set(user);
|
|
37
85
|
return this.cache;
|
|
38
86
|
}
|
|
87
|
+
async resetAll() {
|
|
88
|
+
const route = Routes_1.Routes.guilds.betUsers.getAll(this.guild.id);
|
|
89
|
+
const response = await this.rest.request({
|
|
90
|
+
method: "PUT",
|
|
91
|
+
url: route,
|
|
92
|
+
});
|
|
93
|
+
this.setAll(response);
|
|
94
|
+
return this.cache;
|
|
95
|
+
}
|
|
39
96
|
/**
|
|
40
97
|
* Fetch a user
|
|
41
98
|
* @param id Id of the user to fetch
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Collection } from "../../structures/Collection";
|
|
2
|
+
import { Guild } from "../../structures/guild/Guild";
|
|
3
|
+
import { APIGuildMatch, APIGuildTicket, Optional } from "../../types";
|
|
4
|
+
export declare class BufferManager {
|
|
5
|
+
matches: Collection<string, Optional<APIGuildMatch & {
|
|
6
|
+
id: string;
|
|
7
|
+
}>>;
|
|
8
|
+
tickets: Collection<string, Optional<APIGuildTicket & {
|
|
9
|
+
id: string;
|
|
10
|
+
}>>;
|
|
11
|
+
guild: Guild;
|
|
12
|
+
constructor(guild: Guild);
|
|
13
|
+
flush(key: "matches" | "tickets"): Promise<APIGuildMatch[] & APIGuildTicket[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BufferManager = void 0;
|
|
4
|
+
const Routes_1 = require("../../rest/Routes");
|
|
5
|
+
const Collection_1 = require("../../structures/Collection");
|
|
6
|
+
class BufferManager {
|
|
7
|
+
matches;
|
|
8
|
+
tickets;
|
|
9
|
+
guild;
|
|
10
|
+
constructor(guild) {
|
|
11
|
+
this.matches = new Collection_1.Collection();
|
|
12
|
+
this.tickets = new Collection_1.Collection();
|
|
13
|
+
this.guild = guild;
|
|
14
|
+
}
|
|
15
|
+
async flush(key) {
|
|
16
|
+
const { rest } = this.guild;
|
|
17
|
+
const cache = this[key];
|
|
18
|
+
const { size, clear } = cache;
|
|
19
|
+
if (size >= 3) {
|
|
20
|
+
const response = await rest.request({
|
|
21
|
+
method: "POST",
|
|
22
|
+
url: Routes_1.Routes.guilds.resources(this.guild.id, key, "bulk"),
|
|
23
|
+
payload: { [key]: this[key].toArray() },
|
|
24
|
+
});
|
|
25
|
+
this.guild[key].setAll(response);
|
|
26
|
+
clear();
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.BufferManager = BufferManager;
|
|
@@ -25,7 +25,7 @@ export declare class ChannelManager<Structure extends GuildBet | GuildMatch> {
|
|
|
25
25
|
* @param rest The rest client
|
|
26
26
|
*/
|
|
27
27
|
constructor(guild: Guild, structure: Structure, rest: REST);
|
|
28
|
-
create(
|
|
28
|
+
create(data: Optional<APIBaseChannel>): Promise<Channel<Structure>>;
|
|
29
29
|
createMany(...channels: Channels[]): Promise<Collection<string, Channel<Structure>>>;
|
|
30
30
|
deleteMany(...channels: Optional<APIBaseChannel>[]): Promise<Collection<string, Channel<Structure>>>;
|
|
31
31
|
setAll(data: APIBaseChannel[]): Collection<string, Channel<Structure>>;
|
|
@@ -29,7 +29,8 @@ class ChannelManager {
|
|
|
29
29
|
this.cache = new Collection_1.Collection("channels");
|
|
30
30
|
this.baseUrl = Routes_1.Routes.guilds[structure.key].resource(guild.id, structure._id, "channels");
|
|
31
31
|
}
|
|
32
|
-
async create(
|
|
32
|
+
async create(data) {
|
|
33
|
+
const { id, type } = data;
|
|
33
34
|
Assertion_1.Assertion.assertString(id);
|
|
34
35
|
Assertion_1.Assertion.assertString(type);
|
|
35
36
|
const route = this.baseUrl;
|
|
@@ -28,7 +28,7 @@ class GuildMediatorManager {
|
|
|
28
28
|
const response = await this.rest.request({
|
|
29
29
|
method: "POST",
|
|
30
30
|
url: route,
|
|
31
|
-
payload
|
|
31
|
+
payload,
|
|
32
32
|
});
|
|
33
33
|
const mediator = this.set(response);
|
|
34
34
|
return mediator;
|
|
@@ -74,7 +74,7 @@ class GuildMediatorManager {
|
|
|
74
74
|
}
|
|
75
75
|
async delete(id) {
|
|
76
76
|
Assertion_1.Assertion.assertString(id);
|
|
77
|
-
const route = Routes_1.Routes.guilds.mediators.delete(
|
|
77
|
+
const route = Routes_1.Routes.guilds.mediators.delete(this.guild.id, id);
|
|
78
78
|
const mediator = this.cache.get(id);
|
|
79
79
|
this.rest.emit("mediatorDelete", mediator);
|
|
80
80
|
await this.rest.request({
|
|
@@ -27,6 +27,7 @@ export declare class GuildUserManager {
|
|
|
27
27
|
updateUser(id: string, name: string, data: Optional<APIGuildUser>): Promise<GuildUser>;
|
|
28
28
|
set(data: APIGuildUser): GuildUser;
|
|
29
29
|
setAll(data: APIGuildUser[]): Collection<string, GuildUser>;
|
|
30
|
+
resetAll(): Promise<Collection<string, GuildUser>>;
|
|
30
31
|
delete(id: string): Promise<Collection<string, GuildUser>>;
|
|
31
32
|
deleteAll(): Promise<boolean>;
|
|
32
33
|
}
|
|
@@ -80,6 +80,15 @@ class GuildUserManager {
|
|
|
80
80
|
this.set(user);
|
|
81
81
|
return this.cache;
|
|
82
82
|
}
|
|
83
|
+
async resetAll() {
|
|
84
|
+
const route = Routes_1.Routes.guilds.users.getAll(this.guild.id);
|
|
85
|
+
const response = await this.rest.request({
|
|
86
|
+
method: "PUT",
|
|
87
|
+
url: route,
|
|
88
|
+
});
|
|
89
|
+
this.setAll(response);
|
|
90
|
+
return this.cache;
|
|
91
|
+
}
|
|
83
92
|
async delete(id) {
|
|
84
93
|
Assertion_1.Assertion.assertString(id);
|
|
85
94
|
const route = Routes_1.Routes.guilds.users.delete(id, this.guild.id);
|
package/dist/rest/Routes.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.Routes = exports.Route = void 0;
|
|
|
4
4
|
const Route = (route) => route;
|
|
5
5
|
exports.Route = Route;
|
|
6
6
|
exports.Routes = {
|
|
7
|
-
|
|
8
|
-
base: "https://duquedev.up.railway.app/api/v1",
|
|
7
|
+
base: "http://localhost:3000/api/v1",
|
|
8
|
+
//base: "https://duquedev.up.railway.app/api/v1",
|
|
9
9
|
field: (field) => `${field}`,
|
|
10
10
|
fields: (...fields) => `${fields.join("/")}`,
|
|
11
11
|
guilds: {
|
|
@@ -75,11 +75,12 @@ export declare class GuildBet {
|
|
|
75
75
|
setStatus(status: ExtendedMatchStatus): Promise<this>;
|
|
76
76
|
setWinner(userId: string): Promise<string>;
|
|
77
77
|
setLoser(userId: string): Promise<string>;
|
|
78
|
+
delete(): Promise<boolean>;
|
|
78
79
|
addChannel(id: string, type: string): Promise<import("../..").Channel<GuildBet>>;
|
|
79
80
|
addMessage(id: string, type: string, content?: string): Promise<import("../..").APIMessage>;
|
|
80
81
|
setChannels(channels: APIBetChannel[]): Promise<ChannelManager<GuildBet>>;
|
|
81
|
-
addPlayer(
|
|
82
|
-
removePlayer(
|
|
82
|
+
addPlayer(player: Optional<APIPlayer>): Promise<APIPlayer[]>;
|
|
83
|
+
removePlayer(player: Optional<APIPlayer>): Promise<APIPlayer[]>;
|
|
83
84
|
update(data: Optional<APIGuildBet>): Promise<this>;
|
|
84
85
|
toJSON(): Record<string, unknown>;
|
|
85
86
|
}
|
|
@@ -61,33 +61,33 @@ class GuildBet {
|
|
|
61
61
|
* @param rest The rest client
|
|
62
62
|
*/
|
|
63
63
|
constructor(data, guild, manager, rest) {
|
|
64
|
-
this.type = data
|
|
65
|
-
this.mode = data
|
|
66
|
-
this.status = data
|
|
67
|
-
this.maximumSize = data
|
|
68
|
-
this.price = data
|
|
69
|
-
this.payedBy = data
|
|
70
|
-
this.players = data
|
|
71
|
-
this.teamA = data
|
|
72
|
-
this.teamB = data
|
|
73
|
-
this.winner = data
|
|
74
|
-
this.loser = data
|
|
75
|
-
this.creatorId = data
|
|
76
|
-
this.mediatorId = data
|
|
77
|
-
this.confirmed = data
|
|
78
|
-
this.embedMessageId = data
|
|
64
|
+
this.type = data?.type;
|
|
65
|
+
this.mode = data?.mode;
|
|
66
|
+
this.status = data?.status;
|
|
67
|
+
this.maximumSize = data?.maximumSize;
|
|
68
|
+
this.price = data?.price;
|
|
69
|
+
this.payedBy = data?.payedBy;
|
|
70
|
+
this.players = data?.players;
|
|
71
|
+
this.teamA = data?.teamA;
|
|
72
|
+
this.teamB = data?.teamB;
|
|
73
|
+
this.winner = data?.winner;
|
|
74
|
+
this.loser = data?.loser;
|
|
75
|
+
this.creatorId = data?.creatorId;
|
|
76
|
+
this.mediatorId = data?.mediatorId;
|
|
77
|
+
this.confirmed = data?.confirmed;
|
|
78
|
+
this.embedMessageId = data?.embedMessageId;
|
|
79
79
|
this.winner = data?.winner;
|
|
80
80
|
this.loser = data?.loser;
|
|
81
81
|
this._id = data?._id;
|
|
82
|
-
this.logs = data
|
|
82
|
+
this.logs = data?.logs;
|
|
83
|
+
this.guild = guild;
|
|
84
|
+
this.rest = rest;
|
|
83
85
|
this.manager = manager;
|
|
84
86
|
this.key = "bets";
|
|
85
87
|
this.channels = new ChannelManager_1.ChannelManager(guild, this, rest);
|
|
86
88
|
this.messages = new MessagesManager_1.MessagesManager(this?.guild, `bets/${data?._id}`, rest);
|
|
87
89
|
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
88
90
|
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
89
|
-
this.guild = guild;
|
|
90
|
-
this.rest = rest;
|
|
91
91
|
this.channels.setAll(data?.channels);
|
|
92
92
|
this.messages.setAll(data?.messages);
|
|
93
93
|
}
|
|
@@ -178,8 +178,16 @@ class GuildBet {
|
|
|
178
178
|
this.manager.cache.set(this._id, this);
|
|
179
179
|
return response.loser;
|
|
180
180
|
}
|
|
181
|
+
async delete() {
|
|
182
|
+
const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id);
|
|
183
|
+
const response = await this.rest.request({
|
|
184
|
+
method: "DELETE",
|
|
185
|
+
url: route,
|
|
186
|
+
});
|
|
187
|
+
return response;
|
|
188
|
+
}
|
|
181
189
|
async addChannel(id, type) {
|
|
182
|
-
const ch = await this.channels.create(id, type);
|
|
190
|
+
const ch = await this.channels.create({ id, type });
|
|
183
191
|
this.manager.cache.set(this._id, this);
|
|
184
192
|
return ch;
|
|
185
193
|
}
|
|
@@ -207,11 +215,10 @@ class GuildBet {
|
|
|
207
215
|
this.manager.cache.set(this._id, this);
|
|
208
216
|
return this.channels;
|
|
209
217
|
}
|
|
210
|
-
async addPlayer(
|
|
211
|
-
Assertion_1.Assertion.
|
|
212
|
-
Assertion_1.Assertion.assertString(name);
|
|
218
|
+
async addPlayer(player) {
|
|
219
|
+
Assertion_1.Assertion.assertObject(player);
|
|
213
220
|
const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players");
|
|
214
|
-
const payload = {
|
|
221
|
+
const payload = { ...player };
|
|
215
222
|
const response = await this.rest.request({
|
|
216
223
|
method: "POST",
|
|
217
224
|
url: route,
|
|
@@ -221,11 +228,10 @@ class GuildBet {
|
|
|
221
228
|
this.manager.cache.set(this._id, this);
|
|
222
229
|
return this.players;
|
|
223
230
|
}
|
|
224
|
-
async removePlayer(
|
|
225
|
-
Assertion_1.Assertion.
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
const payload = { id, name };
|
|
231
|
+
async removePlayer(player) {
|
|
232
|
+
Assertion_1.Assertion.assertObject(player);
|
|
233
|
+
const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, this._id, "players", player.id);
|
|
234
|
+
const payload = { ...player };
|
|
229
235
|
const response = await this.rest.request({
|
|
230
236
|
method: "DELETE",
|
|
231
237
|
url: route,
|
|
@@ -3,6 +3,7 @@ import { Daily, Items, Optional, ProfileCard } from "../../types/api";
|
|
|
3
3
|
import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
|
|
4
4
|
import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
|
|
5
5
|
export declare class GuildBetUser implements APIGuildBetUser {
|
|
6
|
+
#private;
|
|
6
7
|
/** User daily */
|
|
7
8
|
daily: Omit<Daily, "points">;
|
|
8
9
|
/** User's name */
|
|
@@ -23,6 +24,7 @@ export declare class GuildBetUser implements APIGuildBetUser {
|
|
|
23
24
|
blacklist: boolean;
|
|
24
25
|
/** User's coins */
|
|
25
26
|
coins: number;
|
|
27
|
+
games: number;
|
|
26
28
|
/** User's items */
|
|
27
29
|
items: Items;
|
|
28
30
|
/** User's profile card */
|
|
@@ -56,6 +58,7 @@ export declare class GuildBetUser implements APIGuildBetUser {
|
|
|
56
58
|
* @returns GuildBetUser
|
|
57
59
|
*/
|
|
58
60
|
add<K extends keyof BetUserAddOptions, V extends BetUserAddOptions[K]>(key: K, value: V): Promise<this>;
|
|
61
|
+
reset(): Promise<this>;
|
|
59
62
|
/**
|
|
60
63
|
* Set the user blacklist
|
|
61
64
|
* @param value Value to set to
|
|
@@ -23,6 +23,7 @@ class GuildBetUser {
|
|
|
23
23
|
blacklist;
|
|
24
24
|
/** User's coins */
|
|
25
25
|
coins;
|
|
26
|
+
games;
|
|
26
27
|
/** User's items */
|
|
27
28
|
items;
|
|
28
29
|
/** User's profile card */
|
|
@@ -42,17 +43,18 @@ class GuildBetUser {
|
|
|
42
43
|
* @param rest The rest client
|
|
43
44
|
*/
|
|
44
45
|
constructor(data, manager, rest) {
|
|
45
|
-
this.name = data
|
|
46
|
-
this.id = data
|
|
47
|
-
this.credit = data
|
|
48
|
-
this.wins = data
|
|
49
|
-
this.mvps = data
|
|
50
|
-
this.losses = data
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
46
|
+
this.name = data?.name;
|
|
47
|
+
this.id = data?.id;
|
|
48
|
+
this.credit = data?.credit;
|
|
49
|
+
this.wins = data?.wins;
|
|
50
|
+
this.mvps = data?.mvps;
|
|
51
|
+
this.losses = data?.losses;
|
|
52
|
+
this.games = data?.games;
|
|
53
|
+
this.coins = data?.coins;
|
|
54
|
+
this.blacklist = data?.blacklist;
|
|
55
|
+
this.items = data?.items;
|
|
56
|
+
this.betsPlayed = data?.betsPlayed;
|
|
57
|
+
this.profileCard = data?.profileCard;
|
|
56
58
|
this.daily = data?.daily;
|
|
57
59
|
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
58
60
|
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
@@ -97,6 +99,27 @@ class GuildBetUser {
|
|
|
97
99
|
this.rest.betUsers.set(this.id, this);
|
|
98
100
|
return this;
|
|
99
101
|
}
|
|
102
|
+
async reset() {
|
|
103
|
+
const route = Routes_1.Routes.guilds.betUsers.get(this.manager.guild.id, this.id);
|
|
104
|
+
const payload = { reset: true };
|
|
105
|
+
const response = await this.rest.request({
|
|
106
|
+
method: "DELETE",
|
|
107
|
+
url: route,
|
|
108
|
+
payload,
|
|
109
|
+
});
|
|
110
|
+
this.#updateData(response);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
#updateData(data) {
|
|
114
|
+
for (const k in data) {
|
|
115
|
+
if (k === "id")
|
|
116
|
+
continue;
|
|
117
|
+
if (Object.hasOwn(this, k)) {
|
|
118
|
+
this[k] = data[k];
|
|
119
|
+
this.data[k] = data[k];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
100
123
|
/**
|
|
101
124
|
* Set the user blacklist
|
|
102
125
|
* @param value Value to set to
|
|
@@ -123,15 +146,9 @@ class GuildBetUser {
|
|
|
123
146
|
async update(data) {
|
|
124
147
|
const route = Routes_1.Routes.guilds.betUsers.get(this.manager.guild.id, this.id);
|
|
125
148
|
const payload = {};
|
|
126
|
-
const numericFields = [
|
|
127
|
-
"coins",
|
|
128
|
-
"wins",
|
|
129
|
-
"credit",
|
|
130
|
-
"losses",
|
|
131
|
-
"mvps",
|
|
132
|
-
];
|
|
149
|
+
const numericFields = ["coins", "wins", "credit", "losses", "mvps", "games"];
|
|
133
150
|
const arrayFields = ["items", "betsPlayed"];
|
|
134
|
-
if (data
|
|
151
|
+
if (data?.type === "add" || data?.type === "remove") {
|
|
135
152
|
for (const key in data) {
|
|
136
153
|
if (key === "type")
|
|
137
154
|
continue;
|
|
@@ -139,7 +156,7 @@ class GuildBetUser {
|
|
|
139
156
|
if (numericFields.includes(key)) {
|
|
140
157
|
const current = this[key];
|
|
141
158
|
const num = value;
|
|
142
|
-
payload[key] = Math.max(0, data
|
|
159
|
+
payload[key] = Math.max(0, data?.type === "add" ? current + num : num - current);
|
|
143
160
|
}
|
|
144
161
|
else if (key === "blacklist") {
|
|
145
162
|
payload["blacklist"] = value;
|
|
@@ -148,7 +165,7 @@ class GuildBetUser {
|
|
|
148
165
|
const current = this[key];
|
|
149
166
|
const incoming = value;
|
|
150
167
|
payload[key] =
|
|
151
|
-
data
|
|
168
|
+
data?.type === "add"
|
|
152
169
|
? [...new Set([...current, ...incoming])]
|
|
153
170
|
: current.filter((x) => !incoming.includes(x));
|
|
154
171
|
}
|
|
@@ -166,6 +183,7 @@ class GuildBetUser {
|
|
|
166
183
|
this[k] = response[k];
|
|
167
184
|
}
|
|
168
185
|
}
|
|
186
|
+
this.updatedAt = new Date();
|
|
169
187
|
this.rest.betUsers.set(this.id, this);
|
|
170
188
|
this.manager.cache.set(this.id, this);
|
|
171
189
|
return this;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GuildBetManager } from "../../managers/bet/GuildBetManager";
|
|
2
2
|
import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
|
|
3
|
+
import { BufferManager } from "../../managers/buffer/BufferManager";
|
|
3
4
|
import { GroupedChannelManager } from "../../managers/groupedchannel/GroupedChannelManager";
|
|
4
5
|
import { GuildMatchManager } from "../../managers/match/GuildMatchManager";
|
|
5
6
|
import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
|
|
@@ -73,6 +74,7 @@ export declare class Guild {
|
|
|
73
74
|
/** Guild Shop */
|
|
74
75
|
shop: GuildShop;
|
|
75
76
|
permissionsManager: GuildPermissionManager;
|
|
77
|
+
buffer: BufferManager;
|
|
76
78
|
/**
|
|
77
79
|
* The guild structure
|
|
78
80
|
* @param data The guild's data
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Guild = void 0;
|
|
4
4
|
const GuildBetManager_1 = require("../../managers/bet/GuildBetManager");
|
|
5
5
|
const GuildBetUserManager_1 = require("../../managers/betuser/GuildBetUserManager");
|
|
6
|
+
const BufferManager_1 = require("../../managers/buffer/BufferManager");
|
|
6
7
|
const GroupedChannelManager_1 = require("../../managers/groupedchannel/GroupedChannelManager");
|
|
7
8
|
const GuildMatchManager_1 = require("../../managers/match/GuildMatchManager");
|
|
8
9
|
const GuildMediatorManager_1 = require("../../managers/mediator/GuildMediatorManager");
|
|
@@ -70,6 +71,7 @@ class Guild {
|
|
|
70
71
|
/** Guild Shop */
|
|
71
72
|
shop;
|
|
72
73
|
permissionsManager;
|
|
74
|
+
buffer;
|
|
73
75
|
/**
|
|
74
76
|
* The guild structure
|
|
75
77
|
* @param data The guild's data
|
|
@@ -92,6 +94,17 @@ class Guild {
|
|
|
92
94
|
this.pricesAvailable = data?.pricesAvailable;
|
|
93
95
|
this.pricesOn = data?.pricesOn;
|
|
94
96
|
this.shop = new GuildShop_1.GuildShop(data?.shop, this, rest);
|
|
97
|
+
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
98
|
+
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
99
|
+
this.blacklist = [];
|
|
100
|
+
for (let blacklisted of data?.blacklist) {
|
|
101
|
+
this.blacklist.push({
|
|
102
|
+
addedBy: blacklisted.addedBy,
|
|
103
|
+
id: blacklisted.id,
|
|
104
|
+
createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
|
|
105
|
+
updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
95
108
|
this.mediators = new GuildMediatorManager_1.GuildMediatorManager(this, rest);
|
|
96
109
|
this.bets = new GuildBetManager_1.GuildBetManager(this, rest);
|
|
97
110
|
this.users = new GuildUserManager_1.GuildUserManager(this, rest);
|
|
@@ -101,6 +114,7 @@ class Guild {
|
|
|
101
114
|
this.categories = new GroupedChannelManager_1.GroupedChannelManager(this, "categories", rest);
|
|
102
115
|
this.tickets = new GuildTicketManager_1.GuildTicketManager(this, rest);
|
|
103
116
|
this.permissionsManager = new GuildPermissionManager_1.GuildPermissionManager(this, rest);
|
|
117
|
+
this.buffer = new BufferManager_1.BufferManager(this);
|
|
104
118
|
this.bets.setAll(data?.bets);
|
|
105
119
|
this.users.setAll(data?.users);
|
|
106
120
|
this.betUsers.setAll(data?.betUsers);
|
|
@@ -111,17 +125,6 @@ class Guild {
|
|
|
111
125
|
this.tickets.setAll(data?.tickets);
|
|
112
126
|
this.permissionsManager.setAll(data?.permissions);
|
|
113
127
|
this.messages.setAll(data?.messages);
|
|
114
|
-
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
115
|
-
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
116
|
-
this.blacklist = [];
|
|
117
|
-
for (let blacklisted of data?.blacklist) {
|
|
118
|
-
this.blacklist.push({
|
|
119
|
-
addedBy: blacklisted.addedBy,
|
|
120
|
-
id: blacklisted.id,
|
|
121
|
-
createdAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
|
|
122
|
-
updatedAt: blacklisted?.createdAt ? new Date(blacklisted?.createdAt) : new Date(),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
128
|
}
|
|
126
129
|
async fetch() {
|
|
127
130
|
const route = Routes_1.Routes.guilds.get(this.id);
|
|
@@ -159,7 +162,6 @@ class Guild {
|
|
|
159
162
|
}
|
|
160
163
|
this.rest.guilds.cache.set(this.id, this);
|
|
161
164
|
this.rest.emit("guildUpdate", this);
|
|
162
|
-
console.log({ bl: response?.blacklist });
|
|
163
165
|
return this;
|
|
164
166
|
}
|
|
165
167
|
async setStatus(key, status) {
|
|
@@ -74,7 +74,7 @@ export declare class GuildMatch {
|
|
|
74
74
|
setLoser(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
|
|
75
75
|
setMvp(userId: string): Promise<GuildMatch>;
|
|
76
76
|
setRoomCreatorId(userId: string): Promise<GuildMatch>;
|
|
77
|
-
kick(player: APIPlayer): Promise<this>;
|
|
77
|
+
kick(player: Optional<APIPlayer>): Promise<this>;
|
|
78
78
|
addChannel(id: string, type: string): Promise<GuildMatch>;
|
|
79
79
|
setChannels(channels: APIBetChannel[]): Promise<GuildMatch>;
|
|
80
80
|
addPlayer(id: string, name: string): Promise<GuildMatch>;
|
|
@@ -232,7 +232,7 @@ class GuildMatch {
|
|
|
232
232
|
return this;
|
|
233
233
|
}
|
|
234
234
|
async addChannel(id, type) {
|
|
235
|
-
await this.channels.create(id, type);
|
|
235
|
+
await this.channels.create({ id, type });
|
|
236
236
|
this.rest.matches.set(this._id, this);
|
|
237
237
|
this.manager.cache.set(this._id, this);
|
|
238
238
|
return this;
|
|
@@ -271,7 +271,7 @@ class GuildMatch {
|
|
|
271
271
|
async removePlayer(id, name) {
|
|
272
272
|
Assertion_1.Assertion.assertString(id);
|
|
273
273
|
Assertion_1.Assertion.assertString(name);
|
|
274
|
-
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this
|
|
274
|
+
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this?._id, "players", id);
|
|
275
275
|
const payload = { id, name };
|
|
276
276
|
const response = await this.rest.request({
|
|
277
277
|
method: "DELETE",
|
|
@@ -3,6 +3,7 @@ import { Accessory, Daily, Items, Optional, OriginalChannels } from "../../types
|
|
|
3
3
|
import { APIGuildUser } from "../../types/api/APIGuildUser";
|
|
4
4
|
import { GuildUserManager } from "../../managers/user/GuildUserManager";
|
|
5
5
|
export declare class GuildUser implements APIGuildUser {
|
|
6
|
+
#private;
|
|
6
7
|
/** User's id */
|
|
7
8
|
id: string;
|
|
8
9
|
/** User name */
|
|
@@ -62,6 +63,7 @@ export declare class GuildUser implements APIGuildUser {
|
|
|
62
63
|
* @returns GuildUser
|
|
63
64
|
*/
|
|
64
65
|
setBlacklist(value: boolean): Promise<this>;
|
|
66
|
+
reset(): Promise<this>;
|
|
65
67
|
/**
|
|
66
68
|
* Update certain property
|
|
67
69
|
* @param data The new data to update with
|
|
@@ -118,6 +118,27 @@ class GuildUser {
|
|
|
118
118
|
this.rest.users.set(this.id, this);
|
|
119
119
|
return this;
|
|
120
120
|
}
|
|
121
|
+
async reset() {
|
|
122
|
+
const route = Routes_1.Routes.guilds.users.get(this.manager.guild.id, this.id);
|
|
123
|
+
const payload = { reset: true };
|
|
124
|
+
const response = await this.rest.request({
|
|
125
|
+
method: "DELETE",
|
|
126
|
+
url: route,
|
|
127
|
+
payload,
|
|
128
|
+
});
|
|
129
|
+
this.#updateData(response);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
#updateData(data) {
|
|
133
|
+
for (const k in data) {
|
|
134
|
+
if (k === "id")
|
|
135
|
+
continue;
|
|
136
|
+
if (Object.hasOwn(this, k)) {
|
|
137
|
+
this[k] = data[k];
|
|
138
|
+
this.data[k] = data[k];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
121
142
|
/**
|
|
122
143
|
* Update certain property
|
|
123
144
|
* @param data The new data to update with
|
|
@@ -26,6 +26,10 @@ export interface LogMessage {
|
|
|
26
26
|
userId: string;
|
|
27
27
|
/** The message's type */
|
|
28
28
|
type: string;
|
|
29
|
+
/** Creation Date */
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
/** Updated Date */
|
|
32
|
+
updatedAt: Date;
|
|
29
33
|
}
|
|
30
34
|
/** Base match modes */
|
|
31
35
|
export type BaseMatchModes = "1x1" | "2x2" | "3x3" | "4x4" | "5x5" | "6x6" | "1v1" | "2v2" | "3v3" | "4v4" | "5v5" | "6v6";
|