<commit_before>from bot.api.domain import Message
from bot.logger.message_sender import IntermediateMessageSender
from bot.logger.message_sender.message_builder import MessageBuilder
from bot.logger.message_sender.reusable.limiter import ReusableMessageLimiter
from bot.logger.message_sender.reusable.same import SameMessageSender


class ReusableMessageSender(IntermediateMessageSender):
    def __init__(self, sender: SameMessageSender, builder: MessageBuilder, limiter: ReusableMessageLimiter):
        super().__init__(sender)
        self.builder = builder
        self.limiter = limiter

    def send(self, text):
        message = self._get_message_for(text)
        self._send(message)

    def _get_message_for(self, text):
        self.__pre_add_limiter_hook(text)
        self.builder.add(text)
        self.__post_add_limiter_hook(text)
        return self.builder.get_message()

    def __pre_add_limiter_hook(self, text):
        if self.limiter.should_issue_new_message_pre_add(text):
            self.new()<commit_msg>Call notify_about_to_send_message in ReusableMessageSender just before sending the message<commit_after>from bot.api.domain import Message
from bot.logger.message_sender import IntermediateMessageSender
from bot.logger.message_sender.message_builder import MessageBuilder
from bot.logger.message_sender.reusable.limiter import ReusableMessageLimiter
from bot.logger.message_sender.reusable.same import SameMessageSender


class ReusableMessageSender(IntermediateMessageSender):
    def __init__(self, sender: SameMessageSender, builder: MessageBuilder, limiter: ReusableMessageLimiter):
        super().__init__(sender)
        self.builder = builder
        self.limiter = limiter

    def send(self, text):
        message = self._get_message_for(text)
        self.limiter.notify_about_to_send_message()
        self._send(message)

    def _get_message_for(self, text):
        self.__pre_add_limiter_hook(text)
        self.builder.add(text)
        self.__post_add_limiter_hook(text)
        return self.builder.get_message()

    def __pre_add_limiter_hook(self, text):
        if self.limiter.should_issue_new_message_pre_add(text):
            self.new()
{'fraction_non_alphanumeric': 0.07464724624487938, 'fraction_numerical': 0.0, 'mean_word_length': 4.258373205741627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4618162', 'n_tokens_mistral': 640, 'n_tokens_neox': 620, 'n_words': 118}