ADD options in news command.

pull/3/head
kevincaires 3 years ago
parent 90a88c74c1
commit 148712f9a6

@ -314,22 +314,51 @@ async def machine_info(bot: object, *args: str) -> str:
@client.command(aliases=['nw']) @client.command(aliases=['nw'])
async def news(bot: object) -> None: async def news(bot: object, *options: str) -> None:
f""" """
Return some news from Google. Return some news from Google.
options:
quantity: int
search: str
""" """
_news = News(quantity=5)
news = _news.news()
embed = Embed(type='rich') embed = Embed(type='rich')
filter = {}
news = None
if not options:
_news = News(quantity=5)
news = _news.news()
else:
# Validate option operation.
if not all(['=' in op for op in options]):
return await bot.send('Blabla')
for op in options:
key, value = op.split('=')
filter[key] = value
_news = News(quantity=filter.get('quantity', 5))
news = _news.filter(phrase=filter.get('search'))
if not news:
return
for new in news: for new in news:
# TODO: Descomentar o código do match case try:
dt = datetime.fromisoformat( dt = datetime.fromisoformat(
new['publishedAt'] new['publishedAt']
).astimezone(pytz.timezone('America/Sao_Paulo')) ).astimezone(pytz.timezone('America/Sao_Paulo'))
except ValueError:
dt = datetime.strptime(new['publishedAt'], '%Y-%m-%dT%H:%M:%Sz')
except Exception as e:
logger.error(e)
continue
embed.add_field(name='Font', value=new['source']['name'], inline=False)
embed.add_field(name='Published at', value=dt.isoformat(), inline=False) embed.add_field(name='Published at', value=dt.isoformat(), inline=False)
embed.add_field(name='link', value=new['url'], inline=False) embed.add_field(name='Link', value=new['url'], inline=False)
embed.add_field(name=new['title'], value=new['description'], inline=False) embed.add_field(name=new['title'], value=new['description'], inline=False)
embed.add_field(name='---', value='---') embed.add_field(name='---', value='---')
return await bot.send(f'**`{new["source"]["name"]}`**', embed=embed) return await bot.send(f'**`News`**', embed=embed)

Loading…
Cancel
Save