UNPKG

notmebotz-tools

Version:

Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT

57 lines (45 loc) 1.45 kB
const GOOGLE_API_KEY = 'AIzaSyDN4XveMYQrF5YGSqgupHwg4Yhg09iT7Gg'; const SEARCH_ENGINE_ID = 'd02711e8677af48e9'; async function googles(query, maxResults = 500) { try { let allResults = []; let currentIndex = 1; const maxAllowedResults = 100; const actualMaxResults = Math.min(maxResults, maxAllowedResults); while (allResults.length < actualMaxResults) { const response = await fetch( `https://www.googleapis.com/customsearch/v1?key=${GOOGLE_API_KEY}&cx=${SEARCH_ENGINE_ID}&q=${encodeURIComponent(query)}&start=${currentIndex}&num=10` ); const data = await response.json(); if (!response.ok || !data.items || data.items.length === 0) { break; } const formattedResults = data.items.map(item => ({ title: item.title || '', url: item.link || '', desc: item.snippet || '', icon: item.pagemap?.cse_image?.[0]?.src || '' })); allResults = [...allResults, ...formattedResults]; if (allResults.length >= actualMaxResults || !data.queries.nextPage) { break; } currentIndex += 10; if (currentIndex > maxAllowedResults) { break; } } return { author: "Herza", status: 200, data: allResults }; } catch (error) { return { author: "Herza", status: 500, error: error.message }; } } module.exports = { googles }