@duque.edits/sdk 0.1.7 → 0.1.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/base.js +0 -6
- package/dist/managers/buffer/BufferManager.js +2 -2
- package/dist/managers/guild/GuildManager.js +6 -4
- package/dist/managers/index.js +5 -1
- package/dist/managers/logs/LogManager.js +60 -0
- package/dist/managers/match/GuildMatchManager.js +1 -1
- package/dist/managers/message/MessagesManager.js +1 -1
- package/dist/managers/minesgame/MinesGameManager.js +67 -0
- package/dist/managers/ticket/TicketManager.js +3 -3
- package/dist/managers/user/GuildUserManager.js +13 -21
- package/dist/managers/vipmember/VipMemberManager.js +2 -2
- package/dist/rest/REST.js +16 -17
- package/dist/rest/Routes.js +3 -3
- package/dist/structures/Collection.js +2 -2
- package/dist/structures/guild/Guild.js +142 -75
- package/dist/structures/index.js +1 -0
- package/dist/structures/match/GuildMatch.js +32 -74
- package/dist/structures/minesgame/MinesGame.js +72 -0
- package/dist/structures/user/GuildUser.js +16 -13
- package/dist/types/api/APIGuild.js +16 -0
- package/dist/types/api/APIGuildMatch.js +9 -0
- package/dist/types/api/APILogEntry.js +2 -0
- package/dist/types/api/APIMinesGame.js +2 -0
- package/dist/types/api/index.js +4 -4
- package/package.json +6 -4
- package/types/managers/base.d.ts +0 -3
- package/types/managers/index.d.ts +5 -1
- package/types/managers/logs/LogManager.d.ts +11 -0
- package/types/managers/minesgame/MinesGameManager.d.ts +17 -0
- package/types/managers/ticket/TicketManager.d.ts +1 -1
- package/types/managers/user/GuildUserManager.d.ts +2 -3
- package/types/managers/vipmember/VipMemberManager.d.ts +1 -2
- package/types/rest/REST.d.ts +10 -7
- package/types/structures/guild/Guild.d.ts +16 -32
- package/types/structures/index.d.ts +1 -0
- package/types/structures/match/GuildMatch.d.ts +4 -7
- package/types/structures/minesgame/MinesGame.d.ts +23 -0
- package/types/structures/ticket/Ticket.d.ts +3 -3
- package/types/structures/user/GuildUser.d.ts +3 -4
- package/types/types/api/APIGuild.d.ts +22 -38
- package/types/types/api/APIGuildGroupedChannel.d.ts +2 -5
- package/types/types/api/APIGuildMatch.d.ts +6 -0
- package/types/types/api/APIGuildUser.d.ts +7 -2
- package/types/types/api/APILogEntry.d.ts +9 -0
- package/types/types/api/APIMessage.d.ts +2 -1
- package/types/types/api/APIMinesGame.d.ts +13 -0
- package/types/types/api/index.d.ts +6 -15
package/dist/managers/base.js
CHANGED
|
@@ -11,16 +11,10 @@ class BaseManager {
|
|
|
11
11
|
guild;
|
|
12
12
|
/** Cache */
|
|
13
13
|
cache;
|
|
14
|
-
/** Internal data when manager is initialized */
|
|
15
|
-
_data;
|
|
16
14
|
constructor(guild, data) {
|
|
17
15
|
this.guild = guild;
|
|
18
16
|
this.rest = guild.rest;
|
|
19
17
|
this.cache = new Collection_1.Collection();
|
|
20
|
-
this._data = data;
|
|
21
|
-
}
|
|
22
|
-
get data() {
|
|
23
|
-
return this._data;
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
exports.BaseManager = BaseManager;
|
|
@@ -8,8 +8,8 @@ class BufferManager {
|
|
|
8
8
|
tickets;
|
|
9
9
|
guild;
|
|
10
10
|
constructor(guild) {
|
|
11
|
-
this.matches = new Collection_1.Collection();
|
|
12
|
-
this.tickets = new Collection_1.Collection();
|
|
11
|
+
this.matches = new Collection_1.Collection("buffer:matches");
|
|
12
|
+
this.tickets = new Collection_1.Collection("buffer:tickets");
|
|
13
13
|
this.guild = guild;
|
|
14
14
|
}
|
|
15
15
|
async flush(key) {
|
|
@@ -42,11 +42,13 @@ class GuildManager {
|
|
|
42
42
|
method: "get",
|
|
43
43
|
url: route,
|
|
44
44
|
});
|
|
45
|
-
for (let
|
|
46
|
-
if (!
|
|
45
|
+
for (let _guild of response) {
|
|
46
|
+
if (!_guild.id)
|
|
47
47
|
continue;
|
|
48
|
-
const guild = new Guild_1.Guild(
|
|
49
|
-
|
|
48
|
+
const guild = new Guild_1.Guild(_guild, this.rest);
|
|
49
|
+
await guild._start().then((g) => {
|
|
50
|
+
this.cache.set(g.id, g);
|
|
51
|
+
});
|
|
50
52
|
}
|
|
51
53
|
return this.cache;
|
|
52
54
|
}
|
package/dist/managers/index.js
CHANGED
|
@@ -16,8 +16,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./buffer/BufferManager"), exports);
|
|
18
18
|
__exportStar(require("./guild/GuildManager"), exports);
|
|
19
|
+
__exportStar(require("./logs/LogManager"), exports);
|
|
19
20
|
__exportStar(require("./match/GuildMatchManager"), exports);
|
|
21
|
+
__exportStar(require("./message/MessagesManager"), exports);
|
|
20
22
|
__exportStar(require("./permission/GuildPermissionManager"), exports);
|
|
23
|
+
__exportStar(require("./ticket/TicketManager"), exports);
|
|
21
24
|
__exportStar(require("./user/GuildUserManager"), exports);
|
|
22
25
|
__exportStar(require("./vipmember/VipMemberManager"), exports);
|
|
23
|
-
__exportStar(require("./
|
|
26
|
+
__exportStar(require("./minesgame/MinesGameManager"), exports);
|
|
27
|
+
__exportStar(require("./base"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogManager = void 0;
|
|
4
|
+
const rest_1 = require("../../rest");
|
|
5
|
+
const structures_1 = require("../../structures");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
class LogManager extends base_1.BaseManager {
|
|
8
|
+
constructor(guild) {
|
|
9
|
+
super(guild);
|
|
10
|
+
this.guild = guild;
|
|
11
|
+
this.rest = guild.rest;
|
|
12
|
+
this.base_url = rest_1.Routes.fields(rest_1.Routes.guilds.get(guild.id), "logs");
|
|
13
|
+
this.cache = new structures_1.Collection();
|
|
14
|
+
}
|
|
15
|
+
async fetch() {
|
|
16
|
+
const route = this.base_url;
|
|
17
|
+
const response = await this.rest.request({
|
|
18
|
+
method: "GET",
|
|
19
|
+
url: route,
|
|
20
|
+
});
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
async create(data) {
|
|
24
|
+
const route = this.base_url;
|
|
25
|
+
const payload = { ...data };
|
|
26
|
+
const response = await this.rest.request({
|
|
27
|
+
method: "POST",
|
|
28
|
+
url: route,
|
|
29
|
+
payload,
|
|
30
|
+
});
|
|
31
|
+
this.set(response);
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
async createMany(data) {
|
|
35
|
+
const route = this.base_url;
|
|
36
|
+
const payload = { ...data };
|
|
37
|
+
const response = await this.rest.request({
|
|
38
|
+
method: "POST",
|
|
39
|
+
url: route,
|
|
40
|
+
payload,
|
|
41
|
+
});
|
|
42
|
+
this.set(response);
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
set(data) {
|
|
46
|
+
if (!data)
|
|
47
|
+
return this.cache;
|
|
48
|
+
if (Array.isArray(data)) {
|
|
49
|
+
for (let entry of data) {
|
|
50
|
+
this.cache.set(entry._id, entry);
|
|
51
|
+
}
|
|
52
|
+
return this.cache;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.cache.set(data._id, data);
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.LogManager = LogManager;
|
|
@@ -42,7 +42,7 @@ class GuildMatchManager extends base_1.BaseManager {
|
|
|
42
42
|
});
|
|
43
43
|
if (!response)
|
|
44
44
|
return this.cache;
|
|
45
|
-
const coll = new Collection_1.Collection();
|
|
45
|
+
const coll = new Collection_1.Collection("matches");
|
|
46
46
|
for (let match of response ?? []) {
|
|
47
47
|
const guildMatch = new GuildMatch_1.GuildMatch(match, this);
|
|
48
48
|
coll.set(match._id, guildMatch);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MinesGameManager = void 0;
|
|
4
|
+
const structures_1 = require("../../structures");
|
|
5
|
+
class MinesGameManager {
|
|
6
|
+
cache;
|
|
7
|
+
rest;
|
|
8
|
+
constructor(rest) {
|
|
9
|
+
this.cache = new structures_1.Collection("minesgames");
|
|
10
|
+
this.rest = rest;
|
|
11
|
+
}
|
|
12
|
+
async create(data) {
|
|
13
|
+
const route = "/minesgames";
|
|
14
|
+
const response = await this.rest.request({
|
|
15
|
+
method: "POST",
|
|
16
|
+
url: route,
|
|
17
|
+
payload: data,
|
|
18
|
+
});
|
|
19
|
+
return this.set(response);
|
|
20
|
+
}
|
|
21
|
+
async delete(gameId) {
|
|
22
|
+
const route = `/minesgames/${gameId}`;
|
|
23
|
+
const response = await this.rest.request({
|
|
24
|
+
method: "DELETE",
|
|
25
|
+
url: route,
|
|
26
|
+
});
|
|
27
|
+
this.cache.delete(gameId);
|
|
28
|
+
return response;
|
|
29
|
+
}
|
|
30
|
+
async fetch(options) {
|
|
31
|
+
if (options && options.cache)
|
|
32
|
+
return this.cache;
|
|
33
|
+
if (options && options.gameId) {
|
|
34
|
+
const route = `/minesgames/${options.gameId}`;
|
|
35
|
+
const response = await this.rest.request({
|
|
36
|
+
method: "GET",
|
|
37
|
+
url: route,
|
|
38
|
+
});
|
|
39
|
+
const game = new structures_1.MinesGame(response, this);
|
|
40
|
+
this.set(game);
|
|
41
|
+
return game;
|
|
42
|
+
}
|
|
43
|
+
const route = "/minesgames";
|
|
44
|
+
const response = await this.rest.request({
|
|
45
|
+
method: "GET",
|
|
46
|
+
url: route,
|
|
47
|
+
});
|
|
48
|
+
return this.set(response);
|
|
49
|
+
}
|
|
50
|
+
set(data) {
|
|
51
|
+
if (!data)
|
|
52
|
+
return this.cache;
|
|
53
|
+
if (Array.isArray(data)) {
|
|
54
|
+
for (let _game of data) {
|
|
55
|
+
const game = new structures_1.MinesGame(_game, this);
|
|
56
|
+
this.cache.set(game._id, game);
|
|
57
|
+
}
|
|
58
|
+
return this.cache;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const game = new structures_1.MinesGame(data, this);
|
|
62
|
+
this.cache.set(game._id, game);
|
|
63
|
+
return game;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.MinesGameManager = MinesGameManager;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GuildTicketManager = void 0;
|
|
4
4
|
const rest_1 = require("../../rest");
|
|
5
5
|
const structures_1 = require("../../structures");
|
|
6
6
|
const Collection_1 = require("../../structures/Collection");
|
|
7
|
-
class
|
|
7
|
+
class GuildTicketManager {
|
|
8
8
|
cache;
|
|
9
9
|
guild;
|
|
10
10
|
rest;
|
|
@@ -74,4 +74,4 @@ class TicketManager {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
exports.
|
|
77
|
+
exports.GuildTicketManager = GuildTicketManager;
|
|
@@ -11,7 +11,7 @@ class GuildUserManager extends base_1.BaseManager {
|
|
|
11
11
|
this.guild = guild;
|
|
12
12
|
this.rest = guild.rest;
|
|
13
13
|
this.base_url = Routes_1.Routes.guilds.users.getAll(guild.id);
|
|
14
|
-
this.cache = new Collection_1.Collection();
|
|
14
|
+
this.cache = new Collection_1.Collection("users");
|
|
15
15
|
}
|
|
16
16
|
async fetch(options) {
|
|
17
17
|
if (options && options.cache)
|
|
@@ -23,7 +23,7 @@ class GuildUserManager extends base_1.BaseManager {
|
|
|
23
23
|
url: route,
|
|
24
24
|
});
|
|
25
25
|
const user = new GuildUser_1.GuildUser(response, this);
|
|
26
|
-
this.
|
|
26
|
+
this.set(user);
|
|
27
27
|
return user;
|
|
28
28
|
}
|
|
29
29
|
const route = this.base_url;
|
|
@@ -34,20 +34,20 @@ class GuildUserManager extends base_1.BaseManager {
|
|
|
34
34
|
this.cache.clear();
|
|
35
35
|
for (let userData of response) {
|
|
36
36
|
const user = new GuildUser_1.GuildUser(userData, this);
|
|
37
|
-
this.
|
|
37
|
+
this.set(user);
|
|
38
38
|
}
|
|
39
39
|
return this.cache;
|
|
40
40
|
}
|
|
41
|
-
async updateMany(users) {
|
|
41
|
+
async updateMany(...users) {
|
|
42
42
|
const route = this.base_url;
|
|
43
43
|
const response = await this.rest.request({
|
|
44
44
|
method: "PATCH",
|
|
45
45
|
url: route,
|
|
46
|
-
payload: users,
|
|
46
|
+
payload: { users },
|
|
47
47
|
});
|
|
48
48
|
for (const userData of response) {
|
|
49
49
|
const user = new GuildUser_1.GuildUser(userData, this);
|
|
50
|
-
this.
|
|
50
|
+
this.set(user);
|
|
51
51
|
}
|
|
52
52
|
return this.cache;
|
|
53
53
|
}
|
|
@@ -66,36 +66,28 @@ class GuildUserManager extends base_1.BaseManager {
|
|
|
66
66
|
url: route,
|
|
67
67
|
});
|
|
68
68
|
this.cache.clear();
|
|
69
|
-
this.
|
|
69
|
+
this.set(response);
|
|
70
70
|
return this.cache;
|
|
71
71
|
}
|
|
72
|
-
_setUsers(data) {
|
|
73
|
-
if (Array.isArray(data)) {
|
|
74
|
-
for (let ud of data) {
|
|
75
|
-
const us = new GuildUser_1.GuildUser(ud, this);
|
|
76
|
-
this.cache.set(us.id, us);
|
|
77
|
-
this.rest.users.set(us.id, us);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
const us = new GuildUser_1.GuildUser(data, this);
|
|
82
|
-
this.cache.set(us.id, us);
|
|
83
|
-
this.rest.users.set(us.id, us);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
72
|
set(data) {
|
|
87
73
|
if (!data)
|
|
88
74
|
return this.cache;
|
|
89
75
|
if (Array.isArray(data)) {
|
|
90
76
|
for (let _user of data) {
|
|
77
|
+
if (!_user.id)
|
|
78
|
+
return;
|
|
91
79
|
const user = new GuildUser_1.GuildUser(_user, this);
|
|
92
80
|
this.cache.set(user.id, user);
|
|
81
|
+
this.rest.users.set(user.id, user);
|
|
93
82
|
}
|
|
94
83
|
return this.cache;
|
|
95
84
|
}
|
|
96
85
|
else {
|
|
86
|
+
if (!data.id)
|
|
87
|
+
return;
|
|
97
88
|
const user = new GuildUser_1.GuildUser(data, this);
|
|
98
89
|
this.cache.set(user.id, user);
|
|
90
|
+
this.rest.users.set(user.id, user);
|
|
99
91
|
return user;
|
|
100
92
|
}
|
|
101
93
|
}
|
|
@@ -12,10 +12,10 @@ class VipMemberManager extends base_1.BaseManager {
|
|
|
12
12
|
* @param vipmembers An array of vipmembers
|
|
13
13
|
* @param rest The rest client
|
|
14
14
|
*/
|
|
15
|
-
constructor(guild
|
|
15
|
+
constructor(guild) {
|
|
16
16
|
super(guild);
|
|
17
|
-
this.rest = rest;
|
|
18
17
|
this.guild = guild;
|
|
18
|
+
this.rest = guild.rest;
|
|
19
19
|
this.base_url = Routes_1.Routes.guilds.resource(guild.id, "vipmembers");
|
|
20
20
|
this.cache = new Collection_1.Collection("vipmembers");
|
|
21
21
|
}
|
package/dist/rest/REST.js
CHANGED
|
@@ -12,6 +12,7 @@ const undici_1 = require("undici");
|
|
|
12
12
|
const Routes_1 = require("./Routes");
|
|
13
13
|
const GuildManager_1 = require("../managers/guild/GuildManager");
|
|
14
14
|
const Collection_1 = require("../structures/Collection");
|
|
15
|
+
const managers_1 = require("../managers");
|
|
15
16
|
const Reset = "\x1b[0m";
|
|
16
17
|
const FgGreen = "\x1b[32m";
|
|
17
18
|
const FgRed = "\x1b[31m";
|
|
@@ -24,34 +25,32 @@ class REST extends events_1.default {
|
|
|
24
25
|
/**
|
|
25
26
|
* The unique key for client
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
clientKey;
|
|
29
|
+
authKey;
|
|
28
30
|
/** The guild manager */
|
|
29
31
|
guilds;
|
|
32
|
+
minesGames;
|
|
30
33
|
users;
|
|
31
34
|
matches;
|
|
32
35
|
/**
|
|
33
36
|
*
|
|
34
37
|
* @param key The unique key for he client
|
|
35
38
|
*/
|
|
36
|
-
constructor(
|
|
39
|
+
constructor(options) {
|
|
37
40
|
super({ captureRejections: true });
|
|
38
|
-
this.
|
|
41
|
+
this.clientKey = options.clientKey ?? "";
|
|
42
|
+
this.authKey = options.authKey ?? "";
|
|
39
43
|
this.guilds = new GuildManager_1.GuildManager(this);
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* Set the api key
|
|
45
|
-
* @param key The unique key of the client
|
|
46
|
-
*/
|
|
47
|
-
setKey(key) {
|
|
48
|
-
this.key = key;
|
|
44
|
+
this.minesGames = new managers_1.MinesGameManager(this);
|
|
45
|
+
this.users = new Collection_1.Collection("rest:users");
|
|
46
|
+
this.matches = new Collection_1.Collection("rest:matches");
|
|
47
|
+
this.setMaxListeners(999);
|
|
49
48
|
}
|
|
50
49
|
/** Initialize the caching sistem */
|
|
51
50
|
async init() {
|
|
52
|
-
if (!this.
|
|
51
|
+
if (!this.clientKey || !this.authKey)
|
|
53
52
|
throw new Error("Key is necessary");
|
|
54
|
-
await Promise.all([this.guilds.fetch()]);
|
|
53
|
+
await Promise.all([this.guilds.fetch(), this.minesGames.fetch()]);
|
|
55
54
|
return this;
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
@@ -71,13 +70,13 @@ class REST extends events_1.default {
|
|
|
71
70
|
async request(options) {
|
|
72
71
|
let { method, url, payload } = options;
|
|
73
72
|
Assertion_1.Assertion.assertString(method);
|
|
74
|
-
Assertion_1.Assertion.assertString(this.
|
|
73
|
+
Assertion_1.Assertion.assertString(this.clientKey);
|
|
75
74
|
Assertion_1.Assertion.assertString(url);
|
|
76
75
|
method = method.toUpperCase();
|
|
77
76
|
url = Routes_1.Routes.base + url;
|
|
78
77
|
const headers = new undici_1.Headers();
|
|
79
|
-
headers.append("authorization",
|
|
80
|
-
headers.append("client_key", this.
|
|
78
|
+
headers.append("authorization", this.authKey);
|
|
79
|
+
headers.append("client_key", this.clientKey);
|
|
81
80
|
headers.append("Content-Type", "application/json");
|
|
82
81
|
const before = Date.now();
|
|
83
82
|
this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
|
package/dist/rest/Routes.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Routes = void 0;
|
|
4
4
|
exports.Routes = {
|
|
5
|
-
base: "http://localhost:80/api/v1",
|
|
6
|
-
|
|
7
|
-
field: (field) =>
|
|
5
|
+
// base: "http://localhost:80/api/v1",
|
|
6
|
+
base: "https://dpqd.shardweb.app/api/v1",
|
|
7
|
+
field: (field) => `/${field}`,
|
|
8
8
|
fields: (...fields) => `${fields.join("/")}`,
|
|
9
9
|
guilds: {
|
|
10
10
|
create: () => `/guilds`,
|
|
@@ -45,7 +45,7 @@ class Collection extends Map {
|
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
47
|
filter(predicate) {
|
|
48
|
-
const results = new Collection(
|
|
48
|
+
const results = new Collection(this.key, []);
|
|
49
49
|
for (const [key, value] of this) {
|
|
50
50
|
if (predicate(value, key, this))
|
|
51
51
|
results.set(key, value);
|
|
@@ -53,7 +53,7 @@ class Collection extends Map {
|
|
|
53
53
|
return results;
|
|
54
54
|
}
|
|
55
55
|
some(predicate) {
|
|
56
|
-
const results = new Collection(
|
|
56
|
+
const results = new Collection(this.key, []);
|
|
57
57
|
for (const [key, value] of this) {
|
|
58
58
|
if (predicate(value, key, this))
|
|
59
59
|
results.set(key, value);
|