82 lines
2.0 KiB
Python
82 lines
2.0 KiB
Python
import discord
|
|
import asyncio
|
|
import threading
|
|
from dotenv import load_dotenv
|
|
import os
|
|
from model.trainer 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 model.scheduler import set_next_action
|
|
from model.reweaver import memory_reweaver_loop
|
|
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)
|
|
|
|
|
|
async def background_cleanup_loop():
|
|
while True:
|
|
full_cleanup()
|
|
set_next_action(300, "Cleaning up")
|
|
await asyncio.sleep(300) # 5 minutes
|
|
|
|
|
|
async def dream_replay_loop():
|
|
while True:
|
|
replay_dreams()
|
|
set_next_action(900, "Dreaming new dreams")
|
|
await asyncio.sleep(900) # Replay every 15 minutes
|
|
|
|
|
|
async def rehearsal_loop():
|
|
while True:
|
|
simulate_conversation()
|
|
set_next_action(1200, "Practicing Conversations")
|
|
await asyncio.sleep(1200) # Every 20 minutes
|
|
|
|
|
|
# Start Ruby's Brain Loops in a separate thread
|
|
def start_brain_loops():
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
|
|
loop.create_task(read_books_forever())
|
|
loop.create_task(dream_replay_loop())
|
|
loop.create_task(background_cleanup_loop())
|
|
loop.create_task(rehearsal_loop())
|
|
loop.create_task(memory_reweaver_loop())
|
|
|
|
loop.run_forever()
|
|
|
|
|
|
threading.Thread(target=run_dashboard, daemon=True).start()
|
|
threading.Thread(target=start_brain_loops, daemon=True).start()
|
|
|
|
# Launch Discord bot (blocking)
|
|
client.run(TOKEN)
|