@fluxerjs/core 1.2.3 → 1.3.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/README.md +10 -0
- package/dist/client.d.mts +8 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.js +3926 -0
- package/dist/client.mjs +3913 -0
- package/dist/errors.d.mts +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +37 -0
- package/dist/errors.mjs +9 -0
- package/dist/index.d.mts +8 -1922
- package/dist/index.d.ts +8 -1922
- package/dist/index.js +587 -125
- package/dist/index.mjs +509 -51
- package/dist/message.d.mts +8 -0
- package/dist/message.d.ts +8 -0
- package/dist/message.js +511 -0
- package/dist/message.mjs +484 -0
- package/dist/subpath-message-b43enjDT.d.mts +2055 -0
- package/dist/subpath-message-b43enjDT.d.ts +2055 -0
- package/package.json +22 -7
package/dist/index.js
CHANGED
|
@@ -18,21 +18,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
AttachmentBuilder: () =>
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AttachmentBuilder: () => import_builders4.AttachmentBuilder,
|
|
24
24
|
Base: () => Base,
|
|
25
|
+
BaseInteraction: () => BaseInteraction,
|
|
25
26
|
CDN_URL: () => CDN_URL,
|
|
26
27
|
CategoryChannel: () => CategoryChannel,
|
|
27
28
|
Channel: () => Channel,
|
|
28
29
|
ChannelManager: () => ChannelManager,
|
|
30
|
+
ChatInputCommandInteraction: () => ChatInputCommandInteraction,
|
|
29
31
|
Client: () => Client,
|
|
30
32
|
ClientUser: () => ClientUser,
|
|
31
33
|
DMChannel: () => DMChannel,
|
|
32
|
-
EmbedBuilder: () =>
|
|
33
|
-
ErrorCodes: () => ErrorCodes,
|
|
34
|
+
EmbedBuilder: () => import_builders4.EmbedBuilder,
|
|
35
|
+
ErrorCodes: () => import_util2.ErrorCodes,
|
|
34
36
|
Events: () => Events,
|
|
35
|
-
FluxerError: () => FluxerError,
|
|
37
|
+
FluxerError: () => import_util.FluxerError,
|
|
36
38
|
GatewayOpcodes: () => import_types22.GatewayOpcodes,
|
|
37
39
|
Guild: () => Guild,
|
|
38
40
|
GuildBan: () => GuildBan,
|
|
@@ -48,18 +50,18 @@ __export(index_exports, {
|
|
|
48
50
|
MessageAttachmentFlags: () => import_types22.MessageAttachmentFlags,
|
|
49
51
|
MessageCollector: () => MessageCollector,
|
|
50
52
|
MessageManager: () => MessageManager,
|
|
51
|
-
MessagePayload: () =>
|
|
53
|
+
MessagePayload: () => import_builders4.MessagePayload,
|
|
52
54
|
MessageReaction: () => MessageReaction,
|
|
53
|
-
PermissionFlags: () =>
|
|
54
|
-
PermissionsBitField: () =>
|
|
55
|
+
PermissionFlags: () => import_util12.PermissionFlags,
|
|
56
|
+
PermissionsBitField: () => import_util12.PermissionsBitField,
|
|
55
57
|
ReactionCollector: () => ReactionCollector,
|
|
56
58
|
Role: () => Role,
|
|
57
59
|
Routes: () => import_types22.Routes,
|
|
58
60
|
STATIC_CDN_URL: () => STATIC_CDN_URL,
|
|
59
61
|
TextChannel: () => TextChannel,
|
|
60
62
|
User: () => User,
|
|
61
|
-
UserFlagsBitField: () =>
|
|
62
|
-
UserFlagsBits: () =>
|
|
63
|
+
UserFlagsBitField: () => import_util12.UserFlagsBitField,
|
|
64
|
+
UserFlagsBits: () => import_util12.UserFlagsBits,
|
|
63
65
|
UsersManager: () => UsersManager,
|
|
64
66
|
VoiceChannel: () => VoiceChannel,
|
|
65
67
|
Webhook: () => Webhook,
|
|
@@ -69,12 +71,14 @@ __export(index_exports, {
|
|
|
69
71
|
cdnDisplayAvatarURL: () => cdnDisplayAvatarURL,
|
|
70
72
|
cdnMemberAvatarURL: () => cdnMemberAvatarURL,
|
|
71
73
|
cdnMemberBannerURL: () => cdnMemberBannerURL,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
createInteraction: () => createInteraction,
|
|
75
|
+
isChatInputCommandInteraction: () => isChatInputCommandInteraction,
|
|
76
|
+
parsePrefixCommand: () => import_util11.parsePrefixCommand,
|
|
77
|
+
parseUserMention: () => import_util11.parseUserMention,
|
|
78
|
+
resolvePermissionsToBitfield: () => import_util12.resolvePermissionsToBitfield,
|
|
79
|
+
resolveTenorToImageUrl: () => import_util11.resolveTenorToImageUrl
|
|
76
80
|
});
|
|
77
|
-
module.exports = __toCommonJS(
|
|
81
|
+
module.exports = __toCommonJS(src_exports);
|
|
78
82
|
|
|
79
83
|
// src/client/Client.ts
|
|
80
84
|
var import_events3 = require("events");
|
|
@@ -85,33 +89,14 @@ var import_types21 = require("@fluxerjs/types");
|
|
|
85
89
|
// src/client/ChannelManager.ts
|
|
86
90
|
var import_collection4 = require("@fluxerjs/collection");
|
|
87
91
|
var import_types6 = require("@fluxerjs/types");
|
|
88
|
-
var
|
|
92
|
+
var import_util5 = require("@fluxerjs/util");
|
|
89
93
|
var import_rest2 = require("@fluxerjs/rest");
|
|
90
94
|
|
|
91
95
|
// src/errors/FluxerError.ts
|
|
92
|
-
var
|
|
93
|
-
code;
|
|
94
|
-
constructor(message, options) {
|
|
95
|
-
super(message, options?.cause ? { cause: options.cause } : void 0);
|
|
96
|
-
this.name = "FluxerError";
|
|
97
|
-
this.code = options?.code;
|
|
98
|
-
Object.setPrototypeOf(this, _FluxerError.prototype);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
96
|
+
var import_util = require("@fluxerjs/util");
|
|
101
97
|
|
|
102
98
|
// src/errors/ErrorCodes.ts
|
|
103
|
-
var
|
|
104
|
-
ClientNotReady: "CLIENT_NOT_READY",
|
|
105
|
-
InvalidToken: "INVALID_TOKEN",
|
|
106
|
-
AlreadyLoggedIn: "ALREADY_LOGGED_IN",
|
|
107
|
-
ChannelNotFound: "CHANNEL_NOT_FOUND",
|
|
108
|
-
MessageNotFound: "MESSAGE_NOT_FOUND",
|
|
109
|
-
GuildNotFound: "GUILD_NOT_FOUND",
|
|
110
|
-
MemberNotFound: "MEMBER_NOT_FOUND",
|
|
111
|
-
RoleNotFound: "ROLE_NOT_FOUND",
|
|
112
|
-
EmojiNotInGuild: "EMOJI_NOT_IN_GUILD",
|
|
113
|
-
EmojiNotFound: "EMOJI_NOT_FOUND"
|
|
114
|
-
};
|
|
99
|
+
var import_util2 = require("@fluxerjs/util");
|
|
115
100
|
|
|
116
101
|
// src/util/messageUtils.ts
|
|
117
102
|
var import_builders = require("@fluxerjs/builders");
|
|
@@ -123,20 +108,37 @@ async function resolveMessageFiles(files) {
|
|
|
123
108
|
const filename = f.filename ?? f.name;
|
|
124
109
|
if ("url" in f && f.url) {
|
|
125
110
|
if (!URL.canParse(f.url)) {
|
|
126
|
-
throw new
|
|
111
|
+
throw new import_util.FluxerError(`Invalid file URL at index ${i}: ${f.url}`, {
|
|
112
|
+
code: import_util2.ErrorCodes.InvalidFileUrl
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
let res;
|
|
116
|
+
try {
|
|
117
|
+
res = await fetch(f.url, {
|
|
118
|
+
signal: AbortSignal.timeout(FILE_FETCH_TIMEOUT_MS)
|
|
119
|
+
});
|
|
120
|
+
} catch (err) {
|
|
121
|
+
throw new import_util.FluxerError(`Failed to fetch file from ${f.url}`, {
|
|
122
|
+
code: import_util2.ErrorCodes.FileFetchFailed,
|
|
123
|
+
cause: err instanceof Error ? err : void 0
|
|
124
|
+
});
|
|
127
125
|
}
|
|
128
|
-
const res = await fetch(f.url, {
|
|
129
|
-
signal: AbortSignal.timeout(FILE_FETCH_TIMEOUT_MS)
|
|
130
|
-
});
|
|
131
126
|
if (!res.ok) {
|
|
132
|
-
throw new
|
|
127
|
+
throw new import_util.FluxerError(
|
|
128
|
+
`Failed to fetch file from ${f.url}: ${res.status} ${res.statusText}`,
|
|
129
|
+
{
|
|
130
|
+
code: import_util2.ErrorCodes.FileFetchFailed
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
133
|
}
|
|
134
134
|
const data = await res.arrayBuffer();
|
|
135
135
|
result.push({ name: f.name, data, filename });
|
|
136
136
|
} else if ("data" in f && f.data != null) {
|
|
137
137
|
result.push({ name: f.name, data: f.data, filename });
|
|
138
138
|
} else {
|
|
139
|
-
throw new
|
|
139
|
+
throw new import_util.FluxerError(`File at index ${i} must have either "data" or "url"`, {
|
|
140
|
+
code: import_util2.ErrorCodes.InvalidAttachment
|
|
141
|
+
});
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
return result;
|
|
@@ -206,6 +208,7 @@ var Events = {
|
|
|
206
208
|
GuildMemberAdd: "guildMemberAdd",
|
|
207
209
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
208
210
|
GuildMemberRemove: "guildMemberRemove",
|
|
211
|
+
GuildMembersChunk: "guildMembersChunk",
|
|
209
212
|
GuildRoleCreate: "guildRoleCreate",
|
|
210
213
|
GuildRoleUpdate: "guildRoleUpdate",
|
|
211
214
|
GuildRoleDelete: "guildRoleDelete",
|
|
@@ -406,7 +409,15 @@ var Message = class _Message extends Base {
|
|
|
406
409
|
const opts = typeof options === "string" ? { content: options } : options;
|
|
407
410
|
const mergedReply = replyOptions ?? (opts.ping !== void 0 || opts.replyTo !== void 0) ? { ping: opts.ping, replyTo: opts.replyTo } : void 0;
|
|
408
411
|
const refMessage = mergedReply?.replyTo ?? this;
|
|
409
|
-
const ref = refMessage instanceof _Message ? {
|
|
412
|
+
const ref = refMessage instanceof _Message ? {
|
|
413
|
+
channel_id: refMessage.channelId,
|
|
414
|
+
message_id: refMessage.id,
|
|
415
|
+
guild_id: refMessage.guildId ?? void 0
|
|
416
|
+
} : {
|
|
417
|
+
channel_id: refMessage.channelId,
|
|
418
|
+
message_id: refMessage.messageId,
|
|
419
|
+
guild_id: void 0
|
|
420
|
+
};
|
|
410
421
|
const payload = await _Message._createMessageBody(opts, ref, mergedReply?.ping !== false);
|
|
411
422
|
return this._send(payload);
|
|
412
423
|
}
|
|
@@ -597,12 +608,12 @@ var MessageManager = class {
|
|
|
597
608
|
} catch (err) {
|
|
598
609
|
if (err instanceof import_rest.RateLimitError) throw err;
|
|
599
610
|
if (err instanceof import_rest.FluxerAPIError && err.statusCode === 404) {
|
|
600
|
-
throw new FluxerError(`Message ${messageId} not found in channel ${this.channelId}`, {
|
|
601
|
-
code: ErrorCodes.MessageNotFound,
|
|
611
|
+
throw new import_util.FluxerError(`Message ${messageId} not found in channel ${this.channelId}`, {
|
|
612
|
+
code: import_util2.ErrorCodes.MessageNotFound,
|
|
602
613
|
cause: err
|
|
603
614
|
});
|
|
604
615
|
}
|
|
605
|
-
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
616
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
606
617
|
}
|
|
607
618
|
}
|
|
608
619
|
};
|
|
@@ -661,11 +672,12 @@ var MessageCollector = class extends import_events2.EventEmitter {
|
|
|
661
672
|
|
|
662
673
|
// src/structures/Channel.ts
|
|
663
674
|
var import_types5 = require("@fluxerjs/types");
|
|
664
|
-
var
|
|
665
|
-
var
|
|
675
|
+
var import_util3 = require("@fluxerjs/util");
|
|
676
|
+
var import_util4 = require("@fluxerjs/util");
|
|
666
677
|
|
|
667
678
|
// src/structures/Webhook.ts
|
|
668
679
|
var import_types3 = require("@fluxerjs/types");
|
|
680
|
+
var import_builders3 = require("@fluxerjs/builders");
|
|
669
681
|
|
|
670
682
|
// src/util/Constants.ts
|
|
671
683
|
var CDN_URL = "https://fluxerusercontent.com";
|
|
@@ -792,8 +804,9 @@ var Webhook = class _Webhook extends Base {
|
|
|
792
804
|
*/
|
|
793
805
|
async send(options, wait) {
|
|
794
806
|
if (!this.token) {
|
|
795
|
-
throw new
|
|
796
|
-
"Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send."
|
|
807
|
+
throw new import_util.FluxerError(
|
|
808
|
+
"Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send.",
|
|
809
|
+
{ code: import_util2.ErrorCodes.WebhookTokenRequired }
|
|
797
810
|
);
|
|
798
811
|
}
|
|
799
812
|
const opts = typeof options === "string" ? { content: options } : options;
|
|
@@ -810,6 +823,59 @@ var Webhook = class _Webhook extends Base {
|
|
|
810
823
|
}
|
|
811
824
|
return void 0;
|
|
812
825
|
}
|
|
826
|
+
/**
|
|
827
|
+
* Edit a message previously sent by this webhook.
|
|
828
|
+
* Requires the webhook token.
|
|
829
|
+
*/
|
|
830
|
+
async editMessage(messageId, options) {
|
|
831
|
+
if (!this.token) {
|
|
832
|
+
throw new import_util.FluxerError(
|
|
833
|
+
"Webhook token is required to edit messages. The token is only returned when creating a webhook; fetched webhooks cannot edit messages.",
|
|
834
|
+
{ code: import_util2.ErrorCodes.WebhookTokenRequired }
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
const body = { ...options };
|
|
838
|
+
if (options.embeds !== void 0) {
|
|
839
|
+
body.embeds = options.embeds.map((e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e);
|
|
840
|
+
}
|
|
841
|
+
const data = await this.client.rest.patch(
|
|
842
|
+
import_types3.Routes.webhookMessage(this.id, this.token, messageId),
|
|
843
|
+
{ body, auth: false }
|
|
844
|
+
);
|
|
845
|
+
return new Message(this.client, data);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Fetch a message sent by this webhook.
|
|
849
|
+
* Requires the webhook token.
|
|
850
|
+
*/
|
|
851
|
+
async fetchMessage(messageId) {
|
|
852
|
+
if (!this.token) {
|
|
853
|
+
throw new import_util.FluxerError(
|
|
854
|
+
"Webhook token is required to fetch messages. The token is only returned when creating a webhook; fetched webhooks cannot fetch messages.",
|
|
855
|
+
{ code: import_util2.ErrorCodes.WebhookTokenRequired }
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
const data = await this.client.rest.get(
|
|
859
|
+
import_types3.Routes.webhookMessage(this.id, this.token, messageId),
|
|
860
|
+
{ auth: false }
|
|
861
|
+
);
|
|
862
|
+
return new Message(this.client, data);
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Delete a message sent by this webhook.
|
|
866
|
+
* Requires the webhook token.
|
|
867
|
+
*/
|
|
868
|
+
async deleteMessage(messageId) {
|
|
869
|
+
if (!this.token) {
|
|
870
|
+
throw new import_util.FluxerError(
|
|
871
|
+
"Webhook token is required to delete messages. The token is only returned when creating a webhook; fetched webhooks cannot delete messages.",
|
|
872
|
+
{ code: import_util2.ErrorCodes.WebhookTokenRequired }
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
await this.client.rest.delete(import_types3.Routes.webhookMessage(this.id, this.token, messageId), {
|
|
876
|
+
auth: false
|
|
877
|
+
});
|
|
878
|
+
}
|
|
813
879
|
/**
|
|
814
880
|
* Fetch a webhook by ID using bot auth.
|
|
815
881
|
* @param client - The client instance
|
|
@@ -842,7 +908,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
842
908
|
|
|
843
909
|
// src/structures/Invite.ts
|
|
844
910
|
var import_types4 = require("@fluxerjs/types");
|
|
845
|
-
var Invite = class extends Base {
|
|
911
|
+
var Invite = class _Invite extends Base {
|
|
846
912
|
client;
|
|
847
913
|
code;
|
|
848
914
|
type;
|
|
@@ -857,6 +923,41 @@ var Invite = class extends Base {
|
|
|
857
923
|
uses;
|
|
858
924
|
maxUses;
|
|
859
925
|
maxAge;
|
|
926
|
+
/**
|
|
927
|
+
* Normalize invite input to a raw code (plain code or URL such as https://fluxer.gg/{code}).
|
|
928
|
+
*/
|
|
929
|
+
static normalizeCode(codeOrUrl) {
|
|
930
|
+
const input = codeOrUrl.trim();
|
|
931
|
+
if (!input) {
|
|
932
|
+
throw new import_util.FluxerError("Invite code cannot be empty", { code: import_util2.ErrorCodes.InvalidInvite });
|
|
933
|
+
}
|
|
934
|
+
const parseInviteCodeFromUrl = (value) => {
|
|
935
|
+
if (!URL.canParse(value)) return null;
|
|
936
|
+
let url;
|
|
937
|
+
try {
|
|
938
|
+
url = new URL(value);
|
|
939
|
+
} catch {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
943
|
+
if (segments.length === 0) return null;
|
|
944
|
+
const inviteSegmentIdx = segments.findIndex((segment) => {
|
|
945
|
+
const lower = segment.toLowerCase();
|
|
946
|
+
return lower === "invite" || lower === "invites";
|
|
947
|
+
});
|
|
948
|
+
const code2 = inviteSegmentIdx >= 0 && segments[inviteSegmentIdx + 1] ? segments[inviteSegmentIdx + 1] : segments[segments.length - 1];
|
|
949
|
+
return decodeURIComponent(code2).trim();
|
|
950
|
+
};
|
|
951
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(input);
|
|
952
|
+
const fromAbsolute = hasScheme ? parseInviteCodeFromUrl(input) : null;
|
|
953
|
+
const fromHostLike = !hasScheme && URL.canParse(`https://${input}`) ? parseInviteCodeFromUrl(`https://${input}`) : null;
|
|
954
|
+
const directCode = decodeURIComponent(input).trim();
|
|
955
|
+
const code = fromAbsolute ?? fromHostLike ?? directCode;
|
|
956
|
+
if (!code || /[\s/?#]/.test(code)) {
|
|
957
|
+
throw new import_util.FluxerError("Invalid invite code or URL", { code: import_util2.ErrorCodes.InvalidInvite });
|
|
958
|
+
}
|
|
959
|
+
return code;
|
|
960
|
+
}
|
|
860
961
|
/** @param data - API invite from GET /invites/{code}, channel/guild invite list, or gateway INVITE_CREATE */
|
|
861
962
|
constructor(client, data) {
|
|
862
963
|
super();
|
|
@@ -875,6 +976,14 @@ var Invite = class extends Base {
|
|
|
875
976
|
this.maxUses = data.max_uses ?? null;
|
|
876
977
|
this.maxAge = data.max_age ?? null;
|
|
877
978
|
}
|
|
979
|
+
/**
|
|
980
|
+
* Fetch invite metadata by code or URL (does not join the guild).
|
|
981
|
+
*/
|
|
982
|
+
static async fetch(client, codeOrUrl) {
|
|
983
|
+
const code = _Invite.normalizeCode(codeOrUrl);
|
|
984
|
+
const data = await client.rest.get(import_types4.Routes.invite(code));
|
|
985
|
+
return new _Invite(client, data);
|
|
986
|
+
}
|
|
878
987
|
/** Full invite URL (https://fluxer.gg/{code} or instance-specific). */
|
|
879
988
|
get url() {
|
|
880
989
|
return `https://fluxer.gg/${this.code}`;
|
|
@@ -1078,7 +1187,7 @@ var GuildChannel = class extends Channel {
|
|
|
1078
1187
|
const me = guild.members.me;
|
|
1079
1188
|
if (!me) return false;
|
|
1080
1189
|
const perms = me.permissionsIn(this);
|
|
1081
|
-
return perms.has(
|
|
1190
|
+
return perms.has(import_util3.PermissionFlags.ViewChannel) && perms.has(import_util3.PermissionFlags.SendMessages);
|
|
1082
1191
|
}
|
|
1083
1192
|
/**
|
|
1084
1193
|
* Send a message to this guild channel.
|
|
@@ -1194,7 +1303,7 @@ var TextChannel = class extends GuildChannel {
|
|
|
1194
1303
|
* @deprecated Use channel.messages.fetch(messageId) instead.
|
|
1195
1304
|
*/
|
|
1196
1305
|
async fetchMessage(messageId) {
|
|
1197
|
-
(0,
|
|
1306
|
+
(0, import_util4.emitDeprecationWarning)(
|
|
1198
1307
|
"Channel.fetchMessage()",
|
|
1199
1308
|
"Use channel.messages.fetch(messageId) instead."
|
|
1200
1309
|
);
|
|
@@ -1281,7 +1390,7 @@ var DMChannel = class extends Channel {
|
|
|
1281
1390
|
* @deprecated Use channel.messages.fetch(messageId) instead.
|
|
1282
1391
|
*/
|
|
1283
1392
|
async fetchMessage(messageId) {
|
|
1284
|
-
(0,
|
|
1393
|
+
(0, import_util4.emitDeprecationWarning)(
|
|
1285
1394
|
"Channel.fetchMessage()",
|
|
1286
1395
|
"Use channel.messages.fetch(messageId) instead."
|
|
1287
1396
|
);
|
|
@@ -1353,8 +1462,8 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
1353
1462
|
const data = await this.client.rest.get(import_types6.Routes.channel(channelId));
|
|
1354
1463
|
const channel = Channel.fromOrCreate(this.client, data);
|
|
1355
1464
|
if (!channel) {
|
|
1356
|
-
throw new FluxerError("Channel data invalid or unsupported type", {
|
|
1357
|
-
code: ErrorCodes.ChannelNotFound
|
|
1465
|
+
throw new import_util.FluxerError("Channel data invalid or unsupported type", {
|
|
1466
|
+
code: import_util2.ErrorCodes.ChannelNotFound
|
|
1358
1467
|
});
|
|
1359
1468
|
}
|
|
1360
1469
|
this.set(channel.id, channel);
|
|
@@ -1366,12 +1475,12 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
1366
1475
|
} catch (err) {
|
|
1367
1476
|
if (err instanceof import_rest2.RateLimitError) throw err;
|
|
1368
1477
|
if (err instanceof import_rest2.FluxerAPIError && err.statusCode === 404) {
|
|
1369
|
-
throw new FluxerError(`Channel ${channelId} not found`, {
|
|
1370
|
-
code: ErrorCodes.ChannelNotFound,
|
|
1478
|
+
throw new import_util.FluxerError(`Channel ${channelId} not found`, {
|
|
1479
|
+
code: import_util2.ErrorCodes.ChannelNotFound,
|
|
1371
1480
|
cause: err
|
|
1372
1481
|
});
|
|
1373
1482
|
}
|
|
1374
|
-
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
1483
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
1375
1484
|
}
|
|
1376
1485
|
}
|
|
1377
1486
|
/**
|
|
@@ -1386,7 +1495,7 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
1386
1495
|
* const message = await channel?.messages?.fetch(messageId);
|
|
1387
1496
|
*/
|
|
1388
1497
|
async fetchMessage(channelId, messageId) {
|
|
1389
|
-
(0,
|
|
1498
|
+
(0, import_util5.emitDeprecationWarning)(
|
|
1390
1499
|
"ChannelManager.fetchMessage()",
|
|
1391
1500
|
"Use channel.messages.fetch(messageId). Prefer (await client.channels.resolve(channelId))?.messages?.fetch(messageId)."
|
|
1392
1501
|
);
|
|
@@ -1398,12 +1507,12 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
1398
1507
|
} catch (err) {
|
|
1399
1508
|
if (err instanceof import_rest2.RateLimitError) throw err;
|
|
1400
1509
|
if (err instanceof import_rest2.FluxerAPIError && err.statusCode === 404) {
|
|
1401
|
-
throw new FluxerError(`Message ${messageId} not found in channel ${channelId}`, {
|
|
1402
|
-
code: ErrorCodes.MessageNotFound,
|
|
1510
|
+
throw new import_util.FluxerError(`Message ${messageId} not found in channel ${channelId}`, {
|
|
1511
|
+
code: import_util2.ErrorCodes.MessageNotFound,
|
|
1403
1512
|
cause: err
|
|
1404
1513
|
});
|
|
1405
1514
|
}
|
|
1406
|
-
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
1515
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
1407
1516
|
}
|
|
1408
1517
|
}
|
|
1409
1518
|
/**
|
|
@@ -1433,7 +1542,7 @@ var import_collection8 = require("@fluxerjs/collection");
|
|
|
1433
1542
|
var import_types16 = require("@fluxerjs/types");
|
|
1434
1543
|
|
|
1435
1544
|
// src/structures/Guild.ts
|
|
1436
|
-
var
|
|
1545
|
+
var import_util9 = require("@fluxerjs/util");
|
|
1437
1546
|
var import_rest3 = require("@fluxerjs/rest");
|
|
1438
1547
|
var import_collection7 = require("@fluxerjs/collection");
|
|
1439
1548
|
|
|
@@ -1442,14 +1551,14 @@ var import_collection6 = require("@fluxerjs/collection");
|
|
|
1442
1551
|
var import_types10 = require("@fluxerjs/types");
|
|
1443
1552
|
|
|
1444
1553
|
// src/structures/GuildMember.ts
|
|
1445
|
-
var
|
|
1554
|
+
var import_util7 = require("@fluxerjs/util");
|
|
1446
1555
|
var import_types9 = require("@fluxerjs/types");
|
|
1447
1556
|
|
|
1448
1557
|
// src/util/permissions.ts
|
|
1449
1558
|
var import_types7 = require("@fluxerjs/types");
|
|
1450
|
-
var
|
|
1559
|
+
var import_util6 = require("@fluxerjs/util");
|
|
1451
1560
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
1452
|
-
if (isOwner) return
|
|
1561
|
+
if (isOwner) return import_util6.ALL_PERMISSIONS_BIGINT;
|
|
1453
1562
|
let perms = basePermissions;
|
|
1454
1563
|
for (const overwrite of overwrites ?? []) {
|
|
1455
1564
|
const applies = overwrite.type === import_types7.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types7.OverwriteType.Member && overwrite.id === memberId;
|
|
@@ -1458,7 +1567,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
1458
1567
|
const deny = BigInt(overwrite.deny || "0");
|
|
1459
1568
|
perms = perms & ~deny | allow;
|
|
1460
1569
|
}
|
|
1461
|
-
return (perms &
|
|
1570
|
+
return (perms & import_util6.PermissionFlags.Administrator) !== 0n ? import_util6.ALL_PERMISSIONS_BIGINT : perms;
|
|
1462
1571
|
}
|
|
1463
1572
|
|
|
1464
1573
|
// src/structures/GuildMemberRoleManager.ts
|
|
@@ -1660,7 +1769,7 @@ var GuildMember = class extends Base {
|
|
|
1660
1769
|
const ownerId = this.guild.ownerId;
|
|
1661
1770
|
const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
|
|
1662
1771
|
const perms = computePermissions(base, [], [], this.id, isOwner);
|
|
1663
|
-
return new
|
|
1772
|
+
return new import_util7.BitField(perms);
|
|
1664
1773
|
}
|
|
1665
1774
|
/**
|
|
1666
1775
|
* Compute the member's effective permissions in a guild channel.
|
|
@@ -1682,7 +1791,26 @@ var GuildMember = class extends Base {
|
|
|
1682
1791
|
this.id,
|
|
1683
1792
|
isOwner
|
|
1684
1793
|
);
|
|
1685
|
-
return new
|
|
1794
|
+
return new import_util7.BitField(perms);
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Move this member to a different voice channel or disconnect them from voice.
|
|
1798
|
+
* Requires Move Members permission.
|
|
1799
|
+
* @param channelId - The voice channel ID to move the member to, or null to disconnect
|
|
1800
|
+
* @param connectionId - Optional connection ID for the specific voice session (usually not needed)
|
|
1801
|
+
* @returns Promise that resolves when the member has been moved
|
|
1802
|
+
* @example
|
|
1803
|
+
* // Move member to a different voice channel
|
|
1804
|
+
* await member.move('123456789012345678');
|
|
1805
|
+
*
|
|
1806
|
+
* // Disconnect member from voice
|
|
1807
|
+
* await member.move(null);
|
|
1808
|
+
*/
|
|
1809
|
+
async move(channelId, connectionId) {
|
|
1810
|
+
await this.edit({
|
|
1811
|
+
channel_id: channelId,
|
|
1812
|
+
connection_id: connectionId
|
|
1813
|
+
});
|
|
1686
1814
|
}
|
|
1687
1815
|
_computeBasePermissions() {
|
|
1688
1816
|
let base = 0n;
|
|
@@ -1734,7 +1862,7 @@ var GuildMemberManager = class extends import_collection6.Collection {
|
|
|
1734
1862
|
* Fetch the current bot user as a GuildMember in this guild.
|
|
1735
1863
|
* Caches the result in guild.members.
|
|
1736
1864
|
*
|
|
1737
|
-
* @throws
|
|
1865
|
+
* @throws FluxerError with CLIENT_NOT_READY if client.user is null
|
|
1738
1866
|
* @example
|
|
1739
1867
|
* const me = await guild.members.fetchMe();
|
|
1740
1868
|
* console.log(me.displayName);
|
|
@@ -1742,7 +1870,9 @@ var GuildMemberManager = class extends import_collection6.Collection {
|
|
|
1742
1870
|
async fetchMe() {
|
|
1743
1871
|
const userId = this.guild.client.user?.id;
|
|
1744
1872
|
if (!userId) {
|
|
1745
|
-
throw new
|
|
1873
|
+
throw new import_util.FluxerError("Cannot fetch me: client.user is null (client not ready)", {
|
|
1874
|
+
code: import_util2.ErrorCodes.ClientNotReady
|
|
1875
|
+
});
|
|
1746
1876
|
}
|
|
1747
1877
|
return this.guild.fetchMember(userId);
|
|
1748
1878
|
}
|
|
@@ -1775,7 +1905,7 @@ var GuildMemberManager = class extends import_collection6.Collection {
|
|
|
1775
1905
|
|
|
1776
1906
|
// src/structures/Role.ts
|
|
1777
1907
|
var import_types11 = require("@fluxerjs/types");
|
|
1778
|
-
var
|
|
1908
|
+
var import_util8 = require("@fluxerjs/util");
|
|
1779
1909
|
var Role = class extends Base {
|
|
1780
1910
|
client;
|
|
1781
1911
|
id;
|
|
@@ -1808,8 +1938,8 @@ var Role = class extends Base {
|
|
|
1808
1938
|
}
|
|
1809
1939
|
get permissions() {
|
|
1810
1940
|
const bits = BigInt(this._permissions);
|
|
1811
|
-
return new
|
|
1812
|
-
(bits &
|
|
1941
|
+
return new import_util8.PermissionsBitField(
|
|
1942
|
+
(bits & import_util8.PermissionFlags.Administrator) !== 0n ? import_util8.ALL_PERMISSIONS_BIGINT : bits
|
|
1813
1943
|
);
|
|
1814
1944
|
}
|
|
1815
1945
|
/** Update mutable fields from fresh API data. Used by edit and gateway events. */
|
|
@@ -1839,7 +1969,7 @@ var Role = class extends Base {
|
|
|
1839
1969
|
const body = {};
|
|
1840
1970
|
if (options.name !== void 0) body.name = options.name;
|
|
1841
1971
|
if (options.permissions !== void 0) {
|
|
1842
|
-
body.permissions = typeof options.permissions === "string" ? options.permissions : (0,
|
|
1972
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util8.resolvePermissionsToBitfield)(options.permissions);
|
|
1843
1973
|
}
|
|
1844
1974
|
if (options.color !== void 0) body.color = options.color;
|
|
1845
1975
|
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
@@ -2032,6 +2162,7 @@ var Guild = class extends Base {
|
|
|
2032
2162
|
channels = new import_collection7.Collection();
|
|
2033
2163
|
roles = new import_collection7.Collection();
|
|
2034
2164
|
emojis = new import_collection7.Collection();
|
|
2165
|
+
stickers = new import_collection7.Collection();
|
|
2035
2166
|
/** @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE */
|
|
2036
2167
|
constructor(client, data) {
|
|
2037
2168
|
super();
|
|
@@ -2110,7 +2241,7 @@ var Guild = class extends Base {
|
|
|
2110
2241
|
const body = {};
|
|
2111
2242
|
if (options.name !== void 0) body.name = options.name;
|
|
2112
2243
|
if (options.permissions !== void 0) {
|
|
2113
|
-
body.permissions = typeof options.permissions === "string" ? options.permissions : (0,
|
|
2244
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util9.resolvePermissionsToBitfield)(options.permissions);
|
|
2114
2245
|
}
|
|
2115
2246
|
if (options.color !== void 0) body.color = options.color;
|
|
2116
2247
|
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
@@ -2158,12 +2289,12 @@ var Guild = class extends Base {
|
|
|
2158
2289
|
} catch (err) {
|
|
2159
2290
|
const statusCode = err instanceof import_rest3.FluxerAPIError ? err.statusCode : err?.statusCode;
|
|
2160
2291
|
if (statusCode === 404) {
|
|
2161
|
-
throw new FluxerError(`Role ${roleId} not found in guild`, {
|
|
2162
|
-
code: ErrorCodes.RoleNotFound,
|
|
2292
|
+
throw new import_util.FluxerError(`Role ${roleId} not found in guild`, {
|
|
2293
|
+
code: import_util2.ErrorCodes.RoleNotFound,
|
|
2163
2294
|
cause: err
|
|
2164
2295
|
});
|
|
2165
2296
|
}
|
|
2166
|
-
throw err instanceof FluxerError ? err : new FluxerError("Failed to fetch guild role", { cause: err });
|
|
2297
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError("Failed to fetch guild role", { cause: err });
|
|
2167
2298
|
}
|
|
2168
2299
|
}
|
|
2169
2300
|
/**
|
|
@@ -2173,7 +2304,7 @@ var Guild = class extends Base {
|
|
|
2173
2304
|
* @returns The role ID, or null if not found
|
|
2174
2305
|
*/
|
|
2175
2306
|
async resolveRoleId(arg) {
|
|
2176
|
-
const parsed = (0,
|
|
2307
|
+
const parsed = (0, import_util9.parseRoleMention)(arg);
|
|
2177
2308
|
if (parsed) return parsed;
|
|
2178
2309
|
if (/^\d{17,19}$/.test(arg.trim())) return arg.trim();
|
|
2179
2310
|
const cached = this.roles.find(
|
|
@@ -2253,12 +2384,12 @@ var Guild = class extends Base {
|
|
|
2253
2384
|
} catch (err) {
|
|
2254
2385
|
const statusCode = err instanceof import_rest3.FluxerAPIError ? err.statusCode : err?.statusCode;
|
|
2255
2386
|
if (statusCode === 404) {
|
|
2256
|
-
throw new FluxerError(`Member ${userId} not found in guild`, {
|
|
2257
|
-
code: ErrorCodes.MemberNotFound,
|
|
2387
|
+
throw new import_util.FluxerError(`Member ${userId} not found in guild`, {
|
|
2388
|
+
code: import_util2.ErrorCodes.MemberNotFound,
|
|
2258
2389
|
cause: err
|
|
2259
2390
|
});
|
|
2260
2391
|
}
|
|
2261
|
-
throw err instanceof FluxerError ? err : new FluxerError("Failed to fetch guild member", { cause: err });
|
|
2392
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError("Failed to fetch guild member", { cause: err });
|
|
2262
2393
|
}
|
|
2263
2394
|
}
|
|
2264
2395
|
/**
|
|
@@ -2282,6 +2413,24 @@ var Guild = class extends Base {
|
|
|
2282
2413
|
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
2283
2414
|
return list.map((w) => new Webhook(this.client, w));
|
|
2284
2415
|
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Fetch all invites in this guild.
|
|
2418
|
+
* Requires Manage Guild permission.
|
|
2419
|
+
*/
|
|
2420
|
+
async fetchInvites() {
|
|
2421
|
+
const data = await this.client.rest.get(
|
|
2422
|
+
import_types15.Routes.guildInvites(this.id)
|
|
2423
|
+
);
|
|
2424
|
+
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
2425
|
+
return list.map((invite) => new Invite(this.client, invite));
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Fetch a guild invite by code or URL.
|
|
2429
|
+
* @see Invite.fetch
|
|
2430
|
+
*/
|
|
2431
|
+
async fetchInvite(codeOrUrl) {
|
|
2432
|
+
return Invite.fetch(this.client, codeOrUrl);
|
|
2433
|
+
}
|
|
2285
2434
|
/**
|
|
2286
2435
|
* Create a channel in this guild.
|
|
2287
2436
|
* @param data - Channel data: type (0=text, 2=voice, 4=category, 5=link), name, and optional parent_id, topic, bitrate, user_limit, nsfw, permission_overwrites
|
|
@@ -2478,12 +2627,12 @@ var Guild = class extends Base {
|
|
|
2478
2627
|
} catch (err) {
|
|
2479
2628
|
const statusCode = err instanceof import_rest3.FluxerAPIError ? err.statusCode : err?.statusCode;
|
|
2480
2629
|
if (statusCode === 404) {
|
|
2481
|
-
throw new FluxerError(`Emoji ${emojiId} not found in guild`, {
|
|
2482
|
-
code: ErrorCodes.EmojiNotFound,
|
|
2630
|
+
throw new import_util.FluxerError(`Emoji ${emojiId} not found in guild`, {
|
|
2631
|
+
code: import_util2.ErrorCodes.EmojiNotFound,
|
|
2483
2632
|
cause: err
|
|
2484
2633
|
});
|
|
2485
2634
|
}
|
|
2486
|
-
throw err instanceof FluxerError ? err : new FluxerError("Failed to fetch guild emoji", { cause: err });
|
|
2635
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError("Failed to fetch guild emoji", { cause: err });
|
|
2487
2636
|
}
|
|
2488
2637
|
}
|
|
2489
2638
|
/**
|
|
@@ -2516,7 +2665,39 @@ var Guild = class extends Base {
|
|
|
2516
2665
|
}
|
|
2517
2666
|
);
|
|
2518
2667
|
const list = Array.isArray(data) ? data : data?.stickers ?? [];
|
|
2519
|
-
|
|
2668
|
+
const created = list.map(
|
|
2669
|
+
(s) => new GuildSticker(this.client, { ...s, guild_id: this.id }, this.id)
|
|
2670
|
+
);
|
|
2671
|
+
for (const sticker of created) {
|
|
2672
|
+
this.stickers.set(sticker.id, sticker);
|
|
2673
|
+
}
|
|
2674
|
+
return created;
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Fetch all stickers in this guild.
|
|
2678
|
+
* @returns GuildSticker instances (cached on guild.stickers)
|
|
2679
|
+
*/
|
|
2680
|
+
async fetchStickers() {
|
|
2681
|
+
const data = await this.client.rest.get(
|
|
2682
|
+
import_types15.Routes.guildStickers(this.id)
|
|
2683
|
+
);
|
|
2684
|
+
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
2685
|
+
const stickers = [];
|
|
2686
|
+
for (const s of list) {
|
|
2687
|
+
const sticker = new GuildSticker(this.client, { ...s, guild_id: this.id }, this.id);
|
|
2688
|
+
this.stickers.set(sticker.id, sticker);
|
|
2689
|
+
stickers.push(sticker);
|
|
2690
|
+
}
|
|
2691
|
+
return stickers;
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Fetch a single guild sticker by ID.
|
|
2695
|
+
*/
|
|
2696
|
+
async fetchSticker(stickerId) {
|
|
2697
|
+
const data = await this.client.rest.get(import_types15.Routes.guildSticker(this.id, stickerId));
|
|
2698
|
+
const sticker = new GuildSticker(this.client, { ...data, guild_id: this.id }, this.id);
|
|
2699
|
+
this.stickers.set(sticker.id, sticker);
|
|
2700
|
+
return sticker;
|
|
2520
2701
|
}
|
|
2521
2702
|
};
|
|
2522
2703
|
|
|
@@ -2710,7 +2891,7 @@ var ClientUser = class extends User {
|
|
|
2710
2891
|
};
|
|
2711
2892
|
|
|
2712
2893
|
// src/client/Client.ts
|
|
2713
|
-
var
|
|
2894
|
+
var import_util10 = require("@fluxerjs/util");
|
|
2714
2895
|
|
|
2715
2896
|
// src/client/UsersManager.ts
|
|
2716
2897
|
var import_collection9 = require("@fluxerjs/collection");
|
|
@@ -2787,6 +2968,153 @@ var UsersManager = class extends import_collection9.Collection {
|
|
|
2787
2968
|
}
|
|
2788
2969
|
};
|
|
2789
2970
|
|
|
2971
|
+
// src/structures/interactions/BaseInteraction.ts
|
|
2972
|
+
var BaseInteraction = class {
|
|
2973
|
+
constructor(client, raw) {
|
|
2974
|
+
this.client = client;
|
|
2975
|
+
this.raw = raw;
|
|
2976
|
+
}
|
|
2977
|
+
get id() {
|
|
2978
|
+
return this.raw.id;
|
|
2979
|
+
}
|
|
2980
|
+
get applicationId() {
|
|
2981
|
+
return this.raw.application_id;
|
|
2982
|
+
}
|
|
2983
|
+
get token() {
|
|
2984
|
+
return this.raw.token;
|
|
2985
|
+
}
|
|
2986
|
+
get type() {
|
|
2987
|
+
return this.raw.type;
|
|
2988
|
+
}
|
|
2989
|
+
get channelId() {
|
|
2990
|
+
return this.raw.channel_id;
|
|
2991
|
+
}
|
|
2992
|
+
get guildId() {
|
|
2993
|
+
return this.raw.guild_id;
|
|
2994
|
+
}
|
|
2995
|
+
};
|
|
2996
|
+
|
|
2997
|
+
// src/structures/interactions/ChatInputCommandInteraction.ts
|
|
2998
|
+
var CommandOptionType = {
|
|
2999
|
+
SubCommand: 1,
|
|
3000
|
+
SubCommandGroup: 2,
|
|
3001
|
+
String: 3,
|
|
3002
|
+
Integer: 4,
|
|
3003
|
+
Boolean: 5,
|
|
3004
|
+
Number: 10
|
|
3005
|
+
};
|
|
3006
|
+
function findOptionDeep(options, name) {
|
|
3007
|
+
if (!options?.length) return void 0;
|
|
3008
|
+
for (const o of options) {
|
|
3009
|
+
if (o.name === name && o.value !== void 0) return o;
|
|
3010
|
+
const nested = findOptionDeep(o.options, name);
|
|
3011
|
+
if (nested) return nested;
|
|
3012
|
+
}
|
|
3013
|
+
return void 0;
|
|
3014
|
+
}
|
|
3015
|
+
var ChatInputCommandInteraction = class extends BaseInteraction {
|
|
3016
|
+
constructor(client, raw) {
|
|
3017
|
+
super(client, raw);
|
|
3018
|
+
if (raw.data?.name == null) {
|
|
3019
|
+
throw new import_util.FluxerError("ChatInputCommandInteraction requires interaction data with a command name", {
|
|
3020
|
+
code: import_util2.ErrorCodes.InteractionInvalidPayload
|
|
3021
|
+
});
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
/** Command name (e.g. `ping`). */
|
|
3025
|
+
get commandName() {
|
|
3026
|
+
return this.raw.data.name;
|
|
3027
|
+
}
|
|
3028
|
+
/** Resolved option leaf by name (searches nested subcommand options). */
|
|
3029
|
+
getOption(name) {
|
|
3030
|
+
const opt = findOptionDeep(this.raw.data?.options, name);
|
|
3031
|
+
if (!opt) {
|
|
3032
|
+
throw new import_util.FluxerError(`Interaction option "${name}" was not provided`, {
|
|
3033
|
+
code: import_util2.ErrorCodes.InteractionOptionNotFound
|
|
3034
|
+
});
|
|
3035
|
+
}
|
|
3036
|
+
return opt;
|
|
3037
|
+
}
|
|
3038
|
+
getString(name) {
|
|
3039
|
+
const o = this.getOption(name);
|
|
3040
|
+
if (o.type !== CommandOptionType.String) {
|
|
3041
|
+
throw new import_util.FluxerError(`Option "${name}" is not a string`, {
|
|
3042
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
3045
|
+
return String(o.value);
|
|
3046
|
+
}
|
|
3047
|
+
getInteger(name) {
|
|
3048
|
+
const o = this.getOption(name);
|
|
3049
|
+
if (o.type !== CommandOptionType.Integer) {
|
|
3050
|
+
throw new import_util.FluxerError(`Option "${name}" is not an integer`, {
|
|
3051
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3052
|
+
});
|
|
3053
|
+
}
|
|
3054
|
+
const v = o.value;
|
|
3055
|
+
if (typeof v !== "number" || !Number.isInteger(v)) {
|
|
3056
|
+
throw new import_util.FluxerError(`Option "${name}" has invalid integer value`, {
|
|
3057
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
return v;
|
|
3061
|
+
}
|
|
3062
|
+
getNumber(name) {
|
|
3063
|
+
const o = this.getOption(name);
|
|
3064
|
+
if (o.type !== CommandOptionType.Number && o.type !== CommandOptionType.Integer) {
|
|
3065
|
+
throw new import_util.FluxerError(`Option "${name}" is not a number`, {
|
|
3066
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3067
|
+
});
|
|
3068
|
+
}
|
|
3069
|
+
const v = o.value;
|
|
3070
|
+
if (typeof v !== "number") {
|
|
3071
|
+
throw new import_util.FluxerError(`Option "${name}" has invalid number value`, {
|
|
3072
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3073
|
+
});
|
|
3074
|
+
}
|
|
3075
|
+
return v;
|
|
3076
|
+
}
|
|
3077
|
+
getBoolean(name) {
|
|
3078
|
+
const o = this.getOption(name);
|
|
3079
|
+
if (o.type !== CommandOptionType.Boolean) {
|
|
3080
|
+
throw new import_util.FluxerError(`Option "${name}" is not a boolean`, {
|
|
3081
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3082
|
+
});
|
|
3083
|
+
}
|
|
3084
|
+
if (typeof o.value !== "boolean") {
|
|
3085
|
+
throw new import_util.FluxerError(`Option "${name}" has invalid boolean value`, {
|
|
3086
|
+
code: import_util2.ErrorCodes.InteractionOptionTypeMismatch
|
|
3087
|
+
});
|
|
3088
|
+
}
|
|
3089
|
+
return o.value;
|
|
3090
|
+
}
|
|
3091
|
+
/** Name of the invoked subcommand (when using subcommands). */
|
|
3092
|
+
getSubcommand(fallback) {
|
|
3093
|
+
const opts = this.raw.data?.options;
|
|
3094
|
+
const first = opts?.[0];
|
|
3095
|
+
if (first?.type === CommandOptionType.SubCommand) return first.name;
|
|
3096
|
+
if (first?.type === CommandOptionType.SubCommandGroup) {
|
|
3097
|
+
const inner = first.options?.[0];
|
|
3098
|
+
if (inner?.type === CommandOptionType.SubCommand) return inner.name;
|
|
3099
|
+
}
|
|
3100
|
+
if (fallback !== void 0) return fallback;
|
|
3101
|
+
throw new import_util.FluxerError("No subcommand in this interaction", {
|
|
3102
|
+
code: import_util2.ErrorCodes.InteractionOptionNotFound
|
|
3103
|
+
});
|
|
3104
|
+
}
|
|
3105
|
+
};
|
|
3106
|
+
|
|
3107
|
+
// src/structures/interactions/createInteraction.ts
|
|
3108
|
+
function createInteraction(client, data) {
|
|
3109
|
+
if (data.data?.name != null) {
|
|
3110
|
+
return new ChatInputCommandInteraction(client, data);
|
|
3111
|
+
}
|
|
3112
|
+
return new BaseInteraction(client, data);
|
|
3113
|
+
}
|
|
3114
|
+
function isChatInputCommandInteraction(interaction) {
|
|
3115
|
+
return interaction instanceof ChatInputCommandInteraction;
|
|
3116
|
+
}
|
|
3117
|
+
|
|
2790
3118
|
// src/util/guildUtils.ts
|
|
2791
3119
|
function normalizeGuildPayload(raw) {
|
|
2792
3120
|
if (!raw || typeof raw !== "object") {
|
|
@@ -2844,18 +3172,54 @@ var MessageReaction = class extends Base {
|
|
|
2844
3172
|
} catch (err) {
|
|
2845
3173
|
if (err instanceof import_rest4.RateLimitError) throw err;
|
|
2846
3174
|
if (err instanceof import_rest4.FluxerAPIError && err.statusCode === 404) {
|
|
2847
|
-
throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
2848
|
-
code: ErrorCodes.MessageNotFound,
|
|
3175
|
+
throw new import_util.FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
3176
|
+
code: import_util2.ErrorCodes.MessageNotFound,
|
|
2849
3177
|
cause: err
|
|
2850
3178
|
});
|
|
2851
3179
|
}
|
|
2852
|
-
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
3180
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
2853
3181
|
}
|
|
2854
3182
|
}
|
|
2855
3183
|
};
|
|
2856
3184
|
|
|
2857
3185
|
// src/client/EventHandlerRegistry.ts
|
|
2858
3186
|
var handlers = /* @__PURE__ */ new Map();
|
|
3187
|
+
function normalizeInviteCreatePayload(client, payload) {
|
|
3188
|
+
if (!payload?.code) return null;
|
|
3189
|
+
const guildId = payload.guild?.id ?? payload.guild_id ?? "0";
|
|
3190
|
+
const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
|
|
3191
|
+
const guild = {
|
|
3192
|
+
id: guildId,
|
|
3193
|
+
name: payload.guild?.name ?? cachedGuild?.name ?? "Unknown Guild",
|
|
3194
|
+
icon: payload.guild?.icon ?? null,
|
|
3195
|
+
banner: payload.guild?.banner ?? null,
|
|
3196
|
+
splash: payload.guild?.splash ?? null,
|
|
3197
|
+
features: payload.guild?.features
|
|
3198
|
+
};
|
|
3199
|
+
const channelId = payload.channel?.id ?? payload.channel_id ?? "0";
|
|
3200
|
+
const cachedChannel = channelId !== "0" ? client.channels.get(channelId) : null;
|
|
3201
|
+
const channel = {
|
|
3202
|
+
id: channelId,
|
|
3203
|
+
type: payload.channel?.type ?? cachedChannel?.type ?? 0,
|
|
3204
|
+
name: payload.channel?.name ?? cachedChannel?.name ?? null,
|
|
3205
|
+
icon: payload.channel?.icon ?? null
|
|
3206
|
+
};
|
|
3207
|
+
return {
|
|
3208
|
+
code: payload.code,
|
|
3209
|
+
type: typeof payload.type === "number" ? payload.type : 0,
|
|
3210
|
+
guild,
|
|
3211
|
+
channel,
|
|
3212
|
+
inviter: payload.inviter ?? null,
|
|
3213
|
+
member_count: payload.member_count,
|
|
3214
|
+
presence_count: payload.presence_count,
|
|
3215
|
+
expires_at: payload.expires_at,
|
|
3216
|
+
temporary: payload.temporary,
|
|
3217
|
+
created_at: payload.created_at,
|
|
3218
|
+
uses: payload.uses,
|
|
3219
|
+
max_uses: payload.max_uses,
|
|
3220
|
+
max_age: payload.max_age
|
|
3221
|
+
};
|
|
3222
|
+
}
|
|
2859
3223
|
handlers.set("MESSAGE_CREATE", async (client, d) => {
|
|
2860
3224
|
const data = d;
|
|
2861
3225
|
if (data.guild_id && data.member && data.author) {
|
|
@@ -3047,8 +3411,25 @@ handlers.set("GUILD_MEMBER_REMOVE", async (client, d) => {
|
|
|
3047
3411
|
}
|
|
3048
3412
|
client.emit(Events.GuildMemberRemove, member);
|
|
3049
3413
|
});
|
|
3414
|
+
handlers.set("GUILD_MEMBERS_CHUNK", async (client, d) => {
|
|
3415
|
+
const data = d;
|
|
3416
|
+
const guild = client.guilds.get(data.guild_id);
|
|
3417
|
+
if (guild) {
|
|
3418
|
+
for (const m of data.members ?? []) {
|
|
3419
|
+
if (m?.user?.id) {
|
|
3420
|
+
const memberData = { ...m, guild_id: guild.id };
|
|
3421
|
+
const member = new GuildMember(client, memberData, guild);
|
|
3422
|
+
guild.members.set(member.id, member);
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
client.emit(Events.GuildMembersChunk, data);
|
|
3427
|
+
});
|
|
3050
3428
|
handlers.set("INTERACTION_CREATE", async (client, d) => {
|
|
3051
|
-
client.emit(
|
|
3429
|
+
client.emit(
|
|
3430
|
+
Events.InteractionCreate,
|
|
3431
|
+
createInteraction(client, d)
|
|
3432
|
+
);
|
|
3052
3433
|
});
|
|
3053
3434
|
handlers.set("VOICE_STATE_UPDATE", async (client, d) => {
|
|
3054
3435
|
client.emit(Events.VoiceStateUpdate, d);
|
|
@@ -3143,7 +3524,14 @@ handlers.set("CHANNEL_PINS_UPDATE", async (client, d) => {
|
|
|
3143
3524
|
client.emit(Events.ChannelPinsUpdate, d);
|
|
3144
3525
|
});
|
|
3145
3526
|
handlers.set("INVITE_CREATE", async (client, d) => {
|
|
3146
|
-
const data = d;
|
|
3527
|
+
const data = normalizeInviteCreatePayload(client, d);
|
|
3528
|
+
if (!data) {
|
|
3529
|
+
client.emit(
|
|
3530
|
+
Events.Debug,
|
|
3531
|
+
"[Gateway] INVITE_CREATE payload had no invite code (documented as possibly empty)"
|
|
3532
|
+
);
|
|
3533
|
+
return;
|
|
3534
|
+
}
|
|
3147
3535
|
client.emit(Events.InviteCreate, new Invite(client, data));
|
|
3148
3536
|
});
|
|
3149
3537
|
handlers.set("INVITE_DELETE", async (client, d) => {
|
|
@@ -3187,6 +3575,7 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3187
3575
|
constructor(options = {}) {
|
|
3188
3576
|
super();
|
|
3189
3577
|
this.options = options;
|
|
3578
|
+
this.setMaxListeners(0);
|
|
3190
3579
|
this.events = createEventMethods(this);
|
|
3191
3580
|
Object.defineProperty(this.channels, "cache", {
|
|
3192
3581
|
get: () => this.channels,
|
|
@@ -3219,8 +3608,22 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3219
3608
|
_ws = null;
|
|
3220
3609
|
/** When waitForGuilds, set of guild IDs we're waiting for GUILD_CREATE on. Null when not waiting. */
|
|
3221
3610
|
_pendingGuildIds = null;
|
|
3611
|
+
/** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
|
|
3612
|
+
_guildStreamSettleTimeout = null;
|
|
3222
3613
|
/** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
|
|
3223
3614
|
_messageCaches = null;
|
|
3615
|
+
on(event, listener) {
|
|
3616
|
+
return super.on(event, listener);
|
|
3617
|
+
}
|
|
3618
|
+
once(event, listener) {
|
|
3619
|
+
return super.once(event, listener);
|
|
3620
|
+
}
|
|
3621
|
+
off(event, listener) {
|
|
3622
|
+
return super.off(event, listener);
|
|
3623
|
+
}
|
|
3624
|
+
emit(event, ...args) {
|
|
3625
|
+
return super.emit(event, ...args);
|
|
3626
|
+
}
|
|
3224
3627
|
/**
|
|
3225
3628
|
* Resolve an emoji argument to the API format (unicode or "name:id").
|
|
3226
3629
|
* Supports: <:name:id>, :name:, name:id, { name, id }, unicode.
|
|
@@ -3235,33 +3638,37 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3235
3638
|
if (guildId) {
|
|
3236
3639
|
await this.assertEmojiInGuild(emoji.id, guildId);
|
|
3237
3640
|
}
|
|
3238
|
-
return (0,
|
|
3641
|
+
return (0, import_util10.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
3239
3642
|
}
|
|
3240
|
-
const parsed = (0,
|
|
3643
|
+
const parsed = (0, import_util10.parseEmoji)(
|
|
3241
3644
|
typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
|
|
3242
3645
|
);
|
|
3243
|
-
if (!parsed)
|
|
3646
|
+
if (!parsed) {
|
|
3647
|
+
throw new import_util.FluxerError("Invalid emoji", { code: import_util2.ErrorCodes.InvalidEmoji });
|
|
3648
|
+
}
|
|
3244
3649
|
if (parsed.id) {
|
|
3245
3650
|
if (guildId) {
|
|
3246
3651
|
await this.assertEmojiInGuild(parsed.id, guildId);
|
|
3247
3652
|
}
|
|
3248
|
-
return (0,
|
|
3653
|
+
return (0, import_util10.formatEmoji)(parsed);
|
|
3249
3654
|
}
|
|
3250
3655
|
if (!/^\w+$/.test(parsed.name)) return parsed.name;
|
|
3251
|
-
const unicodeFromShortcode = (0,
|
|
3656
|
+
const unicodeFromShortcode = (0, import_util10.getUnicodeFromShortcode)(parsed.name);
|
|
3252
3657
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
3253
3658
|
if (guildId) {
|
|
3254
3659
|
const emojis = await this.rest.get(import_types21.Routes.guildEmojis(guildId));
|
|
3255
3660
|
const list = Array.isArray(emojis) ? emojis : Object.values(emojis ?? {});
|
|
3256
3661
|
const found = list.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
3257
|
-
if (found) return (0,
|
|
3258
|
-
throw new
|
|
3259
|
-
`Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format
|
|
3662
|
+
if (found) return (0, import_util10.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
|
|
3663
|
+
throw new import_util.FluxerError(
|
|
3664
|
+
`Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
|
|
3665
|
+
{ code: import_util2.ErrorCodes.EmojiNotFound }
|
|
3260
3666
|
);
|
|
3261
3667
|
}
|
|
3262
3668
|
if (/^\w+$/.test(parsed.name)) {
|
|
3263
|
-
throw new
|
|
3264
|
-
`Custom emoji ":${parsed.name}:" requires guild context. Use message.react() in a guild channel, or pass guildId to client.resolveEmoji()
|
|
3669
|
+
throw new import_util.FluxerError(
|
|
3670
|
+
`Custom emoji ":${parsed.name}:" requires guild context. Use message.react() in a guild channel, or pass guildId to client.resolveEmoji().`,
|
|
3671
|
+
{ code: import_util2.ErrorCodes.EmojiRequiresGuild }
|
|
3265
3672
|
);
|
|
3266
3673
|
}
|
|
3267
3674
|
return parsed.name;
|
|
@@ -3276,8 +3683,8 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3276
3683
|
const list = Array.isArray(emojis) ? emojis : Object.values(emojis ?? {});
|
|
3277
3684
|
const found = list.some((e) => e.id === emojiId);
|
|
3278
3685
|
if (!found) {
|
|
3279
|
-
throw new FluxerError("Custom emoji is from another server. Use an emoji from this server.", {
|
|
3280
|
-
code: ErrorCodes.EmojiNotInGuild
|
|
3686
|
+
throw new import_util.FluxerError("Custom emoji is from another server. Use an emoji from this server.", {
|
|
3687
|
+
code: import_util2.ErrorCodes.EmojiNotInGuild
|
|
3281
3688
|
});
|
|
3282
3689
|
}
|
|
3283
3690
|
}
|
|
@@ -3288,6 +3695,20 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3288
3695
|
async fetchInstance() {
|
|
3289
3696
|
return this.rest.get(import_types21.Routes.instance(), { auth: false });
|
|
3290
3697
|
}
|
|
3698
|
+
/**
|
|
3699
|
+
* Fetch instance discovery document (API URL, gateway URL, features). GET /.well-known/fluxer.
|
|
3700
|
+
* Does not require authentication.
|
|
3701
|
+
*/
|
|
3702
|
+
async fetchInstanceDiscovery() {
|
|
3703
|
+
return this.rest.get(import_types21.Routes.instanceDiscovery(), { auth: false });
|
|
3704
|
+
}
|
|
3705
|
+
/**
|
|
3706
|
+
* Fetch gateway connection metadata (WebSocket URL, recommended shards, session limits).
|
|
3707
|
+
* GET /gateway/bot (authenticated).
|
|
3708
|
+
*/
|
|
3709
|
+
async fetchGatewayInfo() {
|
|
3710
|
+
return this.rest.get(import_types21.Routes.gatewayBot());
|
|
3711
|
+
}
|
|
3291
3712
|
/**
|
|
3292
3713
|
* Fetch a message by channel and message ID. Use when you have IDs (e.g. from a DB).
|
|
3293
3714
|
* @param channelId - Snowflake of the channel
|
|
@@ -3300,7 +3721,7 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3300
3721
|
* const message = await channel?.messages?.fetch(messageId);
|
|
3301
3722
|
*/
|
|
3302
3723
|
async fetchMessage(channelId, messageId) {
|
|
3303
|
-
(0,
|
|
3724
|
+
(0, import_util10.emitDeprecationWarning)(
|
|
3304
3725
|
"Client.fetchMessage()",
|
|
3305
3726
|
"Use channel.messages.fetch(messageId). For IDs-only: (await client.channels.resolve(channelId))?.messages?.fetch(messageId)"
|
|
3306
3727
|
);
|
|
@@ -3312,7 +3733,7 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3312
3733
|
* @deprecated Use client.channels.send(channelId, payload).
|
|
3313
3734
|
*/
|
|
3314
3735
|
async sendToChannel(channelId, payload) {
|
|
3315
|
-
(0,
|
|
3736
|
+
(0, import_util10.emitDeprecationWarning)(
|
|
3316
3737
|
"Client.sendToChannel()",
|
|
3317
3738
|
"Use client.channels.send(channelId, payload)."
|
|
3318
3739
|
);
|
|
@@ -3371,7 +3792,11 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3371
3792
|
}
|
|
3372
3793
|
/** WebSocket manager. Throws if not logged in. */
|
|
3373
3794
|
get ws() {
|
|
3374
|
-
if (!this._ws)
|
|
3795
|
+
if (!this._ws) {
|
|
3796
|
+
throw new import_util.FluxerError("Client is not logged in. Call login() first.", {
|
|
3797
|
+
code: import_util2.ErrorCodes.NotLoggedIn
|
|
3798
|
+
});
|
|
3799
|
+
}
|
|
3375
3800
|
return this._ws;
|
|
3376
3801
|
}
|
|
3377
3802
|
/**
|
|
@@ -3382,15 +3807,35 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3382
3807
|
sendToGateway(shardId, payload) {
|
|
3383
3808
|
this.ws.send(shardId, payload);
|
|
3384
3809
|
}
|
|
3385
|
-
|
|
3386
|
-
|
|
3810
|
+
/**
|
|
3811
|
+
* Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
|
|
3812
|
+
* macrotask so user code does not block the WebSocket `message` callback.
|
|
3813
|
+
*/
|
|
3814
|
+
handleDispatch(payload) {
|
|
3815
|
+
if (payload.op !== 0 || !payload.t) return Promise.resolve();
|
|
3387
3816
|
const { t: event, d } = payload;
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3817
|
+
const handler = eventHandlers.get(event);
|
|
3818
|
+
if (!handler) return Promise.resolve();
|
|
3819
|
+
const run = async () => {
|
|
3820
|
+
try {
|
|
3821
|
+
await handler(this, d);
|
|
3822
|
+
} catch (err) {
|
|
3823
|
+
this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)));
|
|
3824
|
+
}
|
|
3825
|
+
};
|
|
3826
|
+
if (this.options.gatewayDeferHandlers === false) {
|
|
3827
|
+
return run();
|
|
3393
3828
|
}
|
|
3829
|
+
return new Promise((resolve, reject) => {
|
|
3830
|
+
const start = () => {
|
|
3831
|
+
void run().then(resolve).catch(reject);
|
|
3832
|
+
};
|
|
3833
|
+
if (typeof setImmediate === "function") {
|
|
3834
|
+
setImmediate(start);
|
|
3835
|
+
} else {
|
|
3836
|
+
setTimeout(start, 0);
|
|
3837
|
+
}
|
|
3838
|
+
});
|
|
3394
3839
|
}
|
|
3395
3840
|
/**
|
|
3396
3841
|
* Connect to the Fluxer gateway and authenticate.
|
|
@@ -3398,8 +3843,8 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3398
3843
|
*/
|
|
3399
3844
|
async login(token) {
|
|
3400
3845
|
if (this._ws) {
|
|
3401
|
-
throw new FluxerError("Client is already logged in. Call destroy() first.", {
|
|
3402
|
-
code: ErrorCodes.AlreadyLoggedIn
|
|
3846
|
+
throw new import_util.FluxerError("Client is already logged in. Call destroy() first.", {
|
|
3847
|
+
code: import_util2.ErrorCodes.AlreadyLoggedIn
|
|
3403
3848
|
});
|
|
3404
3849
|
}
|
|
3405
3850
|
this.rest.setToken(token);
|
|
@@ -3422,6 +3867,7 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3422
3867
|
presence: this.options.presence,
|
|
3423
3868
|
rest: { get: (route) => this.rest.get(route) },
|
|
3424
3869
|
version: this.options.rest?.version ?? "1",
|
|
3870
|
+
debug: this.options.gatewayDebug !== false,
|
|
3425
3871
|
WebSocket: this.options.WebSocket
|
|
3426
3872
|
});
|
|
3427
3873
|
this._ws.on("dispatch", ({ payload }) => {
|
|
@@ -3465,6 +3911,14 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3465
3911
|
this._pendingGuildIds = pending;
|
|
3466
3912
|
return;
|
|
3467
3913
|
}
|
|
3914
|
+
if (waitForGuilds && (data.guilds ?? []).length === 0) {
|
|
3915
|
+
const GUILD_STREAM_SETTLE_MS = 500;
|
|
3916
|
+
this._guildStreamSettleTimeout = setTimeout(() => {
|
|
3917
|
+
this._guildStreamSettleTimeout = null;
|
|
3918
|
+
this._finalizeReady();
|
|
3919
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
3920
|
+
return;
|
|
3921
|
+
}
|
|
3468
3922
|
this._finalizeReady();
|
|
3469
3923
|
}
|
|
3470
3924
|
);
|
|
@@ -3494,6 +3948,10 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3494
3948
|
}
|
|
3495
3949
|
/** Disconnect from the gateway and clear cached data. */
|
|
3496
3950
|
async destroy() {
|
|
3951
|
+
if (this._guildStreamSettleTimeout !== null) {
|
|
3952
|
+
clearTimeout(this._guildStreamSettleTimeout);
|
|
3953
|
+
this._guildStreamSettleTimeout = null;
|
|
3954
|
+
}
|
|
3497
3955
|
if (this._ws) {
|
|
3498
3956
|
this._ws.destroy();
|
|
3499
3957
|
this._ws = null;
|
|
@@ -3516,10 +3974,10 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3516
3974
|
*/
|
|
3517
3975
|
assertReady() {
|
|
3518
3976
|
if (!this.isReady()) {
|
|
3519
|
-
throw new FluxerError(
|
|
3977
|
+
throw new import_util.FluxerError(
|
|
3520
3978
|
"Client is not ready yet. Wait for the Ready event before accessing client.user.",
|
|
3521
3979
|
{
|
|
3522
|
-
code: ErrorCodes.ClientNotReady
|
|
3980
|
+
code: import_util2.ErrorCodes.ClientNotReady
|
|
3523
3981
|
}
|
|
3524
3982
|
);
|
|
3525
3983
|
}
|
|
@@ -3530,18 +3988,20 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
3530
3988
|
};
|
|
3531
3989
|
|
|
3532
3990
|
// src/index.ts
|
|
3533
|
-
var
|
|
3991
|
+
var import_builders4 = require("@fluxerjs/builders");
|
|
3534
3992
|
var import_types22 = require("@fluxerjs/types");
|
|
3535
|
-
var
|
|
3536
|
-
var
|
|
3993
|
+
var import_util11 = require("@fluxerjs/util");
|
|
3994
|
+
var import_util12 = require("@fluxerjs/util");
|
|
3537
3995
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3538
3996
|
0 && (module.exports = {
|
|
3539
3997
|
AttachmentBuilder,
|
|
3540
3998
|
Base,
|
|
3999
|
+
BaseInteraction,
|
|
3541
4000
|
CDN_URL,
|
|
3542
4001
|
CategoryChannel,
|
|
3543
4002
|
Channel,
|
|
3544
4003
|
ChannelManager,
|
|
4004
|
+
ChatInputCommandInteraction,
|
|
3545
4005
|
Client,
|
|
3546
4006
|
ClientUser,
|
|
3547
4007
|
DMChannel,
|
|
@@ -3585,6 +4045,8 @@ var import_util10 = require("@fluxerjs/util");
|
|
|
3585
4045
|
cdnDisplayAvatarURL,
|
|
3586
4046
|
cdnMemberAvatarURL,
|
|
3587
4047
|
cdnMemberBannerURL,
|
|
4048
|
+
createInteraction,
|
|
4049
|
+
isChatInputCommandInteraction,
|
|
3588
4050
|
parsePrefixCommand,
|
|
3589
4051
|
parseUserMention,
|
|
3590
4052
|
resolvePermissionsToBitfield,
|