def deserialize_presence_update_event( self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject, *, old_presence: typing.Optional[presences_models.MemberPresence], ) -> guild_events.PresenceUpdateEvent: presence = self._app.entity_factory.deserialize_member_presence(payload) user_payload = payload["user"] user: typing.Optional[user_models.PartialUser] = None # Here we're told that the only guaranteed field is "id", so if we only get 1 field in the user payload then # then we've only got an ID and there's no reason to form a user object. if len(user_payload) > 1: # PartialUser discriminator = user_payload["discriminator"] if "discriminator" in user_payload else undefined.UNDEFINED flags: undefined.UndefinedOr[user_models.UserFlag] = undefined.UNDEFINED if "public_flags" in user_payload: flags = user_models.UserFlag(user_payload["public_flags"]) user = user_models.PartialUserImpl( app=self._app, id=snowflakes.Snowflake(user_payload["id"]), discriminator=discriminator, username=user_payload.get("username", undefined.UNDEFINED), avatar_hash=user_payload.get("avatar", undefined.UNDEFINED), is_bot=user_payload.get("bot", undefined.UNDEFINED), is_system=user_payload.get("system", undefined.UNDEFINED), flags=flags, ) return guild_events.PresenceUpdateEvent( app=self._app, shard=shard, presence=presence, user=user, old_presence=old_presence )
def test_str_operator(self): flag = users.UserFlag(1 << 17) assert str(flag) == "EARLY_VERIFIED_DEVELOPER"