Implement Evil Miku mode with persistence, fix API event loop issues, and improve formatting
- Added Evil Miku mode with 4 evil moods (aggressive, cunning, sarcastic, evil_neutral) - Created evil mode content files (evil_miku_lore.txt, evil_miku_prompt.txt, evil_miku_lyrics.txt) - Implemented persistent evil mode state across restarts (saves to memory/evil_mode_state.json) - Fixed API endpoints to use client.loop.create_task() to prevent timeout errors - Added evil mode toggle in web UI with red theme styling - Modified mood rotation to handle evil mode - Configured DarkIdol uncensored model for evil mode text generation - Reduced system prompt redundancy by removing duplicate content - Added markdown escape for single asterisks (actions) while preserving bold formatting - Evil mode now persists username, pfp, and nicknames across restarts without re-applying changes
This commit is contained in:
98
bot/api.py
98
bot/api.py
@@ -75,6 +75,9 @@ class ServerConfigRequest(BaseModel):
|
||||
bedtime_channel_ids: List[int] = None
|
||||
enabled_features: List[str] = None
|
||||
|
||||
class EvilMoodSetRequest(BaseModel):
|
||||
mood: str
|
||||
|
||||
# ========== Routes ==========
|
||||
@app.get("/")
|
||||
def read_index():
|
||||
@@ -131,6 +134,101 @@ def calm_miku_endpoint():
|
||||
|
||||
return {"status": "ok", "message": "Miku has been calmed down"}
|
||||
|
||||
# ========== Evil Mode Management ==========
|
||||
@app.get("/evil-mode")
|
||||
def get_evil_mode_status():
|
||||
"""Get current evil mode status"""
|
||||
from utils.evil_mode import is_evil_mode, get_current_evil_mood
|
||||
evil_mode = is_evil_mode()
|
||||
if evil_mode:
|
||||
mood, mood_desc = get_current_evil_mood()
|
||||
return {
|
||||
"evil_mode": True,
|
||||
"mood": mood,
|
||||
"description": mood_desc,
|
||||
"available_moods": globals.EVIL_AVAILABLE_MOODS
|
||||
}
|
||||
return {
|
||||
"evil_mode": False,
|
||||
"mood": None,
|
||||
"description": None,
|
||||
"available_moods": globals.EVIL_AVAILABLE_MOODS
|
||||
}
|
||||
|
||||
@app.post("/evil-mode/enable")
|
||||
def enable_evil_mode():
|
||||
"""Enable evil mode"""
|
||||
from utils.evil_mode import apply_evil_mode_changes
|
||||
|
||||
if globals.EVIL_MODE:
|
||||
return {"status": "ok", "message": "Evil mode is already enabled", "evil_mode": True}
|
||||
|
||||
if globals.client and globals.client.loop and globals.client.loop.is_running():
|
||||
globals.client.loop.create_task(apply_evil_mode_changes(globals.client))
|
||||
return {"status": "ok", "message": "Evil mode enabled", "evil_mode": True}
|
||||
else:
|
||||
return {"status": "error", "message": "Discord client not ready"}
|
||||
|
||||
@app.post("/evil-mode/disable")
|
||||
def disable_evil_mode():
|
||||
"""Disable evil mode"""
|
||||
from utils.evil_mode import revert_evil_mode_changes
|
||||
|
||||
if not globals.EVIL_MODE:
|
||||
return {"status": "ok", "message": "Evil mode is already disabled", "evil_mode": False}
|
||||
|
||||
if globals.client and globals.client.loop and globals.client.loop.is_running():
|
||||
globals.client.loop.create_task(revert_evil_mode_changes(globals.client))
|
||||
return {"status": "ok", "message": "Evil mode disabled", "evil_mode": False}
|
||||
else:
|
||||
return {"status": "error", "message": "Discord client not ready"}
|
||||
|
||||
@app.post("/evil-mode/toggle")
|
||||
def toggle_evil_mode():
|
||||
"""Toggle evil mode on/off"""
|
||||
from utils.evil_mode import apply_evil_mode_changes, revert_evil_mode_changes
|
||||
|
||||
if not globals.client or not globals.client.loop or not globals.client.loop.is_running():
|
||||
return {"status": "error", "message": "Discord client not ready"}
|
||||
|
||||
if globals.EVIL_MODE:
|
||||
globals.client.loop.create_task(revert_evil_mode_changes(globals.client))
|
||||
return {"status": "ok", "message": "Evil mode disabled", "evil_mode": False}
|
||||
else:
|
||||
globals.client.loop.create_task(apply_evil_mode_changes(globals.client))
|
||||
return {"status": "ok", "message": "Evil mode enabled", "evil_mode": True}
|
||||
|
||||
@app.get("/evil-mode/mood")
|
||||
def get_evil_mood():
|
||||
"""Get current evil mood"""
|
||||
from utils.evil_mode import get_current_evil_mood
|
||||
mood, mood_desc = get_current_evil_mood()
|
||||
return {
|
||||
"mood": mood,
|
||||
"description": mood_desc,
|
||||
"available_moods": globals.EVIL_AVAILABLE_MOODS
|
||||
}
|
||||
|
||||
@app.post("/evil-mode/mood")
|
||||
def set_evil_mood_endpoint(data: EvilMoodSetRequest):
|
||||
"""Set evil mood"""
|
||||
from utils.evil_mode import set_evil_mood, is_valid_evil_mood, update_all_evil_nicknames
|
||||
|
||||
if not is_valid_evil_mood(data.mood):
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Mood '{data.mood}' not recognized. Available evil moods: {', '.join(globals.EVIL_AVAILABLE_MOODS)}"
|
||||
}
|
||||
|
||||
success = set_evil_mood(data.mood)
|
||||
if success:
|
||||
# Update nicknames if evil mode is active
|
||||
if globals.EVIL_MODE and globals.client and globals.client.loop and globals.client.loop.is_running():
|
||||
globals.client.loop.create_task(update_all_evil_nicknames(globals.client))
|
||||
return {"status": "ok", "new_mood": data.mood}
|
||||
|
||||
return {"status": "error", "message": "Failed to set evil mood"}
|
||||
|
||||
# ========== Per-Server Mood Management ==========
|
||||
@app.get("/servers/{guild_id}/mood")
|
||||
def get_server_mood(guild_id: int):
|
||||
|
||||
Reference in New Issue
Block a user