Add role color management to evil mode
- Evil mode now saves current 'Miku Color' role color before changing - Sets role color to #D60004 (dark red) when evil mode is enabled - Restores saved color when evil mode is disabled - Color is persisted in evil_mode_state.json between restarts - Role color changes are skipped on startup restore to avoid rate limits
This commit is contained in:
@@ -16,12 +16,27 @@ import globals
|
||||
|
||||
EVIL_MODE_STATE_FILE = "memory/evil_mode_state.json"
|
||||
|
||||
def save_evil_mode_state():
|
||||
"""Save evil mode state to JSON file"""
|
||||
def save_evil_mode_state(saved_role_color=None):
|
||||
"""Save evil mode state to JSON file
|
||||
|
||||
Args:
|
||||
saved_role_color: Optional hex color string to save (e.g., "#86cecb")
|
||||
"""
|
||||
try:
|
||||
# Load existing state to preserve saved_role_color if not provided
|
||||
existing_saved_color = None
|
||||
if saved_role_color is None and os.path.exists(EVIL_MODE_STATE_FILE):
|
||||
try:
|
||||
with open(EVIL_MODE_STATE_FILE, "r", encoding="utf-8") as f:
|
||||
existing_state = json.load(f)
|
||||
existing_saved_color = existing_state.get("saved_role_color")
|
||||
except:
|
||||
pass
|
||||
|
||||
state = {
|
||||
"evil_mode_enabled": globals.EVIL_MODE,
|
||||
"evil_mood": globals.EVIL_DM_MOOD
|
||||
"evil_mood": globals.EVIL_DM_MOOD,
|
||||
"saved_role_color": saved_role_color if saved_role_color is not None else existing_saved_color
|
||||
}
|
||||
with open(EVIL_MODE_STATE_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(state, f, indent=2)
|
||||
@@ -35,23 +50,24 @@ def load_evil_mode_state():
|
||||
try:
|
||||
if not os.path.exists(EVIL_MODE_STATE_FILE):
|
||||
print(f"ℹ️ No evil mode state file found, using defaults")
|
||||
return False, "evil_neutral"
|
||||
return False, "evil_neutral", None
|
||||
|
||||
with open(EVIL_MODE_STATE_FILE, "r", encoding="utf-8") as f:
|
||||
state = json.load(f)
|
||||
|
||||
evil_mode = state.get("evil_mode_enabled", False)
|
||||
evil_mood = state.get("evil_mood", "evil_neutral")
|
||||
print(f"📂 Loaded evil mode state: evil_mode={evil_mode}, mood={evil_mood}")
|
||||
return evil_mode, evil_mood
|
||||
saved_role_color = state.get("saved_role_color")
|
||||
print(f"📂 Loaded evil mode state: evil_mode={evil_mode}, mood={evil_mood}, saved_color={saved_role_color}")
|
||||
return evil_mode, evil_mood, saved_role_color
|
||||
except Exception as e:
|
||||
print(f"⚠️ Failed to load evil mode state: {e}")
|
||||
return False, "evil_neutral"
|
||||
return False, "evil_neutral", None
|
||||
|
||||
|
||||
def restore_evil_mode_on_startup():
|
||||
"""Restore evil mode state on bot startup (without changing username/pfp)"""
|
||||
evil_mode, evil_mood = load_evil_mode_state()
|
||||
evil_mode, evil_mood, saved_role_color = load_evil_mode_state()
|
||||
|
||||
if evil_mode:
|
||||
print("😈 Restoring evil mode from previous session...")
|
||||
@@ -304,7 +320,70 @@ def get_evil_video_response_prompt(video_description: str, user_prompt: str, med
|
||||
# EVIL MODE TOGGLE HELPERS
|
||||
# ============================================================================
|
||||
|
||||
async def apply_evil_mode_changes(client, change_username=True, change_pfp=True, change_nicknames=True):
|
||||
async def get_current_role_color(client) -> str:
|
||||
"""Get the current 'Miku Color' role color from any server as hex string"""
|
||||
try:
|
||||
for guild in client.guilds:
|
||||
me = guild.get_member(client.user.id)
|
||||
if not me:
|
||||
continue
|
||||
|
||||
# Look for "Miku Color" role
|
||||
for role in me.roles:
|
||||
if role.name.lower() in ["miku color", "miku colour", "miku-color"]:
|
||||
# Convert discord.Color to hex
|
||||
hex_color = f"#{role.color.value:06x}"
|
||||
print(f"🎨 Current role color: {hex_color}")
|
||||
return hex_color
|
||||
|
||||
print("⚠️ No 'Miku Color' role found in any server")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"⚠️ Failed to get current role color: {e}")
|
||||
return None
|
||||
|
||||
|
||||
async def set_role_color(client, hex_color: str):
|
||||
"""Set the 'Miku Color' role to a specific color across all servers"""
|
||||
try:
|
||||
# Convert hex to RGB
|
||||
hex_color = hex_color.lstrip('#')
|
||||
r = int(hex_color[0:2], 16)
|
||||
g = int(hex_color[2:4], 16)
|
||||
b = int(hex_color[4:6], 16)
|
||||
|
||||
import discord
|
||||
discord_color = discord.Color.from_rgb(r, g, b)
|
||||
|
||||
updated_count = 0
|
||||
for guild in client.guilds:
|
||||
try:
|
||||
me = guild.get_member(client.user.id)
|
||||
if not me:
|
||||
continue
|
||||
|
||||
# Find "Miku Color" role
|
||||
color_role = None
|
||||
for role in me.roles:
|
||||
if role.name.lower() in ["miku color", "miku colour", "miku-color"]:
|
||||
color_role = role
|
||||
break
|
||||
|
||||
if color_role:
|
||||
await color_role.edit(color=discord_color, reason="Evil mode color change")
|
||||
updated_count += 1
|
||||
print(f" 🎨 Updated role color in {guild.name}: #{hex_color}")
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Failed to update role color in {guild.name}: {e}")
|
||||
|
||||
print(f"🎨 Updated role color in {updated_count} server(s) to #{hex_color}")
|
||||
return updated_count > 0
|
||||
except Exception as e:
|
||||
print(f"⚠️ Failed to set role color: {e}")
|
||||
return False
|
||||
|
||||
|
||||
async def apply_evil_mode_changes(client, change_username=True, change_pfp=True, change_nicknames=True, change_role_color=True):
|
||||
"""Apply all changes when evil mode is enabled
|
||||
|
||||
Args:
|
||||
@@ -312,8 +391,16 @@ async def apply_evil_mode_changes(client, change_username=True, change_pfp=True,
|
||||
change_username: Whether to change bot username (default True, but skip on startup restore)
|
||||
change_pfp: Whether to change profile picture (default True, but skip on startup restore)
|
||||
change_nicknames: Whether to change server nicknames (default True, but skip on startup restore)
|
||||
change_role_color: Whether to change role color (default True, but skip on startup restore)
|
||||
"""
|
||||
print("😈 Enabling Evil Mode...")
|
||||
|
||||
# Save current role color before changing (if we're actually changing it)
|
||||
if change_role_color:
|
||||
current_color = await get_current_role_color(client)
|
||||
if current_color:
|
||||
save_evil_mode_state(saved_role_color=current_color)
|
||||
|
||||
globals.EVIL_MODE = True
|
||||
|
||||
# Change bot username (if requested and possible - may be rate limited)
|
||||
@@ -332,13 +419,17 @@ async def apply_evil_mode_changes(client, change_username=True, change_pfp=True,
|
||||
if change_pfp:
|
||||
await set_evil_profile_picture(client)
|
||||
|
||||
# Set evil role color (#D60004 - dark red)
|
||||
if change_role_color:
|
||||
await set_role_color(client, "#D60004")
|
||||
|
||||
# Save state to file
|
||||
save_evil_mode_state()
|
||||
|
||||
print("😈 Evil Mode enabled!")
|
||||
|
||||
|
||||
async def revert_evil_mode_changes(client, change_username=True, change_pfp=True, change_nicknames=True):
|
||||
async def revert_evil_mode_changes(client, change_username=True, change_pfp=True, change_nicknames=True, change_role_color=True):
|
||||
"""Revert all changes when evil mode is disabled
|
||||
|
||||
Args:
|
||||
@@ -346,6 +437,7 @@ async def revert_evil_mode_changes(client, change_username=True, change_pfp=True
|
||||
change_username: Whether to change bot username (default True, but skip on startup restore)
|
||||
change_pfp: Whether to change profile picture (default True, but skip on startup restore)
|
||||
change_nicknames: Whether to change server nicknames (default True, but skip on startup restore)
|
||||
change_role_color: Whether to restore role color (default True, but skip on startup restore)
|
||||
"""
|
||||
print("🎤 Disabling Evil Mode...")
|
||||
globals.EVIL_MODE = False
|
||||
@@ -366,8 +458,20 @@ async def revert_evil_mode_changes(client, change_username=True, change_pfp=True
|
||||
if change_pfp:
|
||||
await restore_normal_profile_picture(client)
|
||||
|
||||
# Save state to file
|
||||
save_evil_mode_state()
|
||||
# Restore saved role color
|
||||
if change_role_color:
|
||||
try:
|
||||
_, _, saved_color = load_evil_mode_state()
|
||||
if saved_color:
|
||||
await set_role_color(client, saved_color)
|
||||
print(f"🎨 Restored role color to {saved_color}")
|
||||
else:
|
||||
print("⚠️ No saved role color found, skipping color restoration")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Failed to restore role color: {e}")
|
||||
|
||||
# Save state to file (this will clear saved_role_color since we're back to normal)
|
||||
save_evil_mode_state(saved_role_color=None)
|
||||
|
||||
print("🎤 Evil Mode disabled!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user