Esempio n. 1
0
def test_say_no_repeat_protection(bot):
    # five is fine
    bot.say('hello', '#sopel')
    bot.say('hello', '#sopel')
    bot.say('hello', '#sopel')
    bot.say('hello', '#sopel')
    bot.say('hello', '#sopel')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
    )

    # six: replaced by '...'
    bot.say('hello', '#sopel')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        # the extra hello is replaced by '...'
        'PRIVMSG #sopel :...',
    )

    # these one will add more '...'
    bot.say('hello', '#sopel')
    bot.say('hello', '#sopel')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :...',
        # the new ones are also replaced by '...'
        'PRIVMSG #sopel :...',
        'PRIVMSG #sopel :...',
    )

    # but at some point it just stops talking
    bot.say('hello', '#sopel')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        'PRIVMSG #sopel :hello',
        #  three time, then stop
        'PRIVMSG #sopel :...',
        'PRIVMSG #sopel :...',
        'PRIVMSG #sopel :...',
    )
Esempio n. 2
0
def test_wrapper_kick(mockbot):
    message = line(mockbot,
                   ':[email protected] PRIVMSG #channel :test message')
    wrapper = bot.SopelWrapper(mockbot, message)
    wrapper.kick('SpamUser')

    assert mockbot.backend.message_sent == rawlist('KICK #channel SpamUser')
Esempio n. 3
0
def test_wrapper_notice_override_destination(mockbot):
    message = line(mockbot,
                   ':[email protected] PRIVMSG #channel :test message')
    wrapper = bot.SopelWrapper(mockbot, message)
    wrapper.notice('Hi!', destination='#different')

    assert mockbot.backend.message_sent == rawlist('NOTICE #different :Hi!')
Esempio n. 4
0
def test_wrapper_notice(mockbot):
    message = line(mockbot,
                   ':[email protected] PRIVMSG #channel :test message')
    wrapper = bot.SopelWrapper(mockbot, message)
    wrapper.notice('Hi!')

    assert mockbot.backend.message_sent == rawlist('NOTICE #channel :Hi!')
Esempio n. 5
0
def test_wrapper_kick_override_destination(mockbot):
    message = line(mockbot,
                   ':[email protected] PRIVMSG #channel :test message')
    wrapper = bot.SopelWrapper(mockbot, message)
    wrapper.kick('SpamUser', channel='#another')

    assert mockbot.backend.message_sent == rawlist('KICK #another SpamUser')
Esempio n. 6
0
def test_on_connect_server_auth_password(bot):
    bot.settings.core.server_auth_method = 'server'
    bot.settings.core.server_auth_password = '******'
    bot.on_connect()

    assert bot.backend.message_sent == rawlist(
        'CAP LS 302', 'PASS server_secret', 'NICK Sopel',
        'USER sopel +iw Sopel :Sopel (https://sopel.chat)')
Esempio n. 7
0
def test_write_text_many(bot):
    bot.write(['NICK', 'Sopel'])
    bot.write(['HELP'], '?')

    assert bot.backend.message_sent == rawlist(
        'NICK Sopel',
        'HELP :?',
    )
Esempio n. 8
0
def test_write_args_many(bot):
    bot.write(['NICK', 'Sopel'])
    bot.write(['JOIN', '#sopel'])

    assert bot.backend.message_sent == rawlist(
        'NICK Sopel',
        'JOIN #sopel',
    )
Esempio n. 9
0
def test_say_long_extra(bot):
    """Test a long message that doesn't fit into the 512 bytes limit."""
    text = 'a' * (512 - len('PRIVMSG #sopel :\r\n'))
    bot.say(text + 'b', '#sopel')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :%s' % text,  # the 'b' is truncated out
    )
Esempio n. 10
0
def test_wrapper_action_override_destination(mockbot):
    message = line(mockbot,
                   ':[email protected] PRIVMSG #channel :test message')
    wrapper = bot.SopelWrapper(mockbot, message)
    wrapper.action('Hi!', destination='#different')

    assert mockbot.backend.message_sent == rawlist(
        'PRIVMSG #different :\x01ACTION Hi!\x01')
Esempio n. 11
0
def test_wrapper_reply_override_destination_reply_to(mockbot):
    message = line(mockbot,
                   ':[email protected] PRIVMSG #channel :test message')
    wrapper = bot.SopelWrapper(mockbot, message)
    wrapper.reply('Hi!', destination='#another', reply_to='Admin')

    assert mockbot.backend.message_sent == rawlist(
        'PRIVMSG #another :Admin: Hi!')
Esempio n. 12
0
def test_say_long_extra_multi_message(bot):
    """Test a long message that doesn't fit, with split allowed."""
    text = 'a' * 400
    bot.say(text + 'b', '#sopel', max_messages=2)

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :%s' % text,  # the 'b' is split from message
        'PRIVMSG #sopel :b',
    )
Esempio n. 13
0
def test_write_args_text_safe(bot):
    bot.write(['CMD\nUNSAFE'], 'Unsafe\rtext')

    assert bot.backend.message_sent == rawlist('CMDUNSAFE :Unsafetext')
Esempio n. 14
0
def test_join_password(bot):
    bot.join('#sopel', 'secret_password')

    assert bot.backend.message_sent == rawlist('JOIN #sopel secret_password', )
Esempio n. 15
0
def test_say_safe(bot):
    bot.say('Hello\r\nworld!\r\n', '#sopel')

    assert bot.backend.message_sent == rawlist('PRIVMSG #sopel :Helloworld!', )
Esempio n. 16
0
def test_say_long_fit(bot):
    """Test a long message that fits into the 512 bytes limit."""
    text = 'a' * (512 - len('PRIVMSG #sopel :\r\n'))
    bot.say(text, '#sopel')

    assert bot.backend.message_sent == rawlist('PRIVMSG #sopel :%s' % text, )
Esempio n. 17
0
def test_reply(bot):
    bot.reply('Thank you!', '#sopel', 'dgw')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :dgw: Thank you!', )
Esempio n. 18
0
def test_reply_notice(bot):
    bot.reply('Thank you!', '#sopel', 'dgw', notice=True)

    assert bot.backend.message_sent == rawlist(
        'NOTICE #sopel :dgw: Thank you!', )
Esempio n. 19
0
def test_part_reason(bot):
    bot.part('#channel', 'Bye!')

    assert bot.backend.message_sent == rawlist('PART #channel :Bye!', )
Esempio n. 20
0
def test_part(bot):
    bot.part('#channel')

    assert bot.backend.message_sent == rawlist('PART #channel', )
Esempio n. 21
0
def test_action(bot):
    bot.action('is doing some tests', '#sopel')

    assert bot.backend.message_sent == rawlist(
        'PRIVMSG #sopel :\001ACTION is doing some tests\001', )
Esempio n. 22
0
def test_write_args(bot):
    bot.write(['NICK', 'Sopel'])

    assert bot.backend.message_sent == rawlist('NICK Sopel')
Esempio n. 23
0
def test_join(bot):
    bot.join('#sopel')

    assert bot.backend.message_sent == rawlist('JOIN #sopel', )
Esempio n. 24
0
def test_on_connect(bot):
    bot.on_connect()

    assert bot.backend.message_sent == rawlist(
        'CAP LS 302', 'NICK Sopel',
        'USER sopel +iw Sopel :Sopel (https://sopel.chat)')
Esempio n. 25
0
def test_kick(bot):
    bot.kick('spambot', '#channel')

    assert bot.backend.message_sent == rawlist('KICK #channel spambot', )
Esempio n. 26
0
def test_write(bot):
    bot.write(['INFO'])

    assert bot.backend.message_sent == rawlist('INFO')
Esempio n. 27
0
def test_kick_reason(bot):
    bot.kick('spambot', '#channel', 'Flood!')

    assert bot.backend.message_sent == rawlist(
        'KICK #channel spambot :Flood!', )
Esempio n. 28
0
def test_write_text(bot):
    bot.write(['HELP'], '?')

    assert bot.backend.message_sent == rawlist('HELP :?')
Esempio n. 29
0
def test_notice(bot):
    bot.notice('Hello world!', '#sopel')

    assert bot.backend.message_sent == rawlist('NOTICE #sopel :Hello world!', )