|
|
@ -151,9 +151,37 @@ class Client(object): |
|
|
|
guild['roles'] = [Role(**role) for role in guild['roles']] |
|
|
|
guild['members'] = [Member(**member) for member in guild['members']] |
|
|
|
|
|
|
|
self.servers.append(Server(**guild)) |
|
|
|
channels = [Channel(server=self.servers[-1], **channel) for channel in guild['channels']] |
|
|
|
self.servers[-1].channels = channels |
|
|
|
server = Server(**guild) |
|
|
|
for channel in guild['channels']: |
|
|
|
changed_roles = [] |
|
|
|
permission_overwrites = channel['permission_overwrites'] |
|
|
|
|
|
|
|
for overridden in permission_overwrites: |
|
|
|
# this is pretty inefficient due to the deep nested loops unfortunately |
|
|
|
role = next((role for role in guild['roles'] if role.id == overridden['id']), None) |
|
|
|
if role is None: |
|
|
|
continue |
|
|
|
denied = overridden.get('deny', 0) |
|
|
|
allowed = overridden.get('allow', 0) |
|
|
|
override = copy.deepcopy(role) |
|
|
|
|
|
|
|
# Basically this is what's happening here. |
|
|
|
# We have an original bit array, e.g. 1010 |
|
|
|
# Then we have another bit array that is 'denied', e.g. 1111 |
|
|
|
# And then we have the last one which is 'allowed', e.g. 0101 |
|
|
|
# We want original OP denied to end up resulting in whatever is in denied to be set to 0. |
|
|
|
# So 1010 OP 1111 -> 0000 |
|
|
|
# Then we take this value and look at the allowed values. And whatever is allowed is set to 1. |
|
|
|
# So 0000 OP2 0101 -> 0101 |
|
|
|
# The OP is (base ^ denied) & ~denied. |
|
|
|
# The OP2 is base | allowed. |
|
|
|
override.permissions.value = ((override.permissions.value ^ denied) & ~denied) | allowed |
|
|
|
changed_roles.append(override) |
|
|
|
|
|
|
|
channel['permission_overwrites'] = changed_roles |
|
|
|
channels = [Channel(server=server, **channel) for channel in guild['channels']] |
|
|
|
server.channels = channels |
|
|
|
self.servers.append(server) |
|
|
|
|
|
|
|
for pm in data.get('private_channels'): |
|
|
|
self.private_channels.append(PrivateChannel(id=pm['id'], user=User(**pm['recipient']))) |
|
|
|