diff --git a/disco/types/channel.py b/disco/types/channel.py index 2c2ffb4..9f4a9a5 100644 --- a/disco/types/channel.py +++ b/disco/types/channel.py @@ -162,18 +162,27 @@ class Channel(SlottedModel, Permissible): member = self.guild.get_member(user) base = self.guild.get_permissions(member) - ow_everyone = self.overwrites.get(self.guild_id) - if ow_everyone: - base += ow_everyone.compiled - + # First grab and apply the everyone overwrite + everyone = self.overwrites.get(self.guild_id) + if everyone: + base -= everyone.deny + base += everyone.allow + + denies = 0 + allows = 0 for role_id in member.roles: - ow_role = self.overwrites.get(role_id) - if ow_role: - base += ow_role.compiled + overwrite = self.overwrites.get(role_id) + if overwrite: + denies |= overwrite.deny + allows |= overwrite.allow + + base -= denies + base += allows ow_member = self.overwrites.get(member.user.id) if ow_member: - base += ow_member.compiled + base -= ow_member.deny + base += ow_member.allow return base @@ -200,7 +209,7 @@ class Channel(SlottedModel, Permissible): """ Whether this channel is an NSFW channel. """ - return self.type == ChannelType.GUILD_TEXT and (self.nsfw or NSFW_RE.match(self.name)) + return bool(self.type == ChannelType.GUILD_TEXT and (self.nsfw or NSFW_RE.match(self.name))) @property def is_voice(self): diff --git a/disco/types/guild.py b/disco/types/guild.py index d72e2f9..8df519c 100644 --- a/disco/types/guild.py +++ b/disco/types/guild.py @@ -357,6 +357,7 @@ class Guild(SlottedModel, Permissible): if self.owner_id == member.id: return PermissionValue(Permissions.ADMINISTRATOR) + # Our value starts with the guilds default (@everyone) role permissions value = PermissionValue(self.roles.get(self.id).permissions) # Iterate over all roles the user has (plus the @everyone role) diff --git a/tests/types/channel.py b/tests/types/channel.py index 88695ea..33cebcf 100644 --- a/tests/types/channel.py +++ b/tests/types/channel.py @@ -1,25 +1,23 @@ -from unittest import TestCase - from disco.types.channel import Channel, ChannelType -class TestChannel(TestCase): - def test_deprecated_nsfw_channel(self): - channel = Channel( - name='nsfw-testing', - type=ChannelType.GUILD_TEXT) - self.assertTrue(channel.is_nsfw) +def test_deprecated_nsfw_channel(): + channel = Channel( + name='nsfw-testing', + type=ChannelType.GUILD_TEXT) + assert channel.is_nsfw + + channel = Channel( + name='nsfw-testing', + type=ChannelType.GUILD_VOICE) + assert not channel.is_nsfw - channel = Channel( - name='nsfw-testing', - type=ChannelType.GUILD_VOICE) - self.assertFalse(channel.is_nsfw) + channel = Channel( + name='nsfw_testing', + type=ChannelType.GUILD_TEXT) + assert not channel.is_nsfw - channel = Channel( - name='nsfw_testing', - type=ChannelType.GUILD_TEXT) - self.assertFalse(channel.is_nsfw) - def test_nsfw_channel(self): - channel = Channel(name='test', nsfw=True, type=ChannelType.GUILD_TEXT) - assert channel.is_nsfw +def test_nsfw_channel(): + channel = Channel(name='test', nsfw=True, type=ChannelType.GUILD_TEXT) + assert channel.is_nsfw