Advertisement
samiroexpikachu

Lens

Jul 11th, 2024 (edited)
295
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: "lens",
  6.         version: "1.1",
  7.         author: "Samir Œ",
  8.         countDown: 5,
  9.         role: 0,
  10.         description: {
  11.             vi: "Tìm kiếm hình ảnh và hiển thị kết quả từ URL",
  12.             en: "Search for images and display results from source URL"
  13.         },
  14.         category: "𝗨𝗧𝗜𝗟𝗜𝗧𝗬",
  15.     },
  16.     onStart: async function ({ api, args, message, event }) {
  17.         let imageUrl;
  18.  
  19.         if (event.messageReply && event.messageReply.attachments.length > 0) {
  20.             imageUrl = event.messageReply.attachments[0].url;
  21.         } else if (args.length > 0) {
  22.             imageUrl = args[0];
  23.         } else {
  24.             return message.reply({ body: "Please reply to an image or provide an image URL." });
  25.         }
  26.  
  27.         try {
  28.             const response = await axios.get(`https://samirxpikachuio.onrender.com/glens?url=${encodeURIComponent(imageUrl)}`);
  29.             const results = response.data.slice(0, 6);
  30.  
  31.             if (results.length > 0) {
  32.                 const trackInfo = results.map((result, index) =>
  33.                     `${index + 1}. ${result.title}\nURL: ${result.link}\n`
  34.                 ).join("\n\n");
  35.  
  36.                 const thumbnails = results.map(result => result.thumbnail);
  37.                 const attachments = await Promise.all(
  38.                     thumbnails.map(thumbnail =>
  39.                         global.utils.getStreamFromURL(thumbnail)
  40.                     )
  41.                 );
  42.  
  43.                 await message.reply({
  44.                     body: `${trackInfo}`,
  45.                     attachment: attachments
  46.                 });
  47.             } else {
  48.                 message.reply({ body: "No results found for the given image." });
  49.             }
  50.         } catch (error) {
  51.             console.error(error);
  52.             message.reply({ body: "An error occurred while fetching image search results." });
  53.         }
  54.     }
  55. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement