revbot.js 0.2.2 → 0.2.4

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.mjs CHANGED
@@ -864,11 +864,14 @@ var MessageStruct = class extends Base {
864
864
  /**
865
865
  * Retrieves the author of the message.
866
866
  *
867
- * @returns {User | null} The user who authored the message, or `null` if not found.
867
+ * @returns {User | ServerMember | null} The user who authored the message, or `null` if not found.
868
868
  */
869
869
  get author() {
870
- var _a;
871
- return (_a = this.client.users.cache.get(this.authorId)) != null ? _a : null;
870
+ var _a, _b, _c, _d;
871
+ if (this.inServer()) {
872
+ return (_c = (_b = (_a = this.server) == null ? void 0 : _a.members.cache.get(this.authorId)) != null ? _b : this.client.users.cache.get(this.authorId)) != null ? _c : null;
873
+ }
874
+ return (_d = this.client.users.cache.get(this.authorId)) != null ? _d : null;
872
875
  }
873
876
  /**
874
877
  * Retrieves the channel where the message was sent.
@@ -2276,6 +2279,58 @@ var ServerMember3 = class extends Base {
2276
2279
  leave() {
2277
2280
  return this.client.servers.delete(this.serverId);
2278
2281
  }
2282
+ /**
2283
+ * Gets the effective permissions for this server member based on their roles.
2284
+ *
2285
+ * The permissions are calculated by:
2286
+ * 1. Starting with a base FullPermissions with no permissions
2287
+ * 2. For each role the member has, applying the role's allow permissions
2288
+ * 3. For each role the member has, removing the role's deny permissions
2289
+ *
2290
+ * @returns {FullPermissions} The effective permissions for this member
2291
+ *
2292
+ * @example
2293
+ * ```typescript
2294
+ * const permissions = member.getPermissions();
2295
+ * console.log(permissions.has('MANAGE_MESSAGES')); // true or false
2296
+ * ```
2297
+ */
2298
+ permissions() {
2299
+ var _a, _b;
2300
+ let permissions = new FullPermissions();
2301
+ for (const role of this.roles) {
2302
+ if ((_a = role.overwrite) == null ? void 0 : _a.allow) {
2303
+ permissions = permissions.add(role.overwrite.allow);
2304
+ }
2305
+ }
2306
+ for (const role of this.roles) {
2307
+ if ((_b = role.overwrite) == null ? void 0 : _b.deny) {
2308
+ permissions = permissions.remove(role.overwrite.deny);
2309
+ }
2310
+ }
2311
+ return permissions;
2312
+ }
2313
+ /**
2314
+ * Checks if this server member has a specific permission.
2315
+ *
2316
+ * @param {string | number | FullPermissions} permission - The permission to check for
2317
+ * @returns {boolean} Whether the member has the permission
2318
+ *
2319
+ * @example
2320
+ * ```typescript
2321
+ * if (member.hasPermission('MANAGE_MESSAGES')) {
2322
+ * // Member can manage messages
2323
+ * }
2324
+ * ```
2325
+ *
2326
+ * note this works on the same basis as stoats permissions checking
2327
+ */
2328
+ hasPermission(permission) {
2329
+ var _a;
2330
+ if (((_a = this.client.servers.cache.get(this.serverId)) == null ? void 0 : _a.ownerId) === this.id)
2331
+ return true;
2332
+ return this.permissions().has(permission);
2333
+ }
2279
2334
  // async displayAvatarURL(options?: { size: number }): Promise<string> {
2280
2335
  // return await this.user.displayAvatarURL(options);
2281
2336
  // }
@@ -2287,6 +2342,22 @@ var ServerMember3 = class extends Base {
2287
2342
  get user() {
2288
2343
  return this.client.users.cache.get(this.id);
2289
2344
  }
2345
+ /**
2346
+ * Gets the username of the user.
2347
+ *
2348
+ * @returns {string} The username of the user.
2349
+ */
2350
+ get username() {
2351
+ return this.user.username;
2352
+ }
2353
+ /**
2354
+ * Gets whether the user is a bot.
2355
+ *
2356
+ * @returns {boolean} Whether the user is a bot.
2357
+ */
2358
+ get bot() {
2359
+ return this.user.bot;
2360
+ }
2290
2361
  /**
2291
2362
  * Retrieves the server this member belongs to.
2292
2363
  *
@@ -2691,7 +2762,8 @@ var UserManager = class extends BaseManager {
2691
2762
  });
2692
2763
  }
2693
2764
  resolve(resolvable) {
2694
- if (resolvable instanceof MessageStruct) return resolvable.author;
2765
+ if (resolvable instanceof MessageStruct)
2766
+ return resolvable.author;
2695
2767
  return super.resolve(resolvable);
2696
2768
  }
2697
2769
  /**
@@ -3228,7 +3300,7 @@ import { EventEmitter } from "node:events";
3228
3300
  import axios4, { AxiosError } from "axios";
3229
3301
 
3230
3302
  // package.json
3231
- var version = "0.2.1";
3303
+ var version = "0.2.4";
3232
3304
 
3233
3305
  // src/rest/restUtils/rateLimitQueue.ts
3234
3306
  import axios3 from "axios";
@@ -3994,13 +4066,33 @@ var ServerRoleUpdate = class extends Event {
3994
4066
  * @returns {void}
3995
4067
  */
3996
4068
  handle(data) {
3997
- const server = this.client.servers.cache.get(data.id);
3998
- if (!server) return;
3999
- const role = server.roles.cache.get(data.role_id);
4000
- const oldRole = role == null ? void 0 : role._update(data.data, data.clear);
4001
- if (role && oldRole && !role.equals(oldRole)) {
4002
- this.client.emit("roleUpdate" /* ROLE_UPDATE */, oldRole, role);
4003
- }
4069
+ return __async(this, null, function* () {
4070
+ const server = this.client.servers.cache.get(data.id);
4071
+ if (!server) return;
4072
+ let role = server.roles.cache.get(data.role_id);
4073
+ const oldRole = role == null ? void 0 : role._update(data.data, data.clear);
4074
+ if (!oldRole && !role) {
4075
+ yield Promise.all(
4076
+ Object.values(data.data).map((raw) => __async(this, null, function* () {
4077
+ if (raw && typeof raw === "object") {
4078
+ server.roles._add(__spreadProps(__spreadValues({
4079
+ name: "",
4080
+ permissions: {
4081
+ a: 0,
4082
+ d: 0
4083
+ }
4084
+ }, raw), {
4085
+ id: data.role_id
4086
+ }));
4087
+ }
4088
+ }))
4089
+ );
4090
+ role = server.roles.cache.get(data.role_id);
4091
+ }
4092
+ if (role && oldRole && !role.equals(oldRole)) {
4093
+ this.client.emit("roleUpdate" /* ROLE_UPDATE */, oldRole, role);
4094
+ }
4095
+ });
4004
4096
  }
4005
4097
  };
4006
4098