From ffba60b278162707bc4eb004c3bfb6b2e9595213 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 8 May 2024 12:55:35 -0400 Subject: rework to use songbird --- src/commands/today/mod.rs | 56 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'src/commands/today') diff --git a/src/commands/today/mod.rs b/src/commands/today/mod.rs index 0a0ba7b..7f1dca7 100644 --- a/src/commands/today/mod.rs +++ b/src/commands/today/mod.rs @@ -1,5 +1,4 @@ use chrono::Duration; -use either::Left; use lazy_static::lazy_static; use log::debug; use rand::{ @@ -15,13 +14,14 @@ use serenity::{ model::channel::Message, prelude::*, }; +use songbird::input::YoutubeDl; +use tap::Conv; use crate::{ - audio::{ - PlayArgs, - PlayQueue, - }, + bot::HttpKey, + commands::songbird, util, + CONFIG, }; mod prelude; @@ -50,19 +50,6 @@ pub struct TodayArgs { pub end: Option, } -impl TodayArgs { - #[inline] - pub fn as_play_args(&self, msg: &Message) -> PlayArgs { - PlayArgs { - initiator: "you have done this to yourself :^)".to_string(), - data: Left(self.url.to_owned()), - sender_channel: msg.channel_id, - start: self.start, - end: self.end, - } - } -} - lazy_static! { static ref ALL: Vec TodayIter> = vec![ sept_21::sept_21, @@ -112,17 +99,36 @@ pub async fn today(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { debug!("{} options for {}", options.len(), today); - let play_args = options.choose(&mut thread_rng()).map(|x| x.as_play_args(msg)); + let play_args = options.choose(&mut thread_rng()); if let Some(play_args) = play_args { - play_args.data.as_ref().left().iter().for_each(|url| { - debug!("today selected: {}", url); - }); + let (_sb, call) = songbird(ctx, msg).await?; + let mut call = call.lock().await; - let queue_lock = ctx.data.write().await.get::().cloned().unwrap(); - let mut play_queue = queue_lock.write().unwrap(); + if call.current_channel().is_none() { + call.join(CONFIG.discord.voice_channel()).await?; + } + + let client = { + let data = ctx.data.read().await; + data.get::().unwrap().clone() + }; + + let input = + YoutubeDl::new_ytdl_like("yt-dlp", client.clone(), play_args.url.conv::()); - play_queue.general_queue.push_front(play_args); + call.enqueue_input(input.into()).await; + + let q = call.queue(); + q.pause()?; + q.modify_queue(move |q| { + let last = q.pop_back(); + + if let Some(last) = last { + q.push_front(last); + } + }); + q.resume()?; } else { util::send(ctx, msg.channel_id, "no", false).await?; util::send(ctx, msg.channel_id, ":angry:", false).await?; -- cgit v1.3.1