out console log

Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
ale 2025-06-08 04:41:26 +02:00
parent ab9fa7fdf3
commit f1e792d050
Signed by: ale
GPG Key ID: 244A9C4DAB1C0C81

View File

@ -259,8 +259,6 @@ async function validateImageUrl(url) {
// Real search function using DuckDuckGo API for actual search results // Real search function using DuckDuckGo API for actual search results
async function searchImages(query, limit = 10) { async function searchImages(query, limit = 10) {
try { try {
console.log(`Searching for images: ${query}`);
// Use DuckDuckGo Instant Answer API for real search results // Use DuckDuckGo Instant Answer API for real search results
const searchUrl = `https://api.duckduckgo.com/?q=${encodeURIComponent(query + ' image')}&format=json&no_html=1&skip_disambig=1&safe_search=strict`; const searchUrl = `https://api.duckduckgo.com/?q=${encodeURIComponent(query + ' image')}&format=json&no_html=1&skip_disambig=1&safe_search=strict`;
@ -333,11 +331,10 @@ async function searchImages(query, limit = 10) {
}); });
} }
} catch (unsplashError) { } catch (unsplashError) {
console.log('Unsplash scraping failed:', unsplashError.message); // Unsplash scraping failed silently
} }
} }
console.log(`Found ${searchResults.length} real search results for: ${query}`);
return searchResults.slice(0, limit); return searchResults.slice(0, limit);
} catch (error) { } catch (error) {
@ -349,8 +346,6 @@ async function searchImages(query, limit = 10) {
// Real video search function using YouTube search // Real video search function using YouTube search
async function searchVideos(query, limit = 5) { async function searchVideos(query, limit = 5) {
try { try {
console.log(`Searching for videos: ${query}`);
// Use DuckDuckGo to search for YouTube videos // Use DuckDuckGo to search for YouTube videos
const searchUrl = `https://api.duckduckgo.com/?q=${encodeURIComponent(query + ' site:youtube.com')}&format=json&no_html=1&skip_disambig=1`; const searchUrl = `https://api.duckduckgo.com/?q=${encodeURIComponent(query + ' site:youtube.com')}&format=json&no_html=1&skip_disambig=1`;
@ -419,11 +414,10 @@ async function searchVideos(query, limit = 5) {
} }
} }
} catch (youtubeError) { } catch (youtubeError) {
console.log('YouTube scraping failed:', youtubeError.message); // YouTube scraping failed silently
} }
} }
console.log(`Found ${videoResults.length} real video results for: ${query}`);
return videoResults.slice(0, limit); return videoResults.slice(0, limit);
} catch (error) { } catch (error) {
@ -634,21 +628,15 @@ client.on(Events.InteractionCreate, async interaction => {
break; break;
case 'search': case 'search':
console.log('Search command received');
await interaction.deferReply(); await interaction.deferReply();
const query = interaction.options.getString('query'); const query = interaction.options.getString('query');
const mediaType = interaction.options.getString('type'); const mediaType = interaction.options.getString('type');
const count = interaction.options.getInteger('count') || 3; const count = interaction.options.getInteger('count') || 3;
console.log(`Search parameters: query="${query}", type="${mediaType}", count=${count}`);
try { try {
if (mediaType === 'image') { if (mediaType === 'image') {
console.log('Processing real image search...');
// Use real search function // Use real search function
const results = await searchImages(query, count); const results = await searchImages(query, count);
console.log(`Real search returned ${results.length} results`);
if (results.length === 0) { if (results.length === 0) {
await interaction.editReply(`❌ No image results found for "${query}". The search engines may not have returned any results for this query.`); await interaction.editReply(`❌ No image results found for "${query}". The search engines may not have returned any results for this query.`);
@ -670,11 +658,8 @@ client.on(Events.InteractionCreate, async interaction => {
}); });
} }
else if (mediaType === 'video') { else if (mediaType === 'video') {
console.log('Processing real video search...');
// Use real video search function // Use real video search function
const results = await searchVideos(query, count); const results = await searchVideos(query, count);
console.log(`Real video search returned ${results.length} results`);
if (results.length === 0) { if (results.length === 0) {
await interaction.editReply(`❌ No video results found for "${query}". The search engines may not have returned any results for this query.`); await interaction.editReply(`❌ No video results found for "${query}". The search engines may not have returned any results for this query.`);