Fixed spell descriptions
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user