Advertisement
nonogamer9

GoogleBOT

Dec 10th, 2023 (edited)
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.29 KB | Cybersecurity | 0 0
  1. const prefix = "g!";
  2. const botname = "GoogleBOT (" + prefix + "search/yt)";
  3. const version = "1.0, Bug Fixed To Work On 7.0.0!";
  4. const botinfo = "GoogleBOT Version " + version + ". Find GoogleBOT at: https://pastebin.com/ggYLJ7F4";
  5.  
  6. function sendMsg(msg) {
  7.     setTimeout(() => {
  8.         socket.emit("talk", msg);
  9.     }, 1100);
  10. }
  11.  
  12. // Setting bot name and color, and sending an initial message when the bot comes online
  13. setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 1000);
  14. setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 2100);
  15. setTimeout(() => { socket.emit("command", { command: "color", param: "https://cdn.discordapp.com/attachments/731430123571642390/1209592776883314760/i-tools.png?ex=66032b8f&is=65f0b68f&hm=b12385f6f2f41f132adca66665716f9b61d723b2c9463315cdfc433e46926d4e&" }) }, 3200);
  16. setTimeout(() => {
  17.     sendMsg("GoogleBOT is online. Type " + prefix + "search {Search} to look up something, and g!yt {YTID} to watch some YouTube! Make Sure To Grab The Popcorns!");
  18. }, 4300);
  19.  
  20. // Listening for incoming messages and responding accordingly
  21. socket.on("talk", (message) => {
  22.     if (message === prefix + "botinfo") {
  23.         sendMsg(botinfo);
  24.     }
  25.     // Handling YouTube video commands
  26.     else if (message.startsWith(prefix + "yt")) {
  27.         const videoId = message.substring(prefix.length + 3);
  28.         setTimeout(() => { socket.emit("command", { command: "youtube", param: videoId }); }, 1100);
  29.     }
  30.     // Handling search commands
  31.     else if (message.startsWith(prefix + "search")) {
  32.         const searchQuery = message.substring(prefix.length + 7);
  33.         googleSearch(searchQuery);
  34.     }
  35. });
  36.  
  37. function googleSearch(searchQuery) {
  38.     // Replace 'YOUR_API_KEY' with your actual Google Search API key
  39.     const apiKey = 'AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0';
  40.     const cx = 'c3619c6476b78442f'; // Replace with your custom search engine ID
  41.     const apiUrl = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}`;
  42.  
  43.     const xhr = new XMLHttpRequest();
  44.     xhr.open('GET', apiUrl, true);
  45.  
  46.     xhr.onload = function () {
  47.         if (xhr.status >= 200 && xhr.status < 300) {
  48.             const response = JSON.parse(xhr.responseText);
  49.  
  50.             if (response.items && response.items.length > 0) {
  51.                 // Limit the results to the first two items
  52.                 const limitedResults = response.items.slice(0, 2);
  53.                 const searchResultsText = limitedResults.map((item, index) => `${index + 1}. ${item.title}\n   ${item.link}`).join("\n");
  54.                 sendMsg(`Google Search Results for '${searchQuery}':\n${searchResultsText}`);
  55.             } else {
  56.                 sendMsg(`No results found for '${searchQuery}'.`);
  57.             }
  58.         } else {
  59.             console.error("Error fetching Google Search API:", xhr.statusText);
  60.             sendMsg("An error occurred while fetching Google Search results. That's Because There Is Too Many Request Or Others!");
  61.         }
  62.     };
  63.  
  64.     xhr.onerror = function () {
  65.         console.error("Network error occurred while fetching Google Search API.");
  66.         sendMsg("An error occurred while fetching Google Search results. That's Because It Is In Maintenance!");
  67.     };
  68.  
  69.     xhr.send();
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement