You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. let rssParser = require('rss-parser');
  2. const Discord = require("discord.js")
  3. let feeds = {
  4. "REDDIT" : ['https://www.reddit.com/.rss', 'https://i.redd.it/rq36kl1xjxr01.png', "https://reddit.com" ],
  5. "WIRED" : ['https://www.wired.com/feed/rss', "https://www.wired.com/wp-content/themes/Phoenix/assets/images/article-icon.jpg", "https://www.wired.com"]
  6. };
  7. const threshold = 3;
  8. module.exports = {
  9. name: 'news',
  10. description: 'Get rss feed',
  11. channels: ['734387503464710165'],
  12. async execute(message) {
  13. let channel = message.guild.channels.cache.get("734687050707632239");
  14. let parser = new rssParser();
  15. let news = []
  16. for(item in feeds){
  17. let feed = await parser.parseURL(feeds[item][0]);
  18. for(var i = feed.items.length - 1; i > feed.items.length - 1 - threshold; i --){
  19. let data = feed.items[i];
  20. news.push({
  21. title: data.title,
  22. url: data.link,
  23. author: item,
  24. author_img: feeds[item][1],
  25. author_url: feeds[item][2],
  26. content: data.contentSnippet
  27. });
  28. }
  29. };
  30. news.forEach((item) => {
  31. let newsEmbed = new Discord.MessageEmbed()
  32. .setColor('#0099ff')
  33. .setTitle(item.title)
  34. .setURL(item.url)
  35. .setAuthor(item.author, item.author_img, item.author_url)
  36. .setDescription(item.content)
  37. .setTimestamp();
  38. channel.send(newsEmbed)
  39. });
  40. }
  41. };