module.exports = { config: { name: "web", aliases: [], version: "1.0", author: "Jmlabaco", countDown: 5, role: 0, shortDescription: "Ask a question to different AI APIs.", longDescription: "This command allows you to ask a question to different AI APIs such as Hiro, Hercai, Black AI, Hannah, Mixtral, or another AI API.", category: "Utility", guide: "/web - : Ask a question to the selected AI API.\n/web -list: Show all available AI APIs.", isPrefix: true, }, onStart: async function ({ api, event, args }) { const baseURLs = { hiro: "https://hiro-api.replit.app/ai/hiro?ask=", hercai: "https://hiro-api.replit.app/ai/hercai?ask=", black: "https://hiro-api.replit.app/ai/black?ask=", ai: "https://aiapiviafastapiwithimagebyjonellmagallanes.replit.app/ai?content=", hannah: "https://hercai.onrender.com/v3/hercai?question=", mixtral: "https://mixtral.aliestercrowley.com/api?prompt=" }; const prompts = { hiro: "response", hercai: "reply", black: "message", ai: "airesponse", hannah: "reply", mixtral: "response" }; const options = Object.keys(baseURLs); if (args.length === 0 || args[0] === "-list") { let aiList = "šŸ¤– WEB BOTS šŸ¤–\n"; options.forEach(option => { aiList += `• ${option.toUpperCase()}\n`; }); api.sendMessage(aiList, event.threadID); return; } const selectedOption = args.shift().toLowerCase(); // Convert to lowercase for case-insensitive matching if (!options.includes(selectedOption)) { api.sendMessage("Invalid option. Use '/web -list' to see available options.", event.threadID); return; } const question = encodeURIComponent(args.join(" ")); let url = baseURLs[selectedOption] + question; let thinkingMessageId; try { // Sending "thinking" message const thinkingMessage = await api.sendMessage(`${selectedOption} is thinking...`, event.threadID); thinkingMessageId = thinkingMessage.messageID; // Making request to the selected API const response = await fetch(url); const data = await response.json(); // Handle the response data if (data[prompts[selectedOption]]) { // Unsend the "thinking" message await api.unsendMessage(thinkingMessageId); // Send the answer with the requested format await api.sendMessage(`\n\n============================\n\nšŸ¤–${selectedOption.toUpperCase()} says:\n\n============================\n\n${data[prompts[selectedOption]]}\n\n============================\n\n`, event.threadID); } else { await api.sendMessage("No answer received.", event.threadID); } } catch (error) { console.error("Error fetching data from API:", error); await api.sendMessage("An error occurred while fetching data from the API.", event.threadID); // Unsend the "thinking" message if an error occurs if (thinkingMessageId) { await api.unsendMessage(thinkingMessageId); } } } };