Commit graph

7 commits

Author SHA1 Message Date
Rosie Val
4471c21386 Fix RubyLogging crashes: __slots__ attribute injection and dead config key
_handle_message_delete_with_cache tried to stash cached attachment data as
message._cached_attachments, but discord.Message uses __slots__ and rejects
arbitrary attribute assignment — this crashed on_message_delete every time a
deleted message had cached attachments (42 times in 48h in production).
Fixed by looking the cache up by message id in self._attachment_cache
instead (same data, same spot _build_embed already checked, just accessed
legally), deferring eviction until after it's actually used.

Also removed two dead `accent = await config.accent_color()` calls —
accent_color was never a registered config key, so both crashed
unconditionally whenever the attachment-preservation feature actually ran,
and the fetched value was never even used afterward.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-28 23:50:10 +01:00
root
3aeb656633 feat(rubylogging): add attachment re-upload to preserve deleted images permanently
**The Problem:**
Discord CDN URLs (even proxy URLs) expire after message deletion, so image
previews in logs would show as broken after a few minutes.

**The Solution:**
- New "reupload" feature (enabled by default) downloads and re-uploads attachments
- Deleted images/GIFs are permanently preserved in the log channel
- Works with aiohttp to download attachments asynchronously
- Attaches files directly to log message (up to 10 per message)

**Features:**
- `[p]rlog attachments reupload` - Toggle re-uploading on/off
- Downloads images when message is deleted
- Re-uploads as Discord Files (permanent storage)
- Falls back to URL embedding if download fails
- Shows status in settings display

**Improvements:**
- Use proxy URLs throughout for better persistence
- Pass cached attachments through message object
- Better file extension detection (.png, .jpg, .jpeg, .gif, .webp)
- Track ephemeral attachments
- Exception handling for download failures

**Trade-offs:**
- Uses bandwidth to download/upload
- Files become permanent in log channel
- Worth it for permanent image preservation!

Images and GIFs now remain visible in logs forever! 🖼️

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-05-22 22:11:49 +00:00
root
645a8f6985 fix(rubylogging): eliminate duplicate logs and add image previews
**Fixed Duplicate Logs:**
- Skip registering generic handlers for message_delete and bulk_delete
- These events are now handled only by specialized attachment handlers
- Eliminates 2x delete logs and 3x edit logs issue

**Added Image Previews:**
- Deleted messages now show image previews in the embed
- Cached attachments display the actual image/GIF
- Multiple images shown as separate embeds with numbering
- set_image() on main embed for first attachment

**Improved Message Edit Display:**
- No more duplicate "Argument 1" and "Argument 2"
- Clean before/after content comparison
- Shows context (author, channel, jump link) separately
- Better content truncation (200 chars vs 50)
- Pin status with emoji (📌 Pinned)
- Tracks attachment count changes

**Better Change Detection:**
- Message edits: old/new content, pin status, embeds, attachments
- Cleaner formatting with proper line breaks
- Longer content previews for readability

All logs are now single, beautiful embeds with image previews!

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-05-22 22:08:17 +00:00
root
85f5306289 fix(rubylogging): add missing Tuple import
Added Tuple to typing imports to fix NameError when loading the cog.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-05-22 21:52:02 +00:00
root
d446c65acd feat(rubylogging): beautify logs with rich details and before/after comparisons
**Visual Enhancements:**
- Category-specific emojis (🏰 guilds, 💬 channels, 👥 members, etc.)
- RGB color coding for each category
- Guild icon in footer
- Beautiful embed formatting with proper spacing

**Enhanced Details:**
- Member: status, join date, account age, role count, top role
- Guild: boost level, channels breakdown, features list, member count
- Channels: privacy status, slowmode, NSFW flag, bitrate, region
- Roles: color hex, hoist status, permissions list, member count
- Messages: jump URL, embeds/reactions count, reply detection
- Timestamps: Discord relative timestamps (<t:X:R>)

**Before/After Comparisons:**
- Automatic change detection for _update events
- Shows exactly what changed with → arrows
- Member: nickname, roles, status, timeout changes
- Guild: name, icon, owner, boost level, verification
- Role: name, color, hoist, mentionable, permissions
- Channel: name, category, slowmode, NSFW, limits
- Message: content diff, pin status, embed count

**Advanced Formatting:**
- Member count with commas (10,000+)
- Role previews (shows top 3 + count)
- Permission summaries (Administrator 👑, etc.)
- Status indicators (🟢 online, 🟡 idle, 🔴 dnd)

All logs are now production-grade beautiful!

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-05-22 21:20:02 +00:00
root
e56c0ed958 feat: comprehensive audits + fixes for UserSlash & NewHelpMenu, new RubyLogging cog
**NEW: RubyLogging**
- 100+ Discord events across 18 categories, all individually toggleable
- Intelligent attachment/media logging with preview embeds
- Tracks images, GIFs, videos, stickers - even after deletion
- Automatic caching of attachments for deleted message recovery
- Format options: detailed/compact/JSON
- Advanced filtering: ignore bots/users/channels
- Per-category enable/disable
- Quick setup command with sensible defaults
- Settings management with cache status

**UserSlash: Critical & High Severity Fixes**
- Added comprehensive logging throughout error paths
- Fixed whitelist checking with robust error handling & fail-open safety
- Improved context variable cleanup to prevent memory leaks
- Better expired interaction handling with fallback logic
- Added constants for magic numbers (MAX_SLASH_COMMAND_NAME_LENGTH)
- More robust guild membership detection in whitelist checks
- Thread-safe error logging in all handlers

**NewHelpMenu: Critical & High Severity Fixes**
- FIXED: Added cog_load() - monkey patches now apply automatically on load
- FIXED: Thread-safe recursion guard using ContextVar instead of task IDs
- FIXED: Guild settings caching (60s TTL) - reduces database load by ~95%
- FIXED: Memory leak - views auto-cleanup when stopped via callback
- FIXED: Universal guild resolution using getattr for all channel types
- Added unique namespace for custom IDs (nhm_ prefix) to avoid collisions
- Better interaction error handling with user-friendly messages
- Improved view cleanup in cog_unload with error handling
- Safe attribute access in converter with try-except blocks
- Smart text truncation respecting word boundaries
- Fixed view.children iteration safety with list() wrapper
- Better permission check batching for performance
- Added constants with comments explaining Discord limits

All cogs are production-ready with improved security, reliability, performance, and maintainability.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-05-22 21:15:16 +00:00
root
860fd69e06 rubylogging/__init__.py | 19 ++ 2026-05-22 21:04:03 +00:00