import fs from 'fs'; import BotClient from "../../../libs/BotClient"; export default async(Discord: any, client: BotClient, message: any) => { // let content = message.content; // if (message.channel && typeof message.channel.sendTyping === 'function') { // try { // await message.channel.sendTyping(); // } catch (e) { // console.error('Error sending typing indicator:', e); // } // } // try { // const { content: messageContent, typst } = await client.ai.generateText(message.author.id, message.author.username, content); // const userId = message.author.id; // const typPath = `./storage/typst/message_${userId}.typ`; // const pdfPath = `./storage/typst/message_${userId}.pdf`; // try { // fs.writeFileSync(typPath, typst || messageContent); // } catch (err) { // console.error('Error writing typst file:', err); // await message.reply({ // content: "Failed to write Typst file.", // allowedMentions: { repliedUser: true } // }); // return; // } // const { execSync } = require('child_process'); // let pdfBuffer = null; // let hasPDF = false; // try { // execSync(`typst compile "${typPath}" "${pdfPath}"`); // if (fs.existsSync(pdfPath)) { // try { // pdfBuffer = fs.readFileSync(pdfPath); // hasPDF = true; // } catch (readErr) { // console.error('Error reading PDF file:', readErr); // } // } // } catch (e) { // console.error('Typst compile error:', e); // await message.reply({ // content: "Failed to compile Typst to PDF.", // allowedMentions: { repliedUser: true } // }); // return; // } // const messageOptions: any = { // content: messageContent, // allowedMentions: { repliedUser: true } // }; // if (hasPDF && pdfBuffer) { // messageOptions.files = [ // { // attachment: pdfBuffer, // name: `message_${userId}.pdf` // } // ]; // } // console.log('Sending message with options:', { // contentLength: messageContent.length, // hasFiles: !!messageOptions.files, // fileCount: messageOptions.files ? messageOptions.files.length : 0 // }); // await message.reply(messageOptions); // } catch (error) { // console.error('Error in AI chat:', error); // await message.reply({ // content: "I'm having trouble processing your request right now. Please try again later.", // allowedMentions: { repliedUser: true } // }); // } };