verbose annoucement

This commit is contained in:
deflax 2024-01-17 04:08:55 +02:00
parent 046c0212c8
commit 22646613f8

View file

@ -30,10 +30,8 @@ scheduler = AsyncIOScheduler()
# Set up the logger # Set up the logger
logger_discord = logging.getLogger('discord') logger_discord = logging.getLogger('discord')
logger_job = logging.getLogger('apscheduler')
log_level = os.environ.get('SCHEDULER_LOG_LEVEL', 'INFO').upper() log_level = os.environ.get('SCHEDULER_LOG_LEVEL', 'INFO').upper()
logger_discord.setLevel(log_level) logger_discord.setLevel(log_level)
logger_job.setLevel(log_level)
database = {} database = {}
@ -76,27 +74,31 @@ async def update_database():
database = response.json() database = response.json()
if database != {}: if database != {}:
for key, value in database.items(): for key, value in database.items():
logger_discord.info('test') name = value['name']
if value['start_at'] == 'now': start_at = value['start_at']
scheduler.add_job(func=announce_live_channel, seconds=60, id='announce_live_channel') if start_at == 'now':
logger_discord.info(f'{name} live stream detected!')
scheduler.add_job(func=announce_live_channel, seconds=60, id='announce_live_channel', args=(name))
return return
try: try:
job = scheduler.get_job('announce_live_channel') job = scheduler.get_job('announce_live_channel')
if job: if job:
scheduler.remove_job('announce_live_channel') scheduler.remove_job('announce_live_channel')
live_channel = bot.get_channel(announce_channel_id) live_channel = bot.get_channel(announce_channel_id)
await live_channel.send(f'{announce_channel_id} removed') logger_discord.info(f'{name} finished')
await live_channel.send(f'{name} finished')
else: else:
return return
except JobLookupError: except JobLookupError:
return return
async def announce_live_channel(): async def announce_live_channel(name):
if announce_channel_id == 'disabled': if announce_channel_id == 'disabled':
return return
else: else:
live_channel = bot.get_channel(announce_channel_id) live_channel = bot.get_channel(announce_channel_id)
await live_channel.send(f'{announce_channel_id} ') logger_discord.info(f'{name} is live!')
await live_channel.send(f'{name} is live!')
# Run the bot with your token # Run the bot with your token
asyncio.run(bot.run(bot_token)) asyncio.run(bot.run(bot_token))