-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
71 lines (60 loc) · 2.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require('dotenv').config();
const { Client } = require('discord.js-selfbot-v13');
const fs = require('fs');
const path = require('path');
const Groq = require('groq-sdk');
const client = new Client();
const eightBallCommand = require('./instructions/8ball');
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
const configPath = path.join(__dirname, 'config.json');
let config = {
prefix: "$",
llm_instructions: [
{
"role": "system",
"content": "You are a helpful assistant that provides concise and accurate answers."
}
]
};
// Load the config file if it exists
if (fs.existsSync(configPath)) {
config = require(configPath);
}
// Initialize nuke status
client.nukeActive = false;
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.commands = new Map();
// Dynamically load command files from the instructions folder
const commandFiles = fs.readdirSync('./instructions/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
try {
const command = require(`./instructions/${file}`);
client.commands.set(command.name, command);
// Add aliases to the Map for easy lookup (if command has aliases)
if (command.aliases && Array.isArray(command.aliases)) {
command.aliases.forEach(alias => client.commands.set(alias, command));
}
} catch (error) {
console.error(`Error loading command ${file}:`, error);
}
}
client.on('messageCreate', async (message) => {
if (message.author.id !== client.user.id) return;
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (client.commands.has(commandName)) {
try {
await client.commands.get(commandName).execute(message, args, config, groq, client);
} catch (error) {
console.error(`Error executing command ${commandName}:`, error);
message.channel.send('There was an error executing that command.');
}
} else {
// Send an "Unknown command" message if the command is not found
message.channel.send('Unknown command. Use `$help` to see all available commands.');
}
});
client.login(process.env.TOKEN);