Fixed spell descriptions
This commit is contained in:
@@ -291,16 +291,17 @@ async fn set_volume(path: web::Path<String>, volume: web::Json::<SetVolume>, dat
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
let volume = volume.volume.parse::<i32>().unwrap_or(0);
|
||||
let manager = Arc::clone(&data.songbird);
|
||||
let http = Arc::clone(&data.http);
|
||||
let guild = match http.get_guild(guild_id).await {
|
||||
Ok(guild) => guild,
|
||||
Err(err) => {
|
||||
warn!("Could not get guild: {:?}", err);
|
||||
return ResponseError::error_response(&ServiceError { status: 422, message: err.to_string() })
|
||||
}
|
||||
}
|
||||
};
|
||||
crate::bot::commands::audio::volume::set_volume(manager, guild.id, volume).await;
|
||||
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use log::{error, warn};
|
||||
|
||||
use serenity::prelude::*;
|
||||
use serenity::{prelude::*, model::prelude::GuildId};
|
||||
use serenity::builder::CreateApplicationCommand;
|
||||
use serenity::model::application::interaction::application_command::ApplicationCommandInteraction;
|
||||
use songbird::Songbird;
|
||||
|
||||
use crate::db::guilds::InsertGuild;
|
||||
|
||||
@@ -13,7 +16,7 @@ pub async fn run(ctx: &Context, command: &ApplicationCommandInteraction) {
|
||||
let volume = match command.data.options.get(0) {
|
||||
Some(t) => match &t.value {
|
||||
Some(v) => match v.as_i64() {
|
||||
Some(p) => std::cmp::min(100, std::cmp::max(0, p)),
|
||||
Some(p) => p as i32,
|
||||
None => {
|
||||
warn!("Unable to get volume option as a string");
|
||||
if let Err(why) = create_response(&ctx, &command, format!("Volume option is missing")).await {
|
||||
@@ -39,9 +42,6 @@ pub async fn run(ctx: &Context, command: &ApplicationCommandInteraction) {
|
||||
}
|
||||
};
|
||||
|
||||
// Format volume to f32 bound between 0.0 and 1.0
|
||||
let bound_volume = volume as f32 / 100.0;
|
||||
|
||||
// Create the initial response
|
||||
if let Err(why) = create_response(&ctx, &command, "Processing command...".to_string()).await {
|
||||
error!("Failed to create response message: {}", why);
|
||||
@@ -57,17 +57,25 @@ pub async fn run(ctx: &Context, command: &ApplicationCommandInteraction) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let _ = InsertGuild::update_audio(guild_id.0 as i64, bound_volume as f64);
|
||||
let manager = get_songbird(ctx).await;
|
||||
set_volume(manager, guild_id, volume).await;
|
||||
if let Err(why) = edit_response(&ctx, &command, format!("Setting the volume to {}", volume)).await {
|
||||
error!("Failed to set the volume: {}", why);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_volume(manager: Arc<Songbird>, guild_id: GuildId, volume: i32) {
|
||||
// Format volume to f32 bound between 0.0 and 1.0
|
||||
let volume = std::cmp::min(100, std::cmp::max(0, volume));
|
||||
let bound_volume = volume as f32 / 100.0;
|
||||
let _ = InsertGuild::update_audio(guild_id.0 as i64, volume);
|
||||
|
||||
if let Some(handler_lock) = manager.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(why) = edit_response(&ctx, &command, format!("Setting the volume to {}", volume)).await {
|
||||
error!("Failed to set the volume: {}", why);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
|
||||
@@ -77,7 +77,7 @@ impl EventHandler for Handler {
|
||||
let _ = InsertGuild::insert(InsertGuild {
|
||||
id: (guild.id.0 as i64),
|
||||
bot_id: ctx.cache.current_user().id.0 as i64,
|
||||
volume: 100.0
|
||||
volume: 100
|
||||
});
|
||||
let commands = guild.id.set_application_commands(&ctx.http, |commands| {
|
||||
commands.create_application_command(|command: &mut serenity::builder::CreateApplicationCommand| { commands::ping::register(command) })
|
||||
|
||||
Reference in New Issue
Block a user