From 850fad62f12b4e764f5e64036db35259237994cb Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 19 Aug 2026 02:45:49 +0200 Subject: fix: Various cron fixes Not saving full URL Not using autocompletion content, just label --- src/tasks/mod.rs | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/tasks') diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index 4408857..d4cf9b2 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::sync::Arc; use chrono::{DateTime, Duration, Local, TimeZone, Timelike, Utc}; @@ -18,6 +19,7 @@ pub struct CronContext { pub http: Arc, pub voice_manager: VoiceManager, pub copyparty: CopypartyClient, + pub music_tracks: Arc>>, } /// Normalize user-friendly cron expressions to the 7-field format the `cron` crate expects. @@ -118,15 +120,25 @@ async fn execute_message_job(ctx: &CronContext, job: &crate::database::CronJob) } async fn execute_audio_job(ctx: &CronContext, job: &crate::database::CronJob) { - let Some(ref audio_path) = job.audio_filename else { + let Some(ref audio_url) = job.audio_filename else { error!("Cron audio job {} has no audio_filename", job.id); return; }; let channel_id = serenity::ChannelId::new(job.channel_id as u64); - // Resolve guild + build URL concurrently. - let url = ctx.copyparty.build_url(audio_path); + // Build the full URL with password + let url = if audio_url.starts_with("http://") || audio_url.starts_with("https://") { + // Already a full URL (stored without password), append it now + if let Some(pw) = &ctx.copyparty.password { + format!("{audio_url}?pw={pw}") + } else { + audio_url.clone() + } + } else { + // Legacy relative path — build full URL with password + ctx.copyparty.build_url(audio_url) + }; info!("Cron audio job {} streaming via ffmpeg: {url}", job.id); let guild_channel_fut = channel_id.to_channel(&ctx.http); let input_fut = crate::voice::ffmpeg_stream_input(&url); @@ -157,6 +169,14 @@ async fn execute_audio_job(ctx: &CronContext, job: &crate::database::CronJob) { } }; + // Stop any existing track in this guild. + { + let mut map = ctx.music_tracks.lock().await; + if let Some(handle) = map.remove(&guild_id.get()) { + let _ = handle.stop(); + } + } + // Connect to voice and play. let call = match ctx.voice_manager.connect(guild_id, channel_id).await { Ok(c) => c, @@ -166,14 +186,17 @@ async fn execute_audio_job(ctx: &CronContext, job: &crate::database::CronJob) { } }; - { + let handle = { let mut call_lock = call.lock().await; - call_lock.play_input(input); - } + call_lock.play_input(input) + }; + + // Store the handle so the track stays alive. + ctx.music_tracks.lock().await.insert(guild_id.get(), handle); info!( "Cron audio job {} playing '{}' (url: {url}) in guild {}", - job.id, audio_path, guild_id + job.id, audio_url, guild_id ); } -- cgit v1.2.3