updated songbird. removed the track thing because it wasnt useful

This commit is contained in:
jellywx 2021-04-12 21:40:28 +01:00
parent 29dd3532bb
commit 900fe6a4f0
4 changed files with 11 additions and 109 deletions

10
Cargo.lock generated
View File

@ -1808,8 +1808,9 @@ dependencies = [
[[package]] [[package]]
name = "songbird" name = "songbird"
version = "0.1.5" version = "0.1.6"
source = "git+https://github.com/FelixMcFelix/songbird?branch=fix-driver-leave-join#a5c4f915bc24c09460c36156a96b38e2957bceb4" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "358efdd4b111021b0b7499fa087aa3cba8f01ae7210d37ab45620e4791c09ab8"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite 0.13.1", "async-tungstenite 0.13.1",
@ -1826,6 +1827,7 @@ dependencies = [
"serenity", "serenity",
"serenity-voice-model", "serenity-voice-model",
"spin_sleep", "spin_sleep",
"spinning_top",
"streamcatcher", "streamcatcher",
"tokio", "tokio",
"tracing", "tracing",
@ -1873,9 +1875,9 @@ dependencies = [
[[package]] [[package]]
name = "spinning_top" name = "spinning_top"
version = "0.2.3" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bd0ab6b8c375d2d963503b90d3770010d95bc3b5f98036f948dee24bf4e8879" checksum = "7e529d73e80d64b5f2631f9035113347c578a1c9c7774b83a2b880788459ab36"
dependencies = [ dependencies = [
"lock_api", "lock_api",
] ]

View File

@ -12,7 +12,7 @@ tokio = { version = "1.0", features = ["fs", "process", "io-util"] }
lazy_static = "1.4" lazy_static = "1.4"
reqwest = "0.11" reqwest = "0.11"
env_logger = "0.8" env_logger = "0.8"
songbird = { git = "https://github.com/FelixMcFelix/songbird", branch = "fix-driver-leave-join" } songbird = "0.1.6"
regex = "1.4" regex = "1.4"
log = "0.4" log = "0.4"
serde_json = "1.0" serde_json = "1.0"

View File

@ -1,11 +1,7 @@
use serenity::async_trait; use serenity::async_trait;
use serenity::model::id::GuildId;
use songbird::Event; use songbird::Event;
use songbird::EventContext; use songbird::EventContext;
use songbird::EventHandler as SongbirdEventHandler; use songbird::EventHandler as SongbirdEventHandler;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
pub struct RestartTrack; pub struct RestartTrack;
@ -19,22 +15,3 @@ impl SongbirdEventHandler for RestartTrack {
None None
} }
} }
pub struct UpdateTrackCount {
pub guild_id: GuildId,
pub track_count: Arc<RwLock<HashMap<GuildId, u32>>>,
}
#[async_trait]
impl SongbirdEventHandler for UpdateTrackCount {
async fn act(&self, _ctx: &EventContext<'_>) -> Option<Event> {
{
let mut write_lock = self.track_count.write().await;
let current = write_lock.get(&self.guild_id).cloned();
write_lock.insert(self.guild_id, current.unwrap_or(1) - 1);
}
None
}
}

View File

@ -10,7 +10,7 @@ mod guild_data;
mod sound; mod sound;
use crate::{ use crate::{
event_handlers::{RestartTrack, UpdateTrackCount}, event_handlers::RestartTrack,
framework::RegexFramework, framework::RegexFramework,
guild_data::{CtxGuildData, GuildData}, guild_data::{CtxGuildData, GuildData},
sound::Sound, sound::Sound,
@ -39,7 +39,7 @@ use songbird::{
ffmpeg, ffmpeg,
input::{cached::Memory, Input}, input::{cached::Memory, Input},
tracks::TrackHandle, tracks::TrackHandle,
Call, Event, SerenityInit, TrackEvent, Call, Event, SerenityInit,
}; };
use sqlx::mysql::MySqlPool; use sqlx::mysql::MySqlPool;
@ -74,22 +74,12 @@ impl TypeMapKey for GuildDataCache {
type Value = Arc<DashMap<GuildId, Arc<RwLock<GuildData>>>>; type Value = Arc<DashMap<GuildId, Arc<RwLock<GuildData>>>>;
} }
struct GuildTrackCount;
impl TypeMapKey for GuildTrackCount {
type Value = Arc<RwLock<HashMap<GuildId, u32>>>;
}
const THEME_COLOR: u32 = 0x00e0f3; const THEME_COLOR: u32 = 0x00e0f3;
lazy_static! { lazy_static! {
static ref MAX_SOUNDS: u32 = env::var("MAX_SOUNDS").unwrap().parse::<u32>().unwrap(); static ref MAX_SOUNDS: u32 = env::var("MAX_SOUNDS").unwrap().parse::<u32>().unwrap();
static ref PATREON_GUILD: u64 = env::var("PATREON_GUILD").unwrap().parse::<u64>().unwrap(); static ref PATREON_GUILD: u64 = env::var("PATREON_GUILD").unwrap().parse::<u64>().unwrap();
static ref PATREON_ROLE: u64 = env::var("PATREON_ROLE").unwrap().parse::<u64>().unwrap(); static ref PATREON_ROLE: u64 = env::var("PATREON_ROLE").unwrap().parse::<u64>().unwrap();
static ref AUTODISCONNECT_TIMER: u64 = env::var("AUTODISCONNECT_TIMER")
.unwrap_or("300".to_string())
.parse::<u64>()
.unwrap();
} }
// create event handler for bot // create event handler for bot
@ -159,20 +149,7 @@ impl EventHandler for Handler {
if channel.members(&ctx).await.map(|m| m.len()).unwrap_or(0) <= 1 { if channel.members(&ctx).await.map(|m| m.len()).unwrap_or(0) <= 1 {
let songbird = songbird::get(&ctx).await.unwrap(); let songbird = songbird::get(&ctx).await.unwrap();
{ let _ = songbird.remove(guild_id).await;
let track_count = ctx
.data
.read()
.await
.get::<GuildTrackCount>()
.cloned()
.unwrap();
let mut write_lock = track_count.write().await;
write_lock.insert(guild_id, 0);
}
let _ = songbird.leave(guild_id).await;
} }
} }
} }
@ -394,12 +371,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.unwrap(); .unwrap();
let guild_data_cache = Arc::new(DashMap::new()); let guild_data_cache = Arc::new(DashMap::new());
let guild_track_count = Arc::new(RwLock::new(HashMap::new()));
let mut data = client.data.write().await; let mut data = client.data.write().await;
data.insert::<GuildDataCache>(guild_data_cache); data.insert::<GuildDataCache>(guild_data_cache);
data.insert::<GuildTrackCount>(guild_track_count);
data.insert::<MySQL>(mysql_pool); data.insert::<MySQL>(mysql_pool);
data.insert::<ReqwestClient>(Arc::new(reqwest::Client::new())); data.insert::<ReqwestClient>(Arc::new(reqwest::Client::new()));
@ -597,7 +571,7 @@ async fn play_cmd(ctx: &Context, msg: &Message, args: Args, loop_: bool) -> Comm
let mut lock = call_handler.lock().await; let mut lock = call_handler.lock().await;
let track_handle = play_audio( play_audio(
sound, sound,
guild_data.read().await.volume, guild_data.read().await.volume,
&mut lock, &mut lock,
@ -605,29 +579,6 @@ async fn play_cmd(ctx: &Context, msg: &Message, args: Args, loop_: bool) -> Comm
loop_, loop_,
) )
.await?; .await?;
let track_count = ctx
.data
.read()
.await
.get::<GuildTrackCount>()
.cloned()
.unwrap();
{
let mut write_lock = track_count.write().await;
let current = write_lock.get(&guild_id).cloned();
write_lock.insert(guild_id, current.unwrap_or(0) + 1);
}
let _ = track_handle.add_event(
Event::Track(TrackEvent::End),
UpdateTrackCount {
guild_id,
track_count,
},
);
} }
msg.channel_id msg.channel_id
@ -703,21 +654,6 @@ async fn play_ambience(ctx: &Context, msg: &Message, args: Args) -> CommandResul
RestartTrack {}, RestartTrack {},
); );
{
let track_count = ctx
.data
.read()
.await
.get::<GuildTrackCount>()
.cloned()
.unwrap();
let mut write_lock = track_count.write().await;
let current = write_lock.get(&msg.guild_id.unwrap()).cloned();
write_lock.insert(msg.guild_id.unwrap(), current.unwrap_or(0) + 1);
}
msg.channel_id msg.channel_id
.say(&ctx, format!("Playing ambience **{}**", search_name)) .say(&ctx, format!("Playing ambience **{}**", search_name))
.await?; .await?;
@ -759,19 +695,6 @@ __Available ambience sounds:__
async fn stop_playing(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { async fn stop_playing(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
let guild_id = msg.guild_id.unwrap(); let guild_id = msg.guild_id.unwrap();
{
let track_count = ctx
.data
.read()
.await
.get::<GuildTrackCount>()
.cloned()
.unwrap();
let mut write_lock = track_count.write().await;
write_lock.insert(guild_id, 0);
}
let songbird = songbird::get(ctx).await.unwrap(); let songbird = songbird::get(ctx).await.unwrap();
let call_opt = songbird.get(guild_id); let call_opt = songbird.get(guild_id);