@stoatx/client 0.4.0 → 0.6.0
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/index.cjs +425 -197
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +141 -105
- package/dist/index.d.ts +141 -105
- package/dist/index.js +422 -193
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -30,13 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
API: () => API,
|
|
33
34
|
Attachment: () => Attachment,
|
|
34
35
|
AttachmentBuilder: () => AttachmentBuilder,
|
|
35
36
|
Base: () => Base,
|
|
36
37
|
BaseChannel: () => BaseChannel,
|
|
37
38
|
BitField: () => BitField,
|
|
38
39
|
ChannelManager: () => ChannelManager,
|
|
39
|
-
ChannelType: () => ChannelType,
|
|
40
40
|
Client: () => Client,
|
|
41
41
|
ClientUser: () => ClientUser,
|
|
42
42
|
Collection: () => Collection,
|
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
Emoji: () => Emoji,
|
|
47
47
|
EmojiManager: () => EmojiManager,
|
|
48
48
|
GatewayManager: () => GatewayManager,
|
|
49
|
+
GroupChannel: () => GroupChannel,
|
|
49
50
|
Member: () => Member,
|
|
50
51
|
MemberManager: () => MemberManager,
|
|
51
52
|
Message: () => Message,
|
|
@@ -66,9 +67,7 @@ __export(index_exports, {
|
|
|
66
67
|
TextChannel: () => TextChannel,
|
|
67
68
|
UnknownChannel: () => UnknownChannel,
|
|
68
69
|
User: () => User,
|
|
69
|
-
UserManager: () => UserManager
|
|
70
|
-
UserPresence: () => UserPresence,
|
|
71
|
-
UserRelationship: () => UserRelationship
|
|
70
|
+
UserManager: () => UserManager
|
|
72
71
|
});
|
|
73
72
|
module.exports = __toCommonJS(index_exports);
|
|
74
73
|
|
|
@@ -114,7 +113,7 @@ var Base = class _Base {
|
|
|
114
113
|
};
|
|
115
114
|
|
|
116
115
|
// src/structures/Message.ts
|
|
117
|
-
var
|
|
116
|
+
var util3 = __toESM(require("util"), 1);
|
|
118
117
|
|
|
119
118
|
// src/structures/Attachment.ts
|
|
120
119
|
var Attachment = class extends Base {
|
|
@@ -131,7 +130,7 @@ var Attachment = class extends Base {
|
|
|
131
130
|
serverId;
|
|
132
131
|
objectId;
|
|
133
132
|
constructor(client, data) {
|
|
134
|
-
super(client, { ...data,
|
|
133
|
+
super(client, { ...data, _id: data._id });
|
|
135
134
|
this.id = data._id;
|
|
136
135
|
this.tag = data.tag;
|
|
137
136
|
this.filename = data.filename;
|
|
@@ -460,6 +459,82 @@ var ReactionCollector = class extends Collector {
|
|
|
460
459
|
}
|
|
461
460
|
};
|
|
462
461
|
|
|
462
|
+
// src/structures/MessageMentions.ts
|
|
463
|
+
var import_node_util = __toESM(require("util"), 1);
|
|
464
|
+
var MessageMentions = class _MessageMentions {
|
|
465
|
+
constructor(client, message, userIds, roleIds) {
|
|
466
|
+
this.client = client;
|
|
467
|
+
this.message = message;
|
|
468
|
+
this.userIds = userIds ?? [];
|
|
469
|
+
this.roleIds = roleIds ?? [];
|
|
470
|
+
this.channelIds = message.content ? _MessageMentions.parseChannelIds(message.content) : [];
|
|
471
|
+
}
|
|
472
|
+
/** Raw user IDs from the API */
|
|
473
|
+
userIds;
|
|
474
|
+
/** Raw role IDs from the API */
|
|
475
|
+
roleIds;
|
|
476
|
+
/** Raw channel IDs parsed from message content */
|
|
477
|
+
channelIds;
|
|
478
|
+
/** Mentioned users resolved from cache */
|
|
479
|
+
get users() {
|
|
480
|
+
const col = new Collection();
|
|
481
|
+
for (const id of this.userIds) {
|
|
482
|
+
const user = this.client.users.cache.get(id);
|
|
483
|
+
if (user) col.set(id, user);
|
|
484
|
+
}
|
|
485
|
+
return col;
|
|
486
|
+
}
|
|
487
|
+
/** Mentioned members resolved from cache (only in server channels) */
|
|
488
|
+
get members() {
|
|
489
|
+
const col = new Collection();
|
|
490
|
+
const server = this.message.server;
|
|
491
|
+
if (!server) return col;
|
|
492
|
+
for (const id of this.userIds) {
|
|
493
|
+
const member = server.members.cache.get(id);
|
|
494
|
+
if (member) col.set(id, member);
|
|
495
|
+
}
|
|
496
|
+
return col;
|
|
497
|
+
}
|
|
498
|
+
/** Mentioned roles resolved from cache */
|
|
499
|
+
get roles() {
|
|
500
|
+
const col = new Collection();
|
|
501
|
+
const server = this.message.server;
|
|
502
|
+
if (!server) return col;
|
|
503
|
+
for (const id of this.roleIds) {
|
|
504
|
+
const role = server.roles.cache.get(id);
|
|
505
|
+
if (role) col.set(id, role);
|
|
506
|
+
}
|
|
507
|
+
return col;
|
|
508
|
+
}
|
|
509
|
+
/** Mentioned channels resolved from cache */
|
|
510
|
+
get channels() {
|
|
511
|
+
const col = new Collection();
|
|
512
|
+
for (const id of this.channelIds) {
|
|
513
|
+
const channel = this.client.channels.cache.get(id);
|
|
514
|
+
if (channel) col.set(id, channel);
|
|
515
|
+
}
|
|
516
|
+
return col;
|
|
517
|
+
}
|
|
518
|
+
/** Whether the given user ID is mentioned */
|
|
519
|
+
has(userId) {
|
|
520
|
+
return this.userIds.includes(userId);
|
|
521
|
+
}
|
|
522
|
+
static parseChannelIds(content) {
|
|
523
|
+
return [...content.matchAll(/<#([A-Z0-9]+)>/g)].flatMap((m) => m[1] ? [m[1]] : []);
|
|
524
|
+
}
|
|
525
|
+
[import_node_util.default.inspect.custom](depth, options, inspect12) {
|
|
526
|
+
const { client, message, ...props } = this;
|
|
527
|
+
const data = {
|
|
528
|
+
...props,
|
|
529
|
+
members: this.members,
|
|
530
|
+
channels: this.channels,
|
|
531
|
+
users: this.users,
|
|
532
|
+
roles: this.roles
|
|
533
|
+
};
|
|
534
|
+
return `${this.constructor.name} ${inspect12(data, { ...options, depth: depth ?? options.depth })}`;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
463
538
|
// src/structures/Message.ts
|
|
464
539
|
var Message = class extends Base {
|
|
465
540
|
content = null;
|
|
@@ -472,11 +547,10 @@ var Message = class extends Base {
|
|
|
472
547
|
flags = 0;
|
|
473
548
|
interactions = null;
|
|
474
549
|
masquerade = null;
|
|
475
|
-
mentions
|
|
550
|
+
mentions;
|
|
476
551
|
pinned = false;
|
|
477
552
|
reactions = {};
|
|
478
553
|
replies = [];
|
|
479
|
-
role_mentions = [];
|
|
480
554
|
constructor(client, data) {
|
|
481
555
|
super(client, data);
|
|
482
556
|
this.authorId = data.author;
|
|
@@ -489,10 +563,9 @@ var Message = class extends Base {
|
|
|
489
563
|
this.attachments = data.attachments.map((fileData) => new Attachment(this.client, fileData));
|
|
490
564
|
}
|
|
491
565
|
if (data.masquerade !== void 0) this.masquerade = data.masquerade;
|
|
492
|
-
if (data.mentions !== void 0) this.mentions = data.mentions;
|
|
493
566
|
if (data.replies !== void 0) this.replies = data.replies;
|
|
494
|
-
if (data.role_mentions !== void 0) this.role_mentions = data.role_mentions;
|
|
495
567
|
this._patch(data);
|
|
568
|
+
this.mentions = new MessageMentions(client, this, data.mentions ?? null, data.role_mentions ?? null);
|
|
496
569
|
}
|
|
497
570
|
async reply(contentOrOptions) {
|
|
498
571
|
let channel = this.channel;
|
|
@@ -647,7 +720,7 @@ var Message = class extends Base {
|
|
|
647
720
|
}
|
|
648
721
|
_patch(data) {
|
|
649
722
|
if (data.content !== void 0) this.content = data.content;
|
|
650
|
-
if (data.edited !== void 0) this.editedAt = new Date(data.edited);
|
|
723
|
+
if (data.edited !== void 0) this.editedAt = new Date(data.edited ?? 0);
|
|
651
724
|
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
652
725
|
if (data.embeds !== void 0) this.embeds = data.embeds;
|
|
653
726
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
@@ -666,7 +739,7 @@ var Message = class extends Base {
|
|
|
666
739
|
}
|
|
667
740
|
}
|
|
668
741
|
// This tells Node.js exactly how to print this object in console.log()
|
|
669
|
-
[
|
|
742
|
+
[util3.inspect.custom](depth, options, inspect12) {
|
|
670
743
|
const { client, authorId, channelId, ...props } = this;
|
|
671
744
|
const data = {
|
|
672
745
|
...props,
|
|
@@ -680,24 +753,6 @@ var Message = class extends Base {
|
|
|
680
753
|
};
|
|
681
754
|
|
|
682
755
|
// src/structures/User.ts
|
|
683
|
-
var UserRelationship = /* @__PURE__ */ ((UserRelationship2) => {
|
|
684
|
-
UserRelationship2["None"] = "None";
|
|
685
|
-
UserRelationship2["User"] = "User";
|
|
686
|
-
UserRelationship2["Friend"] = "Friend";
|
|
687
|
-
UserRelationship2["Outgoing"] = "Outgoing";
|
|
688
|
-
UserRelationship2["Incoming"] = "Incoming";
|
|
689
|
-
UserRelationship2["Blocked"] = "Blocked";
|
|
690
|
-
UserRelationship2["BlockedOther"] = "BlockedOther";
|
|
691
|
-
return UserRelationship2;
|
|
692
|
-
})(UserRelationship || {});
|
|
693
|
-
var UserPresence = /* @__PURE__ */ ((UserPresence2) => {
|
|
694
|
-
UserPresence2["Online"] = "Online";
|
|
695
|
-
UserPresence2["Idle"] = "Idle";
|
|
696
|
-
UserPresence2["Focus"] = "Focus";
|
|
697
|
-
UserPresence2["Busy"] = "Busy";
|
|
698
|
-
UserPresence2["Invisible"] = "Invisible";
|
|
699
|
-
return UserPresence2;
|
|
700
|
-
})(UserPresence || {});
|
|
701
756
|
var User = class extends Base {
|
|
702
757
|
discriminator;
|
|
703
758
|
online;
|
|
@@ -731,7 +786,7 @@ var User = class extends Base {
|
|
|
731
786
|
this.bot = data.bot ? { owner: data.bot.owner } : false;
|
|
732
787
|
}
|
|
733
788
|
if (data.avatar !== void 0) {
|
|
734
|
-
this.avatar = new Attachment(this.client, data.avatar);
|
|
789
|
+
this.avatar = data.avatar ? new Attachment(this.client, data.avatar) : null;
|
|
735
790
|
}
|
|
736
791
|
if (clear && Array.isArray(clear)) {
|
|
737
792
|
for (const field of clear) {
|
|
@@ -811,6 +866,7 @@ var GatewayManager = class {
|
|
|
811
866
|
handleMessage(rawData) {
|
|
812
867
|
const payload = JSON.parse(rawData.toString());
|
|
813
868
|
const eventType = payload.type;
|
|
869
|
+
this.client.emit("raw", payload);
|
|
814
870
|
switch (eventType) {
|
|
815
871
|
case "Error":
|
|
816
872
|
this.client.emit("error", new Error(`Gateway Error: ${payload.error || JSON.stringify(payload)}`));
|
|
@@ -837,6 +893,15 @@ var GatewayManager = class {
|
|
|
837
893
|
}
|
|
838
894
|
}
|
|
839
895
|
}
|
|
896
|
+
if (payload.members) {
|
|
897
|
+
for (const rawMember of payload.members) {
|
|
898
|
+
const server = this.client.servers.cache.get(rawMember._id.server);
|
|
899
|
+
const user = this.client.users.cache.get(rawMember._id.user);
|
|
900
|
+
if (server && user) {
|
|
901
|
+
server.members._add({ ...rawMember, user });
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
840
905
|
if (payload.emojis) {
|
|
841
906
|
for (const rawEmoji of payload.emojis) {
|
|
842
907
|
const emoji = this.client.emojis._add(rawEmoji);
|
|
@@ -888,7 +953,7 @@ var GatewayManager = class {
|
|
|
888
953
|
const message = channel?.messages.cache.get(payload.id);
|
|
889
954
|
if (message && payload.append.embeds) {
|
|
890
955
|
const oldMessage = message._clone();
|
|
891
|
-
message.embeds.
|
|
956
|
+
message.embeds = [...message.embeds || [], ...payload.append.embeds];
|
|
892
957
|
this.client.emit("messageUpdate", oldMessage, message);
|
|
893
958
|
}
|
|
894
959
|
break;
|
|
@@ -1028,13 +1093,28 @@ var GatewayManager = class {
|
|
|
1028
1093
|
}
|
|
1029
1094
|
case "ServerMemberLeave": {
|
|
1030
1095
|
const server = this.client.servers.cache.get(payload.id);
|
|
1096
|
+
let member = null;
|
|
1031
1097
|
if (server) {
|
|
1032
|
-
|
|
1098
|
+
member = server.members.cache.get(payload.user);
|
|
1033
1099
|
if (member) {
|
|
1034
1100
|
server.members.cache.delete(payload.user);
|
|
1035
|
-
this.client.emit("serverMemberLeave", member);
|
|
1036
1101
|
}
|
|
1037
1102
|
}
|
|
1103
|
+
const emitData = member || { serverId: payload.id, userId: payload.user };
|
|
1104
|
+
if (payload.reason === "Ban") {
|
|
1105
|
+
if (server) {
|
|
1106
|
+
const dummyBanPayload = {
|
|
1107
|
+
id: payload.user,
|
|
1108
|
+
reason: null
|
|
1109
|
+
};
|
|
1110
|
+
server.bans._add(dummyBanPayload);
|
|
1111
|
+
}
|
|
1112
|
+
this.client.emit("serverBanAdd", emitData);
|
|
1113
|
+
} else if (payload.reason === "Kick") {
|
|
1114
|
+
this.client.emit("serverMemberKick", emitData);
|
|
1115
|
+
} else {
|
|
1116
|
+
this.client.emit("serverMemberLeave", emitData);
|
|
1117
|
+
}
|
|
1038
1118
|
break;
|
|
1039
1119
|
}
|
|
1040
1120
|
case "EmojiCreate": {
|
|
@@ -1068,7 +1148,8 @@ var GatewayManager = class {
|
|
|
1068
1148
|
break;
|
|
1069
1149
|
}
|
|
1070
1150
|
default:
|
|
1071
|
-
this.client.emit("
|
|
1151
|
+
this.client.emit("debug", `Unhandled Gateway Event Type: ${eventType}`);
|
|
1152
|
+
break;
|
|
1072
1153
|
}
|
|
1073
1154
|
}
|
|
1074
1155
|
startPingLoop() {
|
|
@@ -1114,6 +1195,96 @@ var GatewayManager = class {
|
|
|
1114
1195
|
|
|
1115
1196
|
// src/rest/RESTManager.ts
|
|
1116
1197
|
var import_undici = require("undici");
|
|
1198
|
+
|
|
1199
|
+
// src/utils/schema.ts
|
|
1200
|
+
var queryParams = {
|
|
1201
|
+
"/": { get: [] },
|
|
1202
|
+
"/users/@me": { get: [] },
|
|
1203
|
+
"/users/{target}": { get: [], patch: [] },
|
|
1204
|
+
"/users/{target}/flags": { get: [] },
|
|
1205
|
+
"/users/@me/username": { patch: [] },
|
|
1206
|
+
"/users/{target}/default_avatar": { get: [] },
|
|
1207
|
+
"/users/{target}/profile": { get: [] },
|
|
1208
|
+
"/users/dms": { get: [] },
|
|
1209
|
+
"/users/{target}/dm": { get: [] },
|
|
1210
|
+
"/users/{target}/mutual": { get: [] },
|
|
1211
|
+
"/users/{target}/friend": { put: [], delete: [] },
|
|
1212
|
+
"/users/{target}/block": { put: [], delete: [] },
|
|
1213
|
+
"/users/friend": { post: [] },
|
|
1214
|
+
"/bots/create": { post: [] },
|
|
1215
|
+
"/bots/{target}/invite": { get: [], post: [] },
|
|
1216
|
+
"/bots/{bot_id}": { get: [], delete: [], patch: [] },
|
|
1217
|
+
"/bots/@me": { get: [] },
|
|
1218
|
+
"/channels/{target}/ack/{message}": { put: [] },
|
|
1219
|
+
"/channels/{target}": { get: [], delete: ["leave_silently"], patch: [] },
|
|
1220
|
+
"/channels/{target}/members": { get: [] },
|
|
1221
|
+
"/channels/{target}/invites": { post: [] },
|
|
1222
|
+
"/channels/{target}/messages": { get: ["limit", "before", "after", "sort", "nearby", "include_users"], post: [] },
|
|
1223
|
+
"/channels/{target}/search": { post: [] },
|
|
1224
|
+
"/channels/{target}/messages/{msg}/pin": { post: [], delete: [] },
|
|
1225
|
+
"/channels/{target}/messages/{msg}": { get: [], delete: [], patch: [] },
|
|
1226
|
+
"/channels/{target}/messages/bulk": { delete: [] },
|
|
1227
|
+
"/channels/create": { post: [] },
|
|
1228
|
+
"/channels/{group_id}/recipients/{member_id}": { put: [], delete: [] },
|
|
1229
|
+
"/channels/{target}/join_call": { post: [] },
|
|
1230
|
+
"/channels/{target}/end_ring/{target_user}": { put: [] },
|
|
1231
|
+
"/channels/{target}/permissions/{role_id}": { put: [] },
|
|
1232
|
+
"/channels/{target}/permissions/default": { put: [] },
|
|
1233
|
+
"/channels/{target}/messages/{msg}/reactions/{emoji}": { put: [], delete: ["user_id", "remove_all"] },
|
|
1234
|
+
"/channels/{target}/messages/{msg}/reactions": { delete: [] },
|
|
1235
|
+
"/channels/{channel_id}/webhooks": { get: [], post: [] },
|
|
1236
|
+
"/servers/create": { post: [] },
|
|
1237
|
+
"/servers/{target}": { get: ["include_channels"], delete: ["leave_silently"], patch: [] },
|
|
1238
|
+
"/servers/{target}/ack": { put: [] },
|
|
1239
|
+
"/servers/{server}/channels": { post: [] },
|
|
1240
|
+
"/servers/{target}/members": { get: ["exclude_offline"] },
|
|
1241
|
+
"/servers/{server_id}/members/{member_id}": { get: ["roles"], delete: [], patch: [] },
|
|
1242
|
+
"/servers/{target}/members_experimental_query": { get: ["query", "experimental_api"] },
|
|
1243
|
+
"/servers/{server}/bans/{target}": { put: [], delete: [] },
|
|
1244
|
+
"/servers/{target}/bans": { get: [] },
|
|
1245
|
+
"/servers/{target}/invites": { get: [] },
|
|
1246
|
+
"/servers/{target}/roles": { post: [] },
|
|
1247
|
+
"/servers/{target}/roles/{role_id}": { get: [], delete: [], patch: [] },
|
|
1248
|
+
"/servers/{target}/permissions/{role_id}": { put: [] },
|
|
1249
|
+
"/servers/{target}/permissions/default": { put: [] },
|
|
1250
|
+
"/servers/{target}/emojis": { get: [] },
|
|
1251
|
+
"/servers/{target}/roles/ranks": { patch: [] },
|
|
1252
|
+
"/invites/{target}": { get: [], post: [], delete: [] },
|
|
1253
|
+
"/custom/emoji/{emoji_id}": { get: [], put: [], delete: [], patch: [] },
|
|
1254
|
+
"/safety/report": { post: [] },
|
|
1255
|
+
"/auth/account/create": { post: [] },
|
|
1256
|
+
"/auth/account/reverify": { post: [] },
|
|
1257
|
+
"/auth/account/delete": { put: [], post: [] },
|
|
1258
|
+
"/auth/account/": { get: [] },
|
|
1259
|
+
"/auth/account/disable": { post: [] },
|
|
1260
|
+
"/auth/account/change/password": { patch: [] },
|
|
1261
|
+
"/auth/account/change/email": { patch: [] },
|
|
1262
|
+
"/auth/account/verify/{code}": { post: [] },
|
|
1263
|
+
"/auth/account/reset_password": { post: [], patch: [] },
|
|
1264
|
+
"/auth/session/login": { post: [] },
|
|
1265
|
+
"/auth/session/logout": { post: [] },
|
|
1266
|
+
"/auth/session/all": { get: [], delete: ["revoke_self"] },
|
|
1267
|
+
"/auth/session/{id}": { delete: [], patch: [] },
|
|
1268
|
+
"/auth/mfa/ticket": { put: [] },
|
|
1269
|
+
"/auth/mfa/": { get: [] },
|
|
1270
|
+
"/auth/mfa/recovery": { post: [], patch: [] },
|
|
1271
|
+
"/auth/mfa/methods": { get: [] },
|
|
1272
|
+
"/auth/mfa/totp": { put: [], post: [], delete: [] },
|
|
1273
|
+
"/onboard/hello": { get: [] },
|
|
1274
|
+
"/onboard/complete": { post: [] },
|
|
1275
|
+
"/policy/acknowledge": { post: [] },
|
|
1276
|
+
"/push/subscribe": { post: [] },
|
|
1277
|
+
"/push/unsubscribe": { post: [] },
|
|
1278
|
+
"/sync/settings/fetch": { post: [] },
|
|
1279
|
+
"/sync/settings/set": { post: ["timestamp"] },
|
|
1280
|
+
"/sync/unreads": { get: [] },
|
|
1281
|
+
"/webhooks/{webhook_id}/{token}/{message_id}": { delete: [], patch: [] },
|
|
1282
|
+
"/webhooks/{webhook_id}/{token}": { get: [], post: [], delete: [], patch: [] },
|
|
1283
|
+
"/webhooks/{webhook_id}": { get: [], delete: [], patch: [] },
|
|
1284
|
+
"/webhooks/{webhook_id}/{token}/github": { post: [] }
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
// src/rest/RESTManager.ts
|
|
1117
1288
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1118
1289
|
var AsyncBucket = class {
|
|
1119
1290
|
remaining = 1;
|
|
@@ -1160,9 +1331,25 @@ var StoatAPIError = class _StoatAPIError extends Error {
|
|
|
1160
1331
|
Object.setPrototypeOf(this, _StoatAPIError.prototype);
|
|
1161
1332
|
}
|
|
1162
1333
|
};
|
|
1334
|
+
var ALL_QUERY_KEYS = /* @__PURE__ */ new Set();
|
|
1335
|
+
for (const routes of Object.values(queryParams)) {
|
|
1336
|
+
for (const keys of Object.values(routes)) {
|
|
1337
|
+
for (const key of keys) {
|
|
1338
|
+
ALL_QUERY_KEYS.add(key);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1163
1342
|
var RESTManager = class {
|
|
1164
1343
|
constructor(client) {
|
|
1165
1344
|
this.client = client;
|
|
1345
|
+
setInterval(() => {
|
|
1346
|
+
const now = Date.now();
|
|
1347
|
+
for (const [key, bucket] of this.buckets.entries()) {
|
|
1348
|
+
if (now > bucket.resetAt && bucket.remaining > 0) {
|
|
1349
|
+
this.buckets.delete(key);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}, 3e5).unref();
|
|
1166
1353
|
}
|
|
1167
1354
|
baseURL = "https://stoat.chat/api";
|
|
1168
1355
|
token = null;
|
|
@@ -1176,17 +1363,35 @@ var RESTManager = class {
|
|
|
1176
1363
|
getRouteKey(method, endpoint) {
|
|
1177
1364
|
return `${method}:${endpoint}`;
|
|
1178
1365
|
}
|
|
1179
|
-
makeRequest(method, endpoint,
|
|
1180
|
-
|
|
1181
|
-
let
|
|
1182
|
-
if (
|
|
1183
|
-
|
|
1184
|
-
|
|
1366
|
+
makeRequest(method, endpoint, params) {
|
|
1367
|
+
let finalEndpoint = endpoint;
|
|
1368
|
+
let finalBody = void 0;
|
|
1369
|
+
if (params && typeof params === "object") {
|
|
1370
|
+
const query = new URLSearchParams();
|
|
1371
|
+
finalBody = {};
|
|
1372
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1373
|
+
if (value !== void 0) {
|
|
1374
|
+
if (ALL_QUERY_KEYS.has(key)) {
|
|
1375
|
+
query.append(key, String(value));
|
|
1376
|
+
} else {
|
|
1377
|
+
finalBody[key] = value;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
const qs = query.toString();
|
|
1382
|
+
if (qs) finalEndpoint += `?${qs}`;
|
|
1383
|
+
if (Object.keys(finalBody).length === 0) finalBody = void 0;
|
|
1185
1384
|
}
|
|
1385
|
+
const routeKey = this.getRouteKey(method, finalEndpoint);
|
|
1186
1386
|
return new Promise((resolve, reject) => {
|
|
1387
|
+
let bucket = this.buckets.get(routeKey);
|
|
1388
|
+
if (!bucket) {
|
|
1389
|
+
bucket = new AsyncBucket();
|
|
1390
|
+
this.buckets.set(routeKey, bucket);
|
|
1391
|
+
}
|
|
1187
1392
|
bucket.queue = bucket.queue.then(async () => {
|
|
1188
1393
|
try {
|
|
1189
|
-
const result = await this.execute(method,
|
|
1394
|
+
const result = await this.execute(method, finalEndpoint, finalBody, bucket);
|
|
1190
1395
|
resolve(result);
|
|
1191
1396
|
} catch (error) {
|
|
1192
1397
|
reject(error);
|
|
@@ -1267,25 +1472,25 @@ var RESTManager = class {
|
|
|
1267
1472
|
const data = await response.json();
|
|
1268
1473
|
return data.id;
|
|
1269
1474
|
}
|
|
1270
|
-
get(endpoint) {
|
|
1271
|
-
return this.makeRequest("
|
|
1475
|
+
get(endpoint, params) {
|
|
1476
|
+
return this.makeRequest("get", endpoint, params);
|
|
1272
1477
|
}
|
|
1273
|
-
post(endpoint,
|
|
1274
|
-
return this.makeRequest("
|
|
1478
|
+
post(endpoint, params) {
|
|
1479
|
+
return this.makeRequest("post", endpoint, params);
|
|
1275
1480
|
}
|
|
1276
|
-
patch(endpoint,
|
|
1277
|
-
return this.makeRequest("
|
|
1481
|
+
patch(endpoint, params) {
|
|
1482
|
+
return this.makeRequest("patch", endpoint, params);
|
|
1278
1483
|
}
|
|
1279
|
-
delete(endpoint,
|
|
1280
|
-
return this.makeRequest("
|
|
1484
|
+
delete(endpoint, params) {
|
|
1485
|
+
return this.makeRequest("delete", endpoint, params);
|
|
1281
1486
|
}
|
|
1282
|
-
|
|
1283
|
-
return this.makeRequest("
|
|
1487
|
+
put(endpoint, params) {
|
|
1488
|
+
return this.makeRequest("put", endpoint, params);
|
|
1284
1489
|
}
|
|
1285
1490
|
};
|
|
1286
1491
|
|
|
1287
1492
|
// src/managers/MessageManager.ts
|
|
1288
|
-
var
|
|
1493
|
+
var util4 = __toESM(require("util"), 1);
|
|
1289
1494
|
|
|
1290
1495
|
// src/managers/BaseManager.ts
|
|
1291
1496
|
var BaseManager = class {
|
|
@@ -1358,7 +1563,7 @@ var MessageManager = class extends BaseManager {
|
|
|
1358
1563
|
* Tell BaseManager how to find the ID for Messages
|
|
1359
1564
|
*/
|
|
1360
1565
|
extractId(data) {
|
|
1361
|
-
return data._id
|
|
1566
|
+
return data._id;
|
|
1362
1567
|
}
|
|
1363
1568
|
/**
|
|
1364
1569
|
* Tell BaseManager how to build a Message
|
|
@@ -1383,20 +1588,31 @@ var MessageManager = class extends BaseManager {
|
|
|
1383
1588
|
* const history = await channel.messages.fetchMany({ limit: 20, before: "01H..." });
|
|
1384
1589
|
*/
|
|
1385
1590
|
async fetchMany(options = {}) {
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1388
|
-
if (options.
|
|
1389
|
-
if (options.
|
|
1390
|
-
if (options.
|
|
1391
|
-
if (options.
|
|
1392
|
-
if (options.
|
|
1393
|
-
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1591
|
+
const endpoint = `/channels/${this.channel.id}/messages`;
|
|
1592
|
+
const query = {};
|
|
1593
|
+
if (options.limit !== void 0) query.limit = options.limit;
|
|
1594
|
+
if (options.before !== void 0) query.before = options.before;
|
|
1595
|
+
if (options.after !== void 0) query.after = options.after;
|
|
1596
|
+
if (options.sort !== void 0) query.sort = options.sort;
|
|
1597
|
+
if (options.nearby !== void 0) query.nearby = options.nearby;
|
|
1598
|
+
if (options.includeUsers !== void 0) query.include_users = options.includeUsers;
|
|
1599
|
+
const data = await this.client.rest.get(endpoint, query);
|
|
1600
|
+
let rawMessages;
|
|
1601
|
+
if (Array.isArray(data)) {
|
|
1602
|
+
rawMessages = data;
|
|
1603
|
+
} else {
|
|
1604
|
+
rawMessages = data.messages;
|
|
1605
|
+
if (data.users) {
|
|
1606
|
+
for (const userData of data.users) {
|
|
1607
|
+
this.client.users._add(userData);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
if (data.members && this.channel.isText()) {
|
|
1611
|
+
const serverId = this.channel.serverId;
|
|
1612
|
+
const server = await this.client.servers.fetch(serverId);
|
|
1613
|
+
for (const memberData of data.members) {
|
|
1614
|
+
server.members._add(memberData);
|
|
1615
|
+
}
|
|
1400
1616
|
}
|
|
1401
1617
|
}
|
|
1402
1618
|
const fetched = new Collection();
|
|
@@ -1417,18 +1633,19 @@ var MessageManager = class extends BaseManager {
|
|
|
1417
1633
|
* @returns A promise that resolves to the sent Message.
|
|
1418
1634
|
*/
|
|
1419
1635
|
async send(contentOrOptions) {
|
|
1420
|
-
const
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
);
|
|
1636
|
+
const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
|
|
1637
|
+
const payload = {};
|
|
1638
|
+
if (opts.embeds && opts.embeds.length) {
|
|
1639
|
+
payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
|
|
1425
1640
|
}
|
|
1426
|
-
if (
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
(attachment) => resolveAttachment(this.client.rest, attachment, "attachments")
|
|
1430
|
-
)
|
|
1641
|
+
if (opts.attachments && opts.attachments.length > 0) {
|
|
1642
|
+
const resolved = await Promise.all(
|
|
1643
|
+
opts.attachments.map((attachment) => resolveAttachment(this.client.rest, attachment, "attachments"))
|
|
1431
1644
|
);
|
|
1645
|
+
const validAttachments = resolved.filter((id) => id !== void 0);
|
|
1646
|
+
if (validAttachments.length > 0) {
|
|
1647
|
+
payload.attachments = validAttachments;
|
|
1648
|
+
}
|
|
1432
1649
|
}
|
|
1433
1650
|
const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
|
|
1434
1651
|
return new Message(this.client, data);
|
|
@@ -1441,19 +1658,20 @@ var MessageManager = class extends BaseManager {
|
|
|
1441
1658
|
*/
|
|
1442
1659
|
async edit(message, contentOrOptions) {
|
|
1443
1660
|
const id = this.resolveId(message);
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
);
|
|
1661
|
+
const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
|
|
1662
|
+
const payload = {};
|
|
1663
|
+
if (opts.content !== void 0) {
|
|
1664
|
+
payload.content = opts.content;
|
|
1449
1665
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1666
|
+
if (opts.embeds !== void 0) {
|
|
1667
|
+
if (opts.embeds === null) {
|
|
1668
|
+
payload.embeds = [];
|
|
1669
|
+
} else {
|
|
1670
|
+
payload.embeds = opts.embeds.map((embed) => "toJSON" in embed ? embed.toJSON() : embed);
|
|
1671
|
+
}
|
|
1455
1672
|
}
|
|
1456
|
-
|
|
1673
|
+
const data = await this.client.rest.patch(`/channels/${this.channel.id}/messages/${id}`, payload);
|
|
1674
|
+
return this._add(data);
|
|
1457
1675
|
}
|
|
1458
1676
|
/**
|
|
1459
1677
|
* Deletes a message from the channel.
|
|
@@ -1470,7 +1688,7 @@ var MessageManager = class extends BaseManager {
|
|
|
1470
1688
|
*/
|
|
1471
1689
|
async pin(message) {
|
|
1472
1690
|
const id = this.resolveId(message);
|
|
1473
|
-
await this.client.rest.post(`/channels/${this.channel.id}/messages/${id}/pin
|
|
1691
|
+
await this.client.rest.post(`/channels/${this.channel.id}/messages/${id}/pin`);
|
|
1474
1692
|
const existing = this.cache.get(id);
|
|
1475
1693
|
if (existing) existing.pinned = true;
|
|
1476
1694
|
}
|
|
@@ -1516,12 +1734,14 @@ var MessageManager = class extends BaseManager {
|
|
|
1516
1734
|
async removeReaction(message, reaction, userId, removeAll) {
|
|
1517
1735
|
const id = this.resolveId(message);
|
|
1518
1736
|
const targetUser = userId ? this.client.users.resolveId(userId) : void 0;
|
|
1519
|
-
const
|
|
1520
|
-
|
|
1521
|
-
if (
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1737
|
+
const endpoint = `/channels/${this.channel.id}/messages/${id}/reactions/${reaction}`;
|
|
1738
|
+
const query = {};
|
|
1739
|
+
if (targetUser) {
|
|
1740
|
+
query.user_id = targetUser;
|
|
1741
|
+
} else if (removeAll) {
|
|
1742
|
+
query.remove_all = true;
|
|
1743
|
+
}
|
|
1744
|
+
await this.client.rest.delete(endpoint, query);
|
|
1525
1745
|
}
|
|
1526
1746
|
/**
|
|
1527
1747
|
* Remove all reactions from a message
|
|
@@ -1535,7 +1755,7 @@ var MessageManager = class extends BaseManager {
|
|
|
1535
1755
|
const id = this.resolveId(message);
|
|
1536
1756
|
await this.client.rest.delete(`/channels/${this.channel.id}/messages/${id}/reactions`);
|
|
1537
1757
|
}
|
|
1538
|
-
[
|
|
1758
|
+
[util4.inspect.custom]() {
|
|
1539
1759
|
return this.cache;
|
|
1540
1760
|
}
|
|
1541
1761
|
};
|
|
@@ -1572,6 +1792,8 @@ var MessageCollector = class extends Collector {
|
|
|
1572
1792
|
super.handleCollect(message);
|
|
1573
1793
|
if (!this.ended && this.collected.has(message.id)) {
|
|
1574
1794
|
this.total++;
|
|
1795
|
+
}
|
|
1796
|
+
if (!this.ended) {
|
|
1575
1797
|
this.checkEnd();
|
|
1576
1798
|
}
|
|
1577
1799
|
}
|
|
@@ -1584,12 +1806,6 @@ var MessageCollector = class extends Collector {
|
|
|
1584
1806
|
};
|
|
1585
1807
|
|
|
1586
1808
|
// src/structures/BaseChannel.ts
|
|
1587
|
-
var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
|
|
1588
|
-
ChannelType2["TEXT"] = "TextChannel";
|
|
1589
|
-
ChannelType2["DM"] = "DirectMessage";
|
|
1590
|
-
ChannelType2["GROUP"] = "Group";
|
|
1591
|
-
return ChannelType2;
|
|
1592
|
-
})(ChannelType || {});
|
|
1593
1809
|
var BaseChannel = class extends Base {
|
|
1594
1810
|
type;
|
|
1595
1811
|
messages;
|
|
@@ -1713,13 +1929,13 @@ var BaseChannel = class extends Base {
|
|
|
1713
1929
|
});
|
|
1714
1930
|
}
|
|
1715
1931
|
isText() {
|
|
1716
|
-
return this.type === "TextChannel"
|
|
1932
|
+
return this.type === "TextChannel";
|
|
1717
1933
|
}
|
|
1718
1934
|
isDM() {
|
|
1719
|
-
return this.type === "DirectMessage"
|
|
1935
|
+
return this.type === "DirectMessage";
|
|
1720
1936
|
}
|
|
1721
1937
|
isGroup() {
|
|
1722
|
-
return this.type === "Group"
|
|
1938
|
+
return this.type === "Group";
|
|
1723
1939
|
}
|
|
1724
1940
|
};
|
|
1725
1941
|
|
|
@@ -1739,7 +1955,9 @@ var TextChannel = class extends BaseChannel {
|
|
|
1739
1955
|
this.serverId = data.server;
|
|
1740
1956
|
this.defaultPermissions = data.default_permissions;
|
|
1741
1957
|
this.description = data.description;
|
|
1742
|
-
|
|
1958
|
+
if (data.icon !== void 0) {
|
|
1959
|
+
this.icon = data.icon ? new Attachment(this.client, data.icon) : null;
|
|
1960
|
+
}
|
|
1743
1961
|
this.lastMessageId = data.last_message_id;
|
|
1744
1962
|
this.nsfw = data.nsfw ?? false;
|
|
1745
1963
|
this.slowmode = data.slowmode ?? 0;
|
|
@@ -1809,6 +2027,9 @@ var TextChannel = class extends BaseChannel {
|
|
|
1809
2027
|
async setCategory(category) {
|
|
1810
2028
|
const serverId = this.serverId;
|
|
1811
2029
|
const server = await this.client.servers.fetch(serverId);
|
|
2030
|
+
if (!server.categories || server.categories.length === 0) {
|
|
2031
|
+
throw new Error("This server has no categories to move the channel into.");
|
|
2032
|
+
}
|
|
1812
2033
|
const categories = server.categories.map((c) => ({
|
|
1813
2034
|
id: c.id,
|
|
1814
2035
|
title: c.title,
|
|
@@ -1839,6 +2060,9 @@ var TextChannel = class extends BaseChannel {
|
|
|
1839
2060
|
async setPosition(position) {
|
|
1840
2061
|
const serverId = this.serverId;
|
|
1841
2062
|
const server = await this.client.servers.fetch(serverId);
|
|
2063
|
+
if (!server.categories || server.categories.length === 0) {
|
|
2064
|
+
throw new Error("This server has no categories to move the channel into.");
|
|
2065
|
+
}
|
|
1842
2066
|
const categories = server.categories.map((c) => ({
|
|
1843
2067
|
id: c.id,
|
|
1844
2068
|
title: c.title,
|
|
@@ -1950,7 +2174,7 @@ var DMChannel = class extends BaseChannel {
|
|
|
1950
2174
|
};
|
|
1951
2175
|
|
|
1952
2176
|
// src/structures/GroupChannel.ts
|
|
1953
|
-
var
|
|
2177
|
+
var util5 = __toESM(require("util"), 1);
|
|
1954
2178
|
var GroupChannel = class extends BaseChannel {
|
|
1955
2179
|
name;
|
|
1956
2180
|
ownerId;
|
|
@@ -2010,7 +2234,7 @@ var GroupChannel = class extends BaseChannel {
|
|
|
2010
2234
|
async setDefaultPermissions(permissions) {
|
|
2011
2235
|
return await this.client.channels.setDefaultPermissions(this.id, permissions);
|
|
2012
2236
|
}
|
|
2013
|
-
[
|
|
2237
|
+
[util5.inspect.custom](_depth, options, inspect12) {
|
|
2014
2238
|
const { client, ...props } = this;
|
|
2015
2239
|
return `${this.constructor.name} ${inspect12(
|
|
2016
2240
|
{
|
|
@@ -2026,14 +2250,14 @@ var GroupChannel = class extends BaseChannel {
|
|
|
2026
2250
|
// src/utils/ChannelFactory.ts
|
|
2027
2251
|
function createChannel(client, data) {
|
|
2028
2252
|
switch (data.channel_type) {
|
|
2029
|
-
case "TextChannel"
|
|
2253
|
+
case "TextChannel":
|
|
2030
2254
|
return new TextChannel(client, data);
|
|
2031
|
-
case "DirectMessage"
|
|
2255
|
+
case "DirectMessage":
|
|
2032
2256
|
return new DMChannel(client, data);
|
|
2033
|
-
case "Group"
|
|
2257
|
+
case "Group":
|
|
2034
2258
|
return new GroupChannel(client, data);
|
|
2035
2259
|
default:
|
|
2036
|
-
client.emit("debug", `Received unknown channel type: ${data.
|
|
2260
|
+
client.emit("debug", `Received unknown channel type: ${data.channel_type}`);
|
|
2037
2261
|
return new UnknownChannel(client, data);
|
|
2038
2262
|
}
|
|
2039
2263
|
}
|
|
@@ -2342,7 +2566,7 @@ var ChannelManager = class extends BaseManager {
|
|
|
2342
2566
|
super(client, limit);
|
|
2343
2567
|
}
|
|
2344
2568
|
extractId(data) {
|
|
2345
|
-
return data._id
|
|
2569
|
+
return data._id;
|
|
2346
2570
|
}
|
|
2347
2571
|
construct(data) {
|
|
2348
2572
|
return createChannel(this.client, data);
|
|
@@ -2435,8 +2659,14 @@ var ChannelManager = class extends BaseManager {
|
|
|
2435
2659
|
else payload.description = options.description;
|
|
2436
2660
|
}
|
|
2437
2661
|
if (options.icon !== void 0) {
|
|
2438
|
-
if (options.icon === null)
|
|
2439
|
-
|
|
2662
|
+
if (options.icon === null) {
|
|
2663
|
+
remove.push("Icon");
|
|
2664
|
+
} else {
|
|
2665
|
+
const resolvedIcon = await resolveAttachment(this.client.rest, options.icon, "icons");
|
|
2666
|
+
if (resolvedIcon !== void 0) {
|
|
2667
|
+
payload.icon = resolvedIcon;
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2440
2670
|
}
|
|
2441
2671
|
if (remove.length > 0) payload.remove = remove;
|
|
2442
2672
|
if (Object.keys(payload).length === 0) return this.fetch(channel);
|
|
@@ -2521,7 +2751,7 @@ var ChannelManager = class extends BaseManager {
|
|
|
2521
2751
|
* await client.channels.pin("CHANNEL_ID", "MESSAGE_ID");
|
|
2522
2752
|
*/
|
|
2523
2753
|
async pin(id, messageId) {
|
|
2524
|
-
await this.client.rest.post(`/channels/${id}/
|
|
2754
|
+
await this.client.rest.post(`/channels/${id}/messages/${messageId}/pin`);
|
|
2525
2755
|
}
|
|
2526
2756
|
/**
|
|
2527
2757
|
* Unpin a message
|
|
@@ -2551,12 +2781,12 @@ var ChannelManager = class extends BaseManager {
|
|
|
2551
2781
|
if ("id" in msg) return msg.id;
|
|
2552
2782
|
throw new TypeError("Invalid MessageResolvable provided. Expected a Message object or a string ID/Mention.");
|
|
2553
2783
|
});
|
|
2554
|
-
await this.client.rest.delete(`/channels/${id}/messages/bulk`, {
|
|
2784
|
+
await this.client.rest.delete(`/channels/${id}/messages/bulk`, { ids: messageIds });
|
|
2555
2785
|
}
|
|
2556
2786
|
};
|
|
2557
2787
|
|
|
2558
2788
|
// src/structures/Member.ts
|
|
2559
|
-
var
|
|
2789
|
+
var util6 = __toESM(require("util"), 1);
|
|
2560
2790
|
|
|
2561
2791
|
// src/managers/MemberRoleManager.ts
|
|
2562
2792
|
var MemberRoleManager = class {
|
|
@@ -2650,20 +2880,20 @@ var Member = class extends Base {
|
|
|
2650
2880
|
canRecieve = false;
|
|
2651
2881
|
// Member roles manager
|
|
2652
2882
|
roles;
|
|
2653
|
-
constructor(client, data) {
|
|
2654
|
-
super(client, { _id: data.user
|
|
2655
|
-
this.serverId = data.
|
|
2656
|
-
this.joinedAt = new Date(data.
|
|
2883
|
+
constructor(client, data, serverId) {
|
|
2884
|
+
super(client, { _id: data._id?.user });
|
|
2885
|
+
this.serverId = data._id?.server ?? serverId;
|
|
2886
|
+
this.joinedAt = new Date(data.joined_at);
|
|
2657
2887
|
this.roles = new MemberRoleManager(this);
|
|
2658
2888
|
this._patch(data);
|
|
2659
2889
|
}
|
|
2660
2890
|
_patch(data) {
|
|
2661
2891
|
if (data.nickname !== void 0) this.nickname = data.nickname;
|
|
2662
|
-
if (data.avatar !== void 0) this.avatar = data.avatar;
|
|
2892
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ? new Attachment(this.client, data.avatar) : null;
|
|
2663
2893
|
if (data.roles !== void 0) this._roles = data.roles;
|
|
2664
2894
|
if (data.timeout !== void 0) this.timeout = data.timeout ? new Date(data.timeout) : null;
|
|
2665
|
-
if (data.can_publish !== void 0) this.canPublish = data.
|
|
2666
|
-
if (data.
|
|
2895
|
+
if (data.can_publish !== void 0) this.canPublish = data.can_publish;
|
|
2896
|
+
if (data.can_receive !== void 0) this.canRecieve = data.can_receive;
|
|
2667
2897
|
}
|
|
2668
2898
|
/**
|
|
2669
2899
|
* Get member role IDs
|
|
@@ -2783,7 +3013,7 @@ var Member = class extends Base {
|
|
|
2783
3013
|
await server.members.kick(this.id);
|
|
2784
3014
|
}
|
|
2785
3015
|
/** @internal */
|
|
2786
|
-
[
|
|
3016
|
+
[util6.inspect.custom](depth, options, inspect12) {
|
|
2787
3017
|
const { client, serverId, ...props } = this;
|
|
2788
3018
|
return `${this.constructor.name} ${inspect12(
|
|
2789
3019
|
{
|
|
@@ -2797,7 +3027,7 @@ var Member = class extends Base {
|
|
|
2797
3027
|
};
|
|
2798
3028
|
|
|
2799
3029
|
// src/managers/MemberManager.ts
|
|
2800
|
-
var
|
|
3030
|
+
var util7 = __toESM(require("util"), 1);
|
|
2801
3031
|
var MemberManager = class extends BaseManager {
|
|
2802
3032
|
constructor(client, server, limit = Infinity) {
|
|
2803
3033
|
super(client, limit);
|
|
@@ -2808,17 +3038,14 @@ var MemberManager = class extends BaseManager {
|
|
|
2808
3038
|
* @internal
|
|
2809
3039
|
*/
|
|
2810
3040
|
extractId(data) {
|
|
2811
|
-
return data.
|
|
3041
|
+
return data._id?.user;
|
|
2812
3042
|
}
|
|
2813
3043
|
/**
|
|
2814
3044
|
* Tell BaseManager how to build a Member
|
|
2815
3045
|
* @internal
|
|
2816
3046
|
*/
|
|
2817
3047
|
construct(data) {
|
|
2818
|
-
|
|
2819
|
-
data.serverId = this.server.id;
|
|
2820
|
-
}
|
|
2821
|
-
return new Member(this.client, data);
|
|
3048
|
+
return new Member(this.client, data, this.server.id);
|
|
2822
3049
|
}
|
|
2823
3050
|
/**
|
|
2824
3051
|
* Resolve a string or mention to Member
|
|
@@ -2877,23 +3104,22 @@ var MemberManager = class extends BaseManager {
|
|
|
2877
3104
|
* const onlineMembers = await server.members.fetchMany({ exclude_offline: true });
|
|
2878
3105
|
*/
|
|
2879
3106
|
async fetchMany(options = {}) {
|
|
2880
|
-
const
|
|
2881
|
-
if (options.
|
|
2882
|
-
|
|
3107
|
+
const query = {};
|
|
3108
|
+
if (options.excludeOffline !== void 0) {
|
|
3109
|
+
query.exclude_offline = options.excludeOffline;
|
|
2883
3110
|
}
|
|
2884
|
-
const
|
|
2885
|
-
|
|
2886
|
-
const data = await this.client.rest.get(endpoint);
|
|
2887
|
-
if (data.users && Array.isArray(data.users)) {
|
|
3111
|
+
const data = await this.client.rest.get(`/servers/${this.server.id}/members`, query);
|
|
3112
|
+
if (data.users) {
|
|
2888
3113
|
for (const userData of data.users) {
|
|
2889
3114
|
this.client.users._add(userData);
|
|
2890
3115
|
}
|
|
2891
3116
|
}
|
|
2892
3117
|
const fetched = new Collection();
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
3118
|
+
if (data.members) {
|
|
3119
|
+
for (const rawMember of data.members) {
|
|
3120
|
+
const member = this._add(rawMember);
|
|
3121
|
+
fetched.set(member.id, member);
|
|
3122
|
+
}
|
|
2897
3123
|
}
|
|
2898
3124
|
return fetched;
|
|
2899
3125
|
}
|
|
@@ -2971,13 +3197,13 @@ var MemberManager = class extends BaseManager {
|
|
|
2971
3197
|
const id = this.resolveId(member);
|
|
2972
3198
|
await this.client.rest.delete(`/servers/${this.server.id}/bans/${id}`);
|
|
2973
3199
|
}
|
|
2974
|
-
[
|
|
3200
|
+
[util7.inspect.custom]() {
|
|
2975
3201
|
return this.cache;
|
|
2976
3202
|
}
|
|
2977
3203
|
};
|
|
2978
3204
|
|
|
2979
3205
|
// src/managers/ServerChannelManager.ts
|
|
2980
|
-
var
|
|
3206
|
+
var util8 = __toESM(require("util"), 1);
|
|
2981
3207
|
var ServerChannelManager = class {
|
|
2982
3208
|
client;
|
|
2983
3209
|
server;
|
|
@@ -2996,24 +3222,30 @@ var ServerChannelManager = class {
|
|
|
2996
3222
|
async create(options) {
|
|
2997
3223
|
if (!options.name) throw new Error("A channel name must be provided.");
|
|
2998
3224
|
const payload = {
|
|
2999
|
-
name: options.name
|
|
3000
|
-
type: options.type ?? "Text",
|
|
3001
|
-
description: options.description,
|
|
3002
|
-
nsfw: options.nsfw ?? false
|
|
3225
|
+
name: options.name
|
|
3003
3226
|
};
|
|
3227
|
+
if (options.nsfw !== void 0) {
|
|
3228
|
+
payload.nsfw = options.nsfw;
|
|
3229
|
+
}
|
|
3230
|
+
if (options.type !== void 0) {
|
|
3231
|
+
payload.type = options.type;
|
|
3232
|
+
}
|
|
3233
|
+
if (options.description !== void 0) {
|
|
3234
|
+
payload.description = options.description;
|
|
3235
|
+
}
|
|
3004
3236
|
if (options.type === "Voice" && options.voice?.max_users) {
|
|
3005
3237
|
payload.voice = { max_users: options.voice.max_users };
|
|
3006
3238
|
}
|
|
3007
3239
|
const data = await this.client.rest.post(`/servers/${this.server.id}/channels`, payload);
|
|
3008
3240
|
return this.client.channels._add(data);
|
|
3009
3241
|
}
|
|
3010
|
-
[
|
|
3242
|
+
[util8.inspect.custom]() {
|
|
3011
3243
|
return this.cache;
|
|
3012
3244
|
}
|
|
3013
3245
|
};
|
|
3014
3246
|
|
|
3015
3247
|
// src/structures/Role.ts
|
|
3016
|
-
var
|
|
3248
|
+
var util9 = __toESM(require("util"), 1);
|
|
3017
3249
|
var Role = class extends Base {
|
|
3018
3250
|
serverId;
|
|
3019
3251
|
name;
|
|
@@ -3033,14 +3265,14 @@ var Role = class extends Base {
|
|
|
3033
3265
|
*/
|
|
3034
3266
|
_patch(data) {
|
|
3035
3267
|
if (data.name !== void 0) this.name = data.name;
|
|
3036
|
-
if (data.
|
|
3268
|
+
if (data.colour !== void 0) this.color = data.colour;
|
|
3037
3269
|
if (data.hoist !== void 0) this.hoist = data.hoist;
|
|
3038
3270
|
if (data.rank !== void 0) this.rank = data.rank;
|
|
3039
|
-
if (data.icon !== void 0) this.icon = new Attachment(this.client, data.icon);
|
|
3271
|
+
if (data.icon !== void 0) this.icon = data.icon !== null ? new Attachment(this.client, data.icon) : null;
|
|
3040
3272
|
if (data.permissions !== void 0) {
|
|
3041
3273
|
try {
|
|
3042
3274
|
if (typeof data.permissions === "object" && data.permissions !== null) {
|
|
3043
|
-
const allowPerms = data.permissions.a ??
|
|
3275
|
+
const allowPerms = data.permissions.a ?? 0;
|
|
3044
3276
|
this._permissions = BigInt(allowPerms);
|
|
3045
3277
|
} else {
|
|
3046
3278
|
this._permissions = BigInt(data.permissions);
|
|
@@ -3223,14 +3455,14 @@ var Role = class extends Base {
|
|
|
3223
3455
|
* Hides the cyclic client reference and raw serverId for a cleaner output.
|
|
3224
3456
|
* @internal
|
|
3225
3457
|
*/
|
|
3226
|
-
[
|
|
3458
|
+
[util9.inspect.custom]() {
|
|
3227
3459
|
const { client, serverId, ...props } = this;
|
|
3228
|
-
return `${this.constructor.name} ${
|
|
3460
|
+
return `${this.constructor.name} ${util9.inspect(props)}`;
|
|
3229
3461
|
}
|
|
3230
3462
|
};
|
|
3231
3463
|
|
|
3232
3464
|
// src/managers/RoleManager.ts
|
|
3233
|
-
var
|
|
3465
|
+
var util10 = __toESM(require("util"), 1);
|
|
3234
3466
|
var RoleManager = class extends BaseManager {
|
|
3235
3467
|
/**
|
|
3236
3468
|
* Manages API methods and caching for server roles.
|
|
@@ -3243,7 +3475,7 @@ var RoleManager = class extends BaseManager {
|
|
|
3243
3475
|
* Tell BaseManager how to find the ID for Roles
|
|
3244
3476
|
*/
|
|
3245
3477
|
extractId(data) {
|
|
3246
|
-
return data._id
|
|
3478
|
+
return data._id;
|
|
3247
3479
|
}
|
|
3248
3480
|
/**
|
|
3249
3481
|
* Tell BaseManager how to build a Role
|
|
@@ -3259,7 +3491,7 @@ var RoleManager = class extends BaseManager {
|
|
|
3259
3491
|
* @returns The newly created or updated Role object.
|
|
3260
3492
|
*/
|
|
3261
3493
|
_add(data, idParam) {
|
|
3262
|
-
const id = idParam ?? data._id
|
|
3494
|
+
const id = idParam ?? data._id;
|
|
3263
3495
|
const existing = this.cache.get(id);
|
|
3264
3496
|
if (existing) {
|
|
3265
3497
|
existing._patch(data);
|
|
@@ -3269,7 +3501,7 @@ var RoleManager = class extends BaseManager {
|
|
|
3269
3501
|
this.cache.set(role.id, role);
|
|
3270
3502
|
return role;
|
|
3271
3503
|
}
|
|
3272
|
-
[
|
|
3504
|
+
[util10.inspect.custom]() {
|
|
3273
3505
|
return this.cache;
|
|
3274
3506
|
}
|
|
3275
3507
|
/**
|
|
@@ -3322,7 +3554,7 @@ var RoleManager = class extends BaseManager {
|
|
|
3322
3554
|
name: options.name
|
|
3323
3555
|
};
|
|
3324
3556
|
const data = await this.client.rest.post(`/servers/${this.server.id}/roles`, payload);
|
|
3325
|
-
return this._add(data);
|
|
3557
|
+
return this._add(data.role);
|
|
3326
3558
|
}
|
|
3327
3559
|
/**
|
|
3328
3560
|
* Fetches a Role from the API or resolves it from the local cache.
|
|
@@ -3387,7 +3619,10 @@ var RoleManager = class extends BaseManager {
|
|
|
3387
3619
|
if (options.icon === null) {
|
|
3388
3620
|
remove.push("Icon");
|
|
3389
3621
|
} else {
|
|
3390
|
-
|
|
3622
|
+
const resolvedIcon = await resolveAttachment(this.client.rest, options.icon, "icons");
|
|
3623
|
+
if (resolvedIcon !== void 0) {
|
|
3624
|
+
payload.icon = resolvedIcon;
|
|
3625
|
+
}
|
|
3391
3626
|
}
|
|
3392
3627
|
}
|
|
3393
3628
|
if (remove.length > 0) {
|
|
@@ -3396,7 +3631,8 @@ var RoleManager = class extends BaseManager {
|
|
|
3396
3631
|
if (Object.keys(payload).length === 0) {
|
|
3397
3632
|
return this.fetch(id);
|
|
3398
3633
|
}
|
|
3399
|
-
const
|
|
3634
|
+
const endpoint = `/servers/${this.server.id}/roles/${id}`;
|
|
3635
|
+
const data = await this.client.rest.patch(endpoint, payload);
|
|
3400
3636
|
return this._add(data, id);
|
|
3401
3637
|
}
|
|
3402
3638
|
/**
|
|
@@ -3472,7 +3708,7 @@ var RoleManager = class extends BaseManager {
|
|
|
3472
3708
|
const payload = {
|
|
3473
3709
|
ranks: mappedIds
|
|
3474
3710
|
};
|
|
3475
|
-
const data = await this.client.rest.
|
|
3711
|
+
const data = await this.client.rest.patch(`/servers/${this.server.id}/roles/ranks`, payload);
|
|
3476
3712
|
this.server._patch(data);
|
|
3477
3713
|
return this.server;
|
|
3478
3714
|
}
|
|
@@ -3484,7 +3720,7 @@ var ServerInvite = class {
|
|
|
3484
3720
|
creatorId;
|
|
3485
3721
|
channelId;
|
|
3486
3722
|
constructor(data) {
|
|
3487
|
-
this.code = data._id
|
|
3723
|
+
this.code = data._id;
|
|
3488
3724
|
this.creatorId = data.creator;
|
|
3489
3725
|
this.channelId = data.channel;
|
|
3490
3726
|
}
|
|
@@ -3501,7 +3737,7 @@ var ServerInviteManager = class extends BaseManager {
|
|
|
3501
3737
|
this.server = server;
|
|
3502
3738
|
}
|
|
3503
3739
|
extractId(data) {
|
|
3504
|
-
return data._id
|
|
3740
|
+
return data._id;
|
|
3505
3741
|
}
|
|
3506
3742
|
construct(data) {
|
|
3507
3743
|
return new ServerInvite(data);
|
|
@@ -3511,9 +3747,8 @@ var ServerInviteManager = class extends BaseManager {
|
|
|
3511
3747
|
*/
|
|
3512
3748
|
async fetch() {
|
|
3513
3749
|
const data = await this.client.rest.get(`/servers/${this.server.id}/invites`);
|
|
3514
|
-
const rawInvites = Array.isArray(data) ? data : [];
|
|
3515
3750
|
const fetched = new Collection();
|
|
3516
|
-
for (const raw of
|
|
3751
|
+
for (const raw of data) {
|
|
3517
3752
|
const invite = this._add(raw);
|
|
3518
3753
|
fetched.set(invite.code, invite);
|
|
3519
3754
|
}
|
|
@@ -3526,7 +3761,7 @@ var ServerBan = class {
|
|
|
3526
3761
|
userId;
|
|
3527
3762
|
reason;
|
|
3528
3763
|
constructor(data) {
|
|
3529
|
-
this.userId = data._id?.user
|
|
3764
|
+
this.userId = data._id?.user;
|
|
3530
3765
|
this.reason = data.reason ?? null;
|
|
3531
3766
|
}
|
|
3532
3767
|
_patch(data) {
|
|
@@ -3598,7 +3833,7 @@ var Emoji = class extends Base {
|
|
|
3598
3833
|
};
|
|
3599
3834
|
|
|
3600
3835
|
// src/managers/EmojiManager.ts
|
|
3601
|
-
var
|
|
3836
|
+
var util11 = __toESM(require("util"), 1);
|
|
3602
3837
|
var EmojiManager = class extends BaseManager {
|
|
3603
3838
|
constructor(client, server, limit = Infinity) {
|
|
3604
3839
|
super(client, limit);
|
|
@@ -3620,7 +3855,7 @@ var EmojiManager = class extends BaseManager {
|
|
|
3620
3855
|
const data = await this.client.rest.get(`/custom/emoji/${id}`);
|
|
3621
3856
|
return this._add(data);
|
|
3622
3857
|
}
|
|
3623
|
-
[
|
|
3858
|
+
[util11.inspect.custom]() {
|
|
3624
3859
|
return this.cache;
|
|
3625
3860
|
}
|
|
3626
3861
|
};
|
|
@@ -3633,7 +3868,7 @@ var Server = class extends Base {
|
|
|
3633
3868
|
ownerId;
|
|
3634
3869
|
analytics = false;
|
|
3635
3870
|
banner = null;
|
|
3636
|
-
categories =
|
|
3871
|
+
categories = null;
|
|
3637
3872
|
description = null;
|
|
3638
3873
|
discoverable = false;
|
|
3639
3874
|
flags = 0;
|
|
@@ -3686,13 +3921,6 @@ var Server = class extends Base {
|
|
|
3686
3921
|
this.roles._add({ id, ...roleData });
|
|
3687
3922
|
}
|
|
3688
3923
|
}
|
|
3689
|
-
if (data.emojis !== void 0) {
|
|
3690
|
-
if (Array.isArray(data.emojis)) {
|
|
3691
|
-
for (const emoji of data.emojis) {
|
|
3692
|
-
this.emojis._add(emoji);
|
|
3693
|
-
}
|
|
3694
|
-
}
|
|
3695
|
-
}
|
|
3696
3924
|
if (clear && Array.isArray(clear)) {
|
|
3697
3925
|
for (const field of clear) {
|
|
3698
3926
|
switch (field) {
|
|
@@ -3731,7 +3959,7 @@ var Server = class extends Base {
|
|
|
3731
3959
|
};
|
|
3732
3960
|
|
|
3733
3961
|
// src/managers/ServerManager.ts
|
|
3734
|
-
var
|
|
3962
|
+
var util12 = __toESM(require("util"), 1);
|
|
3735
3963
|
var ServerManager = class extends BaseManager {
|
|
3736
3964
|
constructor(client, limit = Infinity) {
|
|
3737
3965
|
super(client, limit);
|
|
@@ -3740,7 +3968,7 @@ var ServerManager = class extends BaseManager {
|
|
|
3740
3968
|
* Tell BaseManager how to find the ID for Servers
|
|
3741
3969
|
*/
|
|
3742
3970
|
extractId(data) {
|
|
3743
|
-
return data._id
|
|
3971
|
+
return data._id;
|
|
3744
3972
|
}
|
|
3745
3973
|
/**
|
|
3746
3974
|
* Tell BaseManager how to build a Server
|
|
@@ -3781,21 +4009,19 @@ var ServerManager = class extends BaseManager {
|
|
|
3781
4009
|
payload.system_messages = {};
|
|
3782
4010
|
const sm = options.systemMessages;
|
|
3783
4011
|
if (sm.userJoined !== void 0) {
|
|
3784
|
-
|
|
3785
|
-
else payload.system_messages.user_joined = sm.userJoined;
|
|
4012
|
+
payload.system_messages.user_joined = sm.userJoined;
|
|
3786
4013
|
}
|
|
3787
4014
|
if (sm.userLeft !== void 0) {
|
|
3788
|
-
|
|
3789
|
-
else payload.system_messages.user_left = sm.userLeft;
|
|
4015
|
+
payload.system_messages.user_left = sm.userLeft;
|
|
3790
4016
|
}
|
|
3791
4017
|
if (sm.userKicked !== void 0) {
|
|
3792
|
-
|
|
3793
|
-
else payload.system_messages.user_kicked = sm.userKicked;
|
|
4018
|
+
payload.system_messages.user_kicked = sm.userKicked;
|
|
3794
4019
|
}
|
|
3795
4020
|
if (sm.userBanned !== void 0) {
|
|
3796
|
-
|
|
3797
|
-
else payload.system_messages.user_banned = sm.userBanned;
|
|
4021
|
+
payload.system_messages.user_banned = sm.userBanned;
|
|
3798
4022
|
}
|
|
4023
|
+
} else if (options.systemMessages === null) {
|
|
4024
|
+
remove.push("SystemMessages");
|
|
3799
4025
|
}
|
|
3800
4026
|
if (options.categories !== void 0) payload.categories = options.categories;
|
|
3801
4027
|
if (options.analytics !== void 0) payload.analytics = options.analytics;
|
|
@@ -3804,7 +4030,7 @@ var ServerManager = class extends BaseManager {
|
|
|
3804
4030
|
const data = await this.client.rest.patch(`/servers/${serverId}`, payload);
|
|
3805
4031
|
return this._add(data);
|
|
3806
4032
|
}
|
|
3807
|
-
[
|
|
4033
|
+
[util12.inspect.custom]() {
|
|
3808
4034
|
return this.cache;
|
|
3809
4035
|
}
|
|
3810
4036
|
};
|
|
@@ -3818,7 +4044,7 @@ var UserManager = class extends BaseManager {
|
|
|
3818
4044
|
* Tell BaseManager how to find the ID for Users
|
|
3819
4045
|
*/
|
|
3820
4046
|
extractId(data) {
|
|
3821
|
-
return data._id
|
|
4047
|
+
return data._id;
|
|
3822
4048
|
}
|
|
3823
4049
|
/**
|
|
3824
4050
|
* Tell BaseManager how to build a User
|
|
@@ -3953,7 +4179,7 @@ var UserManager = class extends BaseManager {
|
|
|
3953
4179
|
if (Object.keys(payload).length === 0) {
|
|
3954
4180
|
return this.fetch("@me");
|
|
3955
4181
|
}
|
|
3956
|
-
const data = await this.client.rest.patch(`/users
|
|
4182
|
+
const data = await this.client.rest.patch(`/users/${this.client.user?.id}`, payload);
|
|
3957
4183
|
return this._add(data);
|
|
3958
4184
|
}
|
|
3959
4185
|
/**
|
|
@@ -4113,15 +4339,18 @@ var EmbedBuilder = class {
|
|
|
4113
4339
|
return { ...this.data };
|
|
4114
4340
|
}
|
|
4115
4341
|
};
|
|
4342
|
+
|
|
4343
|
+
// src/index.ts
|
|
4344
|
+
var API = __toESM(require("stoat-api"), 1);
|
|
4116
4345
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4117
4346
|
0 && (module.exports = {
|
|
4347
|
+
API,
|
|
4118
4348
|
Attachment,
|
|
4119
4349
|
AttachmentBuilder,
|
|
4120
4350
|
Base,
|
|
4121
4351
|
BaseChannel,
|
|
4122
4352
|
BitField,
|
|
4123
4353
|
ChannelManager,
|
|
4124
|
-
ChannelType,
|
|
4125
4354
|
Client,
|
|
4126
4355
|
ClientUser,
|
|
4127
4356
|
Collection,
|
|
@@ -4131,6 +4360,7 @@ var EmbedBuilder = class {
|
|
|
4131
4360
|
Emoji,
|
|
4132
4361
|
EmojiManager,
|
|
4133
4362
|
GatewayManager,
|
|
4363
|
+
GroupChannel,
|
|
4134
4364
|
Member,
|
|
4135
4365
|
MemberManager,
|
|
4136
4366
|
Message,
|
|
@@ -4151,8 +4381,6 @@ var EmbedBuilder = class {
|
|
|
4151
4381
|
TextChannel,
|
|
4152
4382
|
UnknownChannel,
|
|
4153
4383
|
User,
|
|
4154
|
-
UserManager
|
|
4155
|
-
UserPresence,
|
|
4156
|
-
UserRelationship
|
|
4384
|
+
UserManager
|
|
4157
4385
|
});
|
|
4158
4386
|
//# sourceMappingURL=index.cjs.map
|