forked from DiscordBots/Rustendo
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
|
use std::sync::Arc;
|
||
|
use queues::IsQueue;
|
||
|
use serenity::all::{ChannelId, GuildId, Http};
|
||
|
use serenity::async_trait;
|
||
|
use songbird::{Event, EventContext, EventHandler};
|
||
|
use crate::music::music_manager;
|
||
|
|
||
|
pub struct TrackEndNotifier {
|
||
|
pub guild_id: GuildId,
|
||
|
pub channel_id: ChannelId,
|
||
|
pub http: Arc<Http>,
|
||
|
pub cmdctx: Arc<serenity::client::Context>,
|
||
|
}
|
||
|
|
||
|
#[async_trait]
|
||
|
impl EventHandler for TrackEndNotifier {
|
||
|
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
|
||
|
unsafe { // TODO: Does this need to be unsafe?
|
||
|
if let EventContext::Track(track_list) = ctx {
|
||
|
println!("The track ended!");
|
||
|
let queue = music_manager::get_queue(&self.guild_id);
|
||
|
if queue.size() == 0 {
|
||
|
let stopped = match music_manager::stop(&self.cmdctx, &self.guild_id).await {
|
||
|
Ok(stopped) => stopped,
|
||
|
Err(e) => {
|
||
|
println!("Cannot stop: {:?}", e);
|
||
|
return None;
|
||
|
}
|
||
|
};
|
||
|
if stopped {
|
||
|
println!("Stopped playing successfully.");
|
||
|
} else {
|
||
|
println!("Failed to stop playing.");
|
||
|
}
|
||
|
return None;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
None
|
||
|
}
|
||
|
}
|