22import logging
33import os
44import typing as ty
5+ import zoneinfo
56
67import discord
78import googleapiclient .discovery
@@ -32,7 +33,7 @@ def __init__(
3233 )
3334 self .check_subscription .start ()
3435
35- @tasks .loop (hours = 1 )
36+ @tasks .loop (minutes = 15 )
3637 async def check_subscription (self ) -> None :
3738 """Check for upcoming live of subscriptions.
3839
@@ -42,14 +43,16 @@ async def check_subscription(self) -> None:
4243 logger .debug ("GOOGLE_API_KEY not set, skipping subscription check." )
4344 return
4445
45- logger .info ("Checking for new live streams..." )
46+ logger .debug ("Checking for new live streams..." )
4647
4748 ISO_FORMAT = r"%Y-%m-%dT%H:%M:%SZ"
4849 MESSAGE_TEMPLATE = """{role_tag}
4950# {title}
51+ ## Scheduled Start Time
52+ {scheduled_start_time}
53+ ## Description
5054{description}
51-
52- **Link:**
55+ ## Link
5356https://www.youtube.com/watch?v={video_id}"""
5457
5558 async with self .sessionmaker () as session :
@@ -138,7 +141,7 @@ async def check_subscription(self) -> None:
138141 # Not a scheduled stream or stream has already started
139142 continue
140143
141- logger .debug (
144+ logger .info (
142145 f"Sending notification of video title: `{ video ['snippet' ]['title' ]} ` to { bot_channel .id } "
143146 )
144147 await bot_channel .send (
@@ -147,6 +150,19 @@ async def check_subscription(self) -> None:
147150 if subscription .announcement_target
148151 else "@everyone" ,
149152 title = video ["snippet" ]["title" ],
153+ # HKT+8
154+ scheduled_start_time = (
155+ dt .datetime .fromisoformat (
156+ video ["liveStreamingDetails" ][
157+ "scheduledStartTime"
158+ ].replace ("Z" , "+00:00" )
159+ ).replace (
160+ tzinfo = zoneinfo .ZoneInfo (
161+ key = "Asia/Hong_Kong"
162+ )
163+ )
164+ + dt .timedelta (hours = 8 )
165+ ).strftime (r"%B %d (%A), %I:%M %p %Z" ),
150166 description = video ["snippet" ]["description" ],
151167 video_id = video ["id" ],
152168 )
0 commit comments