@duque.edits/sdk 1.0.3 → 1.0.4
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/betuser/GuildBetUserManager.js +1 -2
- package/dist/managers/match/GuildMatchManager.js +4 -21
- package/dist/managers/mediator/GuildMediatorManager.js +94 -0
- package/dist/managers/ticket/TicketManager.js +0 -1
- package/dist/rest/REST.js +6 -1
- package/dist/rest/Routes.js +1 -2
- package/dist/structures/bet/GuildBet.js +29 -16
- package/dist/structures/betuser/GuildBetUser.js +8 -2
- package/dist/structures/guild/Guild.js +4 -0
- package/dist/structures/match/GuildMatch.js +30 -33
- 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/package.json +1 -1
- package/types/managers/betuser/GuildBetUserManager.d.ts +1 -1
- package/types/managers/match/GuildMatchManager.d.ts +1 -2
- package/types/managers/mediator/GuildMediatorManager.d.ts +19 -0
- package/types/rest/REST.d.ts +3 -0
- package/types/structures/bet/GuildBet.d.ts +1 -1
- 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 +5 -1
- package/types/structures/mediator/GuildMediator.d.ts +50 -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
|
@@ -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
|
/**
|
|
@@ -95,26 +95,9 @@ class GuildMatchManager extends base_1.BaseManager {
|
|
|
95
95
|
return this.set(response);
|
|
96
96
|
}
|
|
97
97
|
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;
|
|
98
|
+
const route = Routes_1.Routes.fields(this.base_url, id);
|
|
99
|
+
const response = await this.rest.request({ url: route, method: "DELETE" });
|
|
100
|
+
return this.set(response);
|
|
118
101
|
}
|
|
119
102
|
}
|
|
120
103
|
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;
|
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,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Routes = void 0;
|
|
4
4
|
exports.Routes = {
|
|
5
|
-
base: "
|
|
6
|
-
//base: "https://duque-api.up.railway.app/api/v1",
|
|
5
|
+
base: "https://duque-api.up.railway.app/api/v1",
|
|
7
6
|
field: (field) => `/${field}`,
|
|
8
7
|
fields: (...fields) => `${fields.join("/")}`,
|
|
9
8
|
guilds: {
|
|
@@ -80,28 +80,41 @@ class GuildBet {
|
|
|
80
80
|
const response = await this.rest.request({ url: route, method: "GET" });
|
|
81
81
|
return this._updateInternals(response);
|
|
82
82
|
}
|
|
83
|
-
async addPlayer(player) {
|
|
84
|
-
|
|
85
|
-
if (isFull)
|
|
83
|
+
async addPlayer(player, queue_type) {
|
|
84
|
+
if (this.players.length === 2)
|
|
86
85
|
return this;
|
|
87
|
-
|
|
88
|
-
if (isPlayerIn !== -1)
|
|
86
|
+
if (this.players.some((p) => p.id === player.id))
|
|
89
87
|
return this;
|
|
90
88
|
this.players.push(player);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
if (queue_type) {
|
|
90
|
+
const queue = this.queues.find((q) => q.type === queue_type);
|
|
91
|
+
if (!queue)
|
|
92
|
+
return this;
|
|
93
|
+
for (const q of this.queues) {
|
|
94
|
+
q.players = q.players.filter((p) => p.id !== player.id);
|
|
95
|
+
}
|
|
96
|
+
if (!queue.players.some((p) => p.id === player.id)) {
|
|
97
|
+
queue.players.push({ id: player.id });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
await this.update({
|
|
101
|
+
players: this.players,
|
|
102
|
+
queues: this.queues,
|
|
103
|
+
});
|
|
104
|
+
return this;
|
|
95
105
|
}
|
|
96
106
|
async removePlayer(player) {
|
|
97
|
-
|
|
98
|
-
if (isPlayerIn === -1)
|
|
107
|
+
if (!this.players.some((p) => p.id === player.id))
|
|
99
108
|
return this;
|
|
100
109
|
this.players = this.players.filter((p) => p.id !== player.id);
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
for (const q of this.queues) {
|
|
111
|
+
q.players = q.players.filter((p) => p.id !== player.id);
|
|
112
|
+
}
|
|
113
|
+
await this.update({
|
|
114
|
+
players: this.players,
|
|
115
|
+
queues: this.queues,
|
|
116
|
+
});
|
|
117
|
+
return this;
|
|
105
118
|
}
|
|
106
119
|
async update(data) {
|
|
107
120
|
const payload = data;
|
|
@@ -135,7 +148,7 @@ class GuildBet {
|
|
|
135
148
|
toJSON() {
|
|
136
149
|
let json = {};
|
|
137
150
|
for (const [key, value] of Object.entries(this)) {
|
|
138
|
-
const exclude = ["rest", "
|
|
151
|
+
const exclude = ["rest", "guild", "manager"];
|
|
139
152
|
if (exclude.includes(key))
|
|
140
153
|
continue;
|
|
141
154
|
if (typeof value !== "function") {
|
|
@@ -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();
|
|
@@ -144,7 +150,7 @@ class GuildBetUser {
|
|
|
144
150
|
data.type = "add";
|
|
145
151
|
const route = Routes_1.Routes.guilds.betusers.get(this.manager.guild.id, this.id);
|
|
146
152
|
let payload = {};
|
|
147
|
-
const numericFields = ["wins", "credit", "losses", "mvps", "games"];
|
|
153
|
+
const numericFields = ["wins", "credit", "losses", "mvps", "games", "coins"];
|
|
148
154
|
const arrayFields = ["items", "original_channels", "adverts", "accessories"];
|
|
149
155
|
if (data?.type === "add" || data?.type === "remove") {
|
|
150
156
|
for (const key in data) {
|
|
@@ -193,7 +199,7 @@ class GuildBetUser {
|
|
|
193
199
|
toJSON() {
|
|
194
200
|
let json = {};
|
|
195
201
|
for (const [key, value] of Object.entries(this)) {
|
|
196
|
-
const exclude = ["rest", "guilds", "manager"];
|
|
202
|
+
const exclude = ["rest", "guilds", "guild", "manager"];
|
|
197
203
|
if (exclude.includes(key))
|
|
198
204
|
continue;
|
|
199
205
|
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
|
}
|
|
@@ -41,6 +41,8 @@ class GuildMatch {
|
|
|
41
41
|
/** Match's id */
|
|
42
42
|
mvps;
|
|
43
43
|
manager;
|
|
44
|
+
bet;
|
|
45
|
+
admin_id;
|
|
44
46
|
/** The given guild */
|
|
45
47
|
guild;
|
|
46
48
|
/** The rest client */
|
|
@@ -58,12 +60,14 @@ class GuildMatch {
|
|
|
58
60
|
this.manager = manager;
|
|
59
61
|
this.guild = manager.guild;
|
|
60
62
|
this.rest = manager.rest;
|
|
63
|
+
this.admin_id = data?.admin_id;
|
|
61
64
|
this.challenge = data?.challenge;
|
|
62
65
|
this.players = data?.players;
|
|
63
66
|
this.messages = data?.messages;
|
|
64
67
|
this.channels = data?.channels;
|
|
65
68
|
this.type = data?.type;
|
|
66
69
|
this.status = data?.status;
|
|
70
|
+
this.bet = this.guild.bets.cache.get(data?.bet?._id);
|
|
67
71
|
this.mvps = data?.mvps;
|
|
68
72
|
this.winners = data?.winners;
|
|
69
73
|
this.losers = data?.losers;
|
|
@@ -89,41 +93,20 @@ class GuildMatch {
|
|
|
89
93
|
method: "get",
|
|
90
94
|
url: route,
|
|
91
95
|
});
|
|
92
|
-
|
|
93
|
-
this.manager.cache.set(match._id, match);
|
|
94
|
-
return match;
|
|
96
|
+
return this._updateInternals(response);
|
|
95
97
|
}
|
|
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
98
|
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);
|
|
99
|
+
const confirmed = this.confirmed.find((c) => c.type === type);
|
|
100
|
+
const idsToAdd = Array.isArray(id) ? id : [id];
|
|
101
|
+
if (!confirmed) {
|
|
102
|
+
this.confirmed.push({ type, ids: [...idsToAdd], count: idsToAdd.length });
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const chIndex = this.confirmed.findIndex((ch) => ch.type === type);
|
|
106
|
+
const mergedIds = [...new Set([...(confirmed.ids || []), ...idsToAdd])];
|
|
107
|
+
this.confirmed[chIndex] = { ...confirmed, ids: mergedIds, count: mergedIds.length };
|
|
108
|
+
}
|
|
109
|
+
return this.update({ confirmed: this.confirmed });
|
|
127
110
|
}
|
|
128
111
|
async setConfirmed(set) {
|
|
129
112
|
Assertion_1.Assertion.assertObject(set);
|
|
@@ -191,6 +174,17 @@ class GuildMatch {
|
|
|
191
174
|
});
|
|
192
175
|
return this._updateInternals(response);
|
|
193
176
|
}
|
|
177
|
+
async setRoomAdminId(userId) {
|
|
178
|
+
Assertion_1.Assertion.assertString(userId);
|
|
179
|
+
const payload = { set: userId };
|
|
180
|
+
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "admin_id");
|
|
181
|
+
const response = await this.rest.request({
|
|
182
|
+
method: "PATCH",
|
|
183
|
+
url: route,
|
|
184
|
+
payload,
|
|
185
|
+
});
|
|
186
|
+
return this._updateInternals(response);
|
|
187
|
+
}
|
|
194
188
|
async kick(player) {
|
|
195
189
|
const payload = { set: player };
|
|
196
190
|
const route = Routes_1.Routes.guilds.matches.resource(this.guild.id, this._id, "kickout");
|
|
@@ -237,6 +231,9 @@ class GuildMatch {
|
|
|
237
231
|
if (key in this) {
|
|
238
232
|
this[key] = data[key];
|
|
239
233
|
}
|
|
234
|
+
if (key === "bet") {
|
|
235
|
+
this.bet = this.guild.bets.set(data.bet);
|
|
236
|
+
}
|
|
240
237
|
}
|
|
241
238
|
this.updatedAt = new Date();
|
|
242
239
|
this.manager.set(this);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildMediator = void 0;
|
|
4
|
+
const Routes_1 = require("../../rest/Routes");
|
|
5
|
+
class GuildMediator {
|
|
6
|
+
/** User's name */
|
|
7
|
+
id;
|
|
8
|
+
guild_id;
|
|
9
|
+
/** User's games */
|
|
10
|
+
games;
|
|
11
|
+
paypal;
|
|
12
|
+
revolut;
|
|
13
|
+
mbway;
|
|
14
|
+
external_links;
|
|
15
|
+
/** Creation Date */
|
|
16
|
+
createdAt;
|
|
17
|
+
/** Updated Date */
|
|
18
|
+
updatedAt;
|
|
19
|
+
/** The given manager */
|
|
20
|
+
manager;
|
|
21
|
+
/** The rest client */
|
|
22
|
+
rest;
|
|
23
|
+
guild;
|
|
24
|
+
/**
|
|
25
|
+
* Bet user
|
|
26
|
+
* @param data The user's data
|
|
27
|
+
* @param manager The manager
|
|
28
|
+
* @param rest The rest client
|
|
29
|
+
*/
|
|
30
|
+
constructor(data, manager) {
|
|
31
|
+
this.id = data?.id;
|
|
32
|
+
this.guild_id = data?.guild_id;
|
|
33
|
+
this.manager = manager;
|
|
34
|
+
this.rest = manager.rest;
|
|
35
|
+
this.guild = manager.guild;
|
|
36
|
+
this.games = data?.games;
|
|
37
|
+
this.paypal = data?.paypal;
|
|
38
|
+
this.revolut = data?.revolut;
|
|
39
|
+
this.mbway = data?.mbway;
|
|
40
|
+
this.external_links = data?.external_links;
|
|
41
|
+
this.createdAt = data?.createdAt ? new Date(data?.createdAt) : new Date();
|
|
42
|
+
this.updatedAt = data?.updatedAt ? new Date(data?.updatedAt) : new Date();
|
|
43
|
+
}
|
|
44
|
+
/** String representation of this user */
|
|
45
|
+
toString() {
|
|
46
|
+
return `<@${this.id}>`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Fetches the user
|
|
50
|
+
* @returns New Instance of the user
|
|
51
|
+
*/
|
|
52
|
+
async fetch() {
|
|
53
|
+
const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
|
|
54
|
+
const response = await this.rest.request({
|
|
55
|
+
method: "get",
|
|
56
|
+
url: route,
|
|
57
|
+
});
|
|
58
|
+
const user = new GuildMediator(response, this.manager);
|
|
59
|
+
this.manager.cache.set(user.id, user);
|
|
60
|
+
this.rest.mediators.set(user.id, user);
|
|
61
|
+
return user;
|
|
62
|
+
}
|
|
63
|
+
async reset() {
|
|
64
|
+
const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
|
|
65
|
+
const payload = { reset: true };
|
|
66
|
+
const response = await this.rest.request({
|
|
67
|
+
method: "DELETE",
|
|
68
|
+
url: route,
|
|
69
|
+
payload,
|
|
70
|
+
});
|
|
71
|
+
return this._updateInternals(response);
|
|
72
|
+
}
|
|
73
|
+
_updateInternals(data) {
|
|
74
|
+
for (let key in data) {
|
|
75
|
+
if (key === "id" || key === "createdAt")
|
|
76
|
+
continue;
|
|
77
|
+
if (key in this) {
|
|
78
|
+
this[key] = data[key];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.updatedAt = new Date();
|
|
82
|
+
this.createdAt = new Date(data.createdAt);
|
|
83
|
+
this.manager.set(this);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Update certain property
|
|
88
|
+
* @param data The new data to update with
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
async update(data) {
|
|
92
|
+
const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
|
|
93
|
+
let payload = data;
|
|
94
|
+
const response = await this.rest.request({
|
|
95
|
+
method: "patch",
|
|
96
|
+
url: route,
|
|
97
|
+
payload,
|
|
98
|
+
});
|
|
99
|
+
return this._updateInternals(response);
|
|
100
|
+
}
|
|
101
|
+
async setPaymentlink(type, link) {
|
|
102
|
+
const route = Routes_1.Routes.guilds.mediators.get(this.manager.guild.id, this.id);
|
|
103
|
+
let payload = { [type]: link };
|
|
104
|
+
const response = await this.rest.request({
|
|
105
|
+
method: "patch",
|
|
106
|
+
url: route,
|
|
107
|
+
payload,
|
|
108
|
+
});
|
|
109
|
+
return this._updateInternals(response);
|
|
110
|
+
}
|
|
111
|
+
async delete() {
|
|
112
|
+
const route = Routes_1.Routes.guilds.mediators.delete(this.manager.guild.id, this.id);
|
|
113
|
+
const response = await this.rest.request({
|
|
114
|
+
method: "DELETE",
|
|
115
|
+
url: route,
|
|
116
|
+
});
|
|
117
|
+
this.manager.cache.delete(this.id);
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
toJSON() {
|
|
121
|
+
let json = {};
|
|
122
|
+
for (const [key, value] of Object.entries(this)) {
|
|
123
|
+
const exclude = ["rest", "guilds", "guild", "manager"];
|
|
124
|
+
if (exclude.includes(key))
|
|
125
|
+
continue;
|
|
126
|
+
if (typeof value !== "function") {
|
|
127
|
+
json[key] = value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return json;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.GuildMediator = GuildMediator;
|
|
@@ -265,7 +265,7 @@ class GuildUser {
|
|
|
265
265
|
toJSON() {
|
|
266
266
|
let json = {};
|
|
267
267
|
for (const [key, value] of Object.entries(this)) {
|
|
268
|
-
const exclude = ["rest", "guilds", "manager"];
|
|
268
|
+
const exclude = ["rest", "guilds", "guild", "manager"];
|
|
269
269
|
if (exclude.includes(key))
|
|
270
270
|
continue;
|
|
271
271
|
if (typeof value !== "function") {
|
|
@@ -7,4 +7,5 @@ var GuildPermissionsTypes;
|
|
|
7
7
|
GuildPermissionsTypes["ManageQueues"] = "manage_queues";
|
|
8
8
|
GuildPermissionsTypes["ManageUsers"] = "manage_users";
|
|
9
9
|
GuildPermissionsTypes["ViewQueueChannels"] = "view_queue_channels";
|
|
10
|
+
GuildPermissionsTypes["MediatorRole"] = "mediator_role";
|
|
10
11
|
})(GuildPermissionsTypes || (exports.GuildPermissionsTypes = GuildPermissionsTypes = {}));
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ export declare class GuildBetUserManager extends BaseManager<GuildBetUser> {
|
|
|
12
12
|
fetch(options?: FetchOptions): Promise<Collection<string, GuildBetUser> | GuildBetUser>;
|
|
13
13
|
updateMany(...betusers: Optional<APIGuildBetUser>[]): Promise<Collection<string, GuildBetUser>>;
|
|
14
14
|
deleteAll(): Promise<void>;
|
|
15
|
-
resetAll(): Promise<Collection<string, GuildBetUser>>;
|
|
15
|
+
resetAll(): Promise<GuildBetUser | Collection<string, GuildBetUser>>;
|
|
16
16
|
set(data: APIGuildBetUser | APIGuildBetUser[]): GuildBetUser | Collection<string, GuildBetUser>;
|
|
17
17
|
}
|
|
18
18
|
export {};
|
|
@@ -24,7 +24,6 @@ export declare class GuildMatchManager extends BaseManager<GuildMatch> {
|
|
|
24
24
|
fetchAll(): Promise<Collection<string, GuildMatch>>;
|
|
25
25
|
set(data: APIGuildMatch | APIGuildMatch[]): GuildMatch | Collection<string, GuildMatch>;
|
|
26
26
|
create(payload: Optional<APIGuildMatch>): Promise<GuildMatch>;
|
|
27
|
-
delete(id
|
|
28
|
-
deleteAll(): Promise<boolean>;
|
|
27
|
+
delete(id?: string): Promise<GuildMatch | Collection<string, GuildMatch>>;
|
|
29
28
|
}
|
|
30
29
|
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GuildMediator } from "../../structures/mediator/GuildMediator";
|
|
2
|
+
import { Collection } from "../../structures/Collection";
|
|
3
|
+
import { Guild } from "../../structures/guild/Guild";
|
|
4
|
+
import { Optional, APIGuildMediator } from "../../types";
|
|
5
|
+
import { BaseManager } from "../base";
|
|
6
|
+
type FetchOptions = {
|
|
7
|
+
mediatorId?: string;
|
|
8
|
+
cache?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare class GuildMediatorManager extends BaseManager<GuildMediator> {
|
|
11
|
+
constructor(guild: Guild);
|
|
12
|
+
fetch(options?: FetchOptions): Promise<Collection<string, GuildMediator> | GuildMediator>;
|
|
13
|
+
updateMany(...mediators: Optional<APIGuildMediator>[]): Promise<Collection<string, GuildMediator>>;
|
|
14
|
+
create(payload: Optional<APIGuildMediator>): Promise<GuildMediator>;
|
|
15
|
+
deleteAll(): Promise<void>;
|
|
16
|
+
resetAll(): Promise<Collection<string, GuildMediator>>;
|
|
17
|
+
set(data: APIGuildMediator | APIGuildMediator[]): GuildMediator | Collection<string, GuildMediator>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
package/types/rest/REST.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { MinesGameManager } from "../managers";
|
|
|
8
8
|
import { StatusResponse } from "../types";
|
|
9
9
|
import { GuildBetUser } from "../structures/betuser/GuildBetUser";
|
|
10
10
|
import { GuildBet, GuildTicket, VipMember } from "../structures";
|
|
11
|
+
import { GuildMediator } from "../structures/mediator/GuildMediator";
|
|
11
12
|
interface ClientOptions {
|
|
12
13
|
clientKey: string;
|
|
13
14
|
guildId: string;
|
|
@@ -32,6 +33,7 @@ export declare class REST extends EventEmitter {
|
|
|
32
33
|
bets: Collection<string, GuildBet>;
|
|
33
34
|
tickets: Collection<string, GuildTicket>;
|
|
34
35
|
vipmembers: Collection<string, VipMember>;
|
|
36
|
+
mediators: Collection<string, GuildMediator>;
|
|
35
37
|
/**
|
|
36
38
|
*
|
|
37
39
|
* @param key The unique key for he client
|
|
@@ -39,6 +41,7 @@ export declare class REST extends EventEmitter {
|
|
|
39
41
|
constructor(options: ClientOptions);
|
|
40
42
|
/** Initialize the caching sistem */
|
|
41
43
|
init(): Promise<this>;
|
|
44
|
+
formatUrl(url: string): string;
|
|
42
45
|
/**
|
|
43
46
|
* Request Data from a certain url
|
|
44
47
|
* @param options
|
|
@@ -43,7 +43,7 @@ export declare class GuildBet {
|
|
|
43
43
|
constructor(data: Optional<APIGuildBet>, manager: GuildBetManager);
|
|
44
44
|
toString(): string;
|
|
45
45
|
fetch(): Promise<this>;
|
|
46
|
-
addPlayer(player: APIPlayer): Promise<this>;
|
|
46
|
+
addPlayer(player: APIPlayer, queue_type?: string): Promise<this>;
|
|
47
47
|
removePlayer(player: APIPlayer): Promise<this>;
|
|
48
48
|
update(data: Optional<APIGuildBet>): Promise<this>;
|
|
49
49
|
delete(): Promise<boolean>;
|
|
@@ -2,6 +2,7 @@ import { REST } from "../../rest/REST";
|
|
|
2
2
|
import { Daily, Optional, Profile } from "../../types/api";
|
|
3
3
|
import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
|
|
4
4
|
import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
|
|
5
|
+
import { Guild } from "../guild/Guild";
|
|
5
6
|
export declare class GuildBetUser implements APIGuildBetUser {
|
|
6
7
|
/** User daily */
|
|
7
8
|
daily: Omit<Daily, "points">;
|
|
@@ -27,10 +28,12 @@ export declare class GuildBetUser implements APIGuildBetUser {
|
|
|
27
28
|
createdAt: Date;
|
|
28
29
|
/** Updated Date */
|
|
29
30
|
updatedAt: Date;
|
|
31
|
+
consecutive_wins: number;
|
|
30
32
|
/** The given manager */
|
|
31
33
|
readonly manager: GuildBetUserManager;
|
|
32
34
|
/** The rest client */
|
|
33
35
|
readonly rest: REST;
|
|
36
|
+
readonly guild: Guild;
|
|
34
37
|
/**
|
|
35
38
|
* Bet user
|
|
36
39
|
* @param data The user's data
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BufferManager, GuildBetManager, GuildMatchManager, GuildPermissionManager, GuildTicketManager, GuildUserManager, LogManager, VipMemberManager } from "../../managers";
|
|
2
2
|
import { GuildBetUserManager } from "../../managers/betuser/GuildBetUserManager";
|
|
3
|
+
import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
|
|
3
4
|
import { REST } from "../../rest/REST";
|
|
4
5
|
import { APICode, APIGuildAdvert, APIGuildGroupedChannel, APIGuildPermissions, APIGuildShop, Daily, GuildPermissionsTypes, Optional, Permission } from "../../types/api";
|
|
5
6
|
import { APIGuild, DailyCategories, GuildChannelsType, GuildModes, GuildPrices, GuildScores, GuildStatus, GuildTicketConfiguration } from "../../types/api/APIGuild";
|
|
@@ -44,6 +45,7 @@ export declare class Guild {
|
|
|
44
45
|
shop: APIGuildShop;
|
|
45
46
|
betusers: GuildBetUserManager;
|
|
46
47
|
bets: GuildBetManager;
|
|
48
|
+
mediators: GuildMediatorManager;
|
|
47
49
|
adverts: APIGuildAdvert[];
|
|
48
50
|
codes: APICode[];
|
|
49
51
|
coin_symbol: string;
|
|
@@ -2,6 +2,7 @@ import { REST } from "../../rest/REST";
|
|
|
2
2
|
import { APIBaseChannel, APIGuildMatch, APIMessage, APIPlayer, BaseMatchModes, BaseMatchStatus, Confirm, MatchSelection, Optional } from "../../types";
|
|
3
3
|
import { GuildMatchManager } from "../../managers";
|
|
4
4
|
import { Guild } from "../guild/Guild";
|
|
5
|
+
import { GuildBet } from "../bet/GuildBet";
|
|
5
6
|
export declare class GuildMatch {
|
|
6
7
|
_id: string;
|
|
7
8
|
selections: MatchSelection[];
|
|
@@ -40,6 +41,8 @@ export declare class GuildMatch {
|
|
|
40
41
|
/** Match's id */
|
|
41
42
|
mvps: [];
|
|
42
43
|
manager: GuildMatchManager;
|
|
44
|
+
bet: GuildBet;
|
|
45
|
+
admin_id: string;
|
|
43
46
|
/** The given guild */
|
|
44
47
|
readonly guild: Guild;
|
|
45
48
|
/** The rest client */
|
|
@@ -57,13 +60,14 @@ export declare class GuildMatch {
|
|
|
57
60
|
* @returns New Instance of the match
|
|
58
61
|
*/
|
|
59
62
|
fetch(): Promise<GuildMatch>;
|
|
60
|
-
addConfirmed(type: string, id: string): Promise<
|
|
63
|
+
addConfirmed(type: string, id: string | string[]): Promise<APIGuildMatch>;
|
|
61
64
|
setConfirmed(set: Confirm[]): Promise<GuildMatch>;
|
|
62
65
|
setStatus(status: BaseMatchStatus): Promise<GuildMatch>;
|
|
63
66
|
setWinners(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
|
|
64
67
|
setLoser(players: Optional<APIPlayer>[] | Optional<APIPlayer>): Promise<GuildMatch>;
|
|
65
68
|
setMvps(...usersId: string[]): Promise<GuildMatch>;
|
|
66
69
|
setRoomCreatorId(userId: string): Promise<GuildMatch>;
|
|
70
|
+
setRoomAdminId(userId: string): Promise<GuildMatch>;
|
|
67
71
|
kick(player: Optional<APIPlayer>): Promise<this>;
|
|
68
72
|
update(data: Optional<APIGuildMatch>): Promise<GuildMatch>;
|
|
69
73
|
delete(): Promise<boolean>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GuildMediatorManager } from "../../managers/mediator/GuildMediatorManager";
|
|
2
|
+
import { REST } from "../../rest/REST";
|
|
3
|
+
import { Optional } from "../../types/api";
|
|
4
|
+
import { APIGuildMediator } from "../../types/api/APIGuildMediator";
|
|
5
|
+
import { Guild } from "../guild/Guild";
|
|
6
|
+
export declare class GuildMediator implements APIGuildMediator {
|
|
7
|
+
/** User's name */
|
|
8
|
+
id: string;
|
|
9
|
+
guild_id: string;
|
|
10
|
+
/** User's games */
|
|
11
|
+
games: number;
|
|
12
|
+
paypal: string;
|
|
13
|
+
revolut: string;
|
|
14
|
+
mbway: string;
|
|
15
|
+
external_links: string[];
|
|
16
|
+
/** Creation Date */
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
/** Updated Date */
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
/** The given manager */
|
|
21
|
+
readonly manager: GuildMediatorManager;
|
|
22
|
+
/** The rest client */
|
|
23
|
+
readonly rest: REST;
|
|
24
|
+
readonly guild: Guild;
|
|
25
|
+
/**
|
|
26
|
+
* Bet user
|
|
27
|
+
* @param data The user's data
|
|
28
|
+
* @param manager The manager
|
|
29
|
+
* @param rest The rest client
|
|
30
|
+
*/
|
|
31
|
+
constructor(data: APIGuildMediator, manager: GuildMediatorManager);
|
|
32
|
+
/** String representation of this user */
|
|
33
|
+
toString(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Fetches the user
|
|
36
|
+
* @returns New Instance of the user
|
|
37
|
+
*/
|
|
38
|
+
fetch(): Promise<GuildMediator>;
|
|
39
|
+
reset(): Promise<this>;
|
|
40
|
+
_updateInternals(data: Optional<APIGuildMediator>): this;
|
|
41
|
+
/**
|
|
42
|
+
* Update certain property
|
|
43
|
+
* @param data The new data to update with
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
update(data: Optional<APIGuildMediator>): Promise<this>;
|
|
47
|
+
setPaymentlink(type: string, link: string): Promise<this>;
|
|
48
|
+
delete(): Promise<boolean>;
|
|
49
|
+
toJSON(): Optional<APIGuildMediator>;
|
|
50
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseMatchModes, BaseMatchStatus, Confirm } from ".";
|
|
1
|
+
import { APIGuildBet, BaseMatchModes, BaseMatchStatus, Confirm } from ".";
|
|
2
2
|
import { APIBaseChannel } from "./APIBaseChannel";
|
|
3
3
|
import { APIMessage } from "./APIMessage";
|
|
4
4
|
import { APIPlayer } from "./APIPlayer";
|
|
@@ -16,6 +16,7 @@ export interface APIGuildMatch {
|
|
|
16
16
|
status: BaseMatchStatus;
|
|
17
17
|
/** Match's challenge */
|
|
18
18
|
challenge: boolean;
|
|
19
|
+
admin_id: string;
|
|
19
20
|
/** Match's players */
|
|
20
21
|
players: APIPlayer[];
|
|
21
22
|
/** Match's winners */
|
|
@@ -38,6 +39,7 @@ export interface APIGuildMatch {
|
|
|
38
39
|
creatorId: string;
|
|
39
40
|
/** Match's room creator id */
|
|
40
41
|
roomCreatorId: string;
|
|
42
|
+
bet: APIGuildBet;
|
|
41
43
|
/** Creation Date */
|
|
42
44
|
createdAt: Date;
|
|
43
45
|
/** Updated Date */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export interface APIGuildMediator extends APIPlayer {
|
|
1
|
+
export interface APIGuildMediator {
|
|
3
2
|
/** Mediator's id */
|
|
4
3
|
id: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
guild_id: string;
|
|
5
|
+
paypal: string;
|
|
6
|
+
revolut: string;
|
|
7
|
+
mbway: string;
|
|
8
|
+
external_links: string[];
|
|
9
|
+
games: number;
|
|
9
10
|
/** Creation Date */
|
|
10
11
|
createdAt: Date;
|
|
11
12
|
/** Updated Date */
|