Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

  • Implements automatic deletion of all bot messages after a configurable time period
  • Extends existing karma message deletion system to cover all bot responses
  • Adds new configuration options for fine-grained control
  • Maintains full backward compatibility with existing functionality

Changes Made

  • Config Enhancement: Added BOT_MESSAGE_DELETE_DELAY_MINUTES and BOT_MESSAGE_DELETE_CHATS configuration options
  • Message Scheduling: Modified send_msg() to automatically schedule deletion when enabled
  • Deletion Logic: Enhanced delete_message() to handle both karma and general bot messages
  • Helper Method: Added _should_delete_bot_message() for chat eligibility checking

Configuration Options

BOT_MESSAGE_DELETE_DELAY_MINUTES

  • Set to 0 to disable auto-deletion
  • Set to any positive number for deletion delay in minutes
  • Default: 60 (1 hour)

BOT_MESSAGE_DELETE_CHATS

  • List of chat IDs where bot messages should be auto-deleted
  • If empty, falls back to existing CHATS_DELETING configuration
  • Default: [] (uses CHATS_DELETING fallback)

How It Works

  1. When bot sends any message via send_msg(), it checks if auto-deletion is enabled
  2. If enabled and chat is configured for deletion, message gets scheduled for removal
  3. Existing cleanup mechanism processes scheduled deletions using userbot
  4. Messages are deleted when their scheduled time arrives

Backward Compatibility

✅ Existing karma message deletion (2-second delay) unchanged
✅ If BOT_MESSAGE_DELETE_DELAY_MINUTES = 0, feature is disabled
✅ Existing CHATS_DELETING configuration respected as fallback
✅ No breaking changes to existing API or functionality

Testing

  • Added comprehensive test suite in experiments/ directory
  • Tests validate configuration logic, time calculations, and chat selection
  • All tests pass successfully

Usage Examples

# Delete all bot messages after 30 minutes
BOT_MESSAGE_DELETE_DELAY_MINUTES = 30
BOT_MESSAGE_DELETE_CHATS = [2000000001, 2000000006]

# Delete all bot messages after 2 hours, use existing chat config  
BOT_MESSAGE_DELETE_DELAY_MINUTES = 120
BOT_MESSAGE_DELETE_CHATS = []  # Uses CHATS_DELETING

# Disable auto-deletion
BOT_MESSAGE_DELETE_DELAY_MINUTES = 0

Files Modified

  • python/config.py - Added new configuration options
  • python/__main__.py - Enhanced message handling and deletion logic
  • experiments/ - Added test suite and usage documentation

Fixes #38

🤖 Generated with Claude Code

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

Issue: #38
@konard konard self-assigned this Sep 14, 2025
- Added BOT_MESSAGE_DELETE_DELAY_MINUTES config to control deletion timing
- Added BOT_MESSAGE_DELETE_CHATS config for per-chat control
- Extended send_msg() to automatically schedule deletion of all bot messages
- Enhanced delete_message() to handle both karma and bot message deletions
- Maintained backward compatibility with existing karma deletion system
- Added comprehensive tests and usage documentation

Resolves #38 by allowing bot administrators to configure automatic
cleanup of bot messages to reduce chat clutter.

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

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Delete all bot messages аfter a certain period Implement automatic deletion of bot messages after configurable period Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 00:59
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.

Delete all bot messages аfter a certain period

2 participants