70 lines
1.6 KiB
Python
70 lines
1.6 KiB
Python
import discord
|
|
import asyncio
|
|
import threading
|
|
from dotenv import load_dotenv
|
|
import os
|
|
from model.train import train_on_message
|
|
from model.brain import generate_response
|
|
from model.cleanup import full_cleanup
|
|
from model.dream_replay import replay_dreams
|
|
from model.rehearsal import simulate_conversation
|
|
from reader.reader import read_books_forever
|
|
from dashboard.dashboard import run_dashboard
|
|
|
|
load_dotenv()
|
|
TOKEN = os.getenv("DISCORD_TOKEN")
|
|
|
|
intents = discord.Intents.default()
|
|
intents.messages = True
|
|
intents.message_content = True
|
|
|
|
client = discord.Client(intents=intents)
|
|
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
print(f"Ruby is online as {client.user}.")
|
|
|
|
|
|
@client.event
|
|
async def on_message(message):
|
|
if message.author.bot:
|
|
return
|
|
|
|
content = message.content.strip()
|
|
train_on_message(content)
|
|
response = generate_response()
|
|
await message.channel.send(response)
|
|
|
|
# Launch Flask in background
|
|
threading.Thread(target=run_dashboard, daemon=True).start()
|
|
|
|
|
|
async def background_cleanup_loop():
|
|
while True:
|
|
full_cleanup()
|
|
await asyncio.sleep(300) # 5 minutes
|
|
|
|
|
|
async def dream_replay_loop():
|
|
while True:
|
|
replay_dreams()
|
|
await asyncio.sleep(900) # Replay every 15 minutes
|
|
|
|
|
|
async def rehearsal_loop():
|
|
while True:
|
|
simulate_conversation()
|
|
await asyncio.sleep(1200) # Every 20 minutes
|
|
|
|
|
|
# Launch background tasks
|
|
loop = asyncio.get_event_loop()
|
|
loop.create_task(read_books_forever()) # Book reader task
|
|
loop.create_task(background_cleanup_loop())
|
|
loop.create_task(dream_replay_loop())
|
|
loop.create_task(rehearsal_loop())
|
|
|
|
# Launch Discord bot (blocking)
|
|
client.run(TOKEN)
|