Beispiel #1
0
    def idle_proc(self):

        if len(self.message_queue) == 0:
            return

        # copy the message queue, then empty it
        queue = self.message_queue
        self.message_queue = []

        messages = []

        for message in queue:
            messages.extend(chunk_text(message))

        for message in messages:
            if len(self.users):
                self.log.info(
                    'sending "%s" to %d user(s).', message, len(self.users)
                )

            for user in self.users:
                if not message.startswith("[%s]:" % self.users[user]):
                    self.send(user, highlight_word(message, self.users[user]))

        return
    def test_should_not_chunk_small_messages(self):
        # Given
        limit = 500

        # When
        messages = chunk_text('ab cd ef ', limit)

        # Then
        self.assertEqual(1, len(messages))
        self.assertEqual(9, len(messages[0]))

        return
    def test_should_chunk_message_at_limit(self):
        # Given
        limit = 500

        # When
        messages = chunk_text('x' * 1400, limit)

        # Then
        self.assertEqual(3, len(messages))
        self.assertEqual(500, len(messages[0]))
        self.assertEqual(500, len(messages[1]))
        self.assertEqual(400, len(messages[2]))

        return
    def test_should_chunk_message_at_spaces(self):
        # Given
        limit = 3

        # When
        messages = chunk_text('ab cd ef ', limit)

        # Then
        self.assertEqual(3, len(messages))
        self.assertEqual('ab ', messages[0])
        self.assertEqual('cd ', messages[1])
        self.assertEqual('ef ', messages[2])

        return