Advertisement
samiroexpikachu

Google lens

Jun 19th, 2024
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2.  
  3. module.exports = {
  4.     config: {
  5.         name: "glen",
  6.         version: "1.0",
  7.         author: "Samir Œ",
  8.         countDown: 5,
  9.         role: 0,
  10.         shortDescription: {
  11.             vi: "Tìm kiếm hình ảnh",
  12.             en: "Search for images source"
  13.         },
  14.         longDescription: {
  15.             vi: "Tìm kiếm hình ảnh và hiển thị kết quả từ URL",
  16.             en: "Search for images and display results from source URL"
  17.         },
  18.         category: "utility",
  19.     },
  20.     onStart: async function ({ api, args, message, event }) {
  21.         let imageUrl;
  22.  
  23.         if (event.messageReply && event.messageReply.attachments.length > 0) {
  24.             imageUrl = event.messageReply.attachments[0].url;
  25.         } else if (args.length > 0) {
  26.             imageUrl = args[0];
  27.         } else {
  28.             return message.reply({ body: "Please reply to an image or provide an image URL." });
  29.         }
  30.  
  31.         try {
  32.             const response = await axios.get(`https://samirxpikachu.onrender.com/glens?url=${encodeURIComponent(imageUrl)}`);
  33.             const results = response.data.results[0].content.results.organic.slice(0, 6);
  34.  
  35.             if (results.length > 0) {
  36.                 const trackInfo = results.map((result, index) =>
  37.                     `${index + 1}. ${result.title}\nURL: ${result.url}`
  38.                 ).join("\n\n");
  39.  
  40.                 const thumbnails = results.map(result => result.url_thumbnail);
  41.                 const attachments = await Promise.all(
  42.                     thumbnails.map(thumbnail =>
  43.                         global.utils.getStreamFromURL(thumbnail)
  44.                     )
  45.                 );
  46.  
  47.                 await message.reply({
  48.                     body: `${trackInfo}`,
  49.                     attachment: attachments
  50.                 });
  51.             } else {
  52.                 message.reply({ body: "No results found for the given image." });
  53.             }
  54.         } catch (error) {
  55.             console.error(error);
  56.             message.reply({ body: "An error occurred while fetching image search results." });
  57.         }
  58.     }
  59. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement