Updated to include volume
This commit is contained in:
@@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize};
|
||||
use serenity::model::prelude::{GuildChannel, ChannelType};
|
||||
use siren::ServiceError;
|
||||
|
||||
use crate::{AppState, bot::commands::audio::{play::play_track, join}};
|
||||
use crate::{AppState, bot::commands::audio::{play::play_track, join}, db::guilds::InsertGuild};
|
||||
|
||||
#[get("/guilds")]
|
||||
async fn get_guilds(data: web::Data<Arc<AppState>>) -> HttpResponse {
|
||||
@@ -244,6 +244,46 @@ async fn pause(path: web::Path<String>, data: web::Data<Arc<AppState>>) -> HttpR
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct SetVolume {
|
||||
volume: String
|
||||
}
|
||||
|
||||
#[post("/{guild_id}/voice/volume")]
|
||||
async fn set_volume(path: web::Path<String>, volume: web::Json::<SetVolume>, data: web::Data<Arc<AppState>>) -> HttpResponse {
|
||||
let guild_id = path.into_inner();
|
||||
let guild_id = match guild_id.parse::<u64>() {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
warn!("Could not parse guild id: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError {
|
||||
status: 422,
|
||||
message: err.to_string()
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
let bound_volume = volume.volume.parse::<f32>().unwrap_or(0.0);
|
||||
|
||||
let _ = InsertGuild::update_audio(guild_id as i64, bound_volume as f64);
|
||||
|
||||
if let Some(handler_lock) = data.songbird.get(guild_id) {
|
||||
let handler = handler_lock.lock().await;
|
||||
for (_, track_handle) in handler.queue().current_queue().iter().enumerate() {
|
||||
let _ = track_handle.set_volume(bound_volume);
|
||||
}
|
||||
if let Err(err) = handler.queue().pause() {
|
||||
warn!("Could not pause track: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError {
|
||||
status: 422,
|
||||
message: err.to_string()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
pub fn init_routes(config: &mut web::ServiceConfig) {
|
||||
config
|
||||
.service(get_guilds)
|
||||
|
||||
Reference in New Issue
Block a user