From 2d811a14010eed49cd1a411e3f127c9a8b24c87a Mon Sep 17 00:00:00 2001 From: Bruce Cowan <bruce@bcowan.me.uk> Date: Thu, 13 Jan 2022 19:01:25 +0000 Subject: [PATCH] Only match if at end of line Fixes #12 --- karma.py | 6 +++--- test_karma.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/karma.py b/karma.py index 86bffee..75842eb 100644 --- a/karma.py +++ b/karma.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2016-2021 Bruce Cowan <bruce@bcowan.me.uk> +# SPDX-FileCopyrightText: 2016-2022 Bruce Cowan <bruce@bcowan.me.uk> # # SPDX-License-Identifier: GPL-3.0-or-later @@ -30,7 +30,7 @@ class Karma(errbot.BotPlugin): return f"Karma for '{target}' is now {self['karma'][target]}" - @errbot.re_botcmd(pattern=r"(.+)\+\+", prefixed=False, flags=re.IGNORECASE) + @errbot.re_botcmd(pattern=r"(.+)\+\+$", prefixed=False, flags=re.IGNORECASE) def on_karma_inc(self, message: errbot.Message, match: re.Match) -> str | None: """Adds karma""" if message.frm == self.bot_identifier: @@ -40,7 +40,7 @@ class Karma(errbot.BotPlugin): return self._change_karma(match.group(1), 1) - @errbot.re_botcmd(pattern=r"(.+)--", prefixed=False, flags=re.IGNORECASE) + @errbot.re_botcmd(pattern=r"(.+)--$", prefixed=False, flags=re.IGNORECASE) def on_karma_dec(self, message: errbot.Message, match: re.Match) -> str | None: """Removes karma""" if message.frm == self.bot_identifier: diff --git a/test_karma.py b/test_karma.py index 3fdca90..0f4afe2 100644 --- a/test_karma.py +++ b/test_karma.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2018-2021 Bruce Cowan <bruce@bcowan.me.uk> +# SPDX-FileCopyrightText: 2018-2022 Bruce Cowan <bruce@bcowan.me.uk> # # SPDX-License-Identifier: GPL-3.0-or-later @@ -40,3 +40,13 @@ def test_cpp(testbot): testbot.push_message("C++ is not horrible") with pytest.raises(queue.Empty): testbot.pop_message(1) + + +def test_noend(testbot): + testbot.push_message("Testing++ not at the end of line") + with pytest.raises(queue.Empty): + testbot.pop_message(1) + + testbot.push_message("Testing-- not at the end of the line") + with pytest.raises(queue.Empty): + testbot.pop_message(1) -- GitLab