Example #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_highlight_punctuated_word(self):
        # Given
        word = 'foo'
        text = "foo's bar or foo?"

        # When
        text = highlight_word(text, word)

        # Then
        self.assertEqual(text, "*foo*'s bar or *foo*?")

        return
    def test_should_highlight_word_at_ends(self):
        # Given
        word = 'foo'
        text = 'foo this is foo'

        # When
        text = highlight_word(text, word)

        # Then
        self.assertEqual(text, '*foo* this is *foo*')

        return
    def test_should_highlight_exact_word(self):
        # Given
        word = 'foo'
        text = 'this is foo bar'

        # When
        text = highlight_word(text, word)

        # Then
        self.assertEqual(text, 'this is *foo* bar')

        return