Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

🎯 Summary

This PR implements local karma functionality that allows users to have separate karma values for each chat, in addition to their global karma.

Fixes #45

✨ Features Implemented

Core Functionality

  • Local karma storage: Each user now has a local_karma dictionary storing karma values per chat ID
  • Chat-specific karma tracking: Users can have different karma in different chats
  • Independent from global karma: Local karma works alongside existing global karma without interference

Commands Added

  • local karma / локальная карма - Display local karma for current chat
  • local +/- - Vote to change local karma in current chat
  • local +[NUMBER] / local -[NUMBER] - Transfer specific amount of local karma
  • local top / локальный топ - Show local karma leaderboard for current chat
  • local bottom / локальный низ - Show reverse local karma leaderboard

Technical Implementation

  • Added local_karma field to user data structure as dict: {chat_id: karma_value}
  • Implemented helper methods in BetterBotBaseDataService for local karma operations
  • Created local karma versions of existing karma commands and builders
  • Added comprehensive pattern matching for Russian and English aliases
  • Extended help system to include local karma documentation

Testing

  • Added comprehensive test suite (Test4LocalKarma) covering:
    • Local karma data storage and retrieval
    • Local karma string formatting
    • Local karma command functionality
    • Local karma user sorting and leaderboards
  • All tests validate chat-specific karma isolation

Documentation

  • Updated README.md with all new local karma commands
  • Added command aliases table for local karma
  • Extended in-bot help messages with local karma usage
  • Documented all local karma features with examples

🔧 Technical Details

Data Structure

user.local_karma = {
    "2000000001": 15,  # Chat 1 karma
    "2000000002": -3,  # Chat 2 karma  
    "2000000003": 8    # Chat 3 karma
}

Key Methods Added

  • BetterBotBaseDataService.get_local_karma(user, chat_id)
  • BetterBotBaseDataService.set_local_karma(user, chat_id, karma_value)
  • DataBuilder.build_local_karma(user, data, chat_id)
  • DataBuilder.get_users_sorted_by_local_karma(vk, data, peer_id, chat_id)
  • Commands.local_karma_message(), apply_local_karma(), local_top()

Backward Compatibility

✅ All existing global karma functionality preserved
✅ No breaking changes to existing commands or data structures
✅ Local karma is purely additive feature

🧪 Testing Strategy

  • Unit tests verify local karma isolation between chats
  • Tests confirm global karma remains unaffected
  • Command parsing tests for all new patterns
  • Leaderboard sorting tests with multiple users

📖 Usage Examples

Basic Local Karma

User: local karma
Bot: Ваша локальная карма в этом чате — [5].

User: local +
Bot: Локальная карма в этом чате изменена: [id123|John] [2]->[3].

Local Leaderboards

User: local top 3
Bot: [15] [id456|Alice] github.com/alice Python, C++
     [8] [id789|Bob] Rust, Go  
     [3] [id123|John] JavaScript

🚀 Ready for Review

All implementation is complete with comprehensive testing and documentation.


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #45
@konard konard self-assigned this Sep 14, 2025
This commit implements local karma feature that allows users to have
separate karma values for each chat, in addition to their global karma.

Key features implemented:
- Local karma storage per chat in user profiles
- Local karma commands: 'local karma', 'local +/-', 'local top/bottom'
- Chat-specific karma voting and leaderboards
- Comprehensive test coverage for local karma functionality
- Updated help messages and documentation with local karma commands
- Support for Russian and English command aliases

The local karma system works independently from global karma:
- Users can have different karma values in different chats
- Local karma voting follows same rules as global karma (time limits, negative karma restrictions)
- Local karma is displayed separately from global karma
- Local leaderboards show only participants from current chat

All existing global karma functionality remains unchanged and fully compatible.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add local karma Add local karma functionality for chat-specific karma tracking Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add local karma

2 participants