diff --git a/discord/abc.py b/discord/abc.py index 23e18141d..7b87fba91 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -153,11 +153,14 @@ class PrivateChannel(Snowflake, Protocol): class _Overwrites: __slots__ = ('id', 'allow', 'deny', 'type') + ROLE = 0 + MEMBER = 1 + def __init__(self, **kwargs): self.id = kwargs.pop('id') - self.allow = int(kwargs.pop('allow_new', 0)) - self.deny = int(kwargs.pop('deny_new', 0)) - self.type = sys.intern(kwargs.pop('type')) + self.allow = int(kwargs.pop('allow', 0)) + self.deny = int(kwargs.pop('deny', 0)) + self.type = kwargs.pop('type') def _asdict(self): return { @@ -167,6 +170,12 @@ class _Overwrites: 'type': self.type, } + def is_role(self) -> bool: + return self.type == 0 + + def is_member(self) -> bool: + return self.type == 1 + class GuildChannel(Protocol): """An ABC that details the common operations on a Discord guild channel. @@ -289,9 +298,9 @@ class GuildChannel(Protocol): } if isinstance(target, Role): - payload['type'] = 'role' + payload['type'] = _Overwrites.ROLE else: - payload['type'] = 'member' + payload['type'] = _Overwrites.MEMBER perms.append(payload) options['permission_overwrites'] = perms @@ -318,7 +327,7 @@ class GuildChannel(Protocol): overridden_id = int(overridden.pop('id')) self._overwrites.append(_Overwrites(id=overridden_id, **overridden)) - if overridden['type'] == 'member': + if overridden['type'] == _Overwrites.MEMBER: continue if overridden_id == everyone_id: @@ -340,7 +349,7 @@ class GuildChannel(Protocol): their default values in the :attr:`~discord.Guild.roles` attribute.""" ret = [] g = self.guild - for overwrite in filter(lambda o: o.type == 'role', self._overwrites): + for overwrite in filter(lambda o: o.is_role(), self._overwrites): role = g.get_role(overwrite.id) if role is None: continue @@ -376,9 +385,9 @@ class GuildChannel(Protocol): """ if isinstance(obj, User): - predicate = lambda p: p.type == 'member' + predicate = lambda p: p.is_member() elif isinstance(obj, Role): - predicate = lambda p: p.type == 'role' + predicate = lambda p: p.is_role() else: predicate = lambda p: True @@ -409,9 +418,9 @@ class GuildChannel(Protocol): deny = Permissions(ow.deny) overwrite = PermissionOverwrite.from_pair(allow, deny) - if ow.type == 'role': + if ow.is_role(): target = self.guild.get_role(ow.id) - elif ow.type == 'member': + elif ow.is_member(): target = self.guild.get_member(ow.id) # TODO: There is potential data loss here in the non-chunked @@ -513,7 +522,7 @@ class GuildChannel(Protocol): # Apply channel specific role permission overwrites for overwrite in remaining_overwrites: - if overwrite.type == 'role' and roles.has(overwrite.id): + if overwrite.is_role() and roles.has(overwrite.id): denies |= overwrite.deny allows |= overwrite.allow @@ -521,7 +530,7 @@ class GuildChannel(Protocol): # Apply member specific permission overwrites for overwrite in remaining_overwrites: - if overwrite.type == 'member' and overwrite.id == member.id: + if overwrite.is_member() and overwrite.id == member.id: base.handle_overwrite(allow=overwrite.allow, deny=overwrite.deny) break @@ -632,9 +641,9 @@ class GuildChannel(Protocol): http = self._state.http if isinstance(target, User): - perm_type = 'member' + perm_type = _Overwrites.MEMBER elif isinstance(target, Role): - perm_type = 'role' + perm_type = _Overwrites.ROLE else: raise InvalidArgument('target parameter must be either Member or Role') diff --git a/discord/audit_logs.py b/discord/audit_logs.py index fb94d9fac..fbb0f5a3c 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -290,9 +290,9 @@ class AuditLogEntry(Hashable): # the overwrite_ actions have a dict with some information instance_id = int(self.extra['id']) the_type = self.extra.get('type') - if the_type == 'member': + if the_type == '1': self.extra = self._get_member(instance_id) - else: + elif the_type == '0': role = self.guild.get_role(instance_id) if role is None: role = Object(id=instance_id) diff --git a/discord/gateway.py b/discord/gateway.py index 591cb74d9..4e9e926eb 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -608,7 +608,7 @@ class DiscordWebSocket: payload = { 'op': self.PRESENCE, 'd': { - 'game': activity, + 'activities': [activity], 'afk': afk, 'since': since, 'status': status diff --git a/discord/http.py b/discord/http.py index 1c7030f2c..b32cc9174 100644 --- a/discord/http.py +++ b/discord/http.py @@ -51,7 +51,7 @@ async def json_or_text(response): class Route: - BASE = 'https://discord.com/api/v7' + BASE = 'https://discord.com/api/v8' def __init__(self, method, path, **parameters): self.path = path @@ -151,7 +151,6 @@ class HTTPClient: # header creation headers = { 'User-Agent': self.user_agent, - 'X-Ratelimit-Precision': 'millisecond', } if self.token is not None: @@ -450,7 +449,7 @@ class HTTPClient: return self.request(r, reason=reason) def delete_messages(self, channel_id, message_ids, *, reason=None): - r = Route('POST', '/channels/{channel_id}/messages/bulk_delete', channel_id=channel_id) + r = Route('POST', '/channels/{channel_id}/messages/bulk-delete', channel_id=channel_id) payload = { 'messages': message_ids, } @@ -1279,28 +1278,28 @@ class HTTPClient: def application_info(self): return self.request(Route('GET', '/oauth2/applications/@me')) - async def get_gateway(self, *, encoding='json', v=6, zlib=True): + async def get_gateway(self, *, encoding='json', zlib=True): try: data = await self.request(Route('GET', '/gateway')) except HTTPException as exc: raise GatewayNotFound() from exc if zlib: - value = '{0}?encoding={1}&v={2}&compress=zlib-stream' + value = '{0}?encoding={1}&v=8&compress=zlib-stream' else: - value = '{0}?encoding={1}&v={2}' - return value.format(data['url'], encoding, v) + value = '{0}?encoding={1}&v=8' + return value.format(data['url'], encoding) - async def get_bot_gateway(self, *, encoding='json', v=6, zlib=True): + async def get_bot_gateway(self, *, encoding='json', zlib=True): try: data = await self.request(Route('GET', '/gateway/bot')) except HTTPException as exc: raise GatewayNotFound() from exc if zlib: - value = '{0}?encoding={1}&v={2}&compress=zlib-stream' + value = '{0}?encoding={1}&v=8&compress=zlib-stream' else: - value = '{0}?encoding={1}&v={2}' - return data['shards'], value.format(data['url'], encoding, v) + value = '{0}?encoding={1}&v=8' + return data['shards'], value.format(data['url'], encoding) def get_user(self, user_id): return self.request(Route('GET', '/users/{user_id}', user_id=user_id)) diff --git a/discord/role.py b/discord/role.py index c1060ace8..491fd075b 100644 --- a/discord/role.py +++ b/discord/role.py @@ -210,7 +210,7 @@ class Role(Hashable): def _update(self, data): self.name = data['name'] - self._permissions = int(data.get('permissions_new', 0)) + self._permissions = int(data.get('permissions', 0)) self.position = data.get('position', 0) self._colour = data.get('color', 0) self.hoist = data.get('hoist', False) diff --git a/discord/state.py b/discord/state.py index 8374b30e3..d35ff7df5 100644 --- a/discord/state.py +++ b/discord/state.py @@ -601,7 +601,6 @@ class ConnectionState: user = data['user'] member_id = int(user['id']) member = guild.get_member(member_id) - flags = self.member_cache_flags if member is None: if 'username' not in user: # sometimes we receive 'incomplete' member data post-removal. @@ -609,17 +608,12 @@ class ConnectionState: return member, old_member = Member._from_presence_update(guild=guild, data=data, state=self) - if flags.online or (flags._online_only and member.raw_status != 'offline'): - guild._add_member(member) else: old_member = Member._copy(member) user_update = member._presence_update(data=data, user=user) if user_update: self.dispatch('user_update', user_update[0], user_update[1]) - if member.id != self.self_id and flags._online_only and member.raw_status == 'offline': - guild._remove_member(member) - self.dispatch('member_update', old_member, member) def parse_user_update(self, data): diff --git a/discord/webhook.py b/discord/webhook.py index 43d563198..fd4cd54f4 100644 --- a/discord/webhook.py +++ b/discord/webhook.py @@ -152,7 +152,7 @@ class WebhookAdapter: The webhook that owns this adapter. """ - BASE = 'https://discord.com/api/v7' + BASE = 'https://discord.com/api/v8' def _prepare(self, webhook): self._webhook_id = webhook.id