automated task
This commit is contained in:
parent
643b2de45b
commit
7d3b02c772
18
src/bot.py
18
src/bot.py
@ -7,7 +7,7 @@ import aiohttp
|
||||
import discord
|
||||
from bs4 import BeautifulSoup as bs4
|
||||
from discord import Intents, Interaction, app_commands
|
||||
from discord.ext import commands
|
||||
from discord.ext import commands, tasks
|
||||
from bbc_feeds import news
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ class CommandsCog(commands.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
super().__init__()
|
||||
self.news_task.start()
|
||||
|
||||
async def story_to_embed(self, story) -> discord.Embed:
|
||||
"""
|
||||
@ -72,6 +72,8 @@ class CommandsCog(commands.Cog):
|
||||
description="BBC News"
|
||||
)
|
||||
|
||||
checked_news = set()
|
||||
|
||||
@group.command(name="latest")
|
||||
async def get_latest_news(self, inter: Interaction, limit: int = 1):
|
||||
"""
|
||||
@ -84,6 +86,18 @@ class CommandsCog(commands.Cog):
|
||||
embed = await self.story_to_embed(story)
|
||||
await inter.followup.send(embed=embed)
|
||||
|
||||
@tasks.loop(minutes=15)
|
||||
async def news_task(self):
|
||||
|
||||
story = news().all(limit=1)[0]
|
||||
if story.link in self.checked_news:
|
||||
return
|
||||
|
||||
self.checked_news.add(story.link)
|
||||
embed = await self.story_to_embed(story)
|
||||
channel = self.bot.get_channel(1057004889458348042)
|
||||
await channel.send(embed=embed)
|
||||
|
||||
|
||||
class ErrorCog(commands.Cog):
|
||||
"""Error handling cog."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user