From 1ca7d1214141bc160271041e28a5c8e247d0bcdb Mon Sep 17 00:00:00 2001 From: TNT-Flo Date: Thu, 12 Dec 2024 07:48:46 -0500 Subject: [PATCH] =?UTF-8?q?bot.mjs=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.mjs | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 bot.mjs diff --git a/bot.mjs b/bot.mjs new file mode 100644 index 0000000..1dab9a5 --- /dev/null +++ b/bot.mjs @@ -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);