<commit_before>"""Handle incoming spam messages."""

from ..handler import Handler

import logging
import json

class SpamHandler(Handler):
    """Spam handler."""

    MAX_SCORE = 16
    MAX_EMOTES = 6
    ALLOW_LINKS = False

    def __init__(self):
        self.logger = logging.getLogger(__name__)

    def on_message(self, packet):
        """Handle message events."""
        packet = json.loads(packet)
        # exceeds_caps = self.check_caps(''.join(chunk for chunk in packet if chunk["type"] == "text"))
        print("Caps")
        contains_emotes = self.check_emotes(packet)
        print("emote")
        has_links = self.check_links(packet)
        print("links")

        if contains_emotes or has_links:
            return True
        else:
            return False

    def check_links(self, packet):
        return not self.ALLOW_LINKS and any(chunk["type"] == "link" for chunk in packet)
        
    def check_emotes(self, packet):
        return sum(chunk["type"] == "emote" for chunk in packet) > self.MAX_EMOTES

    def check_caps(self, message):
        return sum(char.isupper() - char.islower() for char in message["text"]) > self.MAX_SCORE<commit_msg>Remove test code<commit_after>"""Handle incoming spam messages."""

from ..handler import Handler

import logging
import json

class SpamHandler(Handler):
    """Spam handler."""

    MAX_SCORE = 16
    MAX_EMOTES = 6
    ALLOW_LINKS = False

    def __init__(self):
        self.logger = logging.getLogger(__name__)

    def on_message(self, packet):
        """Handle message events."""
        packet = json.loads(packet)
        # exceeds_caps = self.check_caps(''.join(chunk for chunk in packet if chunk["type"] == "text"))
        contains_emotes = self.check_emotes(packet)
        has_links = self.check_links(packet)

        if contains_emotes or has_links:
            return True
        else:
            return False

    def check_links(self, packet):
        return not self.ALLOW_LINKS and any(chunk["type"] == "link" for chunk in packet)
        
    def check_emotes(self, packet):
        return sum(chunk["type"] == "emote" for chunk in packet) > self.MAX_EMOTES

    def check_caps(self, message):
        return sum(char.isupper() - char.islower() for char in message["text"]) > self.MAX_SCORE
{'fraction_non_alphanumeric': 0.11493252067914671, 'fraction_numerical': 0.00261210274270788, 'mean_word_length': 2.7796052631578947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4120043', 'n_tokens_mistral': 693, 'n_tokens_neox': 670, 'n_words': 186}