feat: add Discord bot integration
- 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>
This commit is contained in:
33
main.py
33
main.py
@@ -4,6 +4,7 @@ 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
|
||||
@@ -16,6 +17,31 @@ 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
|
||||
@@ -29,10 +55,9 @@ def main():
|
||||
window = WaifuWindow(state_manager)
|
||||
window.show()
|
||||
|
||||
# Start Discord bot in background (if configured)
|
||||
# TODO: Implement Discord bot integration
|
||||
# discord_bot = WaifuBot(state_manager)
|
||||
# asyncio.create_task(discord_bot.start())
|
||||
# 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())
|
||||
|
Reference in New Issue
Block a user