Add GuildMember.permissionsIn and make ChannelResolvables more lenient

This commit is contained in:
Amish Shah
2016-09-11 12:51:26 +01:00
parent 7933d755be
commit 3fba72107b
3 changed files with 19 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -113,8 +113,10 @@ class ClientDataResolver {
/** /**
* Data that can be resolved to give a Channel. This can be: * Data that can be resolved to give a Channel. This can be:
* * An instance of a Channel * * An instance of a Channel
* * An instance of a Message (the channel the message was sent in)
* * An instance of a Guild (the #general channel)
* * An ID of a Channel * * An ID of a Channel
* @typedef {Channel|string} ChannelResolvable * @typedef {Channel|Guild|Message|string} ChannelResolvable
*/ */
/** /**
@@ -124,6 +126,8 @@ class ClientDataResolver {
*/ */
resolveChannel(channel) { resolveChannel(channel) {
if (channel instanceof Channel) return channel; if (channel instanceof Channel) return channel;
if (channel instanceof Message) return channel.channel;
if (channel instanceof Guild) return channel.channels.get(channel.id);
if (typeof channel === 'string') return this.client.channels.get(channel.id); if (typeof channel === 'string') return this.client.channels.get(channel.id);
return null; return null;
} }

View File

@@ -167,6 +167,19 @@ class GuildMember {
return new EvaluatedPermissions(this, permissions); return new EvaluatedPermissions(this, permissions);
} }
/**
* Returns `guildChannel.permissionsFor(guildMember)`. Returns evaluated permissions for a member in a guild channel.
* @param {ChannelResolvable} guildChannel the guild channel to use as context
* @returns {?EvaluatedPermissions}
*/
permissionsIn(guildChannel) {
guildChannel = this.client.resolver.resolveChannel(guildChannel);
if (!guildChannel) {
throw new Error('supply a channel resolvable that resolves to a GuildChannel!');
}
return guildChannel.permissionsFor(this);
}
/** /**
* Checks if any of the member's roles have a permission * Checks if any of the member's roles have a permission
* @param {PermissionResolvable} permission The permission to check for * @param {PermissionResolvable} permission The permission to check for