google trends
Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
parent
5742e1bafc
commit
17a70e8882
17
README.md
17
README.md
@ -7,7 +7,9 @@ A powerful Discord bot that can send messages and search for multimedia files on
|
|||||||
- 🏓 **Ping Command** - Simple ping command to check if the bot is working
|
- 🏓 **Ping Command** - Simple ping command to check if the bot is working
|
||||||
- 📨 **Message Sending** - Send messages to any channel in the server
|
- 📨 **Message Sending** - Send messages to any channel in the server
|
||||||
- 🔍 **Multimedia Search** - Search for images and videos with embedded preview
|
- 🔍 **Multimedia Search** - Search for images and videos with embedded preview
|
||||||
|
- 📈 **Google Trends** - Show current trending topics by country with grouped articles
|
||||||
- ⬇️ **File Download** - Download and share multimedia files directly in Discord
|
- ⬇️ **File Download** - Download and share multimedia files directly in Discord
|
||||||
|
- 🟠 **Bitcoin Monitor** - Real-time Bitcoin transaction monitoring
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -62,6 +64,21 @@ Searches for multimedia content on Google with enhanced display.
|
|||||||
- Includes video descriptions when available
|
- Includes video descriptions when available
|
||||||
- Supports YouTube, Vimeo, and direct video files
|
- Supports YouTube, Vimeo, and direct video files
|
||||||
|
|
||||||
|
### 📈 Google Trends
|
||||||
|
```
|
||||||
|
/trends country:ES
|
||||||
|
```
|
||||||
|
Shows current Google Trends by country with articles grouped by context.
|
||||||
|
- `country`: Country code (US, ES, GB, FR, DE, JP, BR, or Global) (optional, default: US)
|
||||||
|
|
||||||
|
**Trends Features:**
|
||||||
|
- Real-time trending topics from Google Trends
|
||||||
|
- Articles grouped by news source/category
|
||||||
|
- Top 3 articles per trending story
|
||||||
|
- Support for multiple countries
|
||||||
|
- Rich embeds with clickable article links
|
||||||
|
- Timestamp and source attribution
|
||||||
|
|
||||||
### ⬇️ Download Files
|
### ⬇️ Download Files
|
||||||
```
|
```
|
||||||
/download url:https://example.com/image.jpg title:My Image
|
/download url:https://example.com/image.jpg title:My Image
|
||||||
|
147
index.js
147
index.js
@ -11,6 +11,7 @@ import { createRequire } from 'module';
|
|||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
const Socket = require('blockchain.info/Socket');
|
const Socket = require('blockchain.info/Socket');
|
||||||
const blockexplorer = require('blockchain.info/blockexplorer');
|
const blockexplorer = require('blockchain.info/blockexplorer');
|
||||||
|
const googleTrends = require('google-trends-api');
|
||||||
|
|
||||||
// Load environment variables
|
// Load environment variables
|
||||||
config();
|
config();
|
||||||
@ -141,6 +142,28 @@ client.on(Events.ClientReady, async readyClient => {
|
|||||||
min_value: 0
|
min_value: 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'trends',
|
||||||
|
description: 'Show current Google Trends by country',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'country',
|
||||||
|
type: 3, // STRING type
|
||||||
|
description: 'Country code (e.g., US, ES, GB, FR, DE)',
|
||||||
|
required: false,
|
||||||
|
choices: [
|
||||||
|
{ name: 'United States', value: 'US' },
|
||||||
|
{ name: 'Spain', value: 'ES' },
|
||||||
|
{ name: 'United Kingdom', value: 'GB' },
|
||||||
|
{ name: 'France', value: 'FR' },
|
||||||
|
{ name: 'Germany', value: 'DE' },
|
||||||
|
{ name: 'Japan', value: 'JP' },
|
||||||
|
{ name: 'Brazil', value: 'BR' },
|
||||||
|
{ name: 'Global', value: '' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -368,6 +391,55 @@ async function searchVideos(query, limit = 5) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Google Trends function to get real-time trending topics
|
||||||
|
async function getTrends(countryCode = 'US') {
|
||||||
|
try {
|
||||||
|
const query = countryCode ? { geo: countryCode } : {};
|
||||||
|
|
||||||
|
const results = await googleTrends.realTimeTrends(query);
|
||||||
|
const trendsData = JSON.parse(results);
|
||||||
|
|
||||||
|
if (!trendsData.storySummaries || !trendsData.storySummaries.trendingStories) {
|
||||||
|
throw new Error('No trending stories found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group trends by context and format for Discord
|
||||||
|
const trendingStories = trendsData.storySummaries.trendingStories;
|
||||||
|
const groupedTrends = {};
|
||||||
|
|
||||||
|
trendingStories.forEach((story, index) => {
|
||||||
|
// Use the first article's category or create a generic category
|
||||||
|
const category = story.articles && story.articles[0] && story.articles[0].source
|
||||||
|
? story.articles[0].source
|
||||||
|
: 'General';
|
||||||
|
|
||||||
|
if (!groupedTrends[category]) {
|
||||||
|
groupedTrends[category] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get top 3 articles for each story
|
||||||
|
const topArticles = story.articles ? story.articles.slice(0, 3) : [];
|
||||||
|
|
||||||
|
groupedTrends[category].push({
|
||||||
|
title: story.title,
|
||||||
|
rank: index + 1,
|
||||||
|
articles: topArticles.map(article => ({
|
||||||
|
title: article.articleTitle ? article.articleTitle.replace(/\n/g, ' ').trim() : 'No title',
|
||||||
|
source: article.source || 'Unknown',
|
||||||
|
url: article.url || '',
|
||||||
|
time: article.time || 'Unknown'
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return groupedTrends;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Trends fetch failed:', error);
|
||||||
|
throw new Error(`Failed to fetch trends: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Bitcoin transaction monitoring functions
|
// Bitcoin transaction monitoring functions
|
||||||
async function initBitcoinMonitoring() {
|
async function initBitcoinMonitoring() {
|
||||||
try {
|
try {
|
||||||
@ -707,6 +779,81 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'trends':
|
||||||
|
await interaction.deferReply();
|
||||||
|
const countryCode = interaction.options.getString('country') || 'US';
|
||||||
|
const countryNames = {
|
||||||
|
'US': 'United States',
|
||||||
|
'ES': 'Spain',
|
||||||
|
'GB': 'United Kingdom',
|
||||||
|
'FR': 'France',
|
||||||
|
'DE': 'Germany',
|
||||||
|
'JP': 'Japan',
|
||||||
|
'BR': 'Brazil',
|
||||||
|
'': 'Global'
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const trendGroups = await getTrends(countryCode);
|
||||||
|
const countryName = countryNames[countryCode] || countryCode;
|
||||||
|
|
||||||
|
if (Object.keys(trendGroups).length === 0) {
|
||||||
|
await interaction.editReply(`❌ No trending topics found for ${countryName}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create embeds for each category
|
||||||
|
const embeds = [];
|
||||||
|
let trendCount = 0;
|
||||||
|
|
||||||
|
for (const [category, trends] of Object.entries(trendGroups)) {
|
||||||
|
if (embeds.length >= 10) break; // Discord limit
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle(`📈 ${category} Trends`)
|
||||||
|
.setColor(0x4285F4)
|
||||||
|
.setFooter({ text: `Google Trends • ${countryName}` })
|
||||||
|
.setTimestamp();
|
||||||
|
|
||||||
|
// Add top 3 trends from this category
|
||||||
|
const topTrends = trends.slice(0, 3);
|
||||||
|
|
||||||
|
topTrends.forEach((trend, index) => {
|
||||||
|
trendCount++;
|
||||||
|
let fieldValue = `**#${trend.rank} Trending**\n`;
|
||||||
|
|
||||||
|
if (trend.articles && trend.articles.length > 0) {
|
||||||
|
// Show top 2 articles for each trend
|
||||||
|
const topArticles = trend.articles.slice(0, 2);
|
||||||
|
topArticles.forEach(article => {
|
||||||
|
const shortTitle = article.title.length > 60
|
||||||
|
? article.title.substring(0, 60) + '...'
|
||||||
|
: article.title;
|
||||||
|
fieldValue += `• [${shortTitle}](${article.url}) - *${article.source}*\n`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
embed.addFields({
|
||||||
|
name: `${trend.title}`,
|
||||||
|
value: fieldValue,
|
||||||
|
inline: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
embeds.push(embed);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
content: `🌍 **Current Trending Topics in ${countryName}**\nShowing ${trendCount} trending stories:`,
|
||||||
|
embeds: embeds
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Trends error:', error);
|
||||||
|
await interaction.editReply(`❌ Error fetching trends for ${countryName}: ${error.message}\n\nThis could be due to rate limiting or the service being unavailable.`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'btc-monitor':
|
case 'btc-monitor':
|
||||||
const action = interaction.options.getString('action');
|
const action = interaction.options.getString('action');
|
||||||
const channel = interaction.options.getChannel('channel');
|
const channel = interaction.options.getChannel('channel');
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"cheerio": "^1.0.0",
|
"cheerio": "^1.0.0",
|
||||||
"discord.js": "^14.18.0",
|
"discord.js": "^14.18.0",
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
|
"google-trends-api": "^4.9.2",
|
||||||
"node-fetch": "^2.7.0"
|
"node-fetch": "^2.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,13 @@ echo " - Searches for funny videos"
|
|||||||
echo " - Will show video links with thumbnails"
|
echo " - Will show video links with thumbnails"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "5. /download url:https://example.com/image.jpg title:Test Image"
|
echo "5. /trends country:ES"
|
||||||
|
echo " - Shows current Google Trends for Spain"
|
||||||
|
echo " - Displays trending topics grouped by news source"
|
||||||
|
echo " - Includes clickable article links"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "6. /download url:https://example.com/image.jpg title:Test Image"
|
||||||
echo " - Downloads and shares a multimedia file"
|
echo " - Downloads and shares a multimedia file"
|
||||||
echo " - File must be under 8MB for Discord"
|
echo " - File must be under 8MB for Discord"
|
||||||
echo ""
|
echo ""
|
||||||
|
31
test-trends.js
Normal file
31
test-trends.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Test Google Trends API
|
||||||
|
import { createRequire } from 'module';
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const googleTrends = require('google-trends-api');
|
||||||
|
|
||||||
|
async function testTrends() {
|
||||||
|
try {
|
||||||
|
console.log('Testing Google Trends API...');
|
||||||
|
|
||||||
|
const query = { geo: 'ES' };
|
||||||
|
const results = await googleTrends.realTimeTrends(query);
|
||||||
|
const trendsData = JSON.parse(results);
|
||||||
|
|
||||||
|
console.log('✅ API working!');
|
||||||
|
console.log('📈 Found', trendsData.storySummaries.trendingStories.length, 'trending stories');
|
||||||
|
|
||||||
|
// Show first trend
|
||||||
|
if (trendsData.storySummaries.trendingStories.length > 0) {
|
||||||
|
const firstTrend = trendsData.storySummaries.trendingStories[0];
|
||||||
|
console.log('🔥 Top trend:', firstTrend.title);
|
||||||
|
if (firstTrend.articles && firstTrend.articles.length > 0) {
|
||||||
|
console.log('📰 First article:', firstTrend.articles[0].articleTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testTrends();
|
Loading…
x
Reference in New Issue
Block a user