aboutsummaryrefslogtreecommitdiff
path: root/src/commands/today/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/today/mod.rs')
-rw-r--r--src/commands/today/mod.rs56
1 files changed, 31 insertions, 25 deletions
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<Duration>,
}
-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<fn(chrono::NaiveDateTime) -> 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::<PlayQueue>().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::<HttpKey>().unwrap().clone()
+ };
+
+ let input =
+ YoutubeDl::new_ytdl_like("yt-dlp", client.clone(), play_args.url.conv::<String>());
- 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?;