@duque.edits/sdk 1.0.3 → 1.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/dist/managers/bet/GuildBetManager.js +4 -0
- package/dist/managers/betuser/GuildBetUserManager.js +1 -2
- package/dist/managers/match/GuildMatchManager.js +8 -21
- package/dist/managers/mediator/GuildMediatorManager.js +94 -0
- package/dist/managers/message/MessagesManager.js +14 -8
- package/dist/managers/player/PlayerManager.js +35 -0
- package/dist/managers/ticket/TicketManager.js +0 -1
- package/dist/rest/REST.js +6 -1
- package/dist/rest/Routes.js +2 -2
- package/dist/structures/bet/GuildBet.js +36 -18
- package/dist/structures/betuser/GuildBetUser.js +11 -8
- package/dist/structures/guild/Guild.js +4 -0
- package/dist/structures/match/GuildMatch.js +41 -36
- package/dist/structures/mediator/GuildMediator.js +133 -0
- package/dist/structures/user/GuildUser.js +1 -1
- package/dist/types/api/APIGuildMediator.js +0 -1
- package/dist/types/api/APIGuildPermissions.js +1 -0
- package/dist/types/api/APILogEntry.js +6 -0
- package/dist/types/api/index.js +0 -2
- package/package.json +1 -1
- package/types/managers/bet/GuildBetManager.d.ts +1 -1
- package/types/managers/betuser/GuildBetUserManager.d.ts +1 -1
- package/types/managers/match/GuildMatchManager.d.ts +2 -3
- package/types/managers/mediator/GuildMediatorManager.d.ts +19 -0
- package/types/managers/message/MessagesManager.d.ts +5 -2
- package/types/managers/player/PlayerManager.d.ts +9 -0
- package/types/rest/REST.d.ts +3 -0
- package/types/structures/bet/GuildBet.d.ts +5 -4
- package/types/structures/betuser/GuildBetUser.d.ts +3 -0
- package/types/structures/guild/Guild.d.ts +2 -0
- package/types/structures/match/GuildMatch.d.ts +10 -4
- package/types/structures/mediator/GuildMediator.d.ts +50 -0
- package/types/structures/ticket/Ticket.d.ts +3 -3
- package/types/structures/user/GuildUser.d.ts +1 -1
- package/types/types/api/APIGuildBet.d.ts +1 -0
- package/types/types/api/APIGuildBetUser.d.ts +1 -0
- package/types/types/api/APIGuildMatch.d.ts +3 -1
- package/types/types/api/APIGuildMediator.d.ts +7 -6
- package/types/types/api/APIGuildPermissions.d.ts +2 -1
- package/types/types/api/APIGuildTicket.d.ts +2 -2
- package/types/types/api/APILogEntry.d.ts +7 -1
- package/types/types/api/APIMessage.d.ts +3 -5
- package/types/types/api/index.d.ts +0 -2
|
@@ -51,6 +51,10 @@ class GuildBetManager extends base_1.BaseManager {
|
|
|
51
51
|
else {
|
|
52
52
|
if (!data._id)
|
|
53
53
|
return;
|
|
54
|
+
if (data instanceof structures_1.GuildBet) {
|
|
55
|
+
this.cache.set(data._id, data);
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
54
58
|
const bet = new structures_1.GuildBet(data, this);
|
|
55
59
|
this.cache.set(bet._id, bet);
|
|
56
60
|
this.rest.bets.set(bet._id, bet);
|
|
@@ -16,7 +16,7 @@ class GuildMatchManager extends base_1.BaseManager {
|
|
|
16
16
|
super(guild, guild.rest);
|
|
17
17
|
this.guild = guild;
|
|
18
18
|
this.rest = guild.rest;
|
|
19
|
-
this.base_url = Routes_1.Routes.guilds.
|
|
19
|
+
this.base_url = Routes_1.Routes.guilds.matches.getAll(guild.id);
|
|
20
20
|
this.cache = new Collection_1.Collection("matches");
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -79,6 +79,10 @@ class GuildMatchManager extends base_1.BaseManager {
|
|
|
79
79
|
else {
|
|
80
80
|
if (!data._id)
|
|
81
81
|
return this.cache;
|
|
82
|
+
if (data instanceof GuildMatch_1.GuildMatch) {
|
|
83
|
+
this.cache.set(data._id, data);
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
82
86
|
const match = new GuildMatch_1.GuildMatch(data, this);
|
|
83
87
|
this.cache.set(match._id, match);
|
|
84
88
|
return match;
|
|
@@ -95,26 +99,9 @@ class GuildMatchManager extends base_1.BaseManager {
|
|
|
95
99
|
return this.set(response);
|
|
96
100
|
}
|
|
97
101
|
async delete(id) {
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
this.rest.emit("matchDelete", match);
|
|
102
|
-
await this.rest.request({
|
|
103
|
-
method: "DELETE",
|
|
104
|
-
url: route,
|
|
105
|
-
});
|
|
106
|
-
this.cache.delete(id);
|
|
107
|
-
return this.cache;
|
|
108
|
-
}
|
|
109
|
-
async deleteAll() {
|
|
110
|
-
const route = Routes_1.Routes.guilds.matches.deleteAll(this.guild.id);
|
|
111
|
-
this.rest.emit("matchesDelete", this.cache);
|
|
112
|
-
const value = await this.rest.request({
|
|
113
|
-
method: "DELETE",
|
|
114
|
-
url: route,
|
|
115
|
-
});
|
|
116
|
-
this.cache.clear();
|
|
117
|
-
return value;
|
|
102
|
+
const route = Routes_1.Routes.fields(this.base_url, id);
|
|
103
|
+
const response = await this.rest.request({ url: route, method: "DELETE" });
|
|
104
|
+
return this.set(response);
|
|
118
105
|
}
|
|
119
106
|
}
|
|
120
107
|
exports.GuildMatchManager = GuildMatchManager;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildMediatorManager = void 0;
|
|
4
|
+
const Routes_1 = require("../../rest/Routes");
|
|
5
|
+
const GuildMediator_1 = require("../../structures/mediator/GuildMediator");
|
|
6
|
+
const Collection_1 = require("../../structures/Collection");
|
|
7
|
+
const base_1 = require("../base");
|
|
8
|
+
class GuildMediatorManager extends base_1.BaseManager {
|
|
9
|
+
constructor(guild) {
|
|
10
|
+
super(guild);
|
|
11
|
+
this.guild = guild;
|
|
12
|
+
this.rest = guild.rest;
|
|
13
|
+
this.base_url = Routes_1.Routes.guilds.mediators.getAll(guild.id);
|
|
14
|
+
this.cache = new Collection_1.Collection("mediators");
|
|
15
|
+
}
|
|
16
|
+
async fetch(options) {
|
|
17
|
+
if (options && options.cache)
|
|
18
|
+
return this.cache;
|
|
19
|
+
if (options && options.mediatorId) {
|
|
20
|
+
const route = Routes_1.Routes.fields(this.base_url, options.mediatorId);
|
|
21
|
+
const response = await this.rest.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
url: route,
|
|
24
|
+
});
|
|
25
|
+
return this.set(response);
|
|
26
|
+
}
|
|
27
|
+
const route = this.base_url;
|
|
28
|
+
const response = await this.rest.request({
|
|
29
|
+
method: "GET",
|
|
30
|
+
url: route,
|
|
31
|
+
});
|
|
32
|
+
this.set(response);
|
|
33
|
+
return this.cache;
|
|
34
|
+
}
|
|
35
|
+
async updateMany(...mediators) {
|
|
36
|
+
const route = this.base_url;
|
|
37
|
+
const response = await this.rest.request({
|
|
38
|
+
method: "PATCH",
|
|
39
|
+
url: route,
|
|
40
|
+
payload: { mediators },
|
|
41
|
+
});
|
|
42
|
+
return this.set(response);
|
|
43
|
+
}
|
|
44
|
+
async create(payload) {
|
|
45
|
+
const route = Routes_1.Routes.guilds.mediators.create(this.guild.id);
|
|
46
|
+
const response = await this.rest.request({
|
|
47
|
+
method: "POST",
|
|
48
|
+
url: route,
|
|
49
|
+
payload,
|
|
50
|
+
});
|
|
51
|
+
return this.set(response);
|
|
52
|
+
}
|
|
53
|
+
async deleteAll() {
|
|
54
|
+
const route = this.base_url;
|
|
55
|
+
await this.rest.request({
|
|
56
|
+
method: "DELETE",
|
|
57
|
+
url: route,
|
|
58
|
+
});
|
|
59
|
+
this.cache.clear();
|
|
60
|
+
}
|
|
61
|
+
async resetAll() {
|
|
62
|
+
const route = this.base_url;
|
|
63
|
+
const response = await this.rest.request({
|
|
64
|
+
method: "put",
|
|
65
|
+
url: route,
|
|
66
|
+
});
|
|
67
|
+
this.cache.clear();
|
|
68
|
+
this.set(response);
|
|
69
|
+
return this.cache;
|
|
70
|
+
}
|
|
71
|
+
set(data) {
|
|
72
|
+
if (!data)
|
|
73
|
+
return this.cache;
|
|
74
|
+
if (Array.isArray(data)) {
|
|
75
|
+
for (let _mediator of data) {
|
|
76
|
+
if (!_mediator.id)
|
|
77
|
+
return;
|
|
78
|
+
const mediator = new GuildMediator_1.GuildMediator(_mediator, this);
|
|
79
|
+
this.cache.set(mediator.id, mediator);
|
|
80
|
+
this.rest.mediators.set(mediator.id, mediator);
|
|
81
|
+
}
|
|
82
|
+
return this.cache;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (!data.id)
|
|
86
|
+
return;
|
|
87
|
+
const mediator = new GuildMediator_1.GuildMediator(data, this);
|
|
88
|
+
this.cache.set(mediator.id, mediator);
|
|
89
|
+
this.rest.mediators.set(mediator.id, mediator);
|
|
90
|
+
return mediator;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.GuildMediatorManager = GuildMediatorManager;
|
|
@@ -6,8 +6,10 @@ class MessagesManager {
|
|
|
6
6
|
cache;
|
|
7
7
|
base_url;
|
|
8
8
|
rest;
|
|
9
|
+
guild;
|
|
9
10
|
constructor(structure, base_url) {
|
|
10
11
|
this.rest = structure.rest;
|
|
12
|
+
this.guild = structure.guild;
|
|
11
13
|
this.cache = new Collection_1.Collection("messages");
|
|
12
14
|
this.base_url = base_url;
|
|
13
15
|
}
|
|
@@ -27,21 +29,25 @@ class MessagesManager {
|
|
|
27
29
|
else
|
|
28
30
|
messages.push(data);
|
|
29
31
|
const response = await this.rest.request({
|
|
30
|
-
method: "
|
|
32
|
+
method: "PATCH",
|
|
31
33
|
url: this.base_url,
|
|
32
|
-
payload: { messages },
|
|
34
|
+
payload: { set: messages },
|
|
33
35
|
});
|
|
34
|
-
|
|
35
|
-
this.cache.set(message._id, message);
|
|
36
|
-
return response;
|
|
36
|
+
return this.set(response.messages);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
set(data) {
|
|
39
39
|
if (Array.isArray(data)) {
|
|
40
|
-
for (let message of data)
|
|
40
|
+
for (let message of data) {
|
|
41
|
+
if (!message._id)
|
|
42
|
+
continue;
|
|
41
43
|
this.cache.set(message._id, message);
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
|
-
else
|
|
46
|
+
else {
|
|
47
|
+
if (!data._id)
|
|
48
|
+
return this.cache;
|
|
44
49
|
this.cache.set(data._id, data);
|
|
50
|
+
}
|
|
45
51
|
return this.cache;
|
|
46
52
|
}
|
|
47
53
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayerManager = void 0;
|
|
4
|
+
const structures_1 = require("../../structures");
|
|
5
|
+
class PlayerManager {
|
|
6
|
+
_cache;
|
|
7
|
+
constructor(players, base_url) {
|
|
8
|
+
this._cache = new structures_1.Collection();
|
|
9
|
+
if (Array.isArray(players)) {
|
|
10
|
+
for (let p of players) {
|
|
11
|
+
if (!p.id)
|
|
12
|
+
continue;
|
|
13
|
+
this._cache.set(p.id, p);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
get(id) {
|
|
18
|
+
return this._cache.get(id);
|
|
19
|
+
}
|
|
20
|
+
add(player) {
|
|
21
|
+
if (Array.isArray(player)) {
|
|
22
|
+
for (let p of player) {
|
|
23
|
+
if (!p.id)
|
|
24
|
+
continue;
|
|
25
|
+
this._cache.set(p.id, p);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (!player.id)
|
|
30
|
+
return;
|
|
31
|
+
this._cache.set(player.id, player);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.PlayerManager = PlayerManager;
|
package/dist/rest/REST.js
CHANGED
|
@@ -37,6 +37,7 @@ class REST extends events_1.default {
|
|
|
37
37
|
bets;
|
|
38
38
|
tickets;
|
|
39
39
|
vipmembers;
|
|
40
|
+
mediators;
|
|
40
41
|
/**
|
|
41
42
|
*
|
|
42
43
|
* @param key The unique key for he client
|
|
@@ -54,6 +55,7 @@ class REST extends events_1.default {
|
|
|
54
55
|
this.betusers = new Collection_1.Collection("rest:betusers");
|
|
55
56
|
this.tickets = new Collection_1.Collection("rest:tickets");
|
|
56
57
|
this.vipmembers = new Collection_1.Collection("rest:vipmembers");
|
|
58
|
+
this.mediators = new Collection_1.Collection("rest:mediators");
|
|
57
59
|
this.setMaxListeners(999);
|
|
58
60
|
}
|
|
59
61
|
/** Initialize the caching sistem */
|
|
@@ -63,6 +65,9 @@ class REST extends events_1.default {
|
|
|
63
65
|
await Promise.all([this.guilds.fetch({ guildId: this.guildId }), this.minesGames.fetch()]);
|
|
64
66
|
return this;
|
|
65
67
|
}
|
|
68
|
+
formatUrl(url) {
|
|
69
|
+
return url.endsWith("/") ? url.slice(0, url.length - 1) : url;
|
|
70
|
+
}
|
|
66
71
|
/**
|
|
67
72
|
* Request Data from a certain url
|
|
68
73
|
* @param options
|
|
@@ -74,7 +79,7 @@ class REST extends events_1.default {
|
|
|
74
79
|
Assertion_1.Assertion.assertString(this.clientKey);
|
|
75
80
|
Assertion_1.Assertion.assertString(url);
|
|
76
81
|
method = method.toUpperCase();
|
|
77
|
-
url = Routes_1.Routes.base + url;
|
|
82
|
+
url = this.formatUrl(Routes_1.Routes.base + url);
|
|
78
83
|
const headers = new undici_1.Headers();
|
|
79
84
|
headers.append("authorization", this.authKey);
|
|
80
85
|
headers.append("client_key", this.clientKey);
|
package/dist/rest/Routes.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Routes = void 0;
|
|
4
4
|
exports.Routes = {
|
|
5
|
-
base: "
|
|
6
|
-
//base:
|
|
5
|
+
base: "https://duque-api.up.railway.app/api/v1",
|
|
6
|
+
//base: "http://localhost:80/api/v1",
|
|
7
7
|
field: (field) => `/${field}`,
|
|
8
8
|
fields: (...fields) => `${fields.join("/")}`,
|
|
9
9
|
guilds: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GuildBet = void 0;
|
|
4
|
+
const managers_1 = require("../../managers");
|
|
4
5
|
const rest_1 = require("../../rest");
|
|
5
6
|
class GuildBet {
|
|
6
7
|
/** The bet's type */
|
|
@@ -37,6 +38,7 @@ class GuildBet {
|
|
|
37
38
|
/** Bet's id */
|
|
38
39
|
_id;
|
|
39
40
|
queues;
|
|
41
|
+
guild_id;
|
|
40
42
|
rest;
|
|
41
43
|
guild;
|
|
42
44
|
manager;
|
|
@@ -45,6 +47,7 @@ class GuildBet {
|
|
|
45
47
|
this.guild = manager.guild;
|
|
46
48
|
this.rest = manager.rest;
|
|
47
49
|
this._id = data?._id;
|
|
50
|
+
this.guild_id = data?.guild_id;
|
|
48
51
|
this.type = data?.type;
|
|
49
52
|
this.mode = data?.mode;
|
|
50
53
|
this.status = data?.status;
|
|
@@ -53,7 +56,7 @@ class GuildBet {
|
|
|
53
56
|
this.players = data?.players;
|
|
54
57
|
this.teams = data?.teams;
|
|
55
58
|
this.channels = data?.channels;
|
|
56
|
-
this.messages =
|
|
59
|
+
this.messages = new managers_1.MessagesManager(this, rest_1.Routes.guilds.bets.resource(this.guild_id, this._id, "messages"));
|
|
57
60
|
this.winners = data?.winners;
|
|
58
61
|
this.losers = data?.losers;
|
|
59
62
|
this.creatorId = data?.creatorId;
|
|
@@ -71,6 +74,8 @@ class GuildBet {
|
|
|
71
74
|
createdAt: queue?.createdAt ? new Date(queue?.createdAt) : new Date(),
|
|
72
75
|
});
|
|
73
76
|
}
|
|
77
|
+
if (data?.messages?.length !== 0)
|
|
78
|
+
this.messages.set(data.messages);
|
|
74
79
|
}
|
|
75
80
|
toString() {
|
|
76
81
|
return this._id;
|
|
@@ -80,28 +85,41 @@ class GuildBet {
|
|
|
80
85
|
const response = await this.rest.request({ url: route, method: "GET" });
|
|
81
86
|
return this._updateInternals(response);
|
|
82
87
|
}
|
|
83
|
-
async addPlayer(player) {
|
|
84
|
-
|
|
85
|
-
if (isFull)
|
|
88
|
+
async addPlayer(player, queue_type) {
|
|
89
|
+
if (this.players.length === 2)
|
|
86
90
|
return this;
|
|
87
|
-
|
|
88
|
-
if (isPlayerIn !== -1)
|
|
91
|
+
if (this.players.some((p) => p.id === player.id))
|
|
89
92
|
return this;
|
|
90
93
|
this.players.push(player);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
if (queue_type) {
|
|
95
|
+
const queue = this.queues.find((q) => q.type === queue_type);
|
|
96
|
+
if (!queue)
|
|
97
|
+
return this;
|
|
98
|
+
for (const q of this.queues) {
|
|
99
|
+
q.players = q.players.filter((p) => p.id !== player.id);
|
|
100
|
+
}
|
|
101
|
+
if (!queue.players.some((p) => p.id === player.id)) {
|
|
102
|
+
queue.players.push({ id: player.id });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
await this.update({
|
|
106
|
+
players: this.players,
|
|
107
|
+
queues: this.queues,
|
|
108
|
+
});
|
|
109
|
+
return this;
|
|
95
110
|
}
|
|
96
111
|
async removePlayer(player) {
|
|
97
|
-
|
|
98
|
-
if (isPlayerIn === -1)
|
|
112
|
+
if (!this.players.some((p) => p.id === player.id))
|
|
99
113
|
return this;
|
|
100
114
|
this.players = this.players.filter((p) => p.id !== player.id);
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
for (const q of this.queues) {
|
|
116
|
+
q.players = q.players.filter((p) => p.id !== player.id);
|
|
117
|
+
}
|
|
118
|
+
await this.update({
|
|
119
|
+
players: this.players,
|
|
120
|
+
queues: this.queues,
|
|
121
|
+
});
|
|
122
|
+
return this;
|
|
105
123
|
}
|
|
106
124
|
async update(data) {
|
|
107
125
|
const payload = data;
|
|
@@ -135,14 +153,14 @@ class GuildBet {
|
|
|
135
153
|
toJSON() {
|
|
136
154
|
let json = {};
|
|
137
155
|
for (const [key, value] of Object.entries(this)) {
|
|
138
|
-
const exclude = ["rest", "
|
|
156
|
+
const exclude = ["rest", "guild", "manager"];
|
|
139
157
|
if (exclude.includes(key))
|
|
140
158
|
continue;
|
|
141
159
|
if (typeof value !== "function") {
|
|
142
160
|
json[key] = value;
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
|
-
return json;
|
|
163
|
+
return { ...json, messages: this.messages.cache.toArray() };
|
|
146
164
|
}
|
|
147
165
|
}
|
|
148
166
|
exports.GuildBet = GuildBet;
|
|
@@ -27,10 +27,12 @@ class GuildBetUser {
|
|
|
27
27
|
createdAt;
|
|
28
28
|
/** Updated Date */
|
|
29
29
|
updatedAt;
|
|
30
|
+
consecutive_wins;
|
|
30
31
|
/** The given manager */
|
|
31
32
|
manager;
|
|
32
33
|
/** The rest client */
|
|
33
34
|
rest;
|
|
35
|
+
guild;
|
|
34
36
|
/**
|
|
35
37
|
* Bet user
|
|
36
38
|
* @param data The user's data
|
|
@@ -42,11 +44,15 @@ class GuildBetUser {
|
|
|
42
44
|
this.guild_id = data?.guild_id;
|
|
43
45
|
this.manager = manager;
|
|
44
46
|
this.rest = manager.rest;
|
|
47
|
+
this.guild = manager.guild;
|
|
45
48
|
this.wins = data?.wins;
|
|
49
|
+
this.coins = data?.coins;
|
|
46
50
|
this.losses = data?.losses;
|
|
51
|
+
this.credit = data?.credit;
|
|
47
52
|
this.daily = data?.daily;
|
|
48
53
|
this.games = data?.games;
|
|
49
54
|
this.blacklist = data?.blacklist;
|
|
55
|
+
this.consecutive_wins = data?.consecutive_wins;
|
|
50
56
|
this.profile = data?.profile;
|
|
51
57
|
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
52
58
|
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
@@ -96,8 +102,7 @@ class GuildBetUser {
|
|
|
96
102
|
url: route,
|
|
97
103
|
payload,
|
|
98
104
|
});
|
|
99
|
-
this._updateInternals(response);
|
|
100
|
-
return this;
|
|
105
|
+
return this._updateInternals(response);
|
|
101
106
|
}
|
|
102
107
|
async updateProfile(data) {
|
|
103
108
|
const _data = {
|
|
@@ -117,8 +122,7 @@ class GuildBetUser {
|
|
|
117
122
|
url: route,
|
|
118
123
|
payload: _data,
|
|
119
124
|
});
|
|
120
|
-
this._updateInternals(response);
|
|
121
|
-
return this;
|
|
125
|
+
return this._updateInternals(response);
|
|
122
126
|
}
|
|
123
127
|
_updateInternals(data) {
|
|
124
128
|
for (let key in data) {
|
|
@@ -144,7 +148,7 @@ class GuildBetUser {
|
|
|
144
148
|
data.type = "add";
|
|
145
149
|
const route = Routes_1.Routes.guilds.betusers.get(this.manager.guild.id, this.id);
|
|
146
150
|
let payload = {};
|
|
147
|
-
const numericFields = ["wins", "credit", "losses", "mvps", "games"];
|
|
151
|
+
const numericFields = ["wins", "credit", "losses", "mvps", "games", "coins"];
|
|
148
152
|
const arrayFields = ["items", "original_channels", "adverts", "accessories"];
|
|
149
153
|
if (data?.type === "add" || data?.type === "remove") {
|
|
150
154
|
for (const key in data) {
|
|
@@ -177,8 +181,7 @@ class GuildBetUser {
|
|
|
177
181
|
url: route,
|
|
178
182
|
payload,
|
|
179
183
|
});
|
|
180
|
-
this._updateInternals(response);
|
|
181
|
-
return this;
|
|
184
|
+
return this._updateInternals(response);
|
|
182
185
|
}
|
|
183
186
|
async delete() {
|
|
184
187
|
const route = Routes_1.Routes.guilds.betusers.delete(this.manager.guild.id, this.id);
|
|
@@ -193,7 +196,7 @@ class GuildBetUser {
|
|
|
193
196
|
toJSON() {
|
|
194
197
|
let json = {};
|
|
195
198
|
for (const [key, value] of Object.entries(this)) {
|
|
196
|
-
const exclude = ["rest", "guilds", "manager"];
|
|
199
|
+
const exclude = ["rest", "guilds", "guild", "manager"];
|
|
197
200
|
if (exclude.includes(key))
|
|
198
201
|
continue;
|
|
199
202
|
if (typeof value !== "function") {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Guild = void 0;
|
|
4
4
|
const managers_1 = require("../../managers");
|
|
5
5
|
const GuildBetUserManager_1 = require("../../managers/betuser/GuildBetUserManager");
|
|
6
|
+
const GuildMediatorManager_1 = require("../../managers/mediator/GuildMediatorManager");
|
|
6
7
|
const Routes_1 = require("../../rest/Routes");
|
|
7
8
|
const Assertion_1 = require("../../utils/Assertion");
|
|
8
9
|
class Guild {
|
|
@@ -46,6 +47,7 @@ class Guild {
|
|
|
46
47
|
shop;
|
|
47
48
|
betusers;
|
|
48
49
|
bets;
|
|
50
|
+
mediators;
|
|
49
51
|
adverts;
|
|
50
52
|
codes;
|
|
51
53
|
coin_symbol;
|
|
@@ -82,6 +84,7 @@ class Guild {
|
|
|
82
84
|
this.logEntries = new managers_1.LogManager(this);
|
|
83
85
|
this.betusers = new GuildBetUserManager_1.GuildBetUserManager(this);
|
|
84
86
|
this.bets = new managers_1.GuildBetManager(this);
|
|
87
|
+
this.mediators = new GuildMediatorManager_1.GuildMediatorManager(this);
|
|
85
88
|
this.adverts = [];
|
|
86
89
|
for (let _adv of data?.adverts || []) {
|
|
87
90
|
this.adverts.push({
|
|
@@ -242,6 +245,7 @@ class Guild {
|
|
|
242
245
|
this.logEntries.fetch(),
|
|
243
246
|
this.betusers.fetch(),
|
|
244
247
|
this.bets.fetch(),
|
|
248
|
+
this.mediators.fetch(),
|
|
245
249
|
]);
|
|
246
250
|
return this;
|
|
247
251
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GuildMatch = void 0;
|
|
4
4
|
const Routes_1 = require("../../rest/Routes");
|
|
5
5
|
const Assertion_1 = require("../../utils/Assertion");
|
|
6
|
+
const managers_1 = require("../../managers");
|
|
6
7
|
class GuildMatch {
|
|
7
8
|
_id;
|
|
8
9
|
selections;
|
|
@@ -41,6 +42,8 @@ class GuildMatch {
|
|
|
41
42
|
/** Match's id */
|
|
42
43
|
mvps;
|
|
43
44
|
manager;
|
|
45
|
+
bet;
|
|
46
|
+
admin_id;
|
|
44
47
|
/** The given guild */
|
|
45
48
|
guild;
|
|
46
49
|
/** The rest client */
|
|
@@ -58,12 +61,14 @@ class GuildMatch {
|
|
|
58
61
|
this.manager = manager;
|
|
59
62
|
this.guild = manager.guild;
|
|
60
63
|
this.rest = manager.rest;
|
|
64
|
+
this.admin_id = data?.admin_id;
|
|
61
65
|
this.challenge = data?.challenge;
|
|
62
66
|
this.players = data?.players;
|
|
63
|
-
this.messages =
|
|
67
|
+
this.messages = new managers_1.MessagesManager(this, Routes_1.Routes.guilds.matches.resource(this.guild_id, this._id, "messages"));
|
|
64
68
|
this.channels = data?.channels;
|
|
65
69
|
this.type = data?.type;
|
|
66
70
|
this.status = data?.status;
|
|
71
|
+
this.bet = this.guild.bets.cache.get(data?.bet?._id);
|
|
67
72
|
this.mvps = data?.mvps;
|
|
68
73
|
this.winners = data?.winners;
|
|
69
74
|
this.losers = data?.losers;
|
|
@@ -78,6 +83,8 @@ class GuildMatch {
|
|
|
78
83
|
this.key = "matches";
|
|
79
84
|
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
80
85
|
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
86
|
+
if (data?.messages?.length !== 0)
|
|
87
|
+
this.messages.set(data.messages);
|
|
81
88
|
}
|
|
82
89
|
/**
|
|
83
90
|
* Fetches the match
|
|
@@ -89,41 +96,20 @@ class GuildMatch {
|
|
|
89
96
|
method: "get",
|
|
90
97
|
url: route,
|
|
91
98
|
});
|
|
92
|
-
|
|
93
|
-
this.manager.cache.set(match._id, match);
|
|
94
|
-
return match;
|
|
99
|
+
return this._updateInternals(response);
|
|
95
100
|
}
|
|
96
|
-
/* async addMessage(id: string, type: string, content?: string) {
|
|
97
|
-
const response = await this.messages.create({
|
|
98
|
-
userId: id,
|
|
99
|
-
type: type as "img",
|
|
100
|
-
content,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
this.manager.cache.set(this._id, this);
|
|
104
|
-
this.rest.matches.set(this._id, this);
|
|
105
|
-
return response;
|
|
106
|
-
} */
|
|
107
101
|
async addConfirmed(type, id) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
this.rest.emit("matchUpdate", this, this);
|
|
121
|
-
this.confirmed = response;
|
|
122
|
-
this.updatedAt = new Date();
|
|
123
|
-
this.rest.matches.set(this._id, this);
|
|
124
|
-
this.manager.cache.set(this._id, this);
|
|
125
|
-
this.guild.buffer.matches.set(this._id, this);
|
|
126
|
-
return this.confirmed.find((c) => c.type === type);
|
|
102
|
+
const confirmed = this.confirmed.find((c) => c.type === type);
|
|
103
|
+
const idsToAdd = Array.isArray(id) ? id : [id];
|
|
104
|
+
if (!confirmed) {
|
|
105
|
+
this.confirmed.push({ type, ids: [...idsToAdd], count: idsToAdd.length });
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const chIndex = this.confirmed.findIndex((ch) => ch.type === type);
|
|
109
|
+
const mergedIds = [...new Set([...(confirmed.ids || []), ...idsToAdd])];
|
|
110
|
+
this.confirmed[chIndex] = { ...confirmed, ids: mergedIds, count: mergedIds.length };
|
|
111
|
+
}
|
|
112
|
+
return this.update({ confirmed: this.confirmed });
|
|
127
113
|
}
|
|
128
114
|
async setConfirmed(set) {
|
|
129
115
|
Assertion_1.Assertion.assertObject(set);
|
|
@@ -191,6 +177,17 @@ class GuildMatch {
|
|
|
191
177
|
});
|
|
192
178
|
return this._updateInternals(response);
|
|
193
179
|
}
|
|
180
|
+
async setRoomAdminId(userId) {
|
|
181
|
+
Assertion_1.Assertion.assertString(userId);
|
|
182
|
+
const payload = { set: userId };
|
|
183
|
+
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "admin_id");
|
|
184
|
+
const response = await this.rest.request({
|
|
185
|
+
method: "PATCH",
|
|
186
|
+
url: route,
|
|
187
|
+
payload,
|
|
188
|
+
});
|
|
189
|
+
return this._updateInternals(response);
|
|
190
|
+
}
|
|
194
191
|
async kick(player) {
|
|
195
192
|
const payload = { set: player };
|
|
196
193
|
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "kickout");
|
|
@@ -224,20 +221,28 @@ class GuildMatch {
|
|
|
224
221
|
toJSON() {
|
|
225
222
|
const json = {};
|
|
226
223
|
for (const [key, value] of Object.entries(this)) {
|
|
224
|
+
const exclude = ["rest", "guilds", "guild", "manager"];
|
|
225
|
+
if (exclude.includes(key))
|
|
226
|
+
continue;
|
|
227
227
|
if (typeof value !== "function") {
|
|
228
228
|
json[key] = value;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
return json;
|
|
231
|
+
return { ...json, messages: this.messages.cache.toArray() };
|
|
232
232
|
}
|
|
233
233
|
_updateInternals(data) {
|
|
234
234
|
for (let key in data) {
|
|
235
|
-
if (key === "id" || key === "createdAt")
|
|
235
|
+
if (key === "id" || key === "createdAt" || key === "messages")
|
|
236
236
|
continue;
|
|
237
237
|
if (key in this) {
|
|
238
238
|
this[key] = data[key];
|
|
239
239
|
}
|
|
240
|
+
if (key === "bet") {
|
|
241
|
+
this.bet = this.guild.bets.set(data.bet);
|
|
242
|
+
}
|
|
240
243
|
}
|
|
244
|
+
if (data?.messages?.length !== 0)
|
|
245
|
+
this.messages.set(data.messages);
|
|
241
246
|
this.updatedAt = new Date();
|
|
242
247
|
this.manager.set(this);
|
|
243
248
|
return this;
|