use global recorder flag and execute the fn directly

This commit is contained in:
deflax 2025-02-08 03:48:09 +00:00
parent 4676e251e2
commit c95410eda5

View file

@ -40,6 +40,7 @@ logger_discord.setLevel(log_level)
database = {} database = {}
rec_path = "/recordings" rec_path = "/recordings"
recorder = False
# Bot functions # Bot functions
@bot.event @bot.event
@ -94,15 +95,16 @@ async def now(ctx):
@bot.command(name='rec', help='Start the recorder') @bot.command(name='rec', help='Start the recorder')
@has_role(boss_role_name) @has_role(boss_role_name)
async def rec(ctx): async def rec(ctx):
playhead = await query_playhead() global recorder
stream_name = playhead['name']
stream_prio = playhead['prio']
# Check if the recorder job already exists # Check if the recorder job already exists
if scheduler.get_job('recorder') is None: if recorder:
scheduler.add_job(func=exec_recorder, id='recorder', args=playhead)
await ctx.channel.send(f'Recording from {stream_name} (prio={stream_prio})')
else:
await ctx.channel.send(f'Recorder is busy!') await ctx.channel.send(f'Recorder is busy!')
else:
playhead = await query_playhead()
stream_name = playhead['name']
recorder = True
await ctx.channel.send(f'Recording from {stream_name}...')
await exec_recorder(playhead)
@rec.error @rec.error
async def rec_error(ctx, error): async def rec_error(ctx, error):
@ -112,12 +114,14 @@ async def rec_error(ctx, error):
@bot.command(name='stop', help='Stop the recorder') @bot.command(name='stop', help='Stop the recorder')
@has_role(boss_role_name) @has_role(boss_role_name)
async def stop(ctx): async def stop(ctx):
global recorder
# Check if the recorder job already exists # Check if the recorder job already exists
if scheduler.get_job('recorder') is not None: if recorder:
await ctx.channel.send(f'Shutting down recorder') await ctx.channel.send(f'Shutting down recorder...')
scheduler.remove_job('recorder') # kill any process currently running
recorder = False
else: else:
await ctx.channel.send(f'Recorder is stopped.') await ctx.channel.send(f'Recorder is already stopped.')
@stop.error @stop.error
async def stop_error(ctx, error): async def stop_error(ctx, error):