diff options
author | 2024-07-05 14:26:56 +0100 | |
---|---|---|
committer | 2024-07-05 14:28:15 +0100 | |
commit | 8e270b2e9895211bcf0e19c3657f839cb123b8b6 (patch) | |
tree | 27673da5f3feeec3da657eabbcb6b220c304da68 | |
parent | Be more specific when describing the base url for the cat (diff) |
Add daily devops missions for added motivation
-rw-r--r-- | arthur/config.py | 1 | ||||
-rw-r--r-- | arthur/exts/fun/motivation.py | 37 |
2 files changed, 37 insertions, 1 deletions
diff --git a/arthur/config.py b/arthur/config.py index 146db73..59014a8 100644 --- a/arthur/config.py +++ b/arthur/config.py @@ -18,6 +18,7 @@ class Config( prefixes: tuple[str, ...] = ("arthur ", "M-x ") cloudflare_token: pydantic.SecretStr + youtube_api_key: pydantic.SecretStr | None = None grafana_url: str = "https://grafana.pydis.wtf" grafana_token: pydantic.SecretStr github_token: pydantic.SecretStr diff --git a/arthur/exts/fun/motivation.py b/arthur/exts/fun/motivation.py index d256bd4..4da7460 100644 --- a/arthur/exts/fun/motivation.py +++ b/arthur/exts/fun/motivation.py @@ -8,6 +8,7 @@ from discord.ext import commands, tasks from arthur.bot import KingArthur from arthur.config import CONFIG +from arthur.log import logger MOTIVATION_IMAGE_RE = re.compile(r"data-image=\"(https://assets\.amuniversal\.com/.+?)\"") THE_CAT = "https://avatar.amuniversal.com/feature_avatars/ubadge_images/features/ga/mid_u-201701251612.png" @@ -21,8 +22,42 @@ class Motivation(commands.Cog): self.bot = bot self.devops_channel = bot.get_channel(CONFIG.devops_channel_id) self.send_daily_motivation.start() + if CONFIG.youtube_api_key: + self.send_daily_mission.start() - @tasks.loop(time=time(hour=9)) + @tasks.loop(time=time(hour=12, minute=30, tzinfo=UTC)) + async def send_daily_mission(self) -> None: + """Send the daily mission to the team.""" + params = { + "part": "snippet", + "channelId": "UC4CoHBR01SHu6fMy2EaeWcg", + "key": CONFIG.youtube_api_key.get_secret_value(), + "order": "date", + "maxResults": "2", + } + async with self.bot.http_session.get( + "https://www.googleapis.com/youtube/v3/search", + params=params, + ) as resp: + resp.raise_for_status() + data = await resp.json() + todays_date = datetime.now(UTC).date() + for video in data["items"]: + title: str = video["snippet"]["title"] + if not title.startswith("TODAY'S MISSION:"): + continue + date = datetime.fromisoformat(video["snippet"]["publishedAt"]).date() + if date != todays_date: + continue + + await self.devops_channel.send( + f"[Today's mission](https://www.youtube.com/shorts/{video["id"]["videoId"]})" + ) + break + else: + logger.warning("No mission found for %s", todays_date) + + @tasks.loop(time=time(hour=9, tzinfo=UTC)) async def send_daily_motivation(self) -> None: """Send motivation to the people who need it most.""" today_date = datetime.now(UTC).date().isoformat() |