From 08fb465c672013fb3d2ef922e3a8529d4791589d Mon Sep 17 00:00:00 2001 From: koko210Serve Date: Mon, 30 Mar 2026 14:30:34 +0300 Subject: [PATCH] Fix: Cache regular Miku avatar URL to prevent pfp bleed in bipolar arguments When Evil Mode activates, the bot's Discord account avatar is changed to evil_pfp.png. Previously, get_persona_avatar_urls() would read this swapped avatar and pass it to the Miku webhook, causing both webhooks to display Evil Miku's pfp. Now caching the regular Miku CDN URL before Evil Mode changes the bot's avatar. When Evil Mode is active, the cached URL is used instead of reading from the bot account. Discord CDN URLs remain valid after avatar changes, so this reliably preserves the correct pfp for both regular and Evil Miku webhooks during arguments. - Added MIKU_NORMAL_AVATAR_URL global in bot/globals.py - Updated get_persona_avatar_urls() to cache and return the cached URL - Save the normal avatar URL before Evil Mode switches the bot's avatar --- bot/globals.py | 1 + bot/utils/bipolar_mode.py | 23 ++++++++++++----------- bot/utils/evil_mode.py | 8 ++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bot/globals.py b/bot/globals.py index adccc5a..85897af 100644 --- a/bot/globals.py +++ b/bot/globals.py @@ -75,6 +75,7 @@ EVIL_AVAILABLE_MOODS = ["aggressive", "cunning", "sarcastic", "evil_neutral", "b BIPOLAR_MODE = False BIPOLAR_WEBHOOKS = {} # guild_id -> {"miku_webhook_url": str, "evil_webhook_url": str} BIPOLAR_ARGUMENT_IN_PROGRESS = {} # channel_id -> {"active": bool, "exchange_count": int, "current_speaker": str} +MIKU_NORMAL_AVATAR_URL = None # Cached CDN URL of the regular Miku pfp (valid even after evil mode swaps the bot avatar) # MOOD_EMOJIS removed — canonical source is utils/moods.py # bipolar_mode.py now imports from there directly diff --git a/bot/utils/bipolar_mode.py b/bot/utils/bipolar_mode.py index 76cf400..639916a 100644 --- a/bot/utils/bipolar_mode.py +++ b/bot/utils/bipolar_mode.py @@ -263,23 +263,24 @@ def get_persona_avatar_urls() -> dict: """Get current avatar URLs for Miku and Evil Miku personas. Returns a dict with 'miku' and 'evil_miku' avatar URL strings (or None). - When Evil Mode is inactive, uses the bot's current Discord avatar for Miku. - When Evil Mode is active, the bot account avatar has been changed to the evil - pfp, so returning None for Miku causes the webhook to fall back to its own - stored avatar (set to current.png by update_webhook_avatars), preventing - both webhooks from showing the evil pfp. + When Evil Mode is inactive, uses the bot's current Discord avatar for Miku + and caches the CDN URL so it remains available when Evil Mode activates. + When Evil Mode is active, returns the cached regular-Miku CDN URL instead + of the live bot avatar (which has been swapped to evil_pfp). Evil Miku always falls back to the webhook's stored avatar (passed as None). """ miku_url = None evil_url = None - # For Miku: use the bot's actual Discord avatar URL only when Evil Mode is - # not active. When Evil Mode is on, the bot account avatar has been swapped - # to evil_pfp.png, so we pass None here and let the Miku webhook use its - # own correctly-stored avatar (current.png) instead. - if not globals.EVIL_MODE and globals.client and globals.client.user: + if globals.client and globals.client.user: try: - miku_url = str(globals.client.user.display_avatar.url) + if not globals.EVIL_MODE: + # Normal mode: read live bot avatar and cache it for later use + miku_url = str(globals.client.user.display_avatar.url) + globals.MIKU_NORMAL_AVATAR_URL = miku_url + else: + # Evil mode: bot avatar is evil_pfp — use the cached regular URL + miku_url = globals.MIKU_NORMAL_AVATAR_URL except Exception: pass diff --git a/bot/utils/evil_mode.py b/bot/utils/evil_mode.py index 51db133..bd22d16 100644 --- a/bot/utils/evil_mode.py +++ b/bot/utils/evil_mode.py @@ -600,6 +600,14 @@ async def apply_evil_mode_changes(client, change_username=True, change_pfp=True, if current_color: save_evil_mode_state(saved_role_color=current_color) + # Cache the regular Miku avatar URL before switching to evil pfp + # (Discord CDN URLs remain valid after the avatar changes) + if globals.client and globals.client.user: + try: + globals.MIKU_NORMAL_AVATAR_URL = str(globals.client.user.display_avatar.url) + except Exception: + pass + globals.EVIL_MODE = True # Change bot username (if requested and possible - may be rate limited)