aboutsummaryrefslogtreecommitdiff
path: root/src/commands/meme/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/meme/mod.rs')
-rw-r--r--src/commands/meme/mod.rs61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs
index 31d9b78..24fc50d 100644
--- a/src/commands/meme/mod.rs
+++ b/src/commands/meme/mod.rs
@@ -3,6 +3,7 @@ use log::debug;
use rand::random;
use serenity::{
all::ReactionType,
+ async_trait,
builder::{
CreateAttachment,
CreateMessage,
@@ -14,13 +15,21 @@ use serenity::{
model::channel::Message,
prelude::*,
};
+use songbird::input::{
+ core::io::MediaSource,
+ AudioStream,
+ AudioStreamError,
+ Compose,
+ Input,
+};
use crate::{
- audio::{
- PlayArgs,
- PlayQueue,
+ commands::songbird,
+ db::{
+ Audio,
+ Meme,
},
- db::Meme,
+ CONFIG,
};
pub use self::{
@@ -94,27 +103,45 @@ async fn send_meme(
},
};
- // note: slight edge-case race condition here: there could have been something queued since we
- // checked whether anything was playing. not a significant negative impact and unlikely, so i'm
- // not worrying about it
if let Some(audio) = audio {
let audio = audio?;
- {
- let queue_lock = ctx.data.write().await.get::<PlayQueue>().cloned().unwrap();
- let mut play_queue = queue_lock.write().unwrap();
+ let (_sb, call) = songbird(ctx, msg).await?;
+ let mut call = call.lock().await;
- play_queue.meme_queue.push_back(PlayArgs {
- initiator: msg.author.name.clone(),
- data: ::either::Right(audio.data.clone()),
- sender_channel: msg.channel_id,
- start: None,
- end: None,
- });
+ if call.current_channel().is_none() {
+ call.join(CONFIG.discord.voice_channel()).await?;
}
+ call.enqueue_input(Input::Lazy(Box::new(audio))).await;
+
msg.react(ctx, ReactionType::Unicode("📣".to_owned())).await?;
}
Ok(())
}
+
+#[async_trait]
+impl Compose for Audio {
+ fn create(&mut self) -> Result<AudioStream<Box<dyn MediaSource>>, AudioStreamError> {
+ let ms = std::io::Cursor::new(self.data.clone());
+ let ms: Box<dyn MediaSource> = Box::new(ms);
+
+ Ok(AudioStream {
+ input: ms,
+ hint: None,
+ })
+ }
+
+ #[inline]
+ async fn create_async(
+ &mut self,
+ ) -> Result<AudioStream<Box<dyn MediaSource>>, AudioStreamError> {
+ self.create()
+ }
+
+ #[inline]
+ fn should_create_async(&self) -> bool {
+ false
+ }
+}