LOW: Deduplicate MOOD_EMOJIS mapping between moods.py and evil_mode.py #44

Open
opened 2026-02-20 14:52:36 +02:00 by Koko210 · 0 comments
Owner

Problem

The mood-to-emoji mapping dictionary is defined in two separate files:

  1. bot/utils/moods.py — MOOD_EMOJIS dict for regular Miku moods
  2. bot/utils/evil_mode.py — A separate MOOD_EMOJIS (or similar) dict for evil Miku moods

While the evil mode has a different set of moods than regular mode, the pattern of defining emoji mappings is duplicated. If a new mood is added or an emoji needs to change, both files must be updated. The nickname-update logic that applies the emoji is also duplicated.

Proposed Solution

Create a shared mood constants module:

# bot/utils/mood_constants.py

REGULAR_MOOD_EMOJIS = {
    'happy': '😊',
    'sad': '😢',
    'excited': '🎉',
    # ... all regular moods
}

EVIL_MOOD_EMOJIS = {
    'malicious': '😈',
    'scheming': '🗡',
    # ... all evil moods
}

def get_mood_emoji(mood: str, evil_mode: bool = False) -> str:
    emojis = EVIL_MOOD_EMOJIS if evil_mode else REGULAR_MOOD_EMOJIS
    return emojis.get(mood, '')

async def update_nickname_emoji(guild, mood: str, evil_mode: bool = False):
    # Shared nickname update logic
    emoji = get_mood_emoji(mood, evil_mode)
    # ... update nickname

Then both moods.py and evil_mode.py import from mood_constants.py instead of defining their own mappings.

Impact

  • Risk: None
  • Effort: Trivial
  • Benefit: Single source of truth for mood emojis, DRY principle

Files Affected

  • NEW: bot/utils/mood_constants.py (shared constants)
  • bot/utils/moods.py (import from mood_constants)
  • bot/utils/evil_mode.py (import from mood_constants)
## Problem The mood-to-emoji mapping dictionary is defined in two separate files: 1. **bot/utils/moods.py** — MOOD_EMOJIS dict for regular Miku moods 2. **bot/utils/evil_mode.py** — A separate MOOD_EMOJIS (or similar) dict for evil Miku moods While the evil mode has a different set of moods than regular mode, the pattern of defining emoji mappings is duplicated. If a new mood is added or an emoji needs to change, both files must be updated. The nickname-update logic that applies the emoji is also duplicated. ## Proposed Solution Create a shared mood constants module: # bot/utils/mood_constants.py REGULAR_MOOD_EMOJIS = { 'happy': '😊', 'sad': '😢', 'excited': '🎉', # ... all regular moods } EVIL_MOOD_EMOJIS = { 'malicious': '😈', 'scheming': '🗡', # ... all evil moods } def get_mood_emoji(mood: str, evil_mode: bool = False) -> str: emojis = EVIL_MOOD_EMOJIS if evil_mode else REGULAR_MOOD_EMOJIS return emojis.get(mood, '') async def update_nickname_emoji(guild, mood: str, evil_mode: bool = False): # Shared nickname update logic emoji = get_mood_emoji(mood, evil_mode) # ... update nickname Then both moods.py and evil_mode.py import from mood_constants.py instead of defining their own mappings. ## Impact - Risk: None - Effort: Trivial - Benefit: Single source of truth for mood emojis, DRY principle ## Files Affected - NEW: bot/utils/mood_constants.py (shared constants) - bot/utils/moods.py (import from mood_constants) - bot/utils/evil_mode.py (import from mood_constants)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Koko210/miku-discord#44