bot.mjs hinzugefügt

This commit is contained in:
TNT-Flo 2024-12-12 07:48:46 -05:00
parent 032de462f3
commit 1ca7d12141

73
bot.mjs Normal file
View File

@ -0,0 +1,73 @@
import { Client, GatewayIntentBits } from 'discord.js';
import 'dotenv/config';
import Groq from 'groq-sdk';
import unirest from 'unirest';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
const DISCORD_LINUX_API_URL = 'https://api.ssh.surf';
const DISCORD_LINUX_API_KEY = process.env['DISCORD_LINUX_API_KEY'];
const GROQ_API_KEY = process.env['GROQ_API_KEY'];
const groqClient = new Groq({ apiKey: GROQ_API_KEY });
// Command handler
async function execCommandInContainer(cmd) {
const response = await unirest
.post(`${DISCORD_LINUX_API_URL}/exec`)
.headers({
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-ssh-auth': DISCORD_LINUX_API_KEY
})
.send({ cmd });
return response.body;
}
// When the bot is ready
client.once('ready', () => {
console.log('Bot is ready!');
});
// Listen for messages
client.on('messageCreate', async (message) => {
if (message.author.bot) return; // Ignore bot messages
if (message.content.startsWith('!goal ')) {
const goal = message.content.replace('!goal ', '').trim();
if (!goal) {
message.channel.send('Please specify a goal to achieve.');
return;
}
try {
// Automate goal achievement
const context = `Initial attempt. Goal: ${goal}`;
const result = await automateGoal(context, goal);
message.channel.send(result.success ? 'Goal achieved!' : 'Failed to achieve goal.');
} catch (error) {
message.channel.send('An error occurred while processing the goal.');
}
}
// Interactive chat (if needed)
if (message.content.startsWith('!chat ')) {
const userMessage = message.content.replace('!chat ', '').trim();
try {
const aiResponse = await chatWithAI('', userMessage); // Provide current context
message.channel.send(aiResponse);
} catch (error) {
message.channel.send('An error occurred during the chat.');
}
}
});
// Start the bot
client.login(process.env.BOT_TOKEN);