Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ def startup(bot, trigger):
@plugin.priority('medium')
def handle_isupport(bot, trigger):
"""Handle ``RPL_ISUPPORT`` events."""
# remember if NAMESX is known to be supported, before parsing RPL_ISUPPORT
# remember if certain actionable tokens are known to be supported,
# before parsing RPL_ISUPPORT
botmode_support = 'BOT' in bot.isupport
namesx_support = 'NAMESX' in bot.isupport

# parse ISUPPORT message from server
Expand All @@ -326,6 +328,12 @@ def handle_isupport(bot, trigger):

bot._isupport = bot._isupport.apply(**parameters)

# was BOT mode support status updated?
if not botmode_support and 'BOT' in bot.isupport:
# yes it was! set our mode unless the config overrides it
botmode = bot.isupport['BOT']
if botmode not in bot.config.core.modes:
bot.write(('MODE', bot.nick, '+' + botmode))
# was NAMESX support status updated?
if not namesx_support and 'NAMESX' in bot.isupport:
# yes it was!
Expand Down
45 changes: 45 additions & 0 deletions test/test_coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,51 @@ def test_handle_isupport(mockbot):
assert 'CNOTICE' in mockbot.isupport


@pytest.mark.parametrize('modes', ['', 'Rw'])
def test_handle_isupport_bot_mode(mockbot, modes):
mockbot.config.core.modes = modes

mockbot.on_message(
':irc.example.com 005 Sopel '
'SAFELIST ELIST=CTU CPRIVMSG CNOTICE '
':are supported by this server')

assert 'BOT' not in mockbot.isupport
assert mockbot.backend.message_sent == []

mockbot.on_message(
':irc.example.com 005 Sopel '
'BOT=B '
':are supported by this server')

assert 'BOT' in mockbot.isupport
assert mockbot.isupport['BOT'] == 'B'
assert mockbot.backend.message_sent == rawlist('MODE TestBot +B')

mockbot.on_message(
':irc.example.com 005 Sopel '
'BOT=B '
':are supported by this server')

assert len(mockbot.backend.message_sent) == 1, 'No need to resend!'


@pytest.mark.parametrize('modes', ['B', 'RBw'])
def test_handle_isupport_bot_mode_override(mockbot, modes):
mockbot.config.core.modes = modes

mockbot.on_message(
':irc.example.com 005 Sopel '
'BOT=B '
':are supported by this server')

assert 'BOT' in mockbot.isupport
assert mockbot.isupport['BOT'] == 'B'
assert mockbot.backend.message_sent == [], (
'Bot should not set mode overridden by config setting'
)


def test_handle_isupport_namesx(mockbot):
mockbot.on_message(
':irc.example.com 005 Sopel '
Expand Down