From 7d3b02c77238ec5125e39ee7b8b33a65b71a5e03 Mon Sep 17 00:00:00 2001 From: Corban-Lee <77944149+Corban-Lee@users.noreply.github.com> Date: Mon, 12 Jun 2023 21:31:29 +0100 Subject: [PATCH] automated task --- src/bot.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bot.py b/src/bot.py index 34470f6..502c127 100644 --- a/src/bot.py +++ b/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."""