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/",
"https://arstechnica.com/feed",
"https://www.cert.ssi.gouv.fr/feed/",
"http://frenchlegion.eu/feed/",
"https://www.guru3d.com/news_rss",
"https://hardwareleaks.com/feed",
"https://www.lesnumeriques.com/rss.xml",
"https://www.overclock3d.net/xmlfeed",
"https://overclocking.com/feed/",
"https://pcper.com/feed",
"https://www.rtings.com/reviews-rss.xml",
"https://www.storagereview.com/feed",
"https://www.techpowerup.com/rss/news",
"https://www.techpowerup.com/rss/reviews",
"https://www.techspot.com/backend.xml",
"https://videocardz.com/feed",
"https://vonguru.fr/feed/"
]
newsfeed = {} rss_website = {
for i in rss_website: "anandtech": "https://www.anandtech.com/rss/",
newsfeed[i] = feedparser.parse(i) "arstechnica": "https://arstechnica.com/feed",
"certssi": "https://www.cert.ssi.gouv.fr/feed/",
"frenchlegion": "http://frenchlegion.eu/feed/",
"guru3d": "https://www.guru3d.com/news_rss",
"hardwareleaks": "https://hardwareleaks.com/feed",
"lesnumeriques": "https://www.lesnumeriques.com/rss.xml",
"overclock3d": "https://www.overclock3d.net/xmlfeed",
"overclocking": "https://overclocking.com/feed/",
"pcper": "https://pcper.com/feed",
"rtings": "https://www.rtings.com/reviews-rss.xml",
"storagereview": "https://www.storagereview.com/feed",
"techpowerupnews": "https://www.techpowerup.com/rss/news",
"techpowerupreviews": "https://www.techpowerup.com/rss/reviews",
"techspot": "https://www.techspot.com/backend.xml",
"videocardz": "https://videocardz.com/feed",
"vonguru": "https://vonguru.fr/feed/"
}
news = [] choix_site = choice([key for key in rss_website.keys()])
for entry in newsfeed.values():
for i in range(0, 10 if len(entry.entries) > 10 else len(entry.entries)):
news.append(entry.entries[i])
info = choice(news) if arg.lower() in rss_website: # si on specifie la source
await ctx.send(info.link) choix_site = arg.lower()
if arg.lower() == "liste":
embed = discord.Embed(title = "Liste des sources", color = randint(0, 0xFFFFFF), description = ", ".join([key.capitalize() for key in rss_website.keys()]))
return await ctx.send(embed = embed)
newsfeed = feedparser.parse(rss_website[choix_site])
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 = '')