Exemplo n.º 1
0
    def setUp(self):
        self.bot = MagicMock()
        self.actions = MagicMock()
        self.sass = MagicMock()
        self.sass.get_next = MagicMock(name='some sass')
        self.chatroom = MagicMock()
        self.cadmusic = MagicMock()
        self.tell = MagicMock()
        self.tell.get_messages_for = MagicMock(return_value=None)
        self.dictionary = MagicMock()
        self.dictionary.get_definition = MagicMock(
            return_value='a picture of you')

        self.chat = SweetieChat(self.bot, self.actions, self.sass,
                                self.chatroom, self.cadmusic, self.tell,
                                self.dictionary)
Exemplo n.º 2
0
def build_sweetiebot(config=None):
    if config is None: import config
    resource = config.nickname + randomstr()
    if config.fake_redis:
        log.debug('faking out redis')
        redis_conn = FakeRedis()
    else:
        redis_conn = redis.from_url(config.redis_url)

    jid = config.username + '/' + resource
    nick = config.nickname
    room = config.chatroom
    password = config.password
    if config.hostname is not None:
        address = (config.hostname, config.port)
    else:
        address = ()

    bot = MUCJabberBot(jid, password, room, nick, address)
    crest = SweetieCrest(config.crest_base_url, config.crest_client_id,
                         config.crest_client_secret,
                         config.crest_refresh_token)
    lookup = SweetieLookup(bot, crest)
    admin = SweetieAdmin(bot, config.chatroom)
    mq = SweetieMQ(config)
    de = SweetieDe(bot, admin, mq, ResponsesFile('data/deowl_fails.txt'))
    actions = ResponsesFile('data/actions.txt')
    sass = ResponsesFile('data/sass.txt')
    cadmusic = ResponsesFile('data/cadmusic.txt')
    tell = SweetieTell(bot, redis_conn)
    dictionary = SweetieDictionary(bot)
    chat = SweetieChat(bot, actions, sass, config.chatroom, cadmusic, tell,
                       dictionary)
    roulette = SweetieRoulette(bot, admin)
    pings = SweetiePings(bot, redis_conn)
    moon = SweetieMoon(bot)
    if config.twitter_key is not None:
        twitter = TwitterClient.get_client(config.twitter_key,
                                           config.twitter_secret)
        watchers = list(map(twitter.get_timeline_watcher, ['EVE_Status']))
    else:
        watchers = []
    watchers.append(
        AtomWatcher.get_watcher(
            'http://eveion.blogspot.com/feeds/posts/default'))
    seen = SweetieSeen(bot, redis_conn)

    sweet = Sweetiebot(config.nickname, bot, lookup, mq, admin, chat, roulette,
                       de, pings, watchers, moon)
    return sweet
Exemplo n.º 3
0
    def setUp(self):
        self.bot = MagicMock()
        self.actions = MagicMock()
        self.sass = MagicMock()
        self.sass.get_next = MagicMock(name='some sass')
        self.chatroom = MagicMock()
        self.cadmusic = MagicMock()
        self.tell = MagicMock()
        self.tell.get_messages_for = MagicMock(return_value=None)
        self.dictionary = MagicMock()
        self.dictionary.get_definition = MagicMock(return_value='a picture of you')

        self.chat = SweetieChat(self.bot, self.actions, self.sass,
                self.chatroom, self.cadmusic, self.tell,
                self.dictionary)
Exemplo n.º 4
0
class SweetieChatTests(unittest.TestCase):

    def setUp(self):
        self.bot = MagicMock()
        self.actions = MagicMock()
        self.sass = MagicMock()
        self.sass.get_next = MagicMock(name='some sass')
        self.chatroom = MagicMock()
        self.markov = MagicMock()
        self.cadmusic = MagicMock()
        self.tell = MagicMock()
        self.tell.get_messages_for = MagicMock(return_value=None)
        self.dictionary = MagicMock()
        self.dictionary.get_definition = MagicMock(return_value='a picture of you')

        self.chat = SweetieChat(self.bot, self.actions, self.sass,
                self.chatroom, self.markov, self.cadmusic, self.tell,
                self.dictionary)

    def test_can_choose_a_thing(self):
        response = self.chat.choose(create_message('!choose pizza,pie,calzone'))
        self.assertIn(response, ['pizza', 'pie', 'calzone'])

    def test_does_not_show_permission_failed_title(self):
        return # this test is a bit slow
        response = self.chat.random_chat(create_message('https://forum.pleaseignore.com/topic/83206/'))
        self.assertIsNone(response)

    def test_does_not_cd_in_middle_of_word(self):
        response = self.chat.random_chat(create_message('you\'re a medic/doctor, right?'))
        self.assertIsNone(response)

    def test_sweetiebot_yes(self):
        response = self.chat.random_chat(create_message('Sweetiebot no'))
        self.assertEqual('Sweetiebot yes! :sweetieglee:', response)

    def test_how_x_is_y(self):
        response  = self.chat.random_chat(create_message('Sweetiebot: how x is y?'))
        self.assertEqual('sender: y [64.21% x]', response)
        response2 = self.chat.random_chat(create_message('Sweetiebot: how blue is red'))
        self.assertEqual('sender: red [15.42% blue]', response2)
        response3 = self.chat.random_chat(create_message('Sweetiebot: how amazing are amazing people'))
        self.assertEqual('sender: amazing people [79.86% amazing]', response3)
        response4 = self.chat.random_chat(create_message('Sweetiebot: how totally silly are silly people'))
        self.assertEqual('sender: silly people [45.24% totally silly]', response4)

    def test_misc(self):
        print(self.chat.random_chat(create_message('Sweetiebot: how do you do?')))
        print(self.chat.random_chat(create_message('Sweetiebot: how do you want to play this?')))
        print(self.chat.random_chat(create_message('Sweetiebot: what is love?')))
        print(self.chat.random_chat(create_message('Sweetiebot: will she ever love me')))

    def test_dictionary(self):
        response  = self.chat.random_chat(create_message('Sweetiebot: what is an idiot?'))
        self.assertEqual('a picture of you', response)
        
    def test_mlyp(self):
        response = self.chat.random_chat(create_message('Freddy Mercury is gay'))
        self.assertEqual('sender: mlyp', response)
Exemplo n.º 5
0
class SweetieChatTests(unittest.TestCase):
    def setUp(self):
        self.bot = MagicMock()
        self.actions = MagicMock()
        self.sass = MagicMock()
        self.sass.get_next = MagicMock(name='some sass')
        self.chatroom = MagicMock()
        self.cadmusic = MagicMock()
        self.tell = MagicMock()
        self.tell.get_messages_for = MagicMock(return_value=None)
        self.dictionary = MagicMock()
        self.dictionary.get_definition = MagicMock(
            return_value='a picture of you')

        self.chat = SweetieChat(self.bot, self.actions, self.sass,
                                self.chatroom, self.cadmusic, self.tell,
                                self.dictionary)

    def test_can_choose_a_thing(self):
        response = self.chat.choose(
            create_message('!choose pizza,pie,calzone'))
        self.assertIn(response, ['pizza', 'pie', 'calzone'])

    def test_does_not_show_permission_failed_title(self):
        return  # this test is a bit slow
        response = self.chat.random_chat(
            create_message('https://forum.pleaseignore.com/topic/83206/'))
        self.assertIsNone(response)

    def test_does_not_cd_in_middle_of_word(self):
        response = self.chat.random_chat(
            create_message('you\'re a medic/doctor, right?'))
        self.assertIsNone(response)

    def test_sweetiebot_yes(self):
        response = self.chat.random_chat(create_message('Sweetiebot no'))
        self.assertEqual('Sweetiebot yes! :sweetieglee:', response)

    def test_how_x_is_y(self):
        response = self.chat.random_chat(
            create_message('Sweetiebot: how x is y?'))
        self.assertEqual('sender: y [74.06% x]', response)
        response2 = self.chat.random_chat(
            create_message('Sweetiebot: how blue is red'))
        self.assertEqual('sender: red [51.89% blue]', response2)
        response3 = self.chat.random_chat(
            create_message('Sweetiebot: how amazing are amazing people'))
        self.assertEqual('sender: amazing people [13.67% amazing]', response3)
        response4 = self.chat.random_chat(
            create_message('Sweetiebot: how totally silly are silly people'))
        self.assertEqual('sender: silly people [11.49% totally silly]',
                         response4)

    def test_misc(self):
        print(
            self.chat.random_chat(
                create_message('Sweetiebot: how do you do?')))
        print(
            self.chat.random_chat(
                create_message('Sweetiebot: how do you want to play this?')))
        print(
            self.chat.random_chat(create_message('Sweetiebot: what is love?')))
        print(
            self.chat.random_chat(
                create_message('Sweetiebot: will she ever love me')))

    def test_dictionary(self):
        response = self.chat.random_chat(
            create_message('Sweetiebot: what is an idiot?'))
        self.assertEqual('a picture of you', response)

    def test_mlyp(self):
        response = self.chat.random_chat(
            create_message('Freddy Mercury is gay'))
        self.assertEqual('sender: mlyp', response)