2024-11-18 21:46:34 -05:00
|
|
|
# main.py: Discord Bot Code
|
|
|
|
|
2024-10-02 16:44:09 -04:00
|
|
|
import discord
|
|
|
|
import torch
|
2024-11-18 21:46:34 -05:00
|
|
|
from model import JadeModel
|
2024-10-02 16:44:09 -04:00
|
|
|
import os
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
# Load environment variables
|
2024-10-02 16:44:09 -04:00
|
|
|
load_dotenv()
|
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
intents = discord.Intents.default()
|
|
|
|
intents.messages = True
|
|
|
|
intents.message_content = True
|
|
|
|
client = discord.Client(intents=intents)
|
2024-10-02 16:44:09 -04:00
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
# Initialize the model
|
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
model = JadeModel().to(device)
|
2024-10-02 16:44:09 -04:00
|
|
|
|
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
@client.event
|
|
|
|
async def on_ready():
|
|
|
|
print(f'We have logged in as {client.user}')
|
2024-10-02 16:44:09 -04:00
|
|
|
|
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
@client.event
|
|
|
|
async def on_message(message):
|
|
|
|
if message.author == client.user:
|
|
|
|
return
|
2024-10-02 16:44:09 -04:00
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
# Train Jade with the new message
|
|
|
|
model.train_on_message(message.content)
|
2024-10-02 16:44:09 -04:00
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
# Generate a response using Jade
|
|
|
|
response = model.generate_response(message.content)
|
|
|
|
await message.channel.send(response)
|
2024-10-02 16:44:09 -04:00
|
|
|
|
2024-11-18 21:46:34 -05:00
|
|
|
# Start the bot with your token
|
|
|
|
client.run(os.getenv('DISCORD_TOKEN'))
|