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.d.mts CHANGED
@@ -740,9 +740,9 @@ declare class MessageStruct extends Base {
740
740
  /**
741
741
  * Retrieves the author of the message.
742
742
  *
743
- * @returns {User | null} The user who authored the message, or `null` if not found.
743
+ * @returns {User | ServerMember | null} The user who authored the message, or `null` if not found.
744
744
  */
745
- get author(): User | null;
745
+ get author(): User | ServerMember | null;
746
746
  /**
747
747
  * Retrieves the channel where the message was sent.
748
748
  *
@@ -1850,12 +1850,57 @@ declare class ServerMember extends Base {
1850
1850
  * ```
1851
1851
  */
1852
1852
  leave(): Promise<void>;
1853
+ /**
1854
+ * Gets the effective permissions for this server member based on their roles.
1855
+ *
1856
+ * The permissions are calculated by:
1857
+ * 1. Starting with a base FullPermissions with no permissions
1858
+ * 2. For each role the member has, applying the role's allow permissions
1859
+ * 3. For each role the member has, removing the role's deny permissions
1860
+ *
1861
+ * @returns {FullPermissions} The effective permissions for this member
1862
+ *
1863
+ * @example
1864
+ * ```typescript
1865
+ * const permissions = member.getPermissions();
1866
+ * console.log(permissions.has('MANAGE_MESSAGES')); // true or false
1867
+ * ```
1868
+ */
1869
+ permissions(): FullPermissions;
1870
+ /**
1871
+ * Checks if this server member has a specific permission.
1872
+ *
1873
+ * @param {string | number | FullPermissions} permission - The permission to check for
1874
+ * @returns {boolean} Whether the member has the permission
1875
+ *
1876
+ * @example
1877
+ * ```typescript
1878
+ * if (member.hasPermission('MANAGE_MESSAGES')) {
1879
+ * // Member can manage messages
1880
+ * }
1881
+ * ```
1882
+ *
1883
+ * note this works on the same basis as stoats permissions checking
1884
+ */
1885
+ hasPermission(permission: string | number | FullPermissions): boolean;
1853
1886
  /**
1854
1887
  * Retrieves the user associated with this server member.
1855
1888
  *
1856
1889
  * @returns {User} The user instance.
1857
1890
  */
1858
1891
  get user(): User;
1892
+ /**
1893
+ * Gets the username of the user.
1894
+ *
1895
+ * @returns {string} The username of the user.
1896
+ */
1897
+ get username(): string;
1898
+ /**
1899
+ * Gets whether the user is a bot.
1900
+ *
1901
+ * @returns {boolean} Whether the user is a bot.
1902
+ */
1903
+ get bot(): boolean;
1859
1904
  /**
1860
1905
  * Retrieves the server this member belongs to.
1861
1906
  *
@@ -2068,7 +2113,7 @@ declare class UserManager extends BaseManager<User, User$1> {
2068
2113
  * @param resolvable The user to resolve
2069
2114
  * @returns The user or null if it cannot be resolved
2070
2115
  */
2071
- resolve(resolvable: MessageStruct | User): User;
2116
+ resolve(resolvable: MessageStruct | User): User | null;
2072
2117
  resolve(resolvable: string | User$1): User | null;
2073
2118
  /**
2074
2119
  * get a user id form cache
package/dist/index.d.ts CHANGED
@@ -740,9 +740,9 @@ declare class MessageStruct extends Base {
740
740
  /**
741
741
  * Retrieves the author of the message.
742
742
  *
743
- * @returns {User | null} The user who authored the message, or `null` if not found.
743
+ * @returns {User | ServerMember | null} The user who authored the message, or `null` if not found.
744
744
  */
745
- get author(): User | null;
745
+ get author(): User | ServerMember | null;
746
746
  /**
747
747
  * Retrieves the channel where the message was sent.
748
748
  *
@@ -1850,12 +1850,57 @@ declare class ServerMember extends Base {
1850
1850
  * ```
1851
1851
  */
1852
1852
  leave(): Promise<void>;
1853
+ /**
1854
+ * Gets the effective permissions for this server member based on their roles.
1855
+ *
1856
+ * The permissions are calculated by:
1857
+ * 1. Starting with a base FullPermissions with no permissions
1858
+ * 2. For each role the member has, applying the role's allow permissions
1859
+ * 3. For each role the member has, removing the role's deny permissions
1860
+ *
1861
+ * @returns {FullPermissions} The effective permissions for this member
1862
+ *
1863
+ * @example
1864
+ * ```typescript
1865
+ * const permissions = member.getPermissions();
1866
+ * console.log(permissions.has('MANAGE_MESSAGES')); // true or false
1867
+ * ```
1868
+ */
1869
+ permissions(): FullPermissions;
1870
+ /**
1871
+ * Checks if this server member has a specific permission.
1872
+ *
1873
+ * @param {string | number | FullPermissions} permission - The permission to check for
1874
+ * @returns {boolean} Whether the member has the permission
1875
+ *
1876
+ * @example
1877
+ * ```typescript
1878
+ * if (member.hasPermission('MANAGE_MESSAGES')) {
1879
+ * // Member can manage messages
1880
+ * }
1881
+ * ```
1882
+ *
1883
+ * note this works on the same basis as stoats permissions checking
1884
+ */
1885
+ hasPermission(permission: string | number | FullPermissions): boolean;
1853
1886
  /**
1854
1887
  * Retrieves the user associated with this server member.
1855
1888
  *
1856
1889
  * @returns {User} The user instance.
1857
1890
  */
1858
1891
  get user(): User;
1892
+ /**
1893
+ * Gets the username of the user.
1894
+ *
1895
+ * @returns {string} The username of the user.
1896
+ */
1897
+ get username(): string;
1898
+ /**
1899
+ * Gets whether the user is a bot.
1900
+ *
1901
+ * @returns {boolean} Whether the user is a bot.
1902
+ */
1903
+ get bot(): boolean;
1859
1904
  /**
1860
1905
  * Retrieves the server this member belongs to.
1861
1906
  *
@@ -2068,7 +2113,7 @@ declare class UserManager extends BaseManager<User, User$1> {
2068
2113
  * @param resolvable The user to resolve
2069
2114
  * @returns The user or null if it cannot be resolved
2070
2115
  */
2071
- resolve(resolvable: MessageStruct | User): User;
2116
+ resolve(resolvable: MessageStruct | User): User | null;
2072
2117
  resolve(resolvable: string | User$1): User | null;
2073
2118
  /**
2074
2119
  * get a user id form cache
package/dist/index.js CHANGED
@@ -940,11 +940,14 @@ var MessageStruct = class extends Base {
940
940
  /**
941
941
  * Retrieves the author of the message.
942
942
  *
943
- * @returns {User | null} The user who authored the message, or `null` if not found.
943
+ * @returns {User | ServerMember | null} The user who authored the message, or `null` if not found.
944
944
  */
945
945
  get author() {
946
- var _a;
947
- return (_a = this.client.users.cache.get(this.authorId)) != null ? _a : null;
946
+ var _a, _b, _c, _d;
947
+ if (this.inServer()) {
948
+ 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;
949
+ }
950
+ return (_d = this.client.users.cache.get(this.authorId)) != null ? _d : null;
948
951
  }
949
952
  /**
950
953
  * Retrieves the channel where the message was sent.
@@ -2352,6 +2355,58 @@ var ServerMember3 = class extends Base {
2352
2355
  leave() {
2353
2356
  return this.client.servers.delete(this.serverId);
2354
2357
  }
2358
+ /**
2359
+ * Gets the effective permissions for this server member based on their roles.
2360
+ *
2361
+ * The permissions are calculated by:
2362
+ * 1. Starting with a base FullPermissions with no permissions
2363
+ * 2. For each role the member has, applying the role's allow permissions
2364
+ * 3. For each role the member has, removing the role's deny permissions
2365
+ *
2366
+ * @returns {FullPermissions} The effective permissions for this member
2367
+ *
2368
+ * @example
2369
+ * ```typescript
2370
+ * const permissions = member.getPermissions();
2371
+ * console.log(permissions.has('MANAGE_MESSAGES')); // true or false
2372
+ * ```
2373
+ */
2374
+ permissions() {
2375
+ var _a, _b;
2376
+ let permissions = new FullPermissions();
2377
+ for (const role of this.roles) {
2378
+ if ((_a = role.overwrite) == null ? void 0 : _a.allow) {
2379
+ permissions = permissions.add(role.overwrite.allow);
2380
+ }
2381
+ }
2382
+ for (const role of this.roles) {
2383
+ if ((_b = role.overwrite) == null ? void 0 : _b.deny) {
2384
+ permissions = permissions.remove(role.overwrite.deny);
2385
+ }
2386
+ }
2387
+ return permissions;
2388
+ }
2389
+ /**
2390
+ * Checks if this server member has a specific permission.
2391
+ *
2392
+ * @param {string | number | FullPermissions} permission - The permission to check for
2393
+ * @returns {boolean} Whether the member has the permission
2394
+ *
2395
+ * @example
2396
+ * ```typescript
2397
+ * if (member.hasPermission('MANAGE_MESSAGES')) {
2398
+ * // Member can manage messages
2399
+ * }
2400
+ * ```
2401
+ *
2402
+ * note this works on the same basis as stoats permissions checking
2403
+ */
2404
+ hasPermission(permission) {
2405
+ var _a;
2406
+ if (((_a = this.client.servers.cache.get(this.serverId)) == null ? void 0 : _a.ownerId) === this.id)
2407
+ return true;
2408
+ return this.permissions().has(permission);
2409
+ }
2355
2410
  // async displayAvatarURL(options?: { size: number }): Promise<string> {
2356
2411
  // return await this.user.displayAvatarURL(options);
2357
2412
  // }
@@ -2363,6 +2418,22 @@ var ServerMember3 = class extends Base {
2363
2418
  get user() {
2364
2419
  return this.client.users.cache.get(this.id);
2365
2420
  }
2421
+ /**
2422
+ * Gets the username of the user.
2423
+ *
2424
+ * @returns {string} The username of the user.
2425
+ */
2426
+ get username() {
2427
+ return this.user.username;
2428
+ }
2429
+ /**
2430
+ * Gets whether the user is a bot.
2431
+ *
2432
+ * @returns {boolean} Whether the user is a bot.
2433
+ */
2434
+ get bot() {
2435
+ return this.user.bot;
2436
+ }
2366
2437
  /**
2367
2438
  * Retrieves the server this member belongs to.
2368
2439
  *
@@ -2767,7 +2838,8 @@ var UserManager = class extends BaseManager {
2767
2838
  });
2768
2839
  }
2769
2840
  resolve(resolvable) {
2770
- if (resolvable instanceof MessageStruct) return resolvable.author;
2841
+ if (resolvable instanceof MessageStruct)
2842
+ return resolvable.author;
2771
2843
  return super.resolve(resolvable);
2772
2844
  }
2773
2845
  /**
@@ -3304,7 +3376,7 @@ var import_node_events = require("events");
3304
3376
  var import_axios4 = __toESM(require("axios"));
3305
3377
 
3306
3378
  // package.json
3307
- var version = "0.2.1";
3379
+ var version = "0.2.4";
3308
3380
 
3309
3381
  // src/rest/restUtils/rateLimitQueue.ts
3310
3382
  var import_axios3 = __toESM(require("axios"));
@@ -4070,13 +4142,33 @@ var ServerRoleUpdate = class extends Event {
4070
4142
  * @returns {void}
4071
4143
  */
4072
4144
  handle(data) {
4073
- const server = this.client.servers.cache.get(data.id);
4074
- if (!server) return;
4075
- const role = server.roles.cache.get(data.role_id);
4076
- const oldRole = role == null ? void 0 : role._update(data.data, data.clear);
4077
- if (role && oldRole && !role.equals(oldRole)) {
4078
- this.client.emit("roleUpdate" /* ROLE_UPDATE */, oldRole, role);
4079
- }
4145
+ return __async(this, null, function* () {
4146
+ const server = this.client.servers.cache.get(data.id);
4147
+ if (!server) return;
4148
+ let role = server.roles.cache.get(data.role_id);
4149
+ const oldRole = role == null ? void 0 : role._update(data.data, data.clear);
4150
+ if (!oldRole && !role) {
4151
+ yield Promise.all(
4152
+ Object.values(data.data).map((raw) => __async(this, null, function* () {
4153
+ if (raw && typeof raw === "object") {
4154
+ server.roles._add(__spreadProps(__spreadValues({
4155
+ name: "",
4156
+ permissions: {
4157
+ a: 0,
4158
+ d: 0
4159
+ }
4160
+ }, raw), {
4161
+ id: data.role_id
4162
+ }));
4163
+ }
4164
+ }))
4165
+ );
4166
+ role = server.roles.cache.get(data.role_id);
4167
+ }
4168
+ if (role && oldRole && !role.equals(oldRole)) {
4169
+ this.client.emit("roleUpdate" /* ROLE_UPDATE */, oldRole, role);
4170
+ }
4171
+ });
4080
4172
  }
4081
4173
  };
4082
4174