@fluxerjs/core 1.2.0 → 1.2.2
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.d.mts +1166 -1021
- package/dist/index.d.ts +1166 -1021
- package/dist/index.js +2598 -2687
- package/dist/index.mjs +2718 -271
- package/package.json +8 -8
- package/dist/Channel-4YUSB2MM.mjs +0 -22
- package/dist/ClientUser-ET7FW3XL.mjs +0 -9
- package/dist/Guild-4U4U422Z.mjs +0 -12
- package/dist/GuildBan-7CXLTPKY.mjs +0 -7
- package/dist/GuildEmoji-OCXBPS6I.mjs +0 -8
- package/dist/GuildMember-FSGDPKUU.mjs +0 -9
- package/dist/GuildSticker-B7AZADJR.mjs +0 -8
- package/dist/Invite-UM5BU5A6.mjs +0 -7
- package/dist/Message-R7KSI5YU.mjs +0 -9
- package/dist/MessageReaction-EYO7AJTL.mjs +0 -8
- package/dist/Role-SERSJFJC.mjs +0 -7
- package/dist/Webhook-LWYP2BMI.mjs +0 -10
- package/dist/chunk-24E6OQID.mjs +0 -193
- package/dist/chunk-2ZSMLDEI.mjs +0 -114
- package/dist/chunk-3JVE6RW7.mjs +0 -147
- package/dist/chunk-6S3BDHBI.mjs +0 -28
- package/dist/chunk-75ODDXY3.mjs +0 -64
- package/dist/chunk-AH7KYH2Z.mjs +0 -50
- package/dist/chunk-BKPVGBOT.mjs +0 -8
- package/dist/chunk-G6F6VL4O.mjs +0 -54
- package/dist/chunk-HVCL7QLT.mjs +0 -337
- package/dist/chunk-IHXSHE2Z.mjs +0 -56
- package/dist/chunk-IRDYSGQO.mjs +0 -496
- package/dist/chunk-KR26CBFE.mjs +0 -58
- package/dist/chunk-QEXIYXXU.mjs +0 -62
- package/dist/chunk-U33GNMEZ.mjs +0 -140
- package/dist/chunk-UXIF75BV.mjs +0 -36
- package/dist/chunk-VJDH54HJ.mjs +0 -56
- package/dist/chunk-XNS4O6QJ.mjs +0 -7
- package/dist/chunk-YGXCMETR.mjs +0 -592
- package/dist/guildUtils-FTEGCNNJ.mjs +0 -17
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.2",
|
|
7
7
|
"description": "A fully-featured SDK for Fluxer bots",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@fluxerjs/rest": "1.2.
|
|
38
|
-
"@fluxerjs/ws": "1.2.
|
|
39
|
-
"@fluxerjs/
|
|
40
|
-
"@fluxerjs/collection": "1.2.
|
|
41
|
-
"@fluxerjs/
|
|
42
|
-
"@fluxerjs/types": "1.2.
|
|
37
|
+
"@fluxerjs/rest": "1.2.2",
|
|
38
|
+
"@fluxerjs/ws": "1.2.2",
|
|
39
|
+
"@fluxerjs/util": "1.2.2",
|
|
40
|
+
"@fluxerjs/collection": "1.2.2",
|
|
41
|
+
"@fluxerjs/builders": "1.2.2",
|
|
42
|
+
"@fluxerjs/types": "1.2.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "^20.0.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"node": ">=18.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "tsup
|
|
53
|
+
"build": "tsup",
|
|
54
54
|
"clean": "rm -rf dist",
|
|
55
55
|
"lint": "eslint src --max-warnings 0 --config ../../eslint.config.js",
|
|
56
56
|
"lint:fix": "eslint src --fix --config ../../eslint.config.js",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CategoryChannel,
|
|
3
|
-
Channel,
|
|
4
|
-
DMChannel,
|
|
5
|
-
GuildChannel,
|
|
6
|
-
LinkChannel,
|
|
7
|
-
TextChannel,
|
|
8
|
-
VoiceChannel
|
|
9
|
-
} from "./chunk-IRDYSGQO.mjs";
|
|
10
|
-
import "./chunk-6S3BDHBI.mjs";
|
|
11
|
-
import "./chunk-AH7KYH2Z.mjs";
|
|
12
|
-
import "./chunk-VJDH54HJ.mjs";
|
|
13
|
-
import "./chunk-XNS4O6QJ.mjs";
|
|
14
|
-
export {
|
|
15
|
-
CategoryChannel,
|
|
16
|
-
Channel,
|
|
17
|
-
DMChannel,
|
|
18
|
-
GuildChannel,
|
|
19
|
-
LinkChannel,
|
|
20
|
-
TextChannel,
|
|
21
|
-
VoiceChannel
|
|
22
|
-
};
|
package/dist/Guild-4U4U422Z.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Guild
|
|
3
|
-
} from "./chunk-YGXCMETR.mjs";
|
|
4
|
-
import "./chunk-6S3BDHBI.mjs";
|
|
5
|
-
import "./chunk-24E6OQID.mjs";
|
|
6
|
-
import "./chunk-G6F6VL4O.mjs";
|
|
7
|
-
import "./chunk-BKPVGBOT.mjs";
|
|
8
|
-
import "./chunk-2ZSMLDEI.mjs";
|
|
9
|
-
import "./chunk-XNS4O6QJ.mjs";
|
|
10
|
-
export {
|
|
11
|
-
Guild
|
|
12
|
-
};
|
package/dist/Invite-UM5BU5A6.mjs
DELETED
package/dist/Role-SERSJFJC.mjs
DELETED
package/dist/chunk-24E6OQID.mjs
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cdnMemberAvatarURL,
|
|
3
|
-
cdnMemberBannerURL
|
|
4
|
-
} from "./chunk-G6F6VL4O.mjs";
|
|
5
|
-
import {
|
|
6
|
-
Base
|
|
7
|
-
} from "./chunk-XNS4O6QJ.mjs";
|
|
8
|
-
|
|
9
|
-
// src/structures/GuildMember.ts
|
|
10
|
-
import { PermissionFlagsMap } from "@fluxerjs/util";
|
|
11
|
-
import { Routes } from "@fluxerjs/types";
|
|
12
|
-
|
|
13
|
-
// src/util/permissions.ts
|
|
14
|
-
import { OverwriteType } from "@fluxerjs/types";
|
|
15
|
-
import { ALL_PERMISSIONS_BIGINT } from "@fluxerjs/util";
|
|
16
|
-
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
17
|
-
if (isOwner) return ALL_PERMISSIONS_BIGINT;
|
|
18
|
-
let perms = basePermissions;
|
|
19
|
-
for (const overwrite of overwrites ?? []) {
|
|
20
|
-
const applies = overwrite.type === OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === OverwriteType.Member && overwrite.id === memberId;
|
|
21
|
-
if (!applies) continue;
|
|
22
|
-
const allow = BigInt(overwrite.allow || "0");
|
|
23
|
-
const deny = BigInt(overwrite.deny || "0");
|
|
24
|
-
perms = perms & ~deny | allow;
|
|
25
|
-
}
|
|
26
|
-
return perms;
|
|
27
|
-
}
|
|
28
|
-
function hasPermission(bitfield, permission) {
|
|
29
|
-
const Administrator = 1n << 3n;
|
|
30
|
-
if ((bitfield & Administrator) !== 0n) return true;
|
|
31
|
-
return (bitfield & permission) === permission;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/structures/GuildMember.ts
|
|
35
|
-
var GuildMember = class extends Base {
|
|
36
|
-
client;
|
|
37
|
-
id;
|
|
38
|
-
user;
|
|
39
|
-
guild;
|
|
40
|
-
nick;
|
|
41
|
-
roles;
|
|
42
|
-
joinedAt;
|
|
43
|
-
communicationDisabledUntil;
|
|
44
|
-
mute;
|
|
45
|
-
deaf;
|
|
46
|
-
avatar;
|
|
47
|
-
banner;
|
|
48
|
-
accentColor;
|
|
49
|
-
profileFlags;
|
|
50
|
-
/** @param data - API guild member from GET /guilds/{id}/members or GET /guilds/{id}/members/{user_id} */
|
|
51
|
-
constructor(client, data, guild) {
|
|
52
|
-
super();
|
|
53
|
-
this.client = client;
|
|
54
|
-
this.user = client.getOrCreateUser(data.user);
|
|
55
|
-
this.id = data.user.id;
|
|
56
|
-
this.guild = guild;
|
|
57
|
-
this.nick = data.nick ?? null;
|
|
58
|
-
this.roles = data.roles ?? [];
|
|
59
|
-
this.joinedAt = new Date(data.joined_at);
|
|
60
|
-
this.communicationDisabledUntil = data.communication_disabled_until ? new Date(data.communication_disabled_until) : null;
|
|
61
|
-
this.mute = data.mute ?? false;
|
|
62
|
-
this.deaf = data.deaf ?? false;
|
|
63
|
-
this.avatar = data.avatar ?? null;
|
|
64
|
-
this.banner = data.banner ?? null;
|
|
65
|
-
this.accentColor = data.accent_color ?? null;
|
|
66
|
-
this.profileFlags = data.profile_flags ?? null;
|
|
67
|
-
}
|
|
68
|
-
/** Nickname, or global name, or username. */
|
|
69
|
-
get displayName() {
|
|
70
|
-
return this.nick ?? this.user.globalName ?? this.user.username;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get the guild-specific avatar URL for this member.
|
|
74
|
-
* Returns null if the member has no guild avatar (use displayAvatarURL for fallback).
|
|
75
|
-
*/
|
|
76
|
-
avatarURL(options) {
|
|
77
|
-
return cdnMemberAvatarURL(this.guild.id, this.id, this.avatar, options);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get the avatar URL to display for this member.
|
|
81
|
-
* Uses guild-specific avatar if set, otherwise falls back to the user's avatar.
|
|
82
|
-
*/
|
|
83
|
-
displayAvatarURL(options) {
|
|
84
|
-
return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Get the guild-specific banner URL for this member.
|
|
88
|
-
* Returns null if the member has no guild banner.
|
|
89
|
-
*/
|
|
90
|
-
bannerURL(options) {
|
|
91
|
-
return cdnMemberBannerURL(this.guild.id, this.id, this.banner, options);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Add a role to this member.
|
|
95
|
-
* @param roleId - The role ID to add
|
|
96
|
-
* Requires Manage Roles permission.
|
|
97
|
-
*/
|
|
98
|
-
async addRole(roleId) {
|
|
99
|
-
await this.client.rest.put(Routes.guildMemberRole(this.guild.id, this.id, roleId));
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Remove a role from this member.
|
|
103
|
-
* @param roleId - The role ID to remove
|
|
104
|
-
* Requires Manage Roles permission.
|
|
105
|
-
*/
|
|
106
|
-
async removeRole(roleId) {
|
|
107
|
-
await this.client.rest.delete(Routes.guildMemberRole(this.guild.id, this.id, roleId));
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Edit this guild member. PATCH /guilds/{id}/members/{userId} or /members/@me for the bot.
|
|
111
|
-
* For @me: nick, avatar, banner, bio, pronouns, accent_color, profile_flags, mute, deaf,
|
|
112
|
-
* communication_disabled_until, timeout_reason, channel_id, connection_id.
|
|
113
|
-
* For other members: same plus roles (array of role IDs).
|
|
114
|
-
*/
|
|
115
|
-
async edit(options) {
|
|
116
|
-
const isMe = this.client.user?.id === this.id;
|
|
117
|
-
const route = isMe ? `/guilds/${this.guild.id}/members/@me` : Routes.guildMember(this.guild.id, this.id);
|
|
118
|
-
const data = await this.client.rest.patch(route, {
|
|
119
|
-
body: options,
|
|
120
|
-
auth: true
|
|
121
|
-
});
|
|
122
|
-
this.nick = data.nick ?? this.nick;
|
|
123
|
-
if (data.roles) this.roles = data.roles;
|
|
124
|
-
if (data.communication_disabled_until != null) {
|
|
125
|
-
this.communicationDisabledUntil = data.communication_disabled_until ? new Date(data.communication_disabled_until) : null;
|
|
126
|
-
}
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Get the member's guild-level permissions (from roles only, no channel overwrites).
|
|
131
|
-
* Use this for server-wide permission checks (e.g. ban, kick, manage roles).
|
|
132
|
-
* @returns Object with has(permission) to check specific permissions
|
|
133
|
-
* @example
|
|
134
|
-
* const perms = member.permissions;
|
|
135
|
-
* if (perms.has(PermissionFlags.BanMembers)) { ... }
|
|
136
|
-
*/
|
|
137
|
-
get permissions() {
|
|
138
|
-
const base = this._computeBasePermissions();
|
|
139
|
-
const ownerId = this.guild.ownerId;
|
|
140
|
-
const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
|
|
141
|
-
const perms = computePermissions(base, [], [], this.id, isOwner);
|
|
142
|
-
return {
|
|
143
|
-
has(permission) {
|
|
144
|
-
const perm = typeof permission === "number" ? permission : PermissionFlagsMap[String(permission)];
|
|
145
|
-
if (perm === void 0) return false;
|
|
146
|
-
return hasPermission(perms, BigInt(perm));
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Compute the member's effective permissions in a guild channel.
|
|
152
|
-
* Applies role permissions and channel overwrites.
|
|
153
|
-
* @param channel - The guild channel to check permissions for
|
|
154
|
-
* @returns Object with has(permission) to check specific permissions
|
|
155
|
-
* @example
|
|
156
|
-
* const perms = member.permissionsIn(channel);
|
|
157
|
-
* if (perms.has(PermissionFlags.SendMessages)) { ... }
|
|
158
|
-
*/
|
|
159
|
-
permissionsIn(channel) {
|
|
160
|
-
const base = this._computeBasePermissions();
|
|
161
|
-
const ownerId = this.guild.ownerId;
|
|
162
|
-
const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
|
|
163
|
-
const perms = computePermissions(
|
|
164
|
-
base,
|
|
165
|
-
channel.permissionOverwrites,
|
|
166
|
-
this.roles,
|
|
167
|
-
this.id,
|
|
168
|
-
isOwner
|
|
169
|
-
);
|
|
170
|
-
return {
|
|
171
|
-
has(permission) {
|
|
172
|
-
const perm = typeof permission === "number" ? permission : PermissionFlagsMap[String(permission)];
|
|
173
|
-
if (perm === void 0) return false;
|
|
174
|
-
return hasPermission(perms, BigInt(perm));
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
_computeBasePermissions() {
|
|
179
|
-
let base = 0n;
|
|
180
|
-
const everyone = this.guild.roles.get(this.guild.id);
|
|
181
|
-
if (everyone) base |= BigInt(everyone.permissions);
|
|
182
|
-
for (const roleId of this.roles) {
|
|
183
|
-
if (roleId === this.guild.id) continue;
|
|
184
|
-
const role = this.guild.roles.get(roleId);
|
|
185
|
-
if (role) base |= BigInt(role.permissions);
|
|
186
|
-
}
|
|
187
|
-
return base;
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export {
|
|
192
|
-
GuildMember
|
|
193
|
-
};
|
package/dist/chunk-2ZSMLDEI.mjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Base
|
|
3
|
-
} from "./chunk-XNS4O6QJ.mjs";
|
|
4
|
-
|
|
5
|
-
// src/structures/Role.ts
|
|
6
|
-
import { Routes } from "@fluxerjs/types";
|
|
7
|
-
import {
|
|
8
|
-
PermissionFlags,
|
|
9
|
-
resolvePermissionsToBitfield
|
|
10
|
-
} from "@fluxerjs/util";
|
|
11
|
-
var Role = class extends Base {
|
|
12
|
-
client;
|
|
13
|
-
id;
|
|
14
|
-
guildId;
|
|
15
|
-
name;
|
|
16
|
-
color;
|
|
17
|
-
position;
|
|
18
|
-
permissions;
|
|
19
|
-
hoist;
|
|
20
|
-
mentionable;
|
|
21
|
-
unicodeEmoji;
|
|
22
|
-
/** Separately sorted position for hoisted roles. Null if not set. */
|
|
23
|
-
hoistPosition;
|
|
24
|
-
/** @param client - The client instance */
|
|
25
|
-
/** @param data - API role from GET /guilds/{id}/roles or gateway role events */
|
|
26
|
-
/** @param guildId - The guild this role belongs to */
|
|
27
|
-
constructor(client, data, guildId) {
|
|
28
|
-
super();
|
|
29
|
-
this.client = client;
|
|
30
|
-
this.id = data.id;
|
|
31
|
-
this.guildId = guildId;
|
|
32
|
-
this.name = data.name;
|
|
33
|
-
this.color = data.color;
|
|
34
|
-
this.position = data.position;
|
|
35
|
-
this.permissions = data.permissions;
|
|
36
|
-
this.hoist = !!data.hoist;
|
|
37
|
-
this.mentionable = !!data.mentionable;
|
|
38
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
39
|
-
this.hoistPosition = data.hoist_position ?? null;
|
|
40
|
-
}
|
|
41
|
-
/** Update mutable fields from fresh API data. Used by edit and gateway events. */
|
|
42
|
-
_patch(data) {
|
|
43
|
-
if (data.name !== void 0) this.name = data.name;
|
|
44
|
-
if (data.color !== void 0) this.color = data.color;
|
|
45
|
-
if (data.position !== void 0) this.position = data.position;
|
|
46
|
-
if (data.permissions !== void 0) this.permissions = data.permissions;
|
|
47
|
-
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
48
|
-
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
49
|
-
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
50
|
-
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
51
|
-
}
|
|
52
|
-
/** Returns a mention string (e.g. `<@&123456>`). */
|
|
53
|
-
toString() {
|
|
54
|
-
return `<@&${this.id}>`;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Check if this role has a permission. Administrator grants all permissions.
|
|
58
|
-
* @param permission - Permission flag, name, or resolvable
|
|
59
|
-
* @returns true if the role has the permission
|
|
60
|
-
* @example
|
|
61
|
-
* if (role.has(PermissionFlags.BanMembers)) { ... }
|
|
62
|
-
* if (role.has('ManageChannels')) { ... }
|
|
63
|
-
*/
|
|
64
|
-
has(permission) {
|
|
65
|
-
const perm = typeof permission === "number" ? permission : PermissionFlags[permission];
|
|
66
|
-
if (perm === void 0) return false;
|
|
67
|
-
const permNum = Number(perm);
|
|
68
|
-
const rolePerms = BigInt(this.permissions);
|
|
69
|
-
const permBig = BigInt(permNum);
|
|
70
|
-
if (permBig < 0) return false;
|
|
71
|
-
if ((rolePerms & BigInt(PermissionFlags.Administrator)) !== 0n) return true;
|
|
72
|
-
return (rolePerms & permBig) === permBig;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Edit this role.
|
|
76
|
-
* Requires Manage Roles permission.
|
|
77
|
-
* @param options - Role updates (permissions accepts PermissionResolvable for convenience)
|
|
78
|
-
* @returns This role (updated in place)
|
|
79
|
-
* @example
|
|
80
|
-
* await role.edit({ name: 'Moderator', permissions: ['BanMembers', 'KickMembers'] });
|
|
81
|
-
*/
|
|
82
|
-
async edit(options) {
|
|
83
|
-
const body = {};
|
|
84
|
-
if (options.name !== void 0) body.name = options.name;
|
|
85
|
-
if (options.permissions !== void 0) {
|
|
86
|
-
body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield(options.permissions);
|
|
87
|
-
}
|
|
88
|
-
if (options.color !== void 0) body.color = options.color;
|
|
89
|
-
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
90
|
-
if (options.mentionable !== void 0) body.mentionable = options.mentionable;
|
|
91
|
-
if (options.unicode_emoji !== void 0) body.unicode_emoji = options.unicode_emoji;
|
|
92
|
-
if (options.position !== void 0) body.position = options.position;
|
|
93
|
-
if (options.hoist_position !== void 0) body.hoist_position = options.hoist_position;
|
|
94
|
-
const data = await this.client.rest.patch(Routes.guildRole(this.guildId, this.id), {
|
|
95
|
-
body: Object.keys(body).length ? body : void 0,
|
|
96
|
-
auth: true
|
|
97
|
-
});
|
|
98
|
-
this._patch(data);
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Delete this role.
|
|
103
|
-
* Requires Manage Roles permission.
|
|
104
|
-
*/
|
|
105
|
-
async delete() {
|
|
106
|
-
await this.client.rest.delete(Routes.guildRole(this.guildId, this.id), { auth: true });
|
|
107
|
-
const guild = this.client.guilds.get(this.guildId);
|
|
108
|
-
if (guild) guild.roles.delete(this.id);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export {
|
|
113
|
-
Role
|
|
114
|
-
};
|
package/dist/chunk-3JVE6RW7.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildSendBody,
|
|
3
|
-
resolveMessageFiles
|
|
4
|
-
} from "./chunk-VJDH54HJ.mjs";
|
|
5
|
-
import {
|
|
6
|
-
cdnAvatarURL
|
|
7
|
-
} from "./chunk-G6F6VL4O.mjs";
|
|
8
|
-
import {
|
|
9
|
-
Base
|
|
10
|
-
} from "./chunk-XNS4O6QJ.mjs";
|
|
11
|
-
|
|
12
|
-
// src/structures/Webhook.ts
|
|
13
|
-
import { Routes } from "@fluxerjs/types";
|
|
14
|
-
var Webhook = class _Webhook extends Base {
|
|
15
|
-
client;
|
|
16
|
-
id;
|
|
17
|
-
guildId;
|
|
18
|
-
channelId;
|
|
19
|
-
name;
|
|
20
|
-
avatar;
|
|
21
|
-
/** Present only when webhook was created via createWebhook(); not returned when fetching. */
|
|
22
|
-
token;
|
|
23
|
-
/** User who created the webhook. */
|
|
24
|
-
user;
|
|
25
|
-
/** @param data - API webhook from POST /channels/{id}/webhooks (has token) or GET /webhooks/{id} (no token) */
|
|
26
|
-
constructor(client, data) {
|
|
27
|
-
super();
|
|
28
|
-
this.client = client;
|
|
29
|
-
this.id = data.id;
|
|
30
|
-
this.guildId = data.guild_id;
|
|
31
|
-
this.channelId = data.channel_id;
|
|
32
|
-
this.name = data.name ?? "Unknown";
|
|
33
|
-
this.avatar = data.avatar ?? null;
|
|
34
|
-
this.token = data.token ?? null;
|
|
35
|
-
this.user = client.getOrCreateUser(data.user);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get the URL for this webhook's avatar.
|
|
39
|
-
* Returns null if the webhook has no custom avatar.
|
|
40
|
-
*/
|
|
41
|
-
avatarURL(options) {
|
|
42
|
-
return cdnAvatarURL(this.id, this.avatar, options);
|
|
43
|
-
}
|
|
44
|
-
/** Delete this webhook. Requires bot token with Manage Webhooks permission. */
|
|
45
|
-
async delete() {
|
|
46
|
-
await this.client.rest.delete(Routes.webhook(this.id), { auth: true });
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Edit this webhook. With token: name and avatar only. Without token (bot auth): name, avatar, and channel_id.
|
|
50
|
-
* @param options - Fields to update (name, avatar, channel_id when using bot auth)
|
|
51
|
-
* @returns This webhook instance with updated fields
|
|
52
|
-
*/
|
|
53
|
-
async edit(options) {
|
|
54
|
-
const body = {};
|
|
55
|
-
if (options.name !== void 0) body.name = options.name;
|
|
56
|
-
if (options.avatar !== void 0) body.avatar = options.avatar;
|
|
57
|
-
if ("channel_id" in options && options.channel_id !== void 0 && !this.token) {
|
|
58
|
-
body.channel_id = options.channel_id;
|
|
59
|
-
}
|
|
60
|
-
if (this.token) {
|
|
61
|
-
const data2 = await this.client.rest.patch(Routes.webhookExecute(this.id, this.token), {
|
|
62
|
-
body,
|
|
63
|
-
auth: false
|
|
64
|
-
});
|
|
65
|
-
const w2 = data2;
|
|
66
|
-
this.name = w2.name ?? this.name;
|
|
67
|
-
this.avatar = w2.avatar ?? null;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
const data = await this.client.rest.patch(Routes.webhook(this.id), {
|
|
71
|
-
body,
|
|
72
|
-
auth: true
|
|
73
|
-
});
|
|
74
|
-
const w = data;
|
|
75
|
-
this.name = w.name ?? this.name;
|
|
76
|
-
this.avatar = w.avatar ?? null;
|
|
77
|
-
this.channelId = w.channel_id ?? this.channelId;
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Send a message via this webhook. Requires the webhook token (only present when created, not when fetched).
|
|
82
|
-
* @param options - Text content or object with content, embeds, username, avatar_url, tts, files, attachments
|
|
83
|
-
* @param wait - If true, waits for the API and returns the created Message; otherwise returns void (204)
|
|
84
|
-
* @throws Error if token is not available
|
|
85
|
-
* @example
|
|
86
|
-
* await webhook.send('Hello!');
|
|
87
|
-
* await webhook.send({ embeds: [embed] });
|
|
88
|
-
* await webhook.send({ content: 'File attached', files: [{ name: 'data.txt', data: buffer }] });
|
|
89
|
-
* const msg = await webhook.send({ content: 'Hi' }, true);
|
|
90
|
-
*/
|
|
91
|
-
async send(options, wait) {
|
|
92
|
-
if (!this.token) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
"Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send."
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
const opts = typeof options === "string" ? { content: options } : options;
|
|
98
|
-
const body = buildSendBody(options);
|
|
99
|
-
if (opts.username !== void 0) body.username = opts.username;
|
|
100
|
-
if (opts.avatar_url !== void 0) body.avatar_url = opts.avatar_url;
|
|
101
|
-
if (opts.tts !== void 0) body.tts = opts.tts;
|
|
102
|
-
const route = Routes.webhookExecute(this.id, this.token) + (wait ? "?wait=true" : "");
|
|
103
|
-
const files = opts.files?.length ? await resolveMessageFiles(opts.files) : void 0;
|
|
104
|
-
const postOptions = files?.length ? { body, files, auth: false } : { body, auth: false };
|
|
105
|
-
const data = await this.client.rest.post(
|
|
106
|
-
route,
|
|
107
|
-
postOptions
|
|
108
|
-
);
|
|
109
|
-
if (wait && data) {
|
|
110
|
-
const { Message } = await import("./Message-R7KSI5YU.mjs");
|
|
111
|
-
return new Message(this.client, data);
|
|
112
|
-
}
|
|
113
|
-
return void 0;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Fetch a webhook by ID using bot auth.
|
|
117
|
-
* @param client - The client instance
|
|
118
|
-
* @param webhookId - The webhook ID
|
|
119
|
-
* @returns Webhook without token (cannot send)
|
|
120
|
-
*/
|
|
121
|
-
static async fetch(client, webhookId) {
|
|
122
|
-
const data = await client.rest.get(Routes.webhook(webhookId));
|
|
123
|
-
return new _Webhook(client, data);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Create a Webhook instance from an ID and token (e.g. from a stored webhook URL).
|
|
127
|
-
* @param client - The client instance
|
|
128
|
-
* @param webhookId - The webhook ID
|
|
129
|
-
* @param token - The webhook token (from createWebhook or stored)
|
|
130
|
-
* @param options - Optional channelId, guildId, name for display
|
|
131
|
-
*/
|
|
132
|
-
static fromToken(client, webhookId, token, options) {
|
|
133
|
-
return new _Webhook(client, {
|
|
134
|
-
id: webhookId,
|
|
135
|
-
guild_id: options?.guildId ?? "",
|
|
136
|
-
channel_id: options?.channelId ?? "",
|
|
137
|
-
name: options?.name ?? "Webhook",
|
|
138
|
-
avatar: null,
|
|
139
|
-
token,
|
|
140
|
-
user: { id: "", username: "webhook", discriminator: "0" }
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export {
|
|
146
|
-
Webhook
|
|
147
|
-
};
|
package/dist/chunk-6S3BDHBI.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// src/errors/FluxerError.ts
|
|
2
|
-
var FluxerError = class _FluxerError extends Error {
|
|
3
|
-
code;
|
|
4
|
-
constructor(message, options) {
|
|
5
|
-
super(message, options?.cause ? { cause: options.cause } : void 0);
|
|
6
|
-
this.name = "FluxerError";
|
|
7
|
-
this.code = options?.code;
|
|
8
|
-
Object.setPrototypeOf(this, _FluxerError.prototype);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/errors/ErrorCodes.ts
|
|
13
|
-
var ErrorCodes = {
|
|
14
|
-
ClientNotReady: "CLIENT_NOT_READY",
|
|
15
|
-
InvalidToken: "INVALID_TOKEN",
|
|
16
|
-
AlreadyLoggedIn: "ALREADY_LOGGED_IN",
|
|
17
|
-
ChannelNotFound: "CHANNEL_NOT_FOUND",
|
|
18
|
-
MessageNotFound: "MESSAGE_NOT_FOUND",
|
|
19
|
-
GuildNotFound: "GUILD_NOT_FOUND",
|
|
20
|
-
MemberNotFound: "MEMBER_NOT_FOUND",
|
|
21
|
-
RoleNotFound: "ROLE_NOT_FOUND",
|
|
22
|
-
EmojiNotInGuild: "EMOJI_NOT_IN_GUILD"
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
FluxerError,
|
|
27
|
-
ErrorCodes
|
|
28
|
-
};
|