cypher: slightly better display of output with no difficulty or mods

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
Brian S. Stephan 2025-02-08 23:30:59 -06:00
parent cc9b110531
commit fa4815153a
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
2 changed files with 18 additions and 4 deletions

View File

@ -76,7 +76,7 @@ class Dice(Plugin):
# show the adjusted difficulty
detail_str = f"14(d20={result} vs. diff. {difficulty}{mods})"
else:
detail_str = f"14(d20={result} with {mods} levels)"
detail_str = f"14(d20={result}{f' with {mods} levels' if mods else ''})"
if comment:
return self.bot.reply(event, f"{nick}: {comment} {result_str} {detail_str}")

View File

@ -26,12 +26,13 @@ class MarkovTestCase(TestCase):
def test_cypher_roll_strings(self):
"""Simulate incoming Cypher System requests."""
mock_event = mock.MagicMock()
mock_event.arguments = ['!cypher T3']
mock_event.source = 'test!test@test'
mock_event.target = '#test'
mock_event.recursing = False
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, '!cypher T3')
# general task roll
mock_event.arguments = ['!cypher T3']
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, mock_event.arguments[0])
with mock.patch('random.SystemRandom.randint', return_value=17):
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
self.mock_bot.reply.assert_called_with(
@ -39,10 +40,23 @@ class MarkovTestCase(TestCase):
'test: your check 9succeeded, with +1 damage! 14(d20=17 vs. diff. 3)'
)
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, '!cypher +1')
# unknown target roll
mock_event.arguments = ['!cypher +1']
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, mock_event.arguments[0])
with mock.patch('random.SystemRandom.randint', return_value=17):
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
self.mock_bot.reply.assert_called_with(
mock_event,
'test: your check beats a difficulty 4 task, with +1 damage! 14(d20=17 with +1 levels)'
)
# no mod or known difficulty
mock_event.arguments = ['!cypher unmodded attempt']
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, mock_event.arguments[0])
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
with mock.patch('random.SystemRandom.randint', return_value=9):
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
self.mock_bot.reply.assert_called_with(
mock_event,
'test: unmodded attempt beats a difficulty 3 task. 14(d20=9)'
)