Advertisement
nonogamer9

Memphis AI (A AI Bot For BonziWorld!)

Apr 13th, 2025 (edited)
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.48 KB | Software | 0 0
  1. const prefix = "mem!";
  2. const botname = "MemphisAI (" + prefix + "ask)";
  3. const version = "1.0.1";
  4. const update = "April 13th, 2025";
  5. var uses = 0;
  6.  
  7. const PUTER_JS_URL = "https://js.puter.com/v2/";
  8.  
  9. function sendMsg(msg) {
  10.     setTimeout(() => {
  11.         socket.emit("talk", { text: msg });
  12.     }, 1100);
  13. }
  14.  
  15. async function queryPuterAPI(inputText) {
  16.     try {
  17.         const response = await puter.ai.chat(inputText);
  18.         return response || "The AI couldn't generate a proper response.";
  19.     } catch (error) {
  20.         console.error("Error querying Puter.js API:", error);
  21.         return "Sorry, I couldn't process your request.";
  22.     }
  23. }
  24.  
  25. const script = document.createElement("script");
  26. script.src = PUTER_JS_URL;
  27. document.head.appendChild(script);
  28.  
  29. setTimeout(() => {
  30.     socket.emit("command", { list: ["name", botname] });
  31. }, 1000);
  32.  
  33. setTimeout(() => {
  34.     sendMsg("MemphisAI is online. Type " + prefix + "ask {question} to interact with AI.");
  35. }, 2000);
  36.  
  37. socket.on("talk", async (message) => {
  38.     if (message.text.startsWith(prefix + "ask")) {
  39.         const userQuery = message.text.substring(prefix.length + 3).trim();
  40.         if (!userQuery) {
  41.             sendMsg("Please provide a question or prompt after '" + prefix + "ask'.");
  42.             return;
  43.         }
  44.  
  45.         sendMsg("- Processing your query...");
  46.        
  47.         const aiResponse = await queryPuterAPI(userQuery);
  48.         sendMsg(`**AI Response:** ${aiResponse}`);
  49.         uses++;
  50.     }
  51. });
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement