- Discord bot runs in background thread alongside desktop app - State synchronization between Discord and desktop waifu - Commands: !hello, !status - Responds to mentions and DMs - Complete setup guide in DISCORD_SETUP.md - Graceful fallback if no token configured 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
"""
|
|
Desktop Waifu - Main Entry Point
|
|
A VRM-based AI desktop companion with Discord integration
|
|
"""
|
|
import sys
|
|
import asyncio
|
|
import threading
|
|
from PyQt6.QtWidgets import QApplication
|
|
from PyQt6.QtCore import Qt
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
# Import application modules
|
|
from src.ui.waifu_window import WaifuWindow
|
|
from src.discord_bot.bot import WaifuBot
|
|
from src.core.state_manager import StateManager
|
|
|
|
def run_discord_bot(state_manager: StateManager):
|
|
"""Run Discord bot in a separate thread"""
|
|
import os
|
|
token = os.getenv('DISCORD_BOT_TOKEN')
|
|
if not token:
|
|
print("Discord bot disabled: DISCORD_BOT_TOKEN not set in .env file")
|
|
return
|
|
|
|
# Create new event loop for this thread
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
|
|
# Create and start bot
|
|
bot = WaifuBot(state_manager)
|
|
try:
|
|
print("Starting Discord bot...")
|
|
loop.run_until_complete(bot.start(token))
|
|
except KeyboardInterrupt:
|
|
print("Discord bot shutting down...")
|
|
loop.run_until_complete(bot.close())
|
|
except Exception as e:
|
|
print(f"Discord bot error: {e}")
|
|
finally:
|
|
loop.close()
|
|
|
|
def main():
|
|
"""Main application entry point"""
|
|
# Create Qt Application
|
|
app = QApplication(sys.argv)
|
|
app.setApplicationName("Desktop Waifu")
|
|
|
|
# Initialize state manager (shared between desktop and Discord)
|
|
state_manager = StateManager()
|
|
|
|
# Create main window
|
|
window = WaifuWindow(state_manager)
|
|
window.show()
|
|
|
|
# Start Discord bot in background thread
|
|
discord_thread = threading.Thread(target=run_discord_bot, args=(state_manager,), daemon=True)
|
|
discord_thread.start()
|
|
|
|
# Run application
|
|
sys.exit(app.exec())
|
|
|
|
if __name__ == "__main__":
|
|
main()
|