refonte commande news

This commit is contained in:
Mylloon 2020-12-11 14:26:17 +01:00
parent 5b0d2650c5
commit bfefad6073

View file

@ -141,37 +141,45 @@ class Internet(commands.Cog):
await ctx.send(f"Désolé mais je n'envois ce genre de message seulement dans les salons NSFW !") await ctx.send(f"Désolé mais je n'envois ce genre de message seulement dans les salons NSFW !")
@commands.command(name='news', aliases=['rss']) @commands.command(name='news', aliases=['rss'])
async def _news(self, ctx): async def _news(self, ctx, *, arg = ""):
"""Info random sur le domaine de l'informatique""" """Info random sur le domaine de l'informatique\n ➡ Syntaxe: .news/rss [site/liste]"""
rss_website = [
"https://www.anandtech.com/rss/", rss_website = {
"https://arstechnica.com/feed", "anandtech": "https://www.anandtech.com/rss/",
"https://www.cert.ssi.gouv.fr/feed/", "arstechnica": "https://arstechnica.com/feed",
"http://frenchlegion.eu/feed/", "certssi": "https://www.cert.ssi.gouv.fr/feed/",
"https://www.guru3d.com/news_rss", "frenchlegion": "http://frenchlegion.eu/feed/",
"https://hardwareleaks.com/feed", "guru3d": "https://www.guru3d.com/news_rss",
"https://www.lesnumeriques.com/rss.xml", "hardwareleaks": "https://hardwareleaks.com/feed",
"https://www.overclock3d.net/xmlfeed", "lesnumeriques": "https://www.lesnumeriques.com/rss.xml",
"https://overclocking.com/feed/", "overclock3d": "https://www.overclock3d.net/xmlfeed",
"https://pcper.com/feed", "overclocking": "https://overclocking.com/feed/",
"https://www.rtings.com/reviews-rss.xml", "pcper": "https://pcper.com/feed",
"https://www.storagereview.com/feed", "rtings": "https://www.rtings.com/reviews-rss.xml",
"https://www.techpowerup.com/rss/news", "storagereview": "https://www.storagereview.com/feed",
"https://www.techpowerup.com/rss/reviews", "techpowerupnews": "https://www.techpowerup.com/rss/news",
"https://www.techspot.com/backend.xml", "techpowerupreviews": "https://www.techpowerup.com/rss/reviews",
"https://videocardz.com/feed", "techspot": "https://www.techspot.com/backend.xml",
"https://vonguru.fr/feed/" "videocardz": "https://videocardz.com/feed",
] "vonguru": "https://vonguru.fr/feed/"
}
choix_site = choice([key for key in rss_website.keys()])
newsfeed = {} if arg.lower() in rss_website: # si on specifie la source
for i in rss_website: choix_site = arg.lower()
newsfeed[i] = feedparser.parse(i)
news = [] if arg.lower() == "liste":
for entry in newsfeed.values(): embed = discord.Embed(title = "Liste des sources", color = randint(0, 0xFFFFFF), description = ", ".join([key.capitalize() for key in rss_website.keys()]))
for i in range(0, 10 if len(entry.entries) > 10 else len(entry.entries)): return await ctx.send(embed = embed)
news.append(entry.entries[i])
info = choice(news) newsfeed = feedparser.parse(rss_website[choix_site])
await ctx.send(info.link) info = choice([newsfeed.entries[i] for i in range(0, 10 if len(newsfeed.entries) > 10 else len(newsfeed.entries))])
desc = f"\n\n{info.description}"
embed = discord.Embed(title = info.title, color = randint(0, 0xFFFFFF), description = f"[**lien de la news**]({info.link}){'' if '<p>' in desc else desc}")
embed.set_author(name = info.author)
embed.set_footer(text = f"News de {choix_site.capitalize()}")
#embed.set_image(url = submission.url)
await ctx.send(embed = embed)
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')