Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use poise::serenity_prelude as serenity;
#[poise::command(slash_command, prefix_command)]
pub async fn clear(ctx: Context<'_>) -> Result<(), Error> {
let guild_id = ctx.guild_id().unwrap();
let error_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross".to_string()).await;
let playlist_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "album".to_string()).await;
let error_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross").await;
let playlist_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "album").await;
let lava_client = ctx.data().lavalink.clone();

let Some(player) = lava_client.get_player_context(guild_id) else {
Expand Down
26 changes: 13 additions & 13 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ pub async fn view(ctx: Context<'_>) -> Result<(), Error> {
let config = queries::get_guild_config(db, guild_id).await?;

let dj_role = if let Some(role_id) = config.dj_role_id {
format!("<@&{}>", role_id)
format!("<@&{role_id}>")
} else {
"Not set (Everyone can use music commands)".to_string()
};
let announce_channel = if let Some(channel_id) = config.announce_channel_id {
format!("<#{}>", channel_id)
format!("<#{channel_id}>")
} else {
"Current channel".to_string()
};
Expand Down Expand Up @@ -79,8 +79,8 @@ async fn djrole(
) -> Result<(), Error> {
let guild_id = ctx.guild_id().ok_or("Must be in a guild")?.get() as i64;
let db = ctx.data().database.pool();
let success_emoji = get_emoji(ctx.serenity_context(), "check".to_string()).await;
let role_id = role.clone().map(|r| r.id.get() as i64);
let success_emoji = get_emoji(ctx.serenity_context(), "check").await;
let role_id = role.as_ref().map(|r| r.id.get() as i64);
queries::update_dj_role(db, guild_id, role_id).await?;

let description = if let Some(r) = role {
Expand Down Expand Up @@ -115,13 +115,13 @@ async fn volume(

queries::update_volume(db, guild_id, vol).await?;

let volume_emoji = get_emoji(ctx.serenity_context(), "vol3".to_string()).await;
let volume_emoji = get_emoji(ctx.serenity_context(), "vol3").await;
let embed = serenity::CreateEmbed::default()
.title(format!(
"{} Default Volume Updated",
volume_emoji.unwrap_or_default()
))
.description(format!("New tracks will play at {}%", vol))
.description(format!("New tracks will play at {vol}%"))
.color(COLOR_SUCCESS);

ctx.send(poise::CreateReply::default().embed(embed)).await?;
Expand All @@ -148,7 +148,7 @@ async fn autodisconnect(
} else {
"Auto disconnect disabled".to_string()
};
let clock_emoji = get_emoji(ctx.serenity_context(), "clock".to_string()).await;
let clock_emoji = get_emoji(ctx.serenity_context(), "clock").await;
let embed = serenity::CreateEmbed::default()
.title(format!(
"{} Auto Disconnect Updated",
Expand All @@ -173,7 +173,7 @@ async fn announce(
let guild_id = ctx.guild_id().ok_or("Must be in a guild")?.get() as i64;
let db = ctx.data().database.pool();

let channel_id = channel.clone().map(|c| c.id.get() as i64);
let channel_id = channel.as_ref().map(|c| c.id.get() as i64);
queries::update_announce_settings(db, guild_id, enabled, channel_id).await?;

let description = if enabled {
Expand All @@ -186,7 +186,7 @@ async fn announce(
"Song announcements disabled".to_string()
};

let song_emoji = get_emoji(ctx.serenity_context(), "song".to_string()).await;
let song_emoji = get_emoji(ctx.serenity_context(), "song").await;
let embed = serenity::CreateEmbed::default()
.title(format!(
"{} Announcements Updated",
Expand All @@ -213,13 +213,13 @@ async fn maxqueue(

queries::update_max_queue_length(db, guild_id, length).await?;

let album_emoji = get_emoji(ctx.serenity_context(), "album".to_string()).await;
let album_emoji = get_emoji(ctx.serenity_context(), "album").await;
let embed = serenity::CreateEmbed::default()
.title(format!(
"{} Max Queue Length Updated",
album_emoji.unwrap_or_default()
))
.description(format!("Queue can now hold up to {} tracks", length))
.description(format!("Queue can now hold up to {length} tracks"))
.color(COLOR_SUCCESS);

ctx.send(poise::CreateReply::default().embed(embed)).await?;
Expand All @@ -243,7 +243,7 @@ async fn filters(
"Audio filters are now disabled"
};

let filter_emoji = get_emoji(ctx.serenity_context(), "filter".to_string()).await;
let filter_emoji = get_emoji(ctx.serenity_context(), "filter").await;
let embed = serenity::CreateEmbed::default()
.title(format!(
"{} Filters Updated",
Expand All @@ -263,7 +263,7 @@ async fn reset(ctx: Context<'_>) -> Result<(), Error> {
let db = ctx.data().database.pool();

queries::reset_guild_config(db, guild_id).await?;
let recycle_emoji = get_emoji(ctx.serenity_context(), "recycle".to_string()).await;
let recycle_emoji = get_emoji(ctx.serenity_context(), "recycle").await;
let embed = serenity::CreateEmbed::default()
.title(format!(
"{} Configuration Reset",
Expand Down
63 changes: 24 additions & 39 deletions src/commands/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn filter_autocomplete(
_ctx: Context<'_>,
partial: &str,
) -> Vec<serenity::AutocompleteChoice> {
FilterPreset::all_presets()
FilterPreset::ALL
.iter()
.filter(|preset| {
preset
Expand All @@ -24,7 +24,7 @@ async fn filter_autocomplete(
})
.map(|preset| {
serenity::AutocompleteChoice::new(
format!("{}", preset.name()),
preset.name().to_string(),
preset.name().to_lowercase().replace(" ", "_"),
)
})
Expand All @@ -45,7 +45,7 @@ async fn apply(
#[autocomplete = "filter_autocomplete"]
preset: String,
) -> Result<(), Error> {
let error_emoji = get_emoji(ctx.serenity_context(), "error".to_string()).await;
let error_emoji = get_emoji(ctx.serenity_context(), "error").await;

if !permissions::check_dj_or_admin(ctx).await? {
let embed = serenity::CreateEmbed::default()
Expand Down Expand Up @@ -92,23 +92,7 @@ async fn apply(
.get_player_context(guild_id)
.ok_or("Not connected to voice channel")?;

let filter_preset = match preset.as_str() {
"bass_boost" => FilterPreset::Bassboost,
"nightcore" => FilterPreset::Nightcore,
"vaporwave" => FilterPreset::Vaporwave,
"8d_audio" => FilterPreset::EightD,
"karaoke" => FilterPreset::Karaoke,
"treble_boost" => FilterPreset::Treble,
"vibrato" => FilterPreset::Vibrato,
"tremolo" => FilterPreset::Tremolo,
"pop" => FilterPreset::Pop,
"soft" => FilterPreset::Soft,
"electronic" => FilterPreset::Electronic,
"rock" => FilterPreset::Rock,
"clear_(no_filters)" => FilterPreset::Clear,
_ => return Err("Invalid filter preset".into()),
};

let filter_preset = preset.parse::<FilterPreset>()?;
let filters = filter_preset.to_filters();
player.set_filters(filters).await?;

Expand All @@ -131,17 +115,18 @@ async fn apply(
/// List all available filters
#[poise::command(slash_command)]
async fn list(ctx: Context<'_>) -> Result<(), Error> {
let mut description = String::new();
let filter_emoji = get_emoji(ctx.serenity_context(), "filter".to_string()).await;

for preset in FilterPreset::all_presets() {
description.push_str(&format!(
"{} **{}**\n{}\n\n",
preset.emoji(),
preset.name(),
preset.description()
));
}
let description = FilterPreset::ALL
.into_iter()
.map(|preset| {
format!(
"{} **{}**\n{}\n\n",
preset.emoji(),
preset.name(),
preset.description()
)
})
.collect::<String>();
let filter_emoji = get_emoji(ctx.serenity_context(), "filter").await;

let embed = serenity::CreateEmbed::default()
.title(format!(
Expand All @@ -161,8 +146,8 @@ async fn list(ctx: Context<'_>) -> Result<(), Error> {
/// Remove all filters
#[poise::command(slash_command)]
async fn clear(ctx: Context<'_>) -> Result<(), Error> {
let error_emoji = get_emoji(ctx.serenity_context(), "error".to_string()).await;
let check_emoji = get_emoji(ctx.serenity_context(), "check".to_string()).await;
let error_emoji = get_emoji(ctx.serenity_context(), "error").await;
let check_emoji = get_emoji(ctx.serenity_context(), "check").await;

if !permissions::check_dj_or_admin(ctx).await? {
let embed = serenity::CreateEmbed::default()
Expand Down Expand Up @@ -207,8 +192,8 @@ async fn custom(
#[description = "Bass gain (-0.25 to 1.0)"] bass: Option<f64>,
#[description = "Treble gain (-0.25 to 1.0)"] treble: Option<f64>,
) -> Result<(), Error> {
let error_emoji = get_emoji(ctx.serenity_context(), "error".to_string()).await;
let check_emoji = get_emoji(ctx.serenity_context(), "check".to_string()).await;
let error_emoji = get_emoji(ctx.serenity_context(), "error").await;
let check_emoji = get_emoji(ctx.serenity_context(), "check").await;

if !permissions::check_dj_or_admin(ctx).await? {
let embed = serenity::CreateEmbed::default()
Expand Down Expand Up @@ -259,10 +244,10 @@ async fn custom(
});

if let Some(s) = speed {
changes.push(format!("Speed: {:.2}x", s));
changes.push(format!("Speed: {s:.2}x"));
}
if let Some(p) = pitch {
changes.push(format!("Pitch: {:.2}x", p));
changes.push(format!("Pitch: {p:.2}x"));
}
}

Expand All @@ -274,15 +259,15 @@ async fn custom(
for i in 0..4 {
bands.push((i, clamped));
}
changes.push(format!("Bass: {:+.2}", clamped));
changes.push(format!("Bass: {clamped:+.2}"));
}

if let Some(treble_gain) = treble {
let clamped = treble_gain.clamp(-0.25, 1.0);
for i in 10..15 {
bands.push((i, clamped));
}
changes.push(format!("Treble: {:+.2}", clamped));
changes.push(format!("Treble: {clamped:+.2}"));
}

let equalizer_bands: Vec<lavalink_rs::model::player::Equalizer> = bands
Expand Down
9 changes: 3 additions & 6 deletions src/commands/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ pub async fn join(ctx: Context<'_>) -> Result<(), Error> {
.get(&cache.current_user().id)
.and_then(|vs| vs.channel_id)
});
let error_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross".to_string()).await;
let success_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "check".to_string()).await;
let alert_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "caution".to_string()).await;
let error_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross").await;
let success_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "check").await;
let alert_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "caution").await;
if user_voice.is_none() {
let embed = serenity::CreateEmbed::default()
.title(format!("{} Cannot Join", error_emoji.unwrap_or_default()))
Expand Down
2 changes: 1 addition & 1 deletion src/commands/leave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {

let manager = songbird::get(ctx.serenity_context()).await.unwrap().clone();
let lava_client = ctx.data().lavalink.clone();
let success_emoji = emojis::get_emoji(ctx.serenity_context(), "check".to_string()).await;
let success_emoji = emojis::get_emoji(ctx.serenity_context(), "check").await;
lava_client.delete_player(guild_id).await?;

if manager.get(guild_id).is_some() {
Expand Down
6 changes: 2 additions & 4 deletions src/commands/pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ pub async fn pause(ctx: Context<'_>) -> Result<(), Error> {
let guild_id = ctx.guild_id().unwrap();
let is_dj_or_admin = permissions::check_dj_or_admin(ctx).await?;
let check_in_voice = permissions::check_in_voice(ctx).await?;
let error_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross".to_string()).await;
let success_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "check".to_string()).await;
let error_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross").await;
let success_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "check").await;
let lava_client = ctx.data().lavalink.clone();

if !is_dj_or_admin {
Expand Down
30 changes: 13 additions & 17 deletions src/commands/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ fn format_duration(ms: u64) -> String {
let hours = minutes / 60;

if hours > 0 {
format!("{}:{:02}:{:02}", hours, minutes % 60, seconds % 60)
format!("{hours}:{:02}:{:02}", minutes % 60, seconds % 60)
} else {
format!("{}:{:02}", minutes, seconds % 60)
format!("{minutes}:{:02}", seconds % 60)
}
}

Expand All @@ -78,16 +78,11 @@ pub async fn play(
let guild_id = ctx.guild_id().unwrap();
let has_joined = _join(&ctx, guild_id, None).await?;
let lava_client = ctx.data().lavalink.clone();
let error_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross".to_string()).await;
let _success_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "check".to_string()).await;
let playlist_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "album".to_string()).await;
let player_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "player".to_string()).await;
let spotify_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "spotify".to_string()).await;
let error_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross").await;
let _success_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "check").await;
let playlist_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "album").await;
let player_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "player").await;
let spotify_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "spotify").await;
let pool = ctx.data().database.pool();
let guild_config = queries::get_guild_config(pool, guild_id.get() as i64).await?;
let max_queue = guild_config.max_queue_length;
Expand Down Expand Up @@ -178,7 +173,7 @@ pub async fn play(
"**[{} - {}]({})**",
track.info.author,
track.info.title,
track.info.uri.as_ref().unwrap_or(&String::from("#"))
track.info.uri.as_deref().unwrap_or("#")
))
.field("Duration", duration, true)
.field("Requested by", ctx.author().mention().to_string(), true)
Expand Down Expand Up @@ -206,10 +201,11 @@ pub async fn play(
return Ok(());
}

if let Ok(player_data) = player.get_player().await {
if player_data.track.is_none() && queue.get_track(0).await.is_ok_and(|x| x.is_some()) {
player.skip()?;
}
if let Ok(player_data) = player.get_player().await
&& player_data.track.is_none()
&& queue.get_track(0).await.is_ok_and(|x| x.is_some())
{
player.skip()?;
}

Ok(())
Expand Down
5 changes: 2 additions & 3 deletions src/commands/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use poise::serenity_prelude as serenity;
pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
let guild_id = ctx.guild_id().unwrap();
let lava_client = ctx.data().lavalink.clone();
let album_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "album".to_string()).await;
let album_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "album").await;
let player = match lava_client.get_player_context(guild_id) {
Some(p) => p,
None => {
Expand Down Expand Up @@ -53,7 +52,7 @@ pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
};
let embed = serenity::CreateEmbed::default()
.title(format!("{} Queue", album_emoji.unwrap_or_default()))
.description(format!("{}**On Queue**:\n{}", now_playing, queue_list))
.description(format!("{now_playing}**On Queue**:\n{queue_list}"))
.color(COLOR_INFO);

ctx.send(poise::CreateReply::default().embed(embed)).await?;
Expand Down
10 changes: 4 additions & 6 deletions src/commands/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ pub async fn remove(

let is_dj_or_admin = permissions::check_dj_or_admin(ctx).await?;
let check_in_voice = permissions::check_in_voice(ctx).await?;
let error_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross".to_string()).await;
let success_emoji =
crate::utils::emojis::get_emoji(ctx.serenity_context(), "check".to_string()).await;
let error_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "cross").await;
let success_emoji = crate::utils::emojis::get_emoji(ctx.serenity_context(), "check").await;
if !is_dj_or_admin {
let embed = serenity::CreateEmbed::default()
.title(format!(
Expand Down Expand Up @@ -72,10 +70,10 @@ pub async fn remove(
"{} Track removed successfully",
success_emoji.unwrap_or_default()
))
.description(format!("Removed {} from queue", track_name))
.description(format!("Removed {track_name} from queue"))
.color(COLOR_SUCCESS);

let _ = ctx.send(poise::CreateReply::default().embed(embed));
let _ = ctx.send(poise::CreateReply::default().embed(embed)).await;

Ok(())
}
Loading