示例#1
0
    async def test_mentions_exceeding_limit(self):
        """Messages with a higher than allowed amount of mentions."""
        cases = (DisallowedCase(
            [make_msg("bob", 3)],
            ("bob", ),
            3,
        ),
                 DisallowedCase(
                     [
                         make_msg("alice", 2),
                         make_msg("alice", 0),
                         make_msg("alice", 1)
                     ],
                     ("alice", ),
                     3,
                 ),
                 DisallowedCase(
                     [
                         make_msg("bob", 2),
                         make_msg("alice", 3),
                         make_msg("bob", 2)
                     ],
                     ("bob", ),
                     4,
                 ))

        await self.run_disallowed(cases)
示例#2
0
    async def test_disallows_messages_with_too_many_attachments(self):
        """Messages with too many attachments trigger the rule."""
        cases = (
            DisallowedCase(
                [make_msg("bob", 4),
                 make_msg("bob", 0),
                 make_msg("bob", 6)],
                ("bob", ),
                10,
            ),
            DisallowedCase(
                [make_msg("bob", 4),
                 make_msg("alice", 6),
                 make_msg("bob", 2)],
                ("bob", ),
                6,
            ),
            DisallowedCase(
                [make_msg("alice", 6)],
                ("alice", ),
                6,
            ),
            DisallowedCase(
                [make_msg("alice", 1) for _ in range(6)],
                ("alice", ),
                6,
            ),
        )

        await self.run_disallowed(cases)
示例#3
0
    async def test_disallows_messages_beyond_limit(self):
        """Cases with too many duplicate messages from the same author."""
        cases = (
            DisallowedCase(
                [
                    make_msg("alice", "A"),
                    make_msg("alice", "A"),
                    make_msg("alice", "A")
                ],
                ("alice", ),
                3,
            ),
            DisallowedCase(
                [
                    make_msg("bob", "A"),
                    make_msg("alice", "A"),
                    make_msg("bob", "A"),
                    make_msg("bob", "A")
                ],
                ("bob", ),
                3,  # 4 duplicate messages, but only 3 from bob
            ),
            DisallowedCase(
                [
                    make_msg("bob", "A"),
                    make_msg("bob", "B"),
                    make_msg("bob", "A"),
                    make_msg("bob", "A")
                ],
                ("bob", ),
                3,  # 4 message from bob, but only 3 duplicates
            ),
        )

        await self.run_disallowed(cases)
示例#4
0
    async def test_disallows_messages_beyond_limit(self):
        """Cases with more than the allowed amount of discord and unicode emojis."""
        cases = (
            DisallowedCase(
                [make_msg("bob", 3)],
                ("bob",),
                3,
            ),
            DisallowedCase(
                [make_msg("alice", 2), make_msg("bob", 2), make_msg("alice", 2)],
                ("alice",),
                4,
            ),
            DisallowedCase(
                [make_msg("bob", 3, unicode_emoji)],
                ("bob",),
                3,
            ),
            DisallowedCase(
                [
                    make_msg("alice", 2, unicode_emoji),
                    make_msg("bob", 2, unicode_emoji),
                    make_msg("alice", 2, unicode_emoji)
                ],
                ("alice",),
                4
            )
        )

        await self.run_disallowed(cases)
示例#5
0
    async def test_disallows_messages_beyond_limit(self):
        """Cases where the total amount of chars exceeds the limit, triggering the rule."""
        cases = (
            DisallowedCase(
                [make_msg("bob", 21)],
                ("bob", ),
                21,
            ),
            DisallowedCase(
                [make_msg("bob", 15), make_msg("bob", 15)],
                ("bob", ),
                30,
            ),
            DisallowedCase(
                [
                    make_msg("alice", 15),
                    make_msg("bob", 20),
                    make_msg("alice", 15)
                ],
                ("alice", ),
                30,
            ),
        )

        await self.run_disallowed(cases)
示例#6
0
    async def test_disallows_messages_consecutive(self):
        """Cases which violate the rule due to having too many consecutive newlines."""
        cases = (
            DisallowedCase(  # Bob sends a group of newlines too large
                [make_msg("bob", [4])],
                ("bob", ),
                4,
            ),
            DisallowedCase(  # Alice sends 5 in total (allowed), but 4 in one group (disallowed)
                [make_msg("alice", [1]),
                 make_msg("alice", [4])],
                ("alice", ),
                4,
            ),
        )

        await self.run_disallowed(cases)
示例#7
0
    async def test_disallows_messages_beyond_limit(self):
        """Cases with more than the allowed amount of role mentions."""
        cases = (
            DisallowedCase(
                [make_msg("bob", 3)],
                ("bob", ),
                3,
            ),
            DisallowedCase(
                [
                    make_msg("alice", 2),
                    make_msg("bob", 2),
                    make_msg("alice", 2)
                ],
                ("alice", ),
                4,
            ),
        )

        await self.run_disallowed(cases)
示例#8
0
    async def test_disallows_messages_total(self):
        """Cases which violate the rule by having too many newlines in total."""
        cases = (
            DisallowedCase(  # Alice sends a total of 6 newlines (disallowed)
                [make_msg("alice", [2, 2]),
                 make_msg("alice", [2])],
                ("alice", ),
                6,
            ),
            DisallowedCase(  # Here we test that only alice's newlines count in the sum
                [
                    make_msg("alice", [2, 2]),
                    make_msg("bob", [3]),
                    make_msg("alice", [3])
                ],
                ("alice", ),
                7,
            ),
        )

        await self.run_disallowed(cases)
示例#9
0
    async def test_disallows_messages_beyond_limit(self):
        """Cases where the amount of messages exceeds the limit, triggering the rule."""
        cases = (
            DisallowedCase(
                [make_msg("bob"),
                 make_msg("bob"),
                 make_msg("bob")],
                ("bob", ),
                3,
            ),
            DisallowedCase(
                [
                    make_msg("bob"),
                    make_msg("bob"),
                    make_msg("alice"),
                    make_msg("bob")
                ],
                ("bob", ),
                3,
            ),
        )

        await self.run_disallowed(cases)