Implement video message configuration

* Config is update when new key is added (always fully explicit)
This commit is contained in:
BreadTube 2025-10-29 21:32:45 +09:00
commit f59982f745
3 changed files with 36 additions and 9 deletions

View file

@ -11,6 +11,7 @@ import time
import tomllib
from typing import Any, TYPE_CHECKING
import traceback
import urllib.parse
from .config import Config
from .discord_manager import ApiEncoder, DiscordManager
@ -177,6 +178,8 @@ class Bot:
if new_config is None and content.startswith(b'config'):
try:
self.config = Config.from_str(content.decode())
if self.config.to_str() != content.decode():
new_config = self.config
except RuntimeError as error:
self.logger.error('Cannot load config from init message: %s', error)
has_error = True
@ -345,9 +348,15 @@ class Bot:
subscription.video_list, key=lambda x: x.snippet.publishTime, reverse=True)[:internal_size]
subscription.last_update = time.time()
@staticmethod
def _video_message_content(video: SearchResultItem) -> str:
return f'https://www.youtube.com/video/{video.id.videoId}'
def _video_message_content(self, video: SearchResultItem) -> str:
return (self.config.youtube_channel_video_message
.replace('{{video_id}}', str(video.id.videoId))
.replace('{{video_title}}', str(urllib.parse.unquote(video.snippet.title)))
.replace('{{video_description}}', str(video.snippet.description))
.replace('{{video_publish_time}}', video.snippet.publishTime.isoformat())
.replace('{{channel_id}}', str(video.snippet.channelId))
.replace('{{channel_title}}', str(video.snippet.channelTitle))
)
def _refresh_sub(self, subscription: SubscriptionInfo, channel_dict: dict[str, TextChannel],
category_ranges: list[tuple[int, int, ChannelCategory]]):