aboutsummaryrefslogtreecommitdiffstats
path: root/bot/rules/chars.py
blob: d05e3cd83a9ac000f71d2ae176f3b5c8cd4a9a2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Detects total message char count exceeding the limit sent by a single user."""

from typing import Dict, Iterable, List, Optional, Tuple

from discord import Member, Message


async def apply(
    last_message: Message,
    recent_messages: List[Message],
    config: Dict[str, int]
) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:

    relevant_messages = tuple(
        msg
        for msg in recent_messages
        if msg.author == last_message.author
    )

    total_recent_chars = sum(len(msg.content) for msg in relevant_messages)

    if total_recent_chars > config['max']:
        return (
            f"sent {total_recent_chars} characters in {config['interval']}s",
            (last_message.author,),
            relevant_messages
        )
    return None