Ejemplo n.º 1
0
def stub_chunk_event(mock_app):
    return shard_events.MemberChunkEvent(
        app=mock_app,
        shard=mock.Mock(shard.GatewayShardImpl, id=3),
        guild_id=snowflakes.Snowflake(115590097100865541),
        members={id_: object()
                 for id_ in range(1, 12)},
        chunk_index=5,
        chunk_count=10,
        not_found=[snowflakes.Snowflake(54345)],
        presences={},
        nonce="2.billnye",
    )
Ejemplo n.º 2
0
 def event(self):
     return shard_events.MemberChunkEvent(
         app=mock.Mock(),
         shard=mock.Mock(),
         guild_id=snowflakes.Snowflake(69420),
         members={
             snowflakes.Snowflake(1): mock.Mock(),
             snowflakes.Snowflake(55): mock.Mock(),
             snowflakes.Snowflake(99): mock.Mock(),
             snowflakes.Snowflake(455): mock.Mock(),
         },
         chunk_count=1,
         chunk_index=1,
         not_found=(),
         presences={},
         nonce="blah",
     )
Ejemplo n.º 3
0
    async def test_on_chunk_event_when_initial_tracking_information_not_set(
            self, mock_chunker, mock_app):
        event = shard_events.MemberChunkEvent(
            app=mock_app,
            shard=mock.Mock(shard.GatewayShardImpl, id=2),
            guild_id=snowflakes.Snowflake(115590097100865541),
            members={id_: object()
                     for id_ in range(1, 101)},
            chunk_index=5,
            chunk_count=10,
            not_found=[snowflakes.Snowflake(43234)],
            presences={},
            nonce="2.billnye",
        )
        tracker = stateful_guild_chunker._TrackedRequests(
            nonce="4.hiebye",
            guild_id=snowflakes.Snowflake(140502780547694592))
        mock_chunker._tracked = {
            2: {
                "2.blbll": object(),
                "2.billnye": tracker
            }
        }

        with mock.patch.object(time, "monotonic_ns", return_value=4242):
            assert await mock_chunker.consume_chunk_event(event) is None
            time.monotonic_ns.assert_called_once()

        assert mock_chunker._tracked[2]["2.billnye"].average_chunk_size == 100
        assert mock_chunker._tracked[2]["2.billnye"].chunk_count == 10
        assert mock_chunker._tracked[2]["2.billnye"].missing_chunk_indexes == [
            0, 1, 2, 3, 4, 6, 7, 8, 9
        ]
        assert mock_chunker._tracked[2][
            "2.billnye"]._mono_last_received == 4242
        assert mock_chunker._tracked[2]["2.billnye"].not_found_ids == [
            snowflakes.Snowflake(43234)
        ]
Ejemplo n.º 4
0
        if (presence_payloads := payload.get("presences")) is not None:
            presences = {
                snowflakes.Snowflake(p["user"]["id"]):
                self._app.entity_factory.deserialize_member_presence(
                    p, guild_id=guild_id)
                for p in presence_payloads
            }
        else:
            presences = {}

        return shard_events.MemberChunkEvent(
            app=self._app,
            shard=shard,
            guild_id=guild_id,
            members=members,
            chunk_index=index,
            chunk_count=count,
            not_found=not_found,
            presences=presences,
            nonce=nonce,
        )

    ################
    # VOICE EVENTS #
    ################

    def deserialize_voice_state_update_event(
        self,
        shard: gateway_shard.GatewayShard,
        payload: data_binding.JSONObject,
        old_state: typing.Optional[voices_models.VoiceState] = None