@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.js
CHANGED
|
@@ -1168,9 +1168,9 @@ var RESTManager = class {
|
|
|
1168
1168
|
/**
|
|
1169
1169
|
* Uploads a file to Stoat's CDN and returns the File ID
|
|
1170
1170
|
*/
|
|
1171
|
-
async uploadFile(
|
|
1171
|
+
async uploadFile(tag, fileBuffer, filename) {
|
|
1172
1172
|
if (!this.token) throw new Error("REST_NOT_READY: No token available.");
|
|
1173
|
-
const url =
|
|
1173
|
+
const url = `https://cdn.stoatusercontent.com/${tag}`;
|
|
1174
1174
|
const formData = new FormData();
|
|
1175
1175
|
formData.append("file", new Blob([fileBuffer]), filename);
|
|
1176
1176
|
const response = await fetch(url, {
|
|
@@ -1238,6 +1238,42 @@ var BaseManager = class {
|
|
|
1238
1238
|
}
|
|
1239
1239
|
};
|
|
1240
1240
|
|
|
1241
|
+
// src/builders/AttachmentBuilder.ts
|
|
1242
|
+
var AttachmentBuilder = class {
|
|
1243
|
+
// Filename for CDN to use, optional but recommended
|
|
1244
|
+
filename = void 0;
|
|
1245
|
+
file;
|
|
1246
|
+
/**
|
|
1247
|
+
* Creates a new AttachmentBuilder with the given file and optional filename.
|
|
1248
|
+
* @param file The file data as a Buffer or Blob.
|
|
1249
|
+
* @param filename An optional filename to use for the uploaded file. If not provided, the CDN will assign a default name.
|
|
1250
|
+
* Providing a filename can help with organization and debugging, but is not strictly required.
|
|
1251
|
+
* @example
|
|
1252
|
+
* // Create an attachment from a Buffer with a custom filename
|
|
1253
|
+
* const buffer = Buffer.from("Hello, world!");
|
|
1254
|
+
* const attachment = new AttachmentBuilder(buffer, "greeting.txt");
|
|
1255
|
+
*/
|
|
1256
|
+
constructor(file, filename) {
|
|
1257
|
+
this.filename = filename;
|
|
1258
|
+
this.file = file;
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Uploads this attachment to the Stoat CDN and returns the resulting file ID.
|
|
1262
|
+
* @internal — use `resolveAttachment()` instead of calling this directly.
|
|
1263
|
+
*/
|
|
1264
|
+
async upload(rest, tag) {
|
|
1265
|
+
return rest.uploadFile(tag, this.file, this.filename);
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
// src/utils/resolveAttachment.ts
|
|
1270
|
+
async function resolveAttachment(rest, value, tag) {
|
|
1271
|
+
if (value instanceof AttachmentBuilder) {
|
|
1272
|
+
return value.upload(rest, tag);
|
|
1273
|
+
}
|
|
1274
|
+
return value;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1241
1277
|
// src/managers/MessageManager.ts
|
|
1242
1278
|
var MessageManager = class extends BaseManager {
|
|
1243
1279
|
constructor(client, channel, limit = Infinity) {
|
|
@@ -1313,6 +1349,13 @@ var MessageManager = class extends BaseManager {
|
|
|
1313
1349
|
(embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed
|
|
1314
1350
|
);
|
|
1315
1351
|
}
|
|
1352
|
+
if (payload.attachments) {
|
|
1353
|
+
payload.attachments = await Promise.all(
|
|
1354
|
+
payload.attachments.map(
|
|
1355
|
+
(attachment) => resolveAttachment(this.client.rest, attachment, "attachments")
|
|
1356
|
+
)
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1316
1359
|
const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
|
|
1317
1360
|
return new Message(this.client, data);
|
|
1318
1361
|
}
|
|
@@ -1921,6 +1964,233 @@ function createChannel(client, data) {
|
|
|
1921
1964
|
}
|
|
1922
1965
|
}
|
|
1923
1966
|
|
|
1967
|
+
// src/utils/BitField.ts
|
|
1968
|
+
var BitField = class _BitField {
|
|
1969
|
+
static Flags = {};
|
|
1970
|
+
static DefaultBit = 0;
|
|
1971
|
+
bitfield;
|
|
1972
|
+
constructor(bits) {
|
|
1973
|
+
this.bitfield = this.constructor.resolve(
|
|
1974
|
+
bits ?? this.constructor.DefaultBit
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Checks whether this bitfield has any of the given bits set.
|
|
1979
|
+
*
|
|
1980
|
+
* @param bit The bit(s) to test against.
|
|
1981
|
+
* @returns `true` if at least one of the provided bits is set.
|
|
1982
|
+
*
|
|
1983
|
+
* @example
|
|
1984
|
+
* perms.any(['SendMessage', 'ManageChannel']); // true if either is set
|
|
1985
|
+
*/
|
|
1986
|
+
any(bit) {
|
|
1987
|
+
const resolved = this.constructor.resolve(bit);
|
|
1988
|
+
if (typeof this.bitfield === "bigint" && typeof resolved === "bigint") {
|
|
1989
|
+
return (this.bitfield & resolved) !== BigInt(0);
|
|
1990
|
+
}
|
|
1991
|
+
return (Number(this.bitfield) & Number(resolved)) !== 0;
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Checks whether this bitfield is exactly equal to the given bit value.
|
|
1995
|
+
*
|
|
1996
|
+
* @param bit The bit(s) to compare against.
|
|
1997
|
+
* @returns `true` if the resolved bit value is identical to this bitfield.
|
|
1998
|
+
*
|
|
1999
|
+
* @example
|
|
2000
|
+
* new Permissions(0n).equals(0n); // true
|
|
2001
|
+
*/
|
|
2002
|
+
equals(bit) {
|
|
2003
|
+
return this.bitfield === this.constructor.resolve(bit);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Checks whether this bitfield has *all* of the given bits set.
|
|
2007
|
+
*
|
|
2008
|
+
* @param bit The bit(s) to check for.
|
|
2009
|
+
* @returns `true` if every provided bit is set in this bitfield.
|
|
2010
|
+
*
|
|
2011
|
+
* @example
|
|
2012
|
+
* perms.has('SendMessage');
|
|
2013
|
+
* perms.has(['SendMessage', 'ViewChannel']); // true only if both are set
|
|
2014
|
+
*/
|
|
2015
|
+
has(bit, ..._hasParams) {
|
|
2016
|
+
const resolvedBit = this.constructor.resolve(bit);
|
|
2017
|
+
if (typeof this.bitfield === "bigint" && typeof resolvedBit === "bigint") {
|
|
2018
|
+
return (this.bitfield & resolvedBit) === resolvedBit;
|
|
2019
|
+
}
|
|
2020
|
+
return (Number(this.bitfield) & Number(resolvedBit)) === Number(resolvedBit);
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
2023
|
+
* Returns the flag names present in `bits` that are *missing* from this bitfield.
|
|
2024
|
+
*
|
|
2025
|
+
* @param bits The bits to check against.
|
|
2026
|
+
* @returns An array of flag name strings that are in `bits` but not in this bitfield.
|
|
2027
|
+
*
|
|
2028
|
+
* @example
|
|
2029
|
+
* // If perms only has SendMessage:
|
|
2030
|
+
* perms.missing(['SendMessage', 'ManageChannel']); // ['ManageChannel']
|
|
2031
|
+
*/
|
|
2032
|
+
missing(bits, ...hasParams) {
|
|
2033
|
+
return new this.constructor(bits).remove(this).toArray(...hasParams);
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Freezes this BitField instance, making it immutable.
|
|
2037
|
+
* Subsequent calls to `add()` or `remove()` will return a new instance instead of mutating this one.
|
|
2038
|
+
*
|
|
2039
|
+
* @returns This instance, frozen.
|
|
2040
|
+
*/
|
|
2041
|
+
freeze() {
|
|
2042
|
+
return Object.freeze(this);
|
|
2043
|
+
}
|
|
2044
|
+
/**
|
|
2045
|
+
* Adds one or more bits to this bitfield.
|
|
2046
|
+
* If the instance is frozen, returns a new BitField with the bits added.
|
|
2047
|
+
*
|
|
2048
|
+
* @param bits The bit(s) to add.
|
|
2049
|
+
* @returns This instance (or a new one if frozen), with the bits added.
|
|
2050
|
+
*
|
|
2051
|
+
* @example
|
|
2052
|
+
* perms.add('SendMessage', 'ViewChannel');
|
|
2053
|
+
*/
|
|
2054
|
+
add(...bits) {
|
|
2055
|
+
let total = this.constructor.DefaultBit;
|
|
2056
|
+
for (const bit of bits) {
|
|
2057
|
+
const resolved = this.constructor.resolve(bit);
|
|
2058
|
+
if (typeof total === "bigint" && typeof resolved === "bigint") {
|
|
2059
|
+
total |= resolved;
|
|
2060
|
+
} else {
|
|
2061
|
+
total = Number(total) | Number(resolved);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
if (typeof this.bitfield === "bigint" && typeof total === "bigint") {
|
|
2065
|
+
if (Object.isFrozen(this)) return new this.constructor(this.bitfield | total);
|
|
2066
|
+
this.bitfield |= total;
|
|
2067
|
+
} else {
|
|
2068
|
+
if (Object.isFrozen(this))
|
|
2069
|
+
return new this.constructor(Number(this.bitfield) | Number(total));
|
|
2070
|
+
this.bitfield = Number(this.bitfield) | Number(total);
|
|
2071
|
+
}
|
|
2072
|
+
return this;
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Removes one or more bits from this bitfield.
|
|
2076
|
+
* If the instance is frozen, returns a new BitField with the bits removed.
|
|
2077
|
+
*
|
|
2078
|
+
* @param bits The bit(s) to remove.
|
|
2079
|
+
* @returns This instance (or a new one if frozen), with the bits cleared.
|
|
2080
|
+
*
|
|
2081
|
+
* @example
|
|
2082
|
+
* perms.remove('ManageChannel');
|
|
2083
|
+
*/
|
|
2084
|
+
remove(...bits) {
|
|
2085
|
+
let total = this.constructor.DefaultBit;
|
|
2086
|
+
for (const bit of bits) {
|
|
2087
|
+
const resolved = this.constructor.resolve(bit);
|
|
2088
|
+
if (typeof total === "bigint" && typeof resolved === "bigint") {
|
|
2089
|
+
total |= resolved;
|
|
2090
|
+
} else {
|
|
2091
|
+
total = Number(total) | Number(resolved);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
if (typeof this.bitfield === "bigint" && typeof total === "bigint") {
|
|
2095
|
+
if (Object.isFrozen(this)) return new this.constructor(this.bitfield & ~total);
|
|
2096
|
+
this.bitfield &= ~total;
|
|
2097
|
+
} else {
|
|
2098
|
+
if (Object.isFrozen(this))
|
|
2099
|
+
return new this.constructor(Number(this.bitfield) & ~Number(total));
|
|
2100
|
+
this.bitfield = Number(this.bitfield) & ~Number(total);
|
|
2101
|
+
}
|
|
2102
|
+
return this;
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Serializes this bitfield to a plain object mapping each flag name to a boolean
|
|
2106
|
+
* indicating whether that flag is set.
|
|
2107
|
+
*
|
|
2108
|
+
* @returns A record of `{ [flagName]: boolean }` for all defined flags.
|
|
2109
|
+
*
|
|
2110
|
+
* @example
|
|
2111
|
+
* perms.serialize();
|
|
2112
|
+
* // { SendMessage: true, ManageChannel: false, ... }
|
|
2113
|
+
*/
|
|
2114
|
+
serialize(...hasParams) {
|
|
2115
|
+
const serialized = {};
|
|
2116
|
+
for (const [flag, bit] of Object.entries(this.constructor.Flags)) {
|
|
2117
|
+
if (isNaN(Number(flag))) serialized[flag] = this.has(bit, ...hasParams);
|
|
2118
|
+
}
|
|
2119
|
+
return serialized;
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Returns an array of flag names that are set in this bitfield.
|
|
2123
|
+
*
|
|
2124
|
+
* @returns An array of string flag names.
|
|
2125
|
+
*
|
|
2126
|
+
* @example
|
|
2127
|
+
* perms.toArray(); // ['SendMessage', 'ViewChannel']
|
|
2128
|
+
*/
|
|
2129
|
+
toArray(...hasParams) {
|
|
2130
|
+
return [...this[Symbol.iterator](...hasParams)];
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* Returns the bitfield value as a JSON-safe primitive.
|
|
2134
|
+
* Numbers are returned as-is; bigints are converted to their string representation
|
|
2135
|
+
* to avoid JSON serialization errors.
|
|
2136
|
+
*/
|
|
2137
|
+
toJSON() {
|
|
2138
|
+
return typeof this.bitfield === "number" ? this.bitfield : this.bitfield.toString();
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* Returns the underlying numeric value of this bitfield.
|
|
2142
|
+
* Allows BitField instances to be used directly in arithmetic expressions.
|
|
2143
|
+
*/
|
|
2144
|
+
valueOf() {
|
|
2145
|
+
return this.bitfield;
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Iterates over the names of all flags that are set in this bitfield.
|
|
2149
|
+
*
|
|
2150
|
+
* @example
|
|
2151
|
+
* for (const flag of perms) {
|
|
2152
|
+
* console.log(flag); // 'SendMessage', 'ViewChannel', etc.
|
|
2153
|
+
* }
|
|
2154
|
+
*/
|
|
2155
|
+
*[Symbol.iterator](...hasParams) {
|
|
2156
|
+
for (const bitName of Object.keys(this.constructor.Flags)) {
|
|
2157
|
+
if (isNaN(Number(bitName)) && this.has(bitName, ...hasParams)) yield bitName;
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Resolves a {@link BitFieldResolvable} into a raw `number | bigint`.
|
|
2162
|
+
*
|
|
2163
|
+
* Resolution rules (in order):
|
|
2164
|
+
* - `undefined` → `DefaultBit`
|
|
2165
|
+
* - A number or bigint matching `DefaultBit`'s type and >= 0 → returned as-is
|
|
2166
|
+
* - A `BitField` instance → its `.bitfield` value
|
|
2167
|
+
* - An array → each element resolved and OR'd together
|
|
2168
|
+
* - A numeric string → parsed as `BigInt` or `Number` depending on `DefaultBit`'s type
|
|
2169
|
+
* - A named string flag → looked up in `Flags`
|
|
2170
|
+
* - Anything else → throws `RangeError`
|
|
2171
|
+
*
|
|
2172
|
+
* @param bit The value to resolve.
|
|
2173
|
+
* @throws {RangeError} If the value cannot be resolved to a valid bit.
|
|
2174
|
+
*/
|
|
2175
|
+
static resolve(bit) {
|
|
2176
|
+
const { DefaultBit } = this;
|
|
2177
|
+
if (bit === void 0) return DefaultBit;
|
|
2178
|
+
if (typeof DefaultBit === typeof bit && bit >= DefaultBit) return bit;
|
|
2179
|
+
if (bit instanceof _BitField) return bit.bitfield;
|
|
2180
|
+
if (Array.isArray(bit)) {
|
|
2181
|
+
return bit.map((b) => this.resolve(b)).reduce((prev, b) => {
|
|
2182
|
+
if (typeof prev === "bigint" && typeof b === "bigint") return prev | b;
|
|
2183
|
+
return Number(prev) | Number(b);
|
|
2184
|
+
}, DefaultBit);
|
|
2185
|
+
}
|
|
2186
|
+
if (typeof bit === "string") {
|
|
2187
|
+
if (!isNaN(Number(bit))) return typeof DefaultBit === "bigint" ? BigInt(bit) : Number(bit);
|
|
2188
|
+
if (this.Flags[bit] !== void 0) return this.Flags[bit];
|
|
2189
|
+
}
|
|
2190
|
+
throw new RangeError(`Invalid bitfield flag or number: ${String(bit)}`);
|
|
2191
|
+
}
|
|
2192
|
+
};
|
|
2193
|
+
|
|
1924
2194
|
// src/utils/permissions.ts
|
|
1925
2195
|
var PermissionFlags = {
|
|
1926
2196
|
// Server permissions
|
|
@@ -1964,26 +2234,26 @@ var PermissionFlags = {
|
|
|
1964
2234
|
// Grant all
|
|
1965
2235
|
GrantAllSafe: 0x000fffffffffffffn
|
|
1966
2236
|
};
|
|
1967
|
-
var Permissions = class {
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
if (typeof permission === "bigint") return permission;
|
|
1973
|
-
if (typeof permission === "string") {
|
|
1974
|
-
return PermissionFlags[permission] ?? 0n;
|
|
1975
|
-
}
|
|
1976
|
-
if (Array.isArray(permission)) {
|
|
1977
|
-
return permission.reduce((acc, p) => acc | this.resolve(p), 0n);
|
|
1978
|
-
}
|
|
1979
|
-
return 0n;
|
|
2237
|
+
var Permissions = class extends BitField {
|
|
2238
|
+
static Flags = PermissionFlags;
|
|
2239
|
+
static DefaultBit = 0n;
|
|
2240
|
+
static resolve(bit) {
|
|
2241
|
+
return super.resolve(bit);
|
|
1980
2242
|
}
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2243
|
+
has(bit) {
|
|
2244
|
+
return super.has(bit);
|
|
2245
|
+
}
|
|
2246
|
+
any(bit) {
|
|
2247
|
+
return super.any(bit);
|
|
2248
|
+
}
|
|
2249
|
+
missing(bits) {
|
|
2250
|
+
return super.missing(bits);
|
|
2251
|
+
}
|
|
2252
|
+
add(...bits) {
|
|
2253
|
+
return super.add(...bits);
|
|
2254
|
+
}
|
|
2255
|
+
remove(...bits) {
|
|
2256
|
+
return super.remove(...bits);
|
|
1987
2257
|
}
|
|
1988
2258
|
};
|
|
1989
2259
|
|
|
@@ -2092,7 +2362,7 @@ var ChannelManager = class extends BaseManager {
|
|
|
2092
2362
|
}
|
|
2093
2363
|
if (options.icon !== void 0) {
|
|
2094
2364
|
if (options.icon === null) remove.push("Icon");
|
|
2095
|
-
else payload.icon = options.icon;
|
|
2365
|
+
else payload.icon = await resolveAttachment(this.client.rest, options.icon, "icons");
|
|
2096
2366
|
}
|
|
2097
2367
|
if (remove.length > 0) payload.remove = remove;
|
|
2098
2368
|
if (Object.keys(payload).length === 0) return this.fetch(channel);
|
|
@@ -2338,15 +2608,15 @@ var Member = class extends Base {
|
|
|
2338
2608
|
/** Calculates the member's total permissions using BigInt */
|
|
2339
2609
|
get permissions() {
|
|
2340
2610
|
const server = this.server;
|
|
2341
|
-
if (!server) return 0n;
|
|
2611
|
+
if (!server) return new Permissions(0n);
|
|
2612
|
+
if (server.ownerId === this.id) {
|
|
2613
|
+
return new Permissions(PermissionFlags.GrantAllSafe);
|
|
2614
|
+
}
|
|
2342
2615
|
let totalPerms = server.defaultPermissions ?? 0n;
|
|
2343
2616
|
for (const role of this.roles.cache.values()) {
|
|
2344
|
-
totalPerms |= BigInt(role.permissions);
|
|
2617
|
+
totalPerms |= BigInt(role.permissions.bitfield);
|
|
2345
2618
|
}
|
|
2346
|
-
|
|
2347
|
-
return PermissionFlags.GrantAllSafe;
|
|
2348
|
-
}
|
|
2349
|
-
return totalPerms;
|
|
2619
|
+
return new Permissions(totalPerms);
|
|
2350
2620
|
}
|
|
2351
2621
|
/** Get avatar URL for this member, or null if they don't have one.
|
|
2352
2622
|
* @example
|
|
@@ -2410,10 +2680,6 @@ var Member = class extends Base {
|
|
|
2410
2680
|
async setNickname(nickname) {
|
|
2411
2681
|
return this.edit({ nickname });
|
|
2412
2682
|
}
|
|
2413
|
-
/** Checks if the member has a specific permission */
|
|
2414
|
-
hasPermission(permission) {
|
|
2415
|
-
return Permissions.has(this.permissions, permission);
|
|
2416
|
-
}
|
|
2417
2683
|
/**
|
|
2418
2684
|
* Edit this member.
|
|
2419
2685
|
* @param options The options to edit the member with (nickname, roles, timeout, etc.)
|
|
@@ -2680,7 +2946,8 @@ var Role = class extends Base {
|
|
|
2680
2946
|
color = null;
|
|
2681
2947
|
hoist = false;
|
|
2682
2948
|
rank = 0;
|
|
2683
|
-
|
|
2949
|
+
icon = null;
|
|
2950
|
+
_permissions = 0n;
|
|
2684
2951
|
constructor(client, data, serverId) {
|
|
2685
2952
|
super(client, data);
|
|
2686
2953
|
this.serverId = serverId;
|
|
@@ -2695,16 +2962,17 @@ var Role = class extends Base {
|
|
|
2695
2962
|
if (data.color !== void 0) this.color = data.color;
|
|
2696
2963
|
if (data.hoist !== void 0) this.hoist = data.hoist;
|
|
2697
2964
|
if (data.rank !== void 0) this.rank = data.rank;
|
|
2965
|
+
if (data.icon !== void 0) this.icon = new Attachment(this.client, data.icon);
|
|
2698
2966
|
if (data.permissions !== void 0) {
|
|
2699
2967
|
try {
|
|
2700
2968
|
if (typeof data.permissions === "object" && data.permissions !== null) {
|
|
2701
2969
|
const allowPerms = data.permissions.a ?? data.permissions[0] ?? 0;
|
|
2702
|
-
this.
|
|
2970
|
+
this._permissions = BigInt(allowPerms);
|
|
2703
2971
|
} else {
|
|
2704
|
-
this.
|
|
2972
|
+
this._permissions = BigInt(data.permissions);
|
|
2705
2973
|
}
|
|
2706
2974
|
} catch {
|
|
2707
|
-
this.
|
|
2975
|
+
this._permissions = 0n;
|
|
2708
2976
|
}
|
|
2709
2977
|
}
|
|
2710
2978
|
}
|
|
@@ -2716,12 +2984,10 @@ var Role = class extends Base {
|
|
|
2716
2984
|
return this.client.servers.cache.get(this.serverId);
|
|
2717
2985
|
}
|
|
2718
2986
|
/**
|
|
2719
|
-
*
|
|
2720
|
-
* @param permission The permission to check for.
|
|
2721
|
-
* @returns True if the role has the permission.
|
|
2987
|
+
* Permissions for this role
|
|
2722
2988
|
*/
|
|
2723
|
-
|
|
2724
|
-
return Permissions
|
|
2989
|
+
get permissions() {
|
|
2990
|
+
return new Permissions(this._permissions);
|
|
2725
2991
|
}
|
|
2726
2992
|
/**
|
|
2727
2993
|
* Fetches this role directly from the API to ensure data is up to date.
|
|
@@ -2749,10 +3015,10 @@ var Role = class extends Base {
|
|
|
2749
3015
|
* @throws {Error} If the API request fails (e.g., lack of permissions).
|
|
2750
3016
|
* @example
|
|
2751
3017
|
* // Change the role's name and color
|
|
2752
|
-
* await role.edit({ name: "Senior Admin",
|
|
3018
|
+
* await role.edit({ name: "Senior Admin", color: "#FFD700" });
|
|
2753
3019
|
*
|
|
2754
3020
|
* // Remove the custom color from the role
|
|
2755
|
-
* await role.edit({
|
|
3021
|
+
* await role.edit({ color: null });
|
|
2756
3022
|
*/
|
|
2757
3023
|
async edit(options) {
|
|
2758
3024
|
let server = this.server;
|
|
@@ -2811,6 +3077,73 @@ var Role = class extends Base {
|
|
|
2811
3077
|
await server.roles.setRanks(filteredRoles);
|
|
2812
3078
|
return this;
|
|
2813
3079
|
}
|
|
3080
|
+
/**
|
|
3081
|
+
* Change the name for this role
|
|
3082
|
+
* @param name The new name for the role
|
|
3083
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3084
|
+
* @throws {Error} If API request fails.
|
|
3085
|
+
* @example
|
|
3086
|
+
* // Change the role's name
|
|
3087
|
+
* await role.setName("New Role Name");
|
|
3088
|
+
* console.log(`Role's new name: ${role.name}`);
|
|
3089
|
+
*/
|
|
3090
|
+
async setName(name) {
|
|
3091
|
+
return await this.edit({ name });
|
|
3092
|
+
}
|
|
3093
|
+
/**
|
|
3094
|
+
* Change the color for this role, it can be a HEX or CSS colours
|
|
3095
|
+
* @param {[string]} color The new color for the role
|
|
3096
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3097
|
+
* @throws {Error} If API request fails
|
|
3098
|
+
* @example
|
|
3099
|
+
* // Change the role's color
|
|
3100
|
+
* await role.setColour("#FF0000");
|
|
3101
|
+
* console.log(`Role's new color: ${role.color}`);
|
|
3102
|
+
*
|
|
3103
|
+
* // Use CSS color linear-graident
|
|
3104
|
+
* await role.setColour("linear-gradient(90deg, #FF0000, #0000FF)");
|
|
3105
|
+
* console.log(`Role's new color: ${role.color}`);
|
|
3106
|
+
*
|
|
3107
|
+
* // Remove the custom color from the role
|
|
3108
|
+
* await role.setColour(null);
|
|
3109
|
+
* console.log(`Role's color removed, current color: ${role.color}`);
|
|
3110
|
+
*/
|
|
3111
|
+
async setColor(color) {
|
|
3112
|
+
return await this.edit({ color });
|
|
3113
|
+
}
|
|
3114
|
+
/**
|
|
3115
|
+
* Edit the icon of this role
|
|
3116
|
+
* @param icon Autumn ID for the new icon, or null to remove the custom icon
|
|
3117
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3118
|
+
* @throws {Error} If API request fails
|
|
3119
|
+
* @example
|
|
3120
|
+
* // Set a new icon for the role
|
|
3121
|
+
* await role.setIcon("AUTUMN_ID_FOR_ICON");
|
|
3122
|
+
* console.log(`Role's new icon: ${role.icon}`);
|
|
3123
|
+
*
|
|
3124
|
+
* // Use AttachmentBuilder to upload a new icon file
|
|
3125
|
+
* import { readFile } from "node:fs/promises";
|
|
3126
|
+
* const iconFile = await readFile("./a.jpg");
|
|
3127
|
+
* const attachment = new AttachmentBuilder(iconFile, "a.jpg");
|
|
3128
|
+
* await role.setIcon(attachment);
|
|
3129
|
+
* console.log(`Role's new icon: ${role.icon}`);
|
|
3130
|
+
*/
|
|
3131
|
+
async setIcon(icon) {
|
|
3132
|
+
return await this.edit({ icon });
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* Change the hoist status for this role
|
|
3136
|
+
* @param hoist The new hoist status for the role
|
|
3137
|
+
* @returns A promise that resolves to this updated Role object.
|
|
3138
|
+
* @throws {Error} If API request fails
|
|
3139
|
+
* @example
|
|
3140
|
+
* // Enable hoisting for the role
|
|
3141
|
+
* await role.setHoist(true);
|
|
3142
|
+
* console.log(`Role is now hoisted: ${role.hoist}`);
|
|
3143
|
+
*/
|
|
3144
|
+
async setHoist(hoist) {
|
|
3145
|
+
return await this.edit({ hoist });
|
|
3146
|
+
}
|
|
2814
3147
|
/**
|
|
2815
3148
|
* Customizer for Node.js `console.log` and `util.inspect`.
|
|
2816
3149
|
* Hides the cyclic client reference and raw serverId for a cleaner output.
|
|
@@ -2948,7 +3281,7 @@ var RoleManager = class extends BaseManager {
|
|
|
2948
3281
|
}
|
|
2949
3282
|
/**
|
|
2950
3283
|
* Edits an existing role in the server.
|
|
2951
|
-
* @param role The RoleResolvable to edit.
|
|
3284
|
+
* @param role The {@link RoleResolvable} to edit.
|
|
2952
3285
|
* @param options The fields to update.
|
|
2953
3286
|
* @returns A promise that resolves to the updated Role.
|
|
2954
3287
|
* @throws {TypeError} If invalid options or RoleResolvable are provided.
|
|
@@ -2969,11 +3302,18 @@ var RoleManager = class extends BaseManager {
|
|
|
2969
3302
|
const remove = [];
|
|
2970
3303
|
if (options.name !== void 0) payload.name = options.name;
|
|
2971
3304
|
if (options.hoist !== void 0) payload.hoist = options.hoist;
|
|
2972
|
-
if (options.
|
|
2973
|
-
if (options.
|
|
3305
|
+
if (options.color !== void 0) {
|
|
3306
|
+
if (options.color === null) {
|
|
2974
3307
|
remove.push("Colour");
|
|
2975
3308
|
} else {
|
|
2976
|
-
payload.colour = options.
|
|
3309
|
+
payload.colour = options.color;
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
if (options.icon !== void 0) {
|
|
3313
|
+
if (options.icon === null) {
|
|
3314
|
+
remove.push("Icon");
|
|
3315
|
+
} else {
|
|
3316
|
+
payload.icon = await resolveAttachment(this.client.rest, options.icon, "icons");
|
|
2977
3317
|
}
|
|
2978
3318
|
}
|
|
2979
3319
|
if (remove.length > 0) {
|
|
@@ -3701,8 +4041,10 @@ var EmbedBuilder = class {
|
|
|
3701
4041
|
};
|
|
3702
4042
|
export {
|
|
3703
4043
|
Attachment,
|
|
4044
|
+
AttachmentBuilder,
|
|
3704
4045
|
Base,
|
|
3705
4046
|
BaseChannel,
|
|
4047
|
+
BitField,
|
|
3706
4048
|
ChannelManager,
|
|
3707
4049
|
ChannelType,
|
|
3708
4050
|
Client,
|