Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

This pull request implements the 24-hour vote restriction requested in issue #50, preventing users from voting on messages older than 24 hours.

Changes Made

Core Implementation

  • Modified apply_karma() method in python/modules/commands.py:
    • Added timestamp validation before processing votes
    • Calculates message age using VK API's date field from selected_message
    • Blocks votes with user-friendly error message: "❌ Cannot vote on messages older than 24 hours."
    • Preserves all existing karma logic for recent messages

Technical Details

  • Time calculation: (current_timestamp - message_timestamp) / 3600 > 24
  • Scope: Only affects the Python bot implementation (where voting is implemented)
  • Backward compatibility: No changes to existing vote behavior for recent messages
  • Error handling: Graceful degradation when timestamp data is unavailable

Testing

  • Added comprehensive test case in python/tests.py:
    • Tests messages at 25 hours (blocked), 1 hour (allowed), exactly 24 hours (allowed), and 24.1 hours (blocked)
  • Created validation script experiments/test_24h_restriction.py:
    • Standalone test to verify time calculation logic
    • All test cases pass successfully

Test Results

Test 1 - Old message (25 hours ago): Should be blocked: True ✅
Test 2 - Recent message (1 hour ago): Should be blocked: False ✅  
Test 3 - Boundary message (24 hours ago): Should be blocked: False ✅
Test 4 - Just over 24 hours (24.1 hours ago): Should be blocked: True ✅

Behavior

  • Before: Users could vote on any message regardless of age
  • After: Users can only vote on messages less than or equal to 24 hours old
  • User Experience: Clear error message when attempting to vote on old messages
  • Performance: Minimal overhead - single timestamp comparison per vote

This implementation directly addresses the requirement in issue #50 to prevent vote spam on old messages while maintaining full functionality for recent discussions.

Fixes #50

🤖 Generated with Claude Code

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

Issue: #50
@konard konard self-assigned this Sep 14, 2025
- Add time-based validation in apply_karma() method to prevent voting on messages older than 24 hours
- Messages are checked using their timestamp from VK API 'date' field
- Display user-friendly error message when vote is blocked
- Add comprehensive test coverage for the 24-hour boundary
- Include test validation script in experiments/ folder

Fixes #50

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

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Disallow votes for old messages (longer than 24 hours ago) Disallow votes for old messages (longer than 24 hours ago) Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 00:26
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.

Disallow votes for old messages (longer than 24 hours ago)

1 participant