Skip to content

Add callback buttons for top command pagination - #291

Open
konard wants to merge 3 commits into
mainfrom
issue-124-3a75627d
Open

Add callback buttons for top command pagination#291
konard wants to merge 3 commits into
mainfrom
issue-124-3a75627d

Conversation

@konard

@konard konard commented Sep 12, 2025

Copy link
Copy Markdown
Member

Summary

This PR adds callback button pagination to the VK bot's top command as requested in issue #124. Users can now navigate through top users using interactive Previous/Next buttons instead of being limited by message size constraints.

🚀 Key Features

  • Interactive Pagination: Added Previous/Next callback buttons for navigating through user pages
  • Backward Compatibility: Commands with number parameters (e.g., top 15) still work without pagination
  • Multiple Command Support: Works with top, bottom, and people commands
  • Page Display: Shows current page and total pages (e.g., "2/5")
  • Optimized Page Size: 10 users per page for optimal readability

🔧 Technical Implementation

New Components

  1. VkKeyboard Class (keyboard_utils.py):

    • Generic VK inline keyboard builder
    • Support for callback and text buttons
    • Chainable API for easy keyboard construction
  2. TopPaginationKeyboard Class (keyboard_utils.py):

    • Specialized pagination keyboard for top commands
    • Automatic page calculation and navigation
    • Support for different command types
  3. Callback Event Handling:

    • New message_event handler in main Bot class
    • Payload parsing and action routing
    • Error handling with callback acknowledgments

Modified Components

  1. Bot Class (__main__.py):

    • Added message_event handler for callback buttons
    • Added send_msg_with_keyboard method
    • Added send_callback_answer method
  2. Commands Class (commands.py):

    • Enhanced top method with pagination logic
    • New top_paginated method for paginated display
    • New process_callback and handle_top_pagination methods

📋 Usage Examples

Basic Commands (New Behavior)

  • top → Shows first 10 users with pagination buttons
  • bottom → Shows first 10 users from bottom with pagination
  • people → Shows first 10 users with pagination

Legacy Commands (Unchanged)

  • top 15 → Shows exactly 15 users without pagination
  • bottom 5 → Shows exactly 5 users from bottom without pagination

Pagination Navigation

Users can click:

  • ⬅️ Пред. → Navigate to previous page
  • След. ➡️ → Navigate to next page
  • Page indicator (e.g., "2/5") → Shows current position (non-functional)

🧪 Test Plan

  • Created comprehensive test suite (simple_keyboard_test.py)
  • Keyboard JSON generation validation
  • Pagination calculation testing
  • Interactive demo (demo_callback_buttons.py)
  • Backward compatibility verification
  • Error handling validation

📊 Benefits

  1. Better User Experience: No more message size limitations
  2. Easier Navigation: Interactive buttons vs. typing commands
  3. Scalability: Works with any number of users
  4. Mobile Friendly: Touch-friendly button interface
  5. Maintainable: Clean, modular code architecture

Fixes #124

🤖 Generated with Claude Code

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

Issue: #124
@konard konard self-assigned this Sep 12, 2025
- Implement VkKeyboard utility class for creating VK inline keyboards
- Add TopPaginationKeyboard specialized class for top command pagination
- Add message_event handler to process callback button events
- Modify top command to support pagination with callback buttons
- Add send_msg_with_keyboard and send_callback_answer methods
- Maintain backward compatibility for top command with number parameter
- Support pagination for top, bottom, and people commands
- Display 10 users per page with Previous/Next navigation buttons

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

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add callback buttons Add callback buttons for top command pagination Sep 12, 2025
@konard
konard marked this pull request as ready for review September 12, 2025 23:31
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 callback buttons

1 participant