async def receive_message(self, msg): self.ws._dispatch("socket_raw_receive", msg) msg = orjson.loads(msg) self.ws._dispatch("socket_response", msg) op = msg.get("op") data = msg.get("d") event = msg.get("t") old = msg.get("old") if op != self.ws.DISPATCH: return data = tools.upgrade_payload(data) try: func = self.ws._discord_parsers[event] except KeyError: log.debug(f"Unknown event {event}.") return if event not in self._enabled_events: return try: await func(data, old) except asyncio.CancelledError: pass except Exception: try: await self.on_error(event) except asyncio.CancelledError: pass
async def _roles(self): return sorted( [ Role(guild=self, state=self._state, data=tools.upgrade_payload(x)) for x in await self._state._members_get_all("guild", key_id=self.id, name="role") ] )
async def get_role(self, role_id): role = await self._state.get(f"role:{self.id}:{role_id}") if role: return Role(guild=self, state=self._state, data=tools.upgrade_payload(role)) return None
async def _channels(self): channels = [] for channel in await self._state._members_get_all("guild", key_id=self.id, name="channel"): factory, _ = _channel_factory(channel["type"]) channels.append(factory(guild=self, state=self._state, data=tools.upgrade_payload(channel))) return channels
async def get(self, keys, decode=True): results = [] if isinstance(keys, (list, tuple)): if len(keys) == 0: return [] results.extend( [self._loads(x, decode) for x in await self.redis.mget(*keys)]) else: results.append(self._loads(await self.redis.get(keys), decode)) for index, value in enumerate(results): if isinstance(value, dict): value["_key"] = keys[index] if isinstance(keys, (list, tuple)) else keys value = tools.upgrade_payload(value) results[index] = value if isinstance(keys, (list, tuple)): return [x for x in results if x is not None] return results[0]