Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const prefix = "g!";
- const botname = "GoogleBOT (" + prefix + "search/yt)";
- const version = "1.0, Bug Fixed To Work On 7.0.0!";
- const botinfo = "GoogleBOT Version " + version + ". Find GoogleBOT at: https://pastebin.com/ggYLJ7F4";
- function sendMsg(msg) {
- setTimeout(() => {
- socket.emit("talk", msg);
- }, 1100);
- }
- // Setting bot name and color, and sending an initial message when the bot comes online
- setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 1000);
- setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 2100);
- setTimeout(() => { socket.emit("command", { command: "color", param: "https://cdn.discordapp.com/attachments/731430123571642390/1209592776883314760/i-tools.png?ex=66032b8f&is=65f0b68f&hm=b12385f6f2f41f132adca66665716f9b61d723b2c9463315cdfc433e46926d4e&" }) }, 3200);
- setTimeout(() => {
- 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!");
- }, 4300);
- // Listening for incoming messages and responding accordingly
- socket.on("talk", (message) => {
- if (message === prefix + "botinfo") {
- sendMsg(botinfo);
- }
- // Handling YouTube video commands
- else if (message.startsWith(prefix + "yt")) {
- const videoId = message.substring(prefix.length + 3);
- setTimeout(() => { socket.emit("command", { command: "youtube", param: videoId }); }, 1100);
- }
- // Handling search commands
- else if (message.startsWith(prefix + "search")) {
- const searchQuery = message.substring(prefix.length + 7);
- googleSearch(searchQuery);
- }
- });
- function googleSearch(searchQuery) {
- // Replace 'YOUR_API_KEY' with your actual Google Search API key
- const apiKey = 'AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0';
- const cx = 'c3619c6476b78442f'; // Replace with your custom search engine ID
- const apiUrl = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}`;
- const xhr = new XMLHttpRequest();
- xhr.open('GET', apiUrl, true);
- xhr.onload = function () {
- if (xhr.status >= 200 && xhr.status < 300) {
- const response = JSON.parse(xhr.responseText);
- if (response.items && response.items.length > 0) {
- // Limit the results to the first two items
- const limitedResults = response.items.slice(0, 2);
- const searchResultsText = limitedResults.map((item, index) => `${index + 1}. ${item.title}\n ${item.link}`).join("\n");
- sendMsg(`Google Search Results for '${searchQuery}':\n${searchResultsText}`);
- } else {
- sendMsg(`No results found for '${searchQuery}'.`);
- }
- } else {
- console.error("Error fetching Google Search API:", xhr.statusText);
- sendMsg("An error occurred while fetching Google Search results. That's Because There Is Too Many Request Or Others!");
- }
- };
- xhr.onerror = function () {
- console.error("Network error occurred while fetching Google Search API.");
- sendMsg("An error occurred while fetching Google Search results. That's Because It Is In Maintenance!");
- };
- xhr.send();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement