ajout commande news

This commit is contained in:
Mylloon 2020-12-11 15:45:42 +01:00
parent 6d282f28e4
commit 485a442583
2 changed files with 49 additions and 2 deletions

View file

@ -49,3 +49,4 @@ Pour trouver ton token reddit, va sur [ce site](https://www.reddit.com/prefs/app
| [.dog](https://code.up8.edu/Anri/bot-licence/-/blob/master/cogs/internet.py#L90) | Envoie un chien depuis internet |
| [.chifumi](https://code.up8.edu/Anri/bot-licence/-/blob/master/cogs/games.py#L17) | Fais une partie de pierre papier ciseaux contre le bot |
| [.plusoumoins](https://code.up8.edu/Anri/bot-licence/-/blob/master/cogs/games.py#L49) | Fais une partie de guessing game contre le bot |
| [.news](https://code.up8.edu/Anri/bot-licence/-/blob/master/cogs/internet.py#L105) | Info random dans le domaine de l'informatique |

View file

@ -1,7 +1,6 @@
import discord, praw, json, requests, datetime
import discord, praw, json, requests, datetime, time, feedparser
from discord.ext import commands
from random import randint, choice
import time
from tokens import token_reddit as token # à l'importation de l'extension, le fichier se retrouve dans le '/' et non dans 'cogs/', ignorez l'erreur pylint si il y a
def setup(bot):
@ -101,3 +100,50 @@ class Internet(commands.Cog):
await ctx.message.add_reaction(emoji = '')
message = await ctx.send(embed=embed)
return await message.add_reaction('❤️')
@commands.command(name='news', aliases=['rss'])
async def _news(self, ctx, *, arg = ""):
"""Info random dans le domaine de l'informatique\n ➡ Syntaxe: .news/rss [site/liste]"""
rss_website = {
"anandtech": "https://www.anandtech.com/rss/",
"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/"
}
choix_site = choice([key for key in rss_website.keys()])
if arg.lower() in rss_website: # si on specifie la source
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 = "Pas de description trouvée." if "<p>" in info.description or "</a>" in info.description else info.description
embed = discord.Embed(title = info.title, color = randint(0, 0xFFFFFF), description = f"[**lien de la news**]({info.link})\n\n{desc}")
try:
embed.set_author(name = info.author)
except:
pass
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 = '')