From 2d8f2b35159a1c43e3c63bb05aea1990c49a0c66 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 04:01:42 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #117 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Bot/issues/117 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..42381981 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Bot/issues/117 +Your prepared branch: issue-117-b93d3637 +Your prepared working directory: /tmp/gh-issue-solver-1757725298238 + +Proceed. \ No newline at end of file From abc87862d4097e3582ff470dff7834685aabcdf4 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 04:06:57 +0300 Subject: [PATCH 2/3] Add optional reasons to karma voting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified APPLY_KARMA regex pattern to capture optional reasons after karma operators - Updated apply_karma method to extract and pass reason parameter - Enhanced build_karma_change to display reasons in karma change messages - Added test case for karma reasons functionality - Supports formats like "+ решение сработало" and "- вопрос недостаточно конкретный" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- python/modules/commands.py | 8 +++++--- python/modules/commands_builder.py | 12 +++++++----- python/patterns.py | 2 +- python/tests.py | 24 +++++++++++++++++++++++- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/python/modules/commands.py b/python/modules/commands.py index 93d99817..1a0bd6ac 100644 --- a/python/modules/commands.py +++ b/python/modules/commands.py @@ -174,6 +174,7 @@ def apply_karma(self) -> NoReturn: operator = self.matched.group("operator")[0] amount = self.matched.group("amount") amount = int(amount) if amount else 0 + reason = self.matched.group("reason") utcnow = datetime.utcnow() @@ -211,7 +212,7 @@ def apply_karma(self) -> NoReturn: return user_karma_change, selected_user_karma_change, collective_vote_applied, voters = self.apply_karma_change( - operator, amount) + operator, amount, reason) if collective_vote_applied: self.current_user.last_collective_vote = int(utcnow.timestamp()) @@ -223,14 +224,15 @@ def apply_karma(self) -> NoReturn: self.data_service.save_user(self.user) self.vk_instance.send_msg( CommandsBuilder.build_karma_change( - user_karma_change, selected_user_karma_change, voters), + user_karma_change, selected_user_karma_change, voters, reason), self.peer_id) self.vk_instance.delete_message(self.peer_id, self.msg_id) def apply_karma_change( self, operator: str, - amount: int + amount: int, + reason: Optional[str] = None ) -> Tuple[ Optional[Tuple[int, str, int, int]], # current user karma changed Optional[Tuple[int, str, int, int]], # selected user karma changed diff --git a/python/modules/commands_builder.py b/python/modules/commands_builder.py index 29dc739f..c3cce2d9 100644 --- a/python/modules/commands_builder.py +++ b/python/modules/commands_builder.py @@ -174,14 +174,16 @@ def build_top_users( def build_karma_change( user_karma_change: Optional[Tuple[int, str, int, int]], selected_user_karma_change: Optional[Tuple[int, str, int, int]], - voters: List[int] + voters: List[int], + reason: Optional[str] = None ) -> Optional[str]: """Builds karma changing """ if selected_user_karma_change: + reason_text = f" Причина: {reason}" if reason else "" if user_karma_change: - return ("Карма изменена: [id%s|%s] [%s]->[%s], [id%s|%s] [%s]->[%s]." % - (user_karma_change + selected_user_karma_change)) - return ("Карма изменена: [id%s|%s] [%s]->[%s]. Голосовали: (%s)" % - (selected_user_karma_change + (", ".join([f"@id{voter}" for voter in voters]),))) + return ("Карма изменена: [id%s|%s] [%s]->[%s], [id%s|%s] [%s]->[%s].%s" % + (user_karma_change + selected_user_karma_change + (reason_text,))) + return ("Карма изменена: [id%s|%s] [%s]->[%s]. Голосовали: (%s)%s" % + (selected_user_karma_change + (", ".join([f"@id{voter}" for voter in voters]), reason_text))) return None diff --git a/python/patterns.py b/python/patterns.py index 1834c72c..515ecc58 100644 --- a/python/patterns.py +++ b/python/patterns.py @@ -19,7 +19,7 @@ r'\A\s*(карма|karma)\s*\Z', IGNORECASE) APPLY_KARMA = recompile( - r'\A(\[id(?\d+)\|@\w+\])?\s*(?P\+|\-)(?P[0-9]*)\s*\Z') + r'\A(\[id(?P\d+)\|@\w+\])?\s*(?P\+|\-)(?P[0-9]*)(?:\s+(?P.+?))?\s*\Z') ADD_PROGRAMMING_LANGUAGE = recompile( r'\A\s*\+=\s*(?P' + DEFAULT_LANGUAGES + r')\s*\Z', IGNORECASE) diff --git a/python/tests.py b/python/tests.py index 4be4241e..f539c9ca 100644 --- a/python/tests.py +++ b/python/tests.py @@ -219,9 +219,31 @@ def test_apply_collective_vote( def test_apply_karma_change( self ) -> NoReturn: - self.commands.apply_karma_change('-', 6) + self.commands.apply_karma_change('-', 6, "тестовая причина") self.commands.karma_message() + @ordered + def test_karma_with_reasons( + self + ) -> NoReturn: + # Test karma with reasons + test_messages = [ + "+ решение сработало", + "- вопрос недостаточно конкретный", + "+5 отличная помощь", + "-2 неточный ответ" + ] + + for msg in test_messages: + self.commands.msg = msg + self.commands.match_command(patterns.APPLY_KARMA) + if self.commands.matched: + operator = self.commands.matched.group("operator") + amount = self.commands.matched.group("amount") + amount = int(amount) if amount else 0 + reason = self.commands.matched.group("reason") + print(f"Message: '{msg}' -> Operator: '{operator}', Amount: {amount}, Reason: '{reason}'") + if __name__ == '__main__': db = BetterBotBaseDataService("test_db") From 21ccdcb9224453ec8a522bc3b47cd2cca3aa75be Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 04:07:47 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 42381981..00000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Bot/issues/117 -Your prepared branch: issue-117-b93d3637 -Your prepared working directory: /tmp/gh-issue-solver-1757725298238 - -Proceed. \ No newline at end of file