refactor bot record annoncement

This commit is contained in:
deflax 2024-01-18 02:02:19 +02:00
parent b62411f89d
commit 15ab90c00e

View file

@ -101,8 +101,11 @@ async def query_database():
logger_discord.error('Cannot connect to the database!')
return
if database == {}:
logger_discord.error('Database is empty!')
return
# Search for live streams
if database != {}:
for key, value in database.items():
stream_name = value['name']
stream_start_at = value['start_at']
@ -132,20 +135,30 @@ async def query_database():
# Cleanup the announce job
if scheduler.get_job('announce_live_channel') is not None:
scheduler.remove_job('announce_live_channel')
if live_channel_id != 0:
live_channel = bot.get_channel(int(live_channel_id))
if rechead != {}:
video_filename = rechead['video']
thumb_filename = rechead['thumb']
rechead = {}
vod_url = f'https://{scheduler_hostname}/video/{video_filename}'
video_url = f'https://{scheduler_hostname}/video/{video_filename}'
thumb_url = f'https://{scheduler_hostname}/thumb/{thumb_filename}'
offline_msg = f'Live stream is now offline. [Download VoD recording]({vod_url}) {thumb_url}'
# Creating an embed
embed = discord.Embed(
title='Download Example',
description='Click the link below to download the MP4 file.',
color=discord.Color.green()
)
embed.set_thumbnail(url=thumb_url)
embed.add_field(name='Download MP4', value='[Download Video](video_url)', inline=False)
embed.set_author(name='DeflaxTV', icon_url=bot.user.avatar_url)
# Sending the embed to the channel
await live_channel.send(embed=embed)
else:
offline_msg = f'Live stream is now offline.'
logger_discord.info(offline_msg)
if live_channel_id != 0:
live_channel = bot.get_channel(int(live_channel_id))
await live_channel.send(offline_msg)
logger_discord.info('Live stream is now offline.')
async def announce_live_channel(stream_name):
logger_discord.info(f'{stream_name} is live!')