Advertisement
nonogamer9

CustomizeBOT

Oct 7th, 2023 (edited)
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const prefix = "cu!";
  2. const premiumKey = "PREMIUMKEYCU69420"; // Replace with your actual premium key
  3. const apiKey = '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'; // Replace with your actual OpenAI API key
  4. const apiUrl = 'https://api.openai.com/v1/engines/davinci-codex/completions'; // Endpoint for ChatGPT API
  5. let isPremium = false;
  6. const botname = "CustomizeBOT (" + prefix + "help)";
  7. const version = "1.0 Release!"
  8. var help = "__CustomizeBOT Commands__\ncu!help, cu!say {TEXT}, cu!joke, cu!triggered, cu!fact, cu!botinfo, cu!roominfo, cu!image {IMAGE}, cu!video {VIDEO}, cu!color /COLOR/, cu!weather {LOCATION}, cu!name, cu!resetcolor, cu!resetname, cu!snake, cu!youtube {YOUTUBELINK}, cu!ship {USER1} and {USER2}, cu!help2";
  9. var help2 = "__CustomizeBOT Commands__\cu!roast {USER}, cu!linux, cu!incredibleroll, cu!google {SEARCH}, cu!hole {USER}, cu!tts, cu!paypremium (ONLY 10$ FOR KEY!)";
  10. var botinfo = "CustomizeBOT Version " + version + ". Find CustomizeBOT at: https://pastebin.com/SCkeZRw8";
  11.  
  12. function sendMsg(msg) {
  13.     setTimeout(() => {
  14.         if (!isPremium) {
  15.             const advertisement = getRandomAdvertisement();
  16.             socket.emit("talk", { text: `${msg}\n${advertisement}` });
  17.         } else {
  18.             socket.emit("talk", { text: msg });
  19.         }
  20.     }, 1100);
  21. }
  22.  
  23. const advertisements = [
  24.     "Check out our sponsor's latest products at https://www.amazon.com!",
  25.     "Looking for a great server host? Check Out InMotion Hosting!",
  26.     "Need custom Discord bots? go to https://botghost.com/",
  27.     "Looking for reliable hosting? Check out A2 Hosting for top-notch server solutions!",
  28.     "Enhance your gaming experience with RTX's high-performance accessories. Visit https://www.nvidia.com/en-us/geforce/rtx/ now!",
  29.     "Protect your online privacy with NordVPN! Get 70% off for a limited time. Visit nordvpn.com",
  30.     "Check out nintendo's hit game named Mario Farty! At GameStop!",
  31.     "Immerse yourself in the enchanting world of Touhou Project! Discover magical adventures and captivating characters. Download it now on steam!",
  32.     "Are You Hungry? Go Eat At Mcdonald's! I'm Loving It! https://www.mcdonalds.com/us/en-us.html",
  33.     "This is an advertisement for the greatest bonziworld server ever! It is https://nonogamer9world.noanladjal13.repl.co/ ! Join now!",
  34.     "Are you tired Of Drinking the same beer? Don't worry! Introducing Suntory Beer, Where you can hangout with the coolest penguins in the world! Buy Now At https://www.suntory.com/business/beer/",
  35.     "Call Empire To Fix Your Home Today! (800)-588-2300 Empire! Today! https://www.empiretoday.com/",
  36.     "Grubhub, Download our app and enjoy dancing with our food!",
  37.     "Tired with ads! well i don't care! buy our stuffs at https://www.ebay.com !",
  38.     "Introducing, The Iphone 15 Pro Max. Apple",
  39.     "Make sure to support seamus! at https://bonziworld.co!",
  40.     "Play the new hit game named (Chicken Gun Rooster Rudy)! Download it here! https://chickens-gun.en.uptodown.com/android",
  41.     "Test The Incredible Roll Command! With cu!incredibleroll, So You Can Experience Mr Incredible's uncanniests to the fullest!",
  42.     "Are you tired of ADS? Well, Make Sure To Get CustomizeBOT Premium! Only 10$ For A Key!",
  43.  ];
  44.  
  45. const incrediblerollPics = [
  46. "https://media.discordapp.net/attachments/1107412342960033832/1114622683460685854/dfa4skp-4ef45bab-b574-4b4d-aac2-12cf5b53b6c6.png?width=634&height=630",
  47.   "https://media.discordapp.net/attachments/1114637956079173722/1114638247361003541/mr-incredible-becoming-uncanny-phase-1.png?width=722&height=630",
  48.   "https://media.discordapp.net/attachments/1114637956079173722/1114638247642026025/latest.png",
  49.   "https://media.discordapp.net/attachments/1114637956079173722/1114638247973355570/latest.png",
  50.   "https://media.discordapp.net/attachments/1114637956079173722/1114638248258584627/images.png",
  51.   "https://media.discordapp.net/attachments/1114637956079173722/1114638248501858444/images.png",
  52.   "https://media.discordapp.net/attachments/1114637956079173722/1114638248824799332/latest.png",
  53.   "https://media.discordapp.net/attachments/1114637956079173722/1114638486935449782/latest.png",
  54.   "https://media.discordapp.net/attachments/1114637956079173722/1114638487237443584/latest.png",
  55.   "https://media.discordapp.net/attachments/1114637956079173722/1114638487526854737/latest.png",
  56.   "https://media.discordapp.net/attachments/1114637956079173722/1114638487849807872/350.png",
  57.   "https://i1.sndcdn.com/artworks-JeZQh6Hbil2Er51B-U9rx3A-t500x500.jpg",
  58.   "https://i1.sndcdn.com/avatars-RNXmlKLL2AHsRPaz-8LVOoA-t500x500.jpg",
  59.   "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR8FcyNrd8y5BmEwp9xYLRjvYxDlheS4DjwgmLZIEvBO2yHIvCv",
  60.   "https://pbs.twimg.com/media/FTHtsuDVUAIjUnO.jpg",
  61.   "https://i.ytimg.com/vi/Zne8JgObXBc/maxresdefault.jpg",
  62.   "https://i.ytimg.com/vi/BFFIS5r7Aj0/maxresdefault.jpg?sqp=-oaymwEmCIAKENAF8quKqQMa8AEB-AH-CYAC0AWKAgwIABABGH8gFSgTMA8=&rs=AOn4CLB0OOFdzym2aFPtk2jqd4beTm8baA",
  63.   "https://i.ytimg.com/vi/TNpQGA762UU/mqdefault.jpg",
  64.   "https://media.discordapp.net/attachments/1114860678000431254/1114864540321062952/latest.png?width=635&height=630",
  65.   "https://media.discordapp.net/attachments/1114860678000431254/1114864540614660166/latest.png?width=635&height=630",
  66.   "https://media.discordapp.net/attachments/1114860678000431254/1114864540899881030/latest.png?width=635&height=630",
  67.   "https://media.discordapp.net/attachments/1114860678000431254/1114864541155725382/latest.png?width=635&height=630",
  68.   "https://media.discordapp.net/attachments/1114860678000431254/1114864541617106985/latest.png?width=635&height=630",
  69.   "https://media.discordapp.net/attachments/1114860678000431254/1114864541961035866/latest.png?width=646&height=630",
  70.   "https://media.discordapp.net/attachments/1114860678000431254/1114864542409822298/latest.png?width=759&height=630",
  71.   "https://media.discordapp.net/attachments/1114860678000431254/1127302563356741765/1000.png?width=630&height=630",
  72.   "https://media.discordapp.net/attachments/1114860678000431254/1127302563713269851/1000.png?width=630&height=630",
  73.   "https://media.discordapp.net/attachments/1114860678000431254/1127302564011069530/latest.png?width=747&height=630",
  74.   "https://media.discordapp.net/attachments/1114860678000431254/1127302564430487613/1000.png?width=630&height=630",
  75.   "https://media.discordapp.net/attachments/1114860678000431254/1127302564896067635/1000.png",
  76.   "https://media.discordapp.net/attachments/1114860678000431254/1127302565260959744/latest.png",
  77.   "https://media.discordapp.net/attachments/1114860678000431254/1127302701642956860/latest.png",
  78.   "https://media.discordapp.net/attachments/1114860678000431254/1127302701974294699/1000.png?width=630&height=630",
  79.   "https://media.discordapp.net/attachments/1114860678000431254/1127302702569902180/latest.png?width=761&height=630",
  80.   "https://media.discordapp.net/attachments/1114860678000431254/1127302702288879797/1000.png?width=630&height=630",
  81. ];
  82.  
  83. function getRandomPic(picsArray) {
  84.   const randomIndex = Math.floor(Math.random() * picsArray.length);
  85.   return picsArray[randomIndex];
  86. }
  87.  
  88. function getRandomAdvertisement() {
  89.     return advertisements[Math.floor(Math.random() * advertisements.length)];
  90. }
  91.  
  92. function sendMsg(msg) {
  93.     const withAdvertisement = Math.random() < 0.2; // 20% chance of including an advertisement
  94.  
  95.     setTimeout(() => {
  96.         const messageToSend = withAdvertisement ? `${msg}\n${getRandomAdvertisement()}` : msg;
  97.         socket.emit("talk", { text: messageToSend });
  98.     }, 1100);
  99. }
  100.  
  101. setTimeout(() => {socket.emit("command",{list:["name",botname]})},1000);
  102. setTimeout(() => {socket.emit("command",{list:["name",botname]})},2100);
  103. setTimeout(() => {socket.emit("command",{list:["color","https://cdn.discordapp.com/attachments/731430123571642390/1209592776883314760/i-tools.png?ex=65f9f10f&is=65e77c0f&hm=0532f4036672e74f2a3e0191486194518bcd1fcc302e3f98af44d25089ee3397&"]})},3200);
  104. setTimeout(() => {
  105.     sendMsg(`CustomizeBOT is online. Type ${prefix}help to see commands. AD:\n${getRandomAdvertisement()}`);
  106.     setInterval(() => {
  107.         sendMsg(`CustomizeBOT is online. Type ${prefix}help to see commands. AD:\n${getRandomAdvertisement()}`);
  108.     }, 60000);
  109. }, 4300);
  110.  
  111. // Clear the previous ad and replace it with a new ad
  112. function replaceAd() {
  113.     clearInterval(adInterval);
  114.     sendMsg(`CustomizeBOT is online. Type ${prefix}help to see commands.\n${getRandomAdvertisement()}`);
  115.     adInterval = setInterval(() => {
  116.         sendMsg(`CustomizeBOT is online. Type ${prefix}help to see commands.\n${getRandomAdvertisement()}`);
  117.     }, 60000);
  118. }
  119.  
  120. // Example: Replace ad after 5 seconds
  121. setTimeout(replaceAd, 5000);
  122.  
  123. socket.on("talk", (message) => {
  124.     if(message.text == prefix + "roominfo"){
  125.         sendMsg("Amount of users in the room: " + window.usersAmt);
  126.     }
  127.     if(message.text == prefix + "help"){
  128.         sendMsg(help);
  129.     }
  130.     if(message.text == prefix + "help2"){
  131.         sendMsg(help2);
  132.     }
  133.     if(message.text == prefix + "botinfo"){
  134.         sendMsg(botinfo);
  135.     }
  136.     if(message.text == prefix + "incredibleroll"){
  137.         const randomPic = getRandomPic(incrediblerollPics);
  138.         setTimeout(() => {socket.emit("command", { list: ["image", randomPic]});}, 1100);
  139.     }
  140.     if(message.text.startsWith(prefix + "say")){
  141.         sendMsg(message.text.substring(prefix.length + 3));
  142.     }
  143.     if(message.text.startsWith(prefix + "image")){
  144.         let imgUrl = message.text.substring(prefix.length + 6);
  145.         setTimeout(() => {socket.emit("command",{list:["image",imgUrl]});},1100);
  146.     }
  147.     if(message.text.startsWith(prefix + "tts")){
  148.         let tts = message.text.substring(prefix.length + 3);
  149.         setTimeout(() => {audio = new Audio('https://tts.cyzon.us/tts?text=' + tts), audio.play()},5000);
  150.     }
  151.     if(message.text.startsWith(prefix + "video")){
  152.         let imgUrl = message.text.substring(prefix.length + 6);
  153.         setTimeout(() => {socket.emit("command",{list:["video",imgUrl]});},1100);
  154.     }
  155.     if(message.text.startsWith(prefix + "color")){
  156.         let imgUrl = message.text.substring(prefix.length + 6);
  157.         setTimeout(() => {socket.emit("command",{list:["color",imgUrl]});},1100);
  158.     }
  159.     if(message.text.startsWith(prefix + "youtube")){
  160.         let imgUrl = message.text.substring(prefix.length + 8);
  161.         setTimeout(() => {socket.emit("command",{list:["youtube",imgUrl]});},1100);
  162.     }
  163.     if(message.text == prefix + "joke"){
  164.         setTimeout(() => {socket.emit("command",{list:["joke"]});},1100);
  165.     }
  166.     if(message.text == prefix + "triggered"){
  167.         setTimeout(() => {socket.emit("command",{list:["triggered"]});},1100);
  168.     }
  169.     if (message.text.startsWith(prefix + "linux")) {
  170.       setTimeout(() => { socket.emit("command", { list: ["linux"] }); }, 1100);
  171.     }
  172.     if(message.text.startsWith(prefix + "hole")){
  173.         let imgUrl = message.text.substring(prefix.length + 5);
  174.         setTimeout(() => {socket.emit("command",{list:["asshole",imgUrl]});},1100);
  175.     }
  176.     if(message.text.startsWith(prefix + "name")){
  177.         let imgUrl = message.text.substring(prefix.length + 5);
  178.         setTimeout(() => {socket.emit("command",{list:["name",imgUrl]});},1100);
  179.     }
  180.     if(message.text.startsWith(prefix + "resetname")){
  181.         let imgUrl = message.text.substring(prefix.length + 6);
  182.         setTimeout(() => {socket.emit("command",{list:["name","CustomizeBOT (" + prefix + "help)"]});},1100);
  183.     }
  184.     if(message.text == prefix + "fact"){
  185.         setTimeout(() => {socket.emit("command",{list:["fact"]});},1100);
  186.     }
  187.     else if (message.text.startsWith(prefix + "weather")) {
  188.         const location = message.text.substring(prefix.length + 8);
  189.         getWeather(location);
  190.     }
  191.     else if (message.text.startsWith(prefix + "resetcolor")) {
  192.         let imgUrl = message.text.substring(prefix.length + 6);
  193.         setTimeout(() => {socket.emit("command",{list:["color","https://cdn.discordapp.com/attachments/731430123571642390/1209592776883314760/i-tools.png?ex=65f9f10f&is=65e77c0f&hm=0532f4036672e74f2a3e0191486194518bcd1fcc302e3f98af44d25089ee3397&"]});},1100);
  194.     }
  195.     else if (message.text.startsWith(prefix + "snake")) {
  196.         const command = message.text.substring(prefix.length + 6).trim();
  197.         handleSnakeCommand(command);
  198.     }
  199.     else if (message.text.startsWith(prefix + "ship")) {
  200.             const users = message.text.substring(prefix.length + 5).split(" and ");
  201.        
  202.             if (users.length === 2) {
  203.                 const percentage = Math.floor(Math.random() * 101);
  204.                 sendMsg(`${users[0]} and ${users[1]} are ${percentage}% in love!`);
  205.             } else {
  206.                 sendMsg("Invalid usage. Please provide two users separated by 'and'.");
  207.             }
  208.     }
  209.     else if (message.text.startsWith(prefix + "google")) {
  210.         const searchQuery = message.text.substring(prefix.length + 7);
  211.         googleSearch(searchQuery);
  212.     }
  213.     else if (message.text.startsWith(prefix + "chatgpt")) {
  214.         const question = message.text.substring(prefix.length + 7);
  215.         chatGPTAnswer(question);
  216.     }
  217.     if (message.text.startsWith(prefix + "roast")) {
  218.         const user = message.text.substring(prefix.length + 6);
  219.  
  220.         if (user) {
  221.             const roasts = [
  222.                 `${user}, are you made of copper and tellurium? Because you're Cu-Te.`,
  223.                `${user}, I'd agree with you but then we'd both be wrong.`,
  224.                `${user}, if laughter is the best medicine, your face must be curing the world.`,
  225.                `${user}, if you were a vegetable, you'd be a cute-cumber.`,
  226.                 `${user}, I'm not a photographer, but I can definitely picture you without any issues.`,
  227.                `${user}, if laughter is contagious, you're about as infectious as it gets.`,
  228.                 `${user}, you're not dumb; you just have a unique way of looking at things.`,
  229.                `${user}, you're so kind-hearted that you make Mr. Rogers look grumpy.`,
  230.                 `${user}, if beauty were time, you'd be an eternity.`,
  231.                `${user}, I'm not saying you're slow, but you could probably outrun a sloth.`,
  232.                `${user}, if you were a cat, you'd purr-fect.`,
  233.                 `${user}, you're so bright, the sun needs sunglasses when you smile.`,
  234.                `${user}, if you were a cookie, you'd be a smartie.`,
  235.                 `${user}, you're not fat; you're just easier to see.`,
  236.                 `${user}, if you were any sweeter, you'd give sugar a run for its money.`,
  237.                 `${user}, you're like a human mood booster; everyone needs you around.`,
  238.                 `${user}, you're so good-looking that mirrors do a double-take.`,
  239.                 `${user}, I'm not a genie, but if I were, I'd grant you infinite wishes.`,
  240.                 `${user}, if laughter is the best medicine, consider yourself a cure-all.`,
  241.                 `${user}, you're so clever, you make Einstein look like a preschooler.`,
  242.                 `${user}, if you were a superhero, your power would be making people smile.`,
  243.                 `${user}, your charm level is off the charts; I hope you have a license for that.`,
  244.                 `${user}, if you were a star, you'd be the one everyone wishes upon.`,
  245.                 `${user}, you're not just a friend; you're a friendship upgrade.`,
  246.                 `${user}, if life were a game, you'd be the MVP.`,
  247.             ];
  248.  
  249.             const randomRoast = roasts[Math.floor(Math.random() * roasts.length)];
  250.             sendMsg(randomRoast);
  251.         } else {
  252.             sendMsg("Invalid usage. Please provide a user to roast.");
  253.         }
  254.     }
  255.     if (message.text.startsWith(prefix + "paypremium")) {
  256.         const userKey = message.text.substring(prefix.length + 11).trim();
  257.  
  258.         if (userKey === premiumKey) {
  259.             isPremium = true;
  260.             sendMsg("Congratulations! You've unlocked premium access. No more ads!");
  261.         } else {
  262.             sendMsg("Invalid premium key. Ads could not be removed.");
  263.         }
  264.     }
  265. });
  266.  
  267. function getWeather(location) {
  268.   const apiKey = "dcc6b2a3fa3d4fe58d9193316232905";
  269.   const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${encodeURIComponent(location)}`;
  270.  
  271.   fetch(apiUrl)
  272.     .then((response) => response.json())
  273.     .then((data) => {
  274.       if (data.error) {
  275.         sendMsg("Unable to retrieve weather information. Please check the location.");
  276.       } else {
  277.         const weather = data.current;
  278.         const weatherInfo = `Weather in ${data.location.name}, ${data.location.country}:\nCondition: ${weather.condition.text}\nTemperature: ${weather.temp_c}°C\nHumidity: ${weather.humidity}%\nWind Speed: ${weather.wind_kph} km/h\n`;
  279.         sendMsg(weatherInfo);
  280.       }
  281.     })
  282.     .catch((error) => {
  283.       console.error("Error:", error);
  284.       sendMsg("An error occurred while retrieving weather information.");
  285.     });
  286. }
  287. function handleSnakeCommand(command) {
  288.     if (command === "play") {
  289.         startSnakeGame();
  290.     } else if (command === "up" || command === "down" || command === "left" || command === "right") {
  291.         updateSnakeDirection(command);
  292.         moveSnake();
  293.         if (checkCollision()) {
  294.             sendMsg("Game Over. You collided with the wall or yourself!");
  295.             return;
  296.         }
  297.         checkFoodEaten();
  298.         sendMsg(renderSnakeGame());
  299.     } else {
  300.         sendMsg("Invalid command. Use `" + prefix + "snake play` to start the game and `" + prefix + "snake up/down/left/right` to control.");
  301.     }
  302. }
  303.  
  304. // New snake game functions...
  305. let snake = [{ x: 0, y: 0 }]; // Snake's initial position (assuming the top-left corner as [0, 0])
  306. let food = { x: 5, y: 5 }; // Food's initial position
  307. let direction = "right"; // Initial direction of the snake
  308.  
  309. function startSnakeGame() {
  310.     // Initialize the snake game state
  311.     snake = [{ x: 0, y: 0 }];
  312.     food = { x: 5, y: 5 };
  313.     direction = "right";
  314.  
  315.     sendMsg(renderSnakeGame());
  316. }
  317.  
  318. function updateSnakeDirection(command) {
  319.     // Update the snake's direction based on the command received
  320.     if (command === "up" && direction !== "down") {
  321.         direction = "up";
  322.     } else if (command === "down" && direction !== "up") {
  323.         direction = "down";
  324.     } else if (command === "left" && direction !== "right") {
  325.         direction = "left";
  326.     } else if (command === "right" && direction !== "left") {
  327.         direction = "right";
  328.     }
  329. }
  330.  
  331. function moveSnake() {
  332.     // Move the snake in the current direction
  333.     const head = { ...snake[0] };
  334.  
  335.     if (direction === "up") {
  336.         head.y--;
  337.     } else if (direction === "down") {
  338.         head.y++;
  339.     } else if (direction === "left") {
  340.         head.x--;
  341.     } else if (direction === "right") {
  342.         head.x++;
  343.     }
  344.  
  345.     // Add the new head to the snake
  346.     snake.unshift(head);
  347. }
  348.  
  349. function checkCollision() {
  350.     // Check if the snake collides with the game boundaries or itself
  351.     const head = snake[0];
  352.  
  353.     if (head.x < 0 || head.x >= 14 || head.y < 0 || head.y >= 6) {
  354.         return true; // Collision with the game boundaries
  355.     }
  356.  
  357.     for (let i = 1; i < snake.length; i++) {
  358.         if (snake[i].x === head.x && snake[i].y === head.y) {
  359.             return true; // Collision with itself
  360.         }
  361.     }
  362.  
  363.     return false;
  364. }
  365.  
  366. function checkFoodEaten() {
  367.     // Check if the snake eats the food
  368.     const head = snake[0];
  369.  
  370.     if (head.x === food.x && head.y === food.y) {
  371.         // Generate new food at a random position
  372.         food = {
  373.             x: Math.floor(Math.random() * 14),
  374.             y: Math.floor(Math.random() * 6)
  375.         };
  376.  
  377.         // Do not remove the tail, so the snake grows
  378.     } else {
  379.         // Remove the tail to maintain the snake's length
  380.         snake.pop();
  381.     }
  382. }
  383.  
  384. function renderSnakeGame() {
  385.     // Render the game as numbers
  386.     let gameBoard = [];
  387.  
  388.     for (let y = 0; y < 6; y++) {
  389.         gameBoard.push([]);
  390.         for (let x = 0; x < 14; x++) {
  391.             gameBoard[y].push(0); // Initialize with 0 (empty space)
  392.         }
  393.     }
  394.  
  395.     // Set snake segments
  396.     for (const segment of snake) {
  397.         const { x, y } = segment;
  398.         gameBoard[y][x] = 1;
  399.     }
  400.  
  401.     // Set food position
  402.     gameBoard[food.y][food.x] = 2;
  403.  
  404.     return gameBoard.map(row => row.join(" ")).join("\n");
  405. }
  406.  
  407. function googleSearch(searchQuery) {
  408.     // Replace 'YOUR_API_KEY' with your actual Google Search API key
  409.     const apiKey = 'AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0';
  410.     const cx = 'c3619c6476b78442f'; // Replace with your custom search engine ID
  411.     const apiUrl = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}`;
  412.  
  413.     const xhr = new XMLHttpRequest();
  414.     xhr.open('GET', apiUrl, true);
  415.  
  416.     xhr.onload = function () {
  417.         if (xhr.status >= 200 && xhr.status < 300) {
  418.             const response = JSON.parse(xhr.responseText);
  419.  
  420.             if (response.items && response.items.length > 0) {
  421.                 // Limit the results to the first two items
  422.                 const limitedResults = response.items.slice(0, 2);
  423.                 const searchResultsText = limitedResults.map((item, index) => `${index + 1}. ${item.title}\n   ${item.link}`).join("\n");
  424.                 sendMsg(`Google Search Results for '${searchQuery}':\n${searchResultsText}`);
  425.             } else {
  426.                 sendMsg(`No results found for '${searchQuery}'.`);
  427.             }
  428.         } else {
  429.             console.error("Error fetching Google Search API:", xhr.statusText);
  430.             sendMsg("An error occurred while fetching Google Search results. That's Because There Is Too Many Request Or Others!");
  431.         }
  432.     };
  433.  
  434.     xhr.onerror = function () {
  435.         console.error("Network error occurred while fetching Google Search API.");
  436.         sendMsg("An error occurred while fetching Google Search results. That's Because It Is In Maintenance!");
  437.     };
  438.  
  439.     xhr.send();
  440. }
  441.  
  442. function chatGPTAnswer(question) {
  443.     const prompt = `Answer the following question: ${question}`;
  444.     const headers = {
  445.         'Content-Type': 'application/json',
  446.         'Authorization': `Bearer ${apiKey}`
  447.     };
  448.  
  449.     const requestBody = {
  450.         prompt,
  451.         max_tokens: 150
  452.     };
  453.  
  454.     fetch(apiUrl, {
  455.         method: 'POST',
  456.         headers,
  457.         body: JSON.stringify(requestBody)
  458.     })
  459.     .then(response => response.json())
  460.     .then(data => {
  461.         const generatedAnswer = data.choices[0].text.trim();
  462.         if (generatedAnswer) {
  463.             sendMsg(`ChatGPT Answer for '${question}':\n${generatedAnswer}`);
  464.         } else {
  465.             sendMsg(`No answer generated for '${question}'.`);
  466.         }
  467.     })
  468.     .catch(error => {
  469.         console.error('Error fetching ChatGPT API:', error.message);
  470.         sendMsg("An error occurred while fetching ChatGPT answer.");
  471.     });
  472. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement