@stoatx/client 0.3.0 → 0.4.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 +391 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +244 -30
- package/dist/index.d.ts +244 -30
- package/dist/index.js +389 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,8 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Attachment: () => Attachment,
|
|
34
|
+
AttachmentBuilder: () => AttachmentBuilder,
|
|
34
35
|
Base: () => Base,
|
|
35
36
|
BaseChannel: () => BaseChannel,
|
|
37
|
+
BitField: () => BitField,
|
|
36
38
|
ChannelManager: () => ChannelManager,
|
|
37
39
|
ChannelType: () => ChannelType,
|
|
38
40
|
Client: () => Client,
|
|
@@ -1240,9 +1242,9 @@ var RESTManager = class {
|
|
|
1240
1242
|
/**
|
|
1241
1243
|
* Uploads a file to Stoat's CDN and returns the File ID
|
|
1242
1244
|
*/
|
|
1243
|
-
async uploadFile(
|
|
1245
|
+
async uploadFile(tag, fileBuffer, filename) {
|
|
1244
1246
|
if (!this.token) throw new Error("REST_NOT_READY: No token available.");
|
|
1245
|
-
const url =
|
|
1247
|
+
const url = `https://cdn.stoatusercontent.com/${tag}`;
|
|
1246
1248
|
const formData = new FormData();
|
|
1247
1249
|
formData.append("file", new Blob([fileBuffer]), filename);
|
|
1248
1250
|
const response = await fetch(url, {
|
|
@@ -1310,6 +1312,42 @@ var BaseManager = class {
|
|
|
1310
1312
|
}
|
|
1311
1313
|
};
|
|
1312
1314
|
|
|
1315
|
+
// src/builders/AttachmentBuilder.ts
|
|
1316
|
+
var AttachmentBuilder = class {
|
|
1317
|
+
// Filename for CDN to use, optional but recommended
|
|
1318
|
+
filename = void 0;
|
|
1319
|
+
file;
|
|
1320
|
+
/**
|
|
1321
|
+
* Creates a new AttachmentBuilder with the given file and optional filename.
|
|
1322
|
+
* @param file The file data as a Buffer or Blob.
|
|
1323
|
+
* @param filename An optional filename to use for the uploaded file. If not provided, the CDN will assign a default name.
|
|
1324
|
+
* Providing a filename can help with organization and debugging, but is not strictly required.
|
|
1325
|
+
* @example
|
|
1326
|
+
* // Create an attachment from a Buffer with a custom filename
|
|
1327
|
+
* const buffer = Buffer.from("Hello, world!");
|
|
1328
|
+
* const attachment = new AttachmentBuilder(buffer, "greeting.txt");
|
|
1329
|
+
*/
|
|
1330
|
+
constructor(file, filename) {
|
|
1331
|
+
this.filename = filename;
|
|
1332
|
+
this.file = file;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Uploads this attachment to the Stoat CDN and returns the resulting file ID.
|
|
1336
|
+
* @internal — use `resolveAttachment()` instead of calling this directly.
|
|
1337
|
+
*/
|
|
1338
|
+
async upload(rest, tag) {
|
|
1339
|
+
return rest.uploadFile(tag, this.file, this.filename);
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
// src/utils/resolveAttachment.ts
|
|
1344
|
+
async function resolveAttachment(rest, value, tag) {
|
|
1345
|
+
if (value instanceof AttachmentBuilder) {
|
|
1346
|
+
return value.upload(rest, tag);
|
|
1347
|
+
}
|
|
1348
|
+
return value;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1313
1351
|
// src/managers/MessageManager.ts
|
|
1314
1352
|
var MessageManager = class extends BaseManager {
|
|
1315
1353
|
constructor(client, channel, limit = Infinity) {
|
|
@@ -1385,6 +1423,13 @@ var MessageManager = class extends BaseManager {
|
|
|
1385
1423
|
(embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed
|
|
1386
1424
|
);
|
|
1387
1425
|
}
|
|
1426
|
+
if (payload.attachments) {
|
|
1427
|
+
payload.attachments = await Promise.all(
|
|
1428
|
+
payload.attachments.map(
|
|
1429
|
+
(attachment) => resolveAttachment(this.client.rest, attachment, "attachments")
|
|
1430
|
+
)
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1388
1433
|
const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
|
|
1389
1434
|
return new Message(this.client, data);
|
|
1390
1435
|
}
|
|
@@ -1993,6 +2038,233 @@ function createChannel(client, data) {
|
|
|
1993
2038
|
}
|
|
1994
2039
|
}
|
|
1995
2040
|
|
|
2041
|
+
// src/utils/BitField.ts
|
|
2042
|
+
var BitField = class _BitField {
|
|
2043
|
+
static Flags = {};
|
|
2044
|
+
static DefaultBit = 0;
|
|
2045
|
+
bitfield;
|
|
2046
|
+
constructor(bits) {
|
|
2047
|
+
this.bitfield = this.constructor.resolve(
|
|
2048
|
+
bits ?? this.constructor.DefaultBit
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Checks whether this bitfield has any of the given bits set.
|
|
2053
|
+
*
|
|
2054
|
+
* @param bit The bit(s) to test against.
|
|
2055
|
+
* @returns `true` if at least one of the provided bits is set.
|
|
2056
|
+
*
|
|
2057
|
+
* @example
|
|
2058
|
+
* perms.any(['SendMessage', 'ManageChannel']); // true if either is set
|
|
2059
|
+
*/
|
|
2060
|
+
any(bit) {
|
|
2061
|
+
const resolved = this.constructor.resolve(bit);
|
|
2062
|
+
if (typeof this.bitfield === "bigint" && typeof resolved === "bigint") {
|
|
2063
|
+
return (this.bitfield & resolved) !== BigInt(0);
|
|
2064
|
+
}
|
|
2065
|
+
return (Number(this.bitfield) & Number(resolved)) !== 0;
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Checks whether this bitfield is exactly equal to the given bit value.
|
|
2069
|
+
*
|
|
2070
|
+
* @param bit The bit(s) to compare against.
|
|
2071
|
+
* @returns `true` if the resolved bit value is identical to this bitfield.
|
|
2072
|
+
*
|
|
2073
|
+
* @example
|
|
2074
|
+
* new Permissions(0n).equals(0n); // true
|
|
2075
|
+
*/
|
|
2076
|
+
equals(bit) {
|
|
2077
|
+
return this.bitfield === this.constructor.resolve(bit);
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* Checks whether this bitfield has *all* of the given bits set.
|
|
2081
|
+
*
|
|
2082
|
+
* @param bit The bit(s) to check for.
|
|
2083
|
+
* @returns `true` if every provided bit is set in this bitfield.
|
|
2084
|
+
*
|
|
2085
|
+
* @example
|
|
2086
|
+
* perms.has('SendMessage');
|
|
2087
|
+
* perms.has(['SendMessage', 'ViewChannel']); // true only if both are set
|
|
2088
|
+
*/
|
|
2089
|
+
has(bit, ..._hasParams) {
|
|
2090
|
+
const resolvedBit = this.constructor.resolve(bit);
|
|
2091
|
+
if (typeof this.bitfield === "bigint" && typeof resolvedBit === "bigint") {
|
|
2092
|
+
return (this.bitfield & resolvedBit) === resolvedBit;
|
|
2093
|
+
}
|
|
2094
|
+
return (Number(this.bitfield) & Number(resolvedBit)) === Number(resolvedBit);
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Returns the flag names present in `bits` that are *missing* from this bitfield.
|
|
2098
|
+
*
|
|
2099
|
+
* @param bits The bits to check against.
|
|
2100
|
+
* @returns An array of flag name strings that are in `bits` but not in this bitfield.
|
|
2101
|
+
*
|
|
2102
|
+
* @example
|
|
2103
|
+
* // If perms only has SendMessage:
|
|
2104
|
+
* perms.missing(['SendMessage', 'ManageChannel']); // ['ManageChannel']
|
|
2105
|
+
*/
|
|
2106
|
+
missing(bits, ...hasParams) {
|
|
2107
|
+
return new this.constructor(bits).remove(this).toArray(...hasParams);
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* Freezes this BitField instance, making it immutable.
|
|
2111
|
+
* Subsequent calls to `add()` or `remove()` will return a new instance instead of mutating this one.
|
|
2112
|
+
*
|
|
2113
|
+
* @returns This instance, frozen.
|
|
2114
|
+
*/
|
|
2115
|
+
freeze() {
|
|
2116
|
+
return Object.freeze(this);
|
|
2117
|
+
}
|
|
2118
|
+
/**
|
|
2119
|
+
* Adds one or more bits to this bitfield.
|
|
2120
|
+
* If the instance is frozen, returns a new BitField with the bits added.
|
|
2121
|
+
*
|
|
2122
|
+
* @param bits The bit(s) to add.
|
|
2123
|
+
* @returns This instance (or a new one if frozen), with the bits added.
|
|
2124
|
+
*
|
|
2125
|
+
* @example
|
|
2126
|
+
* perms.add('SendMessage', 'ViewChannel');
|
|
2127
|
+
*/
|
|
2128
|
+
add(...bits) {
|
|
2129
|
+
let total = this.constructor.DefaultBit;
|
|
2130
|
+
for (const bit of bits) {
|
|
2131
|
+
const resolved = this.constructor.resolve(bit);
|
|
2132
|
+
if (typeof total === "bigint" && typeof resolved === "bigint") {
|
|
2133
|
+
total |= resolved;
|
|
2134
|
+
} else {
|
|
2135
|
+
total = Number(total) | Number(resolved);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
if (typeof this.bitfield === "bigint" && typeof total === "bigint") {
|
|
2139
|
+
if (Object.isFrozen(this)) return new this.constructor(this.bitfield | total);
|
|
2140
|
+
this.bitfield |= total;
|
|
2141
|
+
} else {
|
|
2142
|
+
if (Object.isFrozen(this))
|
|
2143
|
+
return new this.constructor(Number(this.bitfield) | Number(total));
|
|
2144
|
+
this.bitfield = Number(this.bitfield) | Number(total);
|
|
2145
|
+
}
|
|
2146
|
+
return this;
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* Removes one or more bits from this bitfield.
|
|
2150
|
+
* If the instance is frozen, returns a new BitField with the bits removed.
|
|
2151
|
+
*
|
|
2152
|
+
* @param bits The bit(s) to remove.
|
|
2153
|
+
* @returns This instance (or a new one if frozen), with the bits cleared.
|
|
2154
|
+
*
|
|
2155
|
+
* @example
|
|
2156
|
+
* perms.remove('ManageChannel');
|
|
2157
|
+
*/
|
|
2158
|
+
remove(...bits) {
|
|
2159
|
+
let total = this.constructor.DefaultBit;
|
|
2160
|
+
for (const bit of bits) {
|
|
2161
|
+
const resolved = this.constructor.resolve(bit);
|
|
2162
|
+
if (typeof total === "bigint" && typeof resolved === "bigint") {
|
|
2163
|
+
total |= resolved;
|
|
2164
|
+
} else {
|
|
2165
|
+
total = Number(total) | Number(resolved);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
if (typeof this.bitfield === "bigint" && typeof total === "bigint") {
|
|
2169
|
+
if (Object.isFrozen(this)) return new this.constructor(this.bitfield & ~total);
|
|
2170
|
+
this.bitfield &= ~total;
|
|
2171
|
+
} else {
|
|
2172
|
+
if (Object.isFrozen(this))
|
|
2173
|
+
return new this.constructor(Number(this.bitfield) & ~Number(total));
|
|
2174
|
+
this.bitfield = Number(this.bitfield) & ~Number(total);
|
|
2175
|
+
}
|
|
2176
|
+
return this;
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Serializes this bitfield to a plain object mapping each flag name to a boolean
|
|
2180
|
+
* indicating whether that flag is set.
|
|
2181
|
+
*
|
|
2182
|
+
* @returns A record of `{ [flagName]: boolean }` for all defined flags.
|
|
2183
|
+
*
|
|
2184
|
+
* @example
|
|
2185
|
+
* perms.serialize();
|
|
2186
|
+
* // { SendMessage: true, ManageChannel: false, ... }
|
|
2187
|
+
*/
|
|
2188
|
+
serialize(...hasParams) {
|
|
2189
|
+
const serialized = {};
|
|
2190
|
+
for (const [flag, bit] of Object.entries(this.constructor.Flags)) {
|
|
2191
|
+
if (isNaN(Number(flag))) serialized[flag] = this.has(bit, ...hasParams);
|
|
2192
|
+
}
|
|
2193
|
+
return serialized;
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* Returns an array of flag names that are set in this bitfield.
|
|
2197
|
+
*
|
|
2198
|
+
* @returns An array of string flag names.
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* perms.toArray(); // ['SendMessage', 'ViewChannel']
|
|
2202
|
+
*/
|
|
2203
|
+
toArray(...hasParams) {
|
|
2204
|
+
return [...this[Symbol.iterator](...hasParams)];
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Returns the bitfield value as a JSON-safe primitive.
|
|
2208
|
+
* Numbers are returned as-is; bigints are converted to their string representation
|
|
2209
|
+
* to avoid JSON serialization errors.
|
|
2210
|
+
*/
|
|
2211
|
+
toJSON() {
|
|
2212
|
+
return typeof this.bitfield === "number" ? this.bitfield : this.bitfield.toString();
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Returns the underlying numeric value of this bitfield.
|
|
2216
|
+
* Allows BitField instances to be used directly in arithmetic expressions.
|
|
2217
|
+
*/
|
|
2218
|
+
valueOf() {
|
|
2219
|
+
return this.bitfield;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Iterates over the names of all flags that are set in this bitfield.
|
|
2223
|
+
*
|
|
2224
|
+
* @example
|
|
2225
|
+
* for (const flag of perms) {
|
|
2226
|
+
* console.log(flag); // 'SendMessage', 'ViewChannel', etc.
|
|
2227
|
+
* }
|
|
2228
|
+
*/
|
|
2229
|
+
*[Symbol.iterator](...hasParams) {
|
|
2230
|
+
for (const bitName of Object.keys(this.constructor.Flags)) {
|
|
2231
|
+
if (isNaN(Number(bitName)) && this.has(bitName, ...hasParams)) yield bitName;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
/**
|
|
2235
|
+
* Resolves a {@link BitFieldResolvable} into a raw `number | bigint`.
|
|
2236
|
+
*
|
|
2237
|
+
* Resolution rules (in order):
|
|
2238
|
+
* - `undefined` → `DefaultBit`
|
|
2239
|
+
* - A number or bigint matching `DefaultBit`'s type and >= 0 → returned as-is
|
|
2240
|
+
* - A `BitField` instance → its `.bitfield` value
|
|
2241
|
+
* - An array → each element resolved and OR'd together
|
|
2242
|
+
* - A numeric string → parsed as `BigInt` or `Number` depending on `DefaultBit`'s type
|
|
2243
|
+
* - A named string flag → looked up in `Flags`
|
|
2244
|
+
* - Anything else → throws `RangeError`
|
|
2245
|
+
*
|
|
2246
|
+
* @param bit The value to resolve.
|
|
2247
|
+
* @throws {RangeError} If the value cannot be resolved to a valid bit.
|
|
2248
|
+
*/
|
|
2249
|
+
static resolve(bit) {
|
|
2250
|
+
const { DefaultBit } = this;
|
|
2251
|
+
if (bit === void 0) return DefaultBit;
|
|
2252
|
+
if (typeof DefaultBit === typeof bit && bit >= DefaultBit) return bit;
|
|
2253
|
+
if (bit instanceof _BitField) return bit.bitfield;
|
|
2254
|
+
if (Array.isArray(bit)) {
|
|
2255
|
+
return bit.map((b) => this.resolve(b)).reduce((prev, b) => {
|
|
2256
|
+
if (typeof prev === "bigint" && typeof b === "bigint") return prev | b;
|
|
2257
|
+
return Number(prev) | Number(b);
|
|
2258
|
+
}, DefaultBit);
|
|
2259
|
+
}
|
|
2260
|
+
if (typeof bit === "string") {
|
|
2261
|
+
if (!isNaN(Number(bit))) return typeof DefaultBit === "bigint" ? BigInt(bit) : Number(bit);
|
|
2262
|
+
if (this.Flags[bit] !== void 0) return this.Flags[bit];
|
|
2263
|
+
}
|
|
2264
|
+
throw new RangeError(`Invalid bitfield flag or number: ${String(bit)}`);
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
|
|
1996
2268
|
// src/utils/permissions.ts
|
|
1997
2269
|
var PermissionFlags = {
|
|
1998
2270
|
// Server permissions
|
|
@@ -2036,26 +2308,26 @@ var PermissionFlags = {
|
|
|
2036
2308
|
// Grant all
|
|
2037
2309
|
GrantAllSafe: 0x000fffffffffffffn
|
|
2038
2310
|
};
|
|
2039
|
-
var Permissions = class {
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
if (typeof permission === "bigint") return permission;
|
|
2045
|
-
if (typeof permission === "string") {
|
|
2046
|
-
return PermissionFlags[permission] ?? 0n;
|
|
2047
|
-
}
|
|
2048
|
-
if (Array.isArray(permission)) {
|
|
2049
|
-
return permission.reduce((acc, p) => acc | this.resolve(p), 0n);
|
|
2050
|
-
}
|
|
2051
|
-
return 0n;
|
|
2311
|
+
var Permissions = class extends BitField {
|
|
2312
|
+
static Flags = PermissionFlags;
|
|
2313
|
+
static DefaultBit = 0n;
|
|
2314
|
+
static resolve(bit) {
|
|
2315
|
+
return super.resolve(bit);
|
|
2052
2316
|
}
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2317
|
+
has(bit) {
|
|
2318
|
+
return super.has(bit);
|
|
2319
|
+
}
|
|
2320
|
+
any(bit) {
|
|
2321
|
+
return super.any(bit);
|
|
2322
|
+
}
|
|
2323
|
+
missing(bits) {
|
|
2324
|
+
return super.missing(bits);
|
|
2325
|
+
}
|
|
2326
|
+
add(...bits) {
|
|
2327
|
+
return super.add(...bits);
|
|
2328
|
+
}
|
|
2329
|
+
remove(...bits) {
|
|
2330
|
+
return super.remove(...bits);
|
|
2059
2331
|
}
|
|
2060
2332
|
};
|
|
2061
2333
|
|
|
@@ -2164,7 +2436,7 @@ var ChannelManager = class extends BaseManager {
|
|
|
2164
2436
|
}
|
|
2165
2437
|
if (options.icon !== void 0) {
|
|
2166
2438
|
if (options.icon === null) remove.push("Icon");
|
|
2167
|
-
else payload.icon = options.icon;
|
|
2439
|
+
else payload.icon = await resolveAttachment(this.client.rest, options.icon, "icons");
|
|
2168
2440
|
}
|
|
2169
2441
|
if (remove.length > 0) payload.remove = remove;
|
|
2170
2442
|
if (Object.keys(payload).length === 0) return this.fetch(channel);
|
|
@@ -2410,15 +2682,15 @@ var Member = class extends Base {
|
|
|
2410
2682
|
/** Calculates the member's total permissions using BigInt */
|
|
2411
2683
|
get permissions() {
|
|
2412
2684
|
const server = this.server;
|
|
2413
|
-
if (!server) return 0n;
|
|
2685
|
+
if (!server) return new Permissions(0n);
|
|
2686
|
+
if (server.ownerId === this.id) {
|
|
2687
|
+
return new Permissions(PermissionFlags.GrantAllSafe);
|
|
2688
|
+
}
|
|
2414
2689
|
let totalPerms = server.defaultPermissions ?? 0n;
|
|
2415
2690
|
for (const role of this.roles.cache.values()) {
|
|
2416
|
-
totalPerms |= BigInt(role.permissions);
|
|
2691
|
+
totalPerms |= BigInt(role.permissions.bitfield);
|
|
2417
2692
|
}
|
|
2418
|
-
|
|
2419
|
-
return PermissionFlags.GrantAllSafe;
|
|
2420
|
-
}
|
|
2421
|
-
return totalPerms;
|
|
2693
|
+
return new Permissions(totalPerms);
|
|
2422
2694
|
}
|
|
2423
2695
|
/** Get avatar URL for this member, or null if they don't have one.
|
|
2424
2696
|
* @example
|
|
@@ -2482,10 +2754,6 @@ var Member = class extends Base {
|
|
|
2482
2754
|
async setNickname(nickname) {
|
|
2483
2755
|
return this.edit({ nickname });
|
|
2484
2756
|
}
|
|
2485
|
-
/** Checks if the member has a specific permission */
|
|
2486
|
-
hasPermission(permission) {
|
|
2487
|
-
return Permissions.has(this.permissions, permission);
|
|
2488
|
-
}
|
|
2489
2757
|
/**
|
|
2490
2758
|
* Edit this member.
|
|
2491
2759
|
* @param options The options to edit the member with (nickname, roles, timeout, etc.)
|
|
@@ -2752,7 +3020,8 @@ var Role = class extends Base {
|
|
|
2752
3020
|
color = null;
|
|
2753
3021
|
hoist = false;
|
|
2754
3022
|
rank = 0;
|
|
2755
|
-
|
|
3023
|
+
icon = null;
|
|
3024
|
+
_permissions = 0n;
|
|
2756
3025
|
constructor(client, data, serverId) {
|
|
2757
3026
|
super(client, data);
|
|
2758
3027
|
this.serverId = serverId;
|
|
@@ -2767,16 +3036,17 @@ var Role = class extends Base {
|
|
|
2767
3036
|
if (data.color !== void 0) this.color = data.color;
|
|
2768
3037
|
if (data.hoist !== void 0) this.hoist = data.hoist;
|
|
2769
3038
|
if (data.rank !== void 0) this.rank = data.rank;
|
|
3039
|
+
if (data.icon !== void 0) this.icon = new Attachment(this.client, data.icon);
|
|
2770
3040
|
if (data.permissions !== void 0) {
|
|
2771
3041
|
try {
|
|
2772
3042
|
if (typeof data.permissions === "object" && data.permissions !== null) {
|
|
2773
3043
|
const allowPerms = data.permissions.a ?? data.permissions[0] ?? 0;
|
|
2774
|
-
this.
|
|
3044
|
+
this._permissions = BigInt(allowPerms);
|
|
2775
3045
|
} else {
|
|
2776
|
-
this.
|
|
3046
|
+
this._permissions = BigInt(data.permissions);
|
|
2777
3047
|
}
|
|
2778
3048
|
} catch {
|
|
2779
|
-
this.
|
|
3049
|
+
this._permissions = 0n;
|
|
2780
3050
|
}
|
|
2781
3051
|
}
|
|
2782
3052
|
}
|
|
@@ -2788,12 +3058,10 @@ var Role = class extends Base {
|
|
|
2788
3058
|
return this.client.servers.cache.get(this.serverId);
|
|
2789
3059
|
}
|
|
2790
3060
|
/**
|
|
2791
|
-
*
|
|
2792
|
-
* @param permission The permission to check for.
|
|
2793
|
-
* @returns True if the role has the permission.
|
|
3061
|
+
* Permissions for this role
|
|
2794
3062
|
*/
|
|
2795
|
-
|
|
2796
|
-
return Permissions
|
|
3063
|
+
get permissions() {
|
|
3064
|
+
return new Permissions(this._permissions);
|
|
2797
3065
|
}
|
|
2798
3066
|
/**
|
|
2799
3067
|
* Fetches this role directly from the API to ensure data is up to date.
|
|
@@ -2821,10 +3089,10 @@ var Role = class extends Base {
|
|
|
2821
3089
|
* @throws {Error} If the API request fails (e.g., lack of permissions).
|
|
2822
3090
|
* @example
|
|
2823
3091
|
* // Change the role's name and color
|
|
2824
|
-
* await role.edit({ name: "Senior Admin",
|
|
3092
|
+
* await role.edit({ name: "Senior Admin", color: "#FFD700" });
|
|
2825
3093
|
*
|
|
2826
3094
|
* // Remove the custom color from the role
|
|
2827
|
-
* await role.edit({
|
|
3095
|
+
* await role.edit({ color: null });
|
|
2828
3096
|
*/
|
|
2829
3097
|
async edit(options) {
|
|
2830
3098
|
let server = this.server;
|
|
@@ -2883,6 +3151,73 @@ var Role = class extends Base {
|
|
|
2883
3151
|
await server.roles.setRanks(filteredRoles);
|
|
2884
3152
|
return this;
|
|
2885
3153
|
}
|
|
3154
|
+
/**
|
|
3155
|
+
* Change the name for this role
|
|
3156
|
+
* @param name The new name for the role
|
|
3157
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3158
|
+
* @throws {Error} If API request fails.
|
|
3159
|
+
* @example
|
|
3160
|
+
* // Change the role's name
|
|
3161
|
+
* await role.setName("New Role Name");
|
|
3162
|
+
* console.log(`Role's new name: ${role.name}`);
|
|
3163
|
+
*/
|
|
3164
|
+
async setName(name) {
|
|
3165
|
+
return await this.edit({ name });
|
|
3166
|
+
}
|
|
3167
|
+
/**
|
|
3168
|
+
* Change the color for this role, it can be a HEX or CSS colours
|
|
3169
|
+
* @param {[string]} color The new color for the role
|
|
3170
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3171
|
+
* @throws {Error} If API request fails
|
|
3172
|
+
* @example
|
|
3173
|
+
* // Change the role's color
|
|
3174
|
+
* await role.setColour("#FF0000");
|
|
3175
|
+
* console.log(`Role's new color: ${role.color}`);
|
|
3176
|
+
*
|
|
3177
|
+
* // Use CSS color linear-graident
|
|
3178
|
+
* await role.setColour("linear-gradient(90deg, #FF0000, #0000FF)");
|
|
3179
|
+
* console.log(`Role's new color: ${role.color}`);
|
|
3180
|
+
*
|
|
3181
|
+
* // Remove the custom color from the role
|
|
3182
|
+
* await role.setColour(null);
|
|
3183
|
+
* console.log(`Role's color removed, current color: ${role.color}`);
|
|
3184
|
+
*/
|
|
3185
|
+
async setColor(color) {
|
|
3186
|
+
return await this.edit({ color });
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* Edit the icon of this role
|
|
3190
|
+
* @param icon Autumn ID for the new icon, or null to remove the custom icon
|
|
3191
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3192
|
+
* @throws {Error} If API request fails
|
|
3193
|
+
* @example
|
|
3194
|
+
* // Set a new icon for the role
|
|
3195
|
+
* await role.setIcon("AUTUMN_ID_FOR_ICON");
|
|
3196
|
+
* console.log(`Role's new icon: ${role.icon}`);
|
|
3197
|
+
*
|
|
3198
|
+
* // Use AttachmentBuilder to upload a new icon file
|
|
3199
|
+
* import { readFile } from "node:fs/promises";
|
|
3200
|
+
* const iconFile = await readFile("./a.jpg");
|
|
3201
|
+
* const attachment = new AttachmentBuilder(iconFile, "a.jpg");
|
|
3202
|
+
* await role.setIcon(attachment);
|
|
3203
|
+
* console.log(`Role's new icon: ${role.icon}`);
|
|
3204
|
+
*/
|
|
3205
|
+
async setIcon(icon) {
|
|
3206
|
+
return await this.edit({ icon });
|
|
3207
|
+
}
|
|
3208
|
+
/**
|
|
3209
|
+
* Change the hoist status for this role
|
|
3210
|
+
* @param hoist The new hoist status for the role
|
|
3211
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3212
|
+
* @throws {Error} If API request fails
|
|
3213
|
+
* @example
|
|
3214
|
+
* // Enable hoisting for the role
|
|
3215
|
+
* await role.setHoist(true);
|
|
3216
|
+
* console.log(`Role is now hoisted: ${role.hoist}`);
|
|
3217
|
+
*/
|
|
3218
|
+
async setHoist(hoist) {
|
|
3219
|
+
return await this.edit({ hoist });
|
|
3220
|
+
}
|
|
2886
3221
|
/**
|
|
2887
3222
|
* Customizer for Node.js `console.log` and `util.inspect`.
|
|
2888
3223
|
* Hides the cyclic client reference and raw serverId for a cleaner output.
|
|
@@ -3020,7 +3355,7 @@ var RoleManager = class extends BaseManager {
|
|
|
3020
3355
|
}
|
|
3021
3356
|
/**
|
|
3022
3357
|
* Edits an existing role in the server.
|
|
3023
|
-
* @param role The RoleResolvable to edit.
|
|
3358
|
+
* @param role The {@link RoleResolvable} to edit.
|
|
3024
3359
|
* @param options The fields to update.
|
|
3025
3360
|
* @returns A promise that resolves to the updated Role.
|
|
3026
3361
|
* @throws {TypeError} If invalid options or RoleResolvable are provided.
|
|
@@ -3041,11 +3376,18 @@ var RoleManager = class extends BaseManager {
|
|
|
3041
3376
|
const remove = [];
|
|
3042
3377
|
if (options.name !== void 0) payload.name = options.name;
|
|
3043
3378
|
if (options.hoist !== void 0) payload.hoist = options.hoist;
|
|
3044
|
-
if (options.
|
|
3045
|
-
if (options.
|
|
3379
|
+
if (options.color !== void 0) {
|
|
3380
|
+
if (options.color === null) {
|
|
3046
3381
|
remove.push("Colour");
|
|
3047
3382
|
} else {
|
|
3048
|
-
payload.colour = options.
|
|
3383
|
+
payload.colour = options.color;
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
if (options.icon !== void 0) {
|
|
3387
|
+
if (options.icon === null) {
|
|
3388
|
+
remove.push("Icon");
|
|
3389
|
+
} else {
|
|
3390
|
+
payload.icon = await resolveAttachment(this.client.rest, options.icon, "icons");
|
|
3049
3391
|
}
|
|
3050
3392
|
}
|
|
3051
3393
|
if (remove.length > 0) {
|
|
@@ -3774,8 +4116,10 @@ var EmbedBuilder = class {
|
|
|
3774
4116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3775
4117
|
0 && (module.exports = {
|
|
3776
4118
|
Attachment,
|
|
4119
|
+
AttachmentBuilder,
|
|
3777
4120
|
Base,
|
|
3778
4121
|
BaseChannel,
|
|
4122
|
+
BitField,
|
|
3779
4123
|
ChannelManager,
|
|
3780
4124
|
ChannelType,
|
|
3781
4125
|
Client,
|