From fa4815153aa1a3954ce7862bdaa01000b95d1b2b Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 8 Feb 2025 23:30:59 -0600 Subject: [PATCH] cypher: slightly better display of output with no difficulty or mods Signed-off-by: Brian S. Stephan --- dice/ircplugin.py | 2 +- tests/test_dice_ircplugin.py | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dice/ircplugin.py b/dice/ircplugin.py index 2d836c9..5ba73cd 100644 --- a/dice/ircplugin.py +++ b/dice/ircplugin.py @@ -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}") diff --git a/tests/test_dice_ircplugin.py b/tests/test_dice_ircplugin.py index 92a656f..991ff07 100644 --- a/tests/test_dice_ircplugin.py +++ b/tests/test_dice_ircplugin.py @@ -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)' + )