diff --git a/.env b/.env index e289375..650885b 100644 --- a/.env +++ b/.env @@ -6,6 +6,9 @@ DISCORD_TOKEN=MTQ5MTAxODYzOTc0MTI5MjY0NA.GxBqVk.dB3cWx8t8-kWLrMLGFL-g2ePkrs7l_XE # Right-click a channel and select "Copy Channel ID" (enable Developer Mode first) DISCORD_CHANNEL_IDS=600347996080701506,720537868996444230,1480636166150816007 +# Channel name mapping (channel_id=name, comma-separated) +CHANNEL_NAMES=600347996080701506=noticias,720537868996444230=eventos,1480636166150816007=changelog + # Server port (optional, defaults to 3000) PORT=8000 diff --git a/data/messages.db b/data/messages.db index 8a16843..7946588 100644 Binary files a/data/messages.db and b/data/messages.db differ diff --git a/src/rss.js b/src/rss.js index 2cf96d5..056e291 100644 --- a/src/rss.js +++ b/src/rss.js @@ -4,10 +4,44 @@ import { getMessagesByChannel, getAllChannels, getAllMessages } from './database const router = express.Router(); +// Channel emoji badges (add more as needed) +const CHANNEL_EMOJIS = { + 'noticias': '📢', + 'eventos': '📅', + 'changelog': '🔄', + 'general': '💬', + 'announcements': '📣', +}; + +// Parse channel names from environment variable +function getChannelNames() { + const namesStr = process.env.CHANNEL_NAMES || ''; + const names = {}; + if (namesStr) { + namesStr.split(',').forEach(pair => { + const [id, name] = pair.split('='); + if (id && name) { + names[id.trim()] = name.trim(); + } + }); + } + return names; +} + +function getChannelDisplayName(channelId) { + const names = getChannelNames(); + return names[channelId] || channelId; +} + +function getChannelEmoji(channelName) { + return CHANNEL_EMOJIS[channelName.toLowerCase()] || '📄'; +} + function generateRSSFeed(messages, channelInfo, feedUrlSuffix = null) { + const isCombined = channelInfo === 'All Channels'; const feed = new RSS({ - title: `Discord Channel - ${channelInfo}`, - description: 'Messages from Discord channel', + title: `Discord - ${channelInfo}`, + description: isCombined ? 'Latest messages from all channels' : `Messages from ${channelInfo}`, feed_url: `${process.env.BASE_URL || 'http://localhost:3000'}/rss/${feedUrlSuffix || channelInfo}`, site_url: process.env.BASE_URL || 'http://localhost:3000', language: 'en', @@ -17,9 +51,28 @@ function generateRSSFeed(messages, channelInfo, feedUrlSuffix = null) { for (const msg of messages) { const pubDate = new Date(msg.created_at); + const channelName = getChannelDisplayName(msg.channel_id); + const emoji = getChannelEmoji(channelName); + + // HTML-formatted description with visual badge + const formattedDescription = ` +
+ + ${emoji} ${channelName} + +
+
+ ${msg.content} +
+ `.trim(); + feed.item({ - title: `Update patch from ${pubDate.toISOString()}`, - description: msg.content, + title: `${emoji} [${channelName}] ${pubDate.toLocaleString()}`, + description: formattedDescription, + categories: [ + { name: channelName }, + { name: msg.author_name }, + ], url: `https://discord.com/channels/_/${msg.channel_id}/${msg.id}`, guid: msg.id, date: pubDate, @@ -41,25 +94,7 @@ router.get('/', (req, res) => { }); }); -// GET /rss/:channelId - RSS feed for specific channel -router.get('/:channelId', (req, res) => { - const { channelId } = req.params; - const limit = parseInt(req.query.limit, 10) || 50; - - const messages = getMessagesByChannel(channelId, limit); - - if (messages.length === 0) { - return res.status(404).json({ - error: 'No messages found for this channel', - hint: 'Make sure the bot has fetched messages from this channel', - }); - } - - const xml = generateRSSFeed(messages, channelId); - res.type('application/rss+xml').send(xml); -}); - -// GET /rss-all - Combined RSS feed from all channels +// GET /rss/all - Combined RSS feed from all channels router.get('/all', (req, res) => { const limit = parseInt(req.query.limit, 10) || 50; @@ -76,4 +111,23 @@ router.get('/all', (req, res) => { res.type('application/rss+xml').send(xml); }); +// GET /rss/:channelId - RSS feed for specific channel +router.get('/:channelId', (req, res) => { + const { channelId } = req.params; + const limit = parseInt(req.query.limit, 10) || 50; + + const messages = getMessagesByChannel(channelId, limit); + + if (messages.length === 0) { + return res.status(404).json({ + error: 'No messages found for this channel', + hint: 'Make sure the bot has fetched messages from this channel', + }); + } + + const displayName = getChannelDisplayName(channelId); + const xml = generateRSSFeed(messages, displayName, channelId); + res.type('application/rss+xml').send(xml); +}); + export default router;