mirror of https://github.com/stijndcl/didier
Optimize tasks
parent
5c0ebb7eeb
commit
3509bd81e4
|
@ -73,6 +73,7 @@ class Tasks(commands.Cog):
|
|||
self.remove_old_ufora_announcements.start()
|
||||
|
||||
# Start other tasks
|
||||
self.init_schedules.start()
|
||||
self.reminders.start()
|
||||
self.reset_wordle_word.start()
|
||||
self.pull_schedules.start()
|
||||
|
@ -134,6 +135,16 @@ class Tasks(commands.Cog):
|
|||
async def _before_check_birthdays(self):
|
||||
await self.client.wait_until_ready()
|
||||
|
||||
@tasks.loop(count=1)
|
||||
async def init_schedules(self, **kwargs):
|
||||
"""Tasks that loads the schedules in memory on startup"""
|
||||
_ = kwargs
|
||||
await self.client.load_schedules()
|
||||
|
||||
@init_schedules.before_loop
|
||||
async def _before_init_schedules(self):
|
||||
await self.client.wait_until_ready()
|
||||
|
||||
@tasks.loop(minutes=15)
|
||||
async def pull_free_games(self, **kwargs):
|
||||
"""Task that checks for free games occasionally"""
|
||||
|
|
|
@ -70,6 +70,8 @@ class FreeGameEmbed(EmbedPydantic):
|
|||
|
||||
if "steam" in store:
|
||||
self.store_page = await get_steam_webpage_info(http_session, self.link)
|
||||
elif "epic" in store:
|
||||
self.link = "https://store.epicgames.com/free-games"
|
||||
|
||||
if self.store_page is not None and self.store_page.url is not None:
|
||||
self.link = self.store_page.url
|
||||
|
|
|
@ -5,7 +5,7 @@ import feedparser
|
|||
from aiohttp import ClientSession
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.crud.free_games import filter_present_games
|
||||
from database.crud.free_games import add_free_games, filter_present_games
|
||||
from didier.data.embeds.free_games import SEPARATOR, FreeGameEmbed
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -40,7 +40,7 @@ async def fetch_free_games(http_session: ClientSession, database_session: AsyncS
|
|||
filtered_ids = await filter_present_games(database_session, game_ids)
|
||||
|
||||
# Insert new games into the database
|
||||
# await add_free_games(database_session, filtered_ids) TODO uncomment
|
||||
await add_free_games(database_session, filtered_ids)
|
||||
|
||||
games = list(filter(lambda x: x.dc_identifier in filtered_ids, games))
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ from bs4 import BeautifulSoup, Tag
|
|||
__all__ = ["GameStorePage", "parse_open_graph_tags"]
|
||||
|
||||
|
||||
# TODO make this an ABC that all other store pages implement instead
|
||||
@dataclass
|
||||
class GameStorePage:
|
||||
"""Dataclass for information on a game's store page"""
|
||||
|
|
|
@ -78,9 +78,6 @@ class Didier(commands.Bot):
|
|||
# Create directories that are ignored on GitHub
|
||||
self._create_ignored_directories()
|
||||
|
||||
# Load schedules
|
||||
await self.load_schedules()
|
||||
|
||||
# Load the Wordle dictionary
|
||||
self._load_wordle_words()
|
||||
|
||||
|
|
Loading…
Reference in New Issue