Skip to content

Commit

Permalink
Allow passing a plain object to permissionsOf (abalabahaha#1224)
Browse files Browse the repository at this point in the history
Co-authored by: curtisf <[email protected]>
  • Loading branch information
bsian03 authored Jul 12, 2021
1 parent 0abf61a commit 7e55222
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ declare namespace Eris {
id: string;
user: User;
}
interface MemberRoles extends BaseData {
roles: string[];
}
interface PartialUser {
avatar: string | null;
discriminator: string;
Expand Down Expand Up @@ -2062,7 +2065,7 @@ declare namespace Eris {
kickMember(userID: string, reason?: string): Promise<void>;
leave(): Promise<void>;
leaveVoiceChannel(): void;
permissionsOf(memberID: string | Member): Permission;
permissionsOf(memberID: string | Member | MemberRoles): Permission;
pruneMembers(options?: PruneMemberOptions): Promise<number>;
removeMemberRole(memberID: string, roleID: string, reason?: string): Promise<void>;
searchMembers(query: string, limit?: number): Promise<Member[]>;
Expand Down Expand Up @@ -2112,7 +2115,7 @@ declare namespace Eris {
): Promise<PermissionOverwrite>;
editPosition(position: number, options?: EditChannelPositionOptions): Promise<void>;
getInvites(): Promise<Invite[]>;
permissionsOf(memberID: string | Member): Permission;
permissionsOf(memberID: string | Member | MemberRoles): Permission;
}

export class GuildIntegration extends Base {
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,11 @@ class Guild extends Base {

/**
* Get the guild permissions of a member
* @arg {String | Member} memberID The ID of the member or a Member instance
* @arg {String | Member | Object} memberID The ID of the member or a Member object
* @returns {Permission}
*/
permissionsOf(memberID) {
const member = memberID instanceof Member ? memberID : this.members.get(memberID);
const member = typeof memberID === "string" ? this.members.get(memberID) : memberID;
if(member.id === this.ownerID) {
return new Permission(Permissions.all);
} else {
Expand Down
5 changes: 2 additions & 3 deletions lib/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const Channel = require("./Channel");
const Collection = require("../util/Collection");
const Member = require("./Member");
const Permission = require("./Permission");
const {Permissions} = require("../Constants");
const PermissionOverwrite = require("./PermissionOverwrite");
Expand Down Expand Up @@ -115,11 +114,11 @@ class GuildChannel extends Channel {

/**
* Get the channel-specific permissions of a member
* @arg {String | Member} memberID The ID of the member or a Member instance
* @arg {String | Member | Object} memberID The ID of the member or a Member object
* @returns {Permission}
*/
permissionsOf(memberID) {
const member = memberID instanceof Member ? memberID : this.guild.members.get(memberID);
const member = typeof memberID === "string" ? this.guild.members.get(memberID) : memberID;
let permission = this.guild.permissionsOf(member).allow;
if(permission & Permissions.administrator) {
return new Permission(Permissions.all);
Expand Down

0 comments on commit 7e55222

Please sign in to comment.