Spaces:
Paused
Paused
𝗗𝗔𝗥𝗥𝗘𝗟𝗟 𝗠𝗨𝗖𝗛𝗘𝗥𝗜 ⚡
commited on
Create google.js
Browse files- plugins/google.js +45 -0
plugins/google.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// GOOGLE CMD
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
const axios = require("axios");
|
| 5 |
+
const { cmd } = require("../command");
|
| 6 |
+
|
| 7 |
+
cmd({
|
| 8 |
+
pattern: "google",
|
| 9 |
+
alias: ["gsearch", "search"],
|
| 10 |
+
desc: "Search Google for a query.",
|
| 11 |
+
category: "tools",
|
| 12 |
+
react: "🌐",
|
| 13 |
+
filename: __filename
|
| 14 |
+
}, async (conn, mek, m, { args, reply }) => {
|
| 15 |
+
try {
|
| 16 |
+
// Vérifiez si un mot-clé est fourni
|
| 17 |
+
if (args.length === 0) {
|
| 18 |
+
return reply(`❗ *Please provide a search query.*\n\n*Example:*\n.google OpenAI`);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const query = args.join(" ");
|
| 22 |
+
const apiKey = "AIzaSyDMbI3nvmQUrfjoCJYLS69Lej1hSXQjnWI"; // Votre clé API Google
|
| 23 |
+
const cx = "baf9bdb0c631236e5"; // Votre ID de moteur de recherche personnalisé
|
| 24 |
+
const apiUrl = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(query)}&key=${apiKey}&cx=${cx}`;
|
| 25 |
+
|
| 26 |
+
// Appel API
|
| 27 |
+
const response = await axios.get(apiUrl);
|
| 28 |
+
|
| 29 |
+
// Vérifiez si l'API a renvoyé des résultats
|
| 30 |
+
if (response.status !== 200 || !response.data.items || response.data.items.length === 0) {
|
| 31 |
+
return reply(`❌ *No results found for:* ${query}`);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// Format et envoi des résultats
|
| 35 |
+
let results = `🔎 *Google Search Results for:* "${query}"\n\n`;
|
| 36 |
+
response.data.items.slice(0, 5).forEach((item, index) => {
|
| 37 |
+
results += `*${index + 1}. ${item.title}*\n${item.link}\n${item.snippet}\n\n`;
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
reply(results.trim());
|
| 41 |
+
} catch (error) {
|
| 42 |
+
console.error(error);
|
| 43 |
+
reply(`⚠️ *An error occurred while fetching search results.*\n\n${error.message}`);
|
| 44 |
+
}
|
| 45 |
+
});
|