Updated to include volume
This commit is contained in:
@@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize};
|
|||||||
use serenity::model::prelude::{GuildChannel, ChannelType};
|
use serenity::model::prelude::{GuildChannel, ChannelType};
|
||||||
use siren::ServiceError;
|
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")]
|
#[get("/guilds")]
|
||||||
async fn get_guilds(data: web::Data<Arc<AppState>>) -> HttpResponse {
|
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()
|
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) {
|
pub fn init_routes(config: &mut web::ServiceConfig) {
|
||||||
config
|
config
|
||||||
.service(get_guilds)
|
.service(get_guilds)
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ export async function playTrack(guildId: number, channelId: number, track: strin
|
|||||||
await postRequest(`guilds/${guildId}/voice/${channelId}/play`, { track_url: track });
|
await postRequest(`guilds/${guildId}/voice/${channelId}/play`, { track_url: track });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function stopTrack(guildId: number, channelId: number): Promise<void> {
|
export async function stopTrack(guildId: number): Promise<void> {
|
||||||
await postRequest(`guilds/${guildId}/voice/${channelId}/stop`, {});
|
await postRequest(`guilds/${guildId}/voice/stop`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function pauseTrack(guildId: number, channelId: number): Promise<void> {
|
export async function pauseTrack(guildId: number): Promise<void> {
|
||||||
await postRequest(`guilds/${guildId}/voice/${channelId}/pause`, {});
|
await postRequest(`guilds/${guildId}/voice/pause`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resumeTrack(guildId: number, channelId: number): Promise<void> {
|
export async function resumeTrack(guildId: number): Promise<void> {
|
||||||
await postRequest(`guilds/${guildId}/voice/${channelId}/resume`, {});
|
await postRequest(`guilds/${guildId}/voice/resume`, {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ export default function Page() {
|
|||||||
<Tabs.Panel key={channel.id} value={channel.name}>
|
<Tabs.Panel key={channel.id} value={channel.name}>
|
||||||
{channel.name}
|
{channel.name}
|
||||||
<form
|
<form
|
||||||
style={{ display: 'flex' }}
|
style={{ margin: '1em' }}
|
||||||
onSubmit={playForm.onSubmit((values) => {
|
onSubmit={playForm.onSubmit((values) => {
|
||||||
playTrack(activeGuild!.id, channel.id, values.trackUrl);
|
playTrack(activeGuild!.id, channel.id, values.trackUrl);
|
||||||
})}
|
})}
|
||||||
@@ -90,11 +90,22 @@ export default function Page() {
|
|||||||
<TextInput placeholder='Youtube URL...' {...playForm.getInputProps('trackUrl')} />
|
<TextInput placeholder='Youtube URL...' {...playForm.getInputProps('trackUrl')} />
|
||||||
<Button type='submit'>Play Track</Button>
|
<Button type='submit'>Play Track</Button>
|
||||||
</form>
|
</form>
|
||||||
<Button onClick={() => stopTrack(activeGuild!.id, channel.id)}>Stop</Button>
|
<div style={{ margin: '1em' }}>
|
||||||
<Button onClick={() => pauseTrack(activeGuild!.id, channel.id)}>Pause</Button>
|
<Button style={{ marginRight: '1em' }} onClick={() => stopTrack(activeGuild!.id)}>
|
||||||
<Button onClick={() => resumeTrack(activeGuild!.id, channel.id)}>Resume</Button>
|
Stop
|
||||||
<div>
|
</Button>
|
||||||
|
<Button style={{ marginRight: '1em' }} onClick={() => pauseTrack(activeGuild!.id)}>
|
||||||
|
Pause
|
||||||
|
</Button>
|
||||||
|
<Button style={{ marginRight: '1em' }} onClick={() => resumeTrack(activeGuild!.id)}>
|
||||||
|
Resume
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div style={{ margin: '1em' }}>
|
||||||
<Slider label='Volume' style={{ width: '20%' }} defaultValue={50} onChange={(v) => {}} />
|
<Slider label='Volume' style={{ width: '20%' }} defaultValue={50} onChange={(v) => {}} />
|
||||||
|
<Button style={{ marginRight: '1em' }} onClick={() => {}}>
|
||||||
|
Set Volume
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user