Rustendo/src/music/music_queue.rs

47 lines
1.4 KiB
Rust

use serenity::all::GuildId;
use songbird::input::YoutubeDl;
#[derive(Debug, Clone)]
pub struct MusicQueue {
// God this sucks. This needs to be reprogrammed properly.
pub guild_id: GuildId,
pub queue: Vec<YoutubeDl>,
pub now_playing: Option<YoutubeDl>,
}
pub async fn delete_queue(guild_id: &GuildId) {
let mut queue = crate::get_queue(*guild_id).await;
queue.now_playing = None;
queue.queue = Vec::new();
crate::set_queue(*guild_id, queue);
}
pub async fn add_to_queue(guild_id: &GuildId, input: YoutubeDl) {
let mut queue = crate::get_queue(*guild_id).await;
queue.queue.push(input);
crate::set_queue(*guild_id, queue);
}
pub async fn get_head(guild_id: &GuildId) -> Option<&YoutubeDl> {
let music_queue = crate::get_queue(*guild_id).await;
if music_queue.queue.is_empty() {
return None;
}
let mut queue = music_queue.queue;
let result = queue.first();
queue.remove(0);
music_queue.queue = queue;
crate::set_queue(*guild_id, music_queue);
result
}
pub fn set_now_playing(guild_id: &GuildId, now_playing: Option<YoutubeDl>) {
let mut queue = crate::get_queue(*guild_id);
queue.now_playing = now_playing;
crate::set_queue(*guild_id, queue)
}
pub fn get_now_playing(guild_id: &GuildId) -> Option<YoutubeDl> {
let queue = crate::get_queue(*guild_id);
queue.now_playing
}