Chart info command
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
8339ce7054
commit
373e54c55e
12 changed files with 345 additions and 85 deletions
76
src/commands/chart.rs
Normal file
76
src/commands/chart.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
use poise::serenity_prelude::{CreateAttachment, CreateEmbed, CreateMessage};
|
||||
use sqlx::query;
|
||||
|
||||
use crate::{
|
||||
chart::Side,
|
||||
context::{Context, Error},
|
||||
score::guess_song_and_chart,
|
||||
};
|
||||
|
||||
// {{{ Chart
|
||||
/// Show a chart given it's name
|
||||
#[poise::command(prefix_command, slash_command)]
|
||||
pub async fn chart(
|
||||
ctx: Context<'_>,
|
||||
#[rest]
|
||||
#[description = "Name of chart to show (difficulty at the end)"]
|
||||
name: String,
|
||||
) -> Result<(), Error> {
|
||||
let (song, chart) = guess_song_and_chart(&ctx.data(), &name)?;
|
||||
|
||||
let attachement_name = "chart.png";
|
||||
let icon_attachement = match chart.cached_jacket {
|
||||
Some(bytes) => Some(CreateAttachment::bytes(bytes, attachement_name)),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let play_count = query!(
|
||||
"
|
||||
SELECT COUNT(*) as count
|
||||
FROM plays
|
||||
WHERE chart_id=?
|
||||
",
|
||||
chart.id
|
||||
)
|
||||
.fetch_one(&ctx.data().db)
|
||||
.await?;
|
||||
|
||||
let mut embed = CreateEmbed::default()
|
||||
.title(format!(
|
||||
"{} [{:?} {}]",
|
||||
&song.title, chart.difficulty, chart.level
|
||||
))
|
||||
.field("Note count", format!("{}", chart.note_count), true)
|
||||
.field(
|
||||
"Chart constant",
|
||||
format!("{:.1}", chart.chart_constant as f32 / 100.0),
|
||||
true,
|
||||
)
|
||||
.field("Total plays", format!("{}", play_count.count), true)
|
||||
.field("BPM", &song.bpm, true)
|
||||
.field("Side", Side::SIDE_STRINGS[song.side.to_index()], true)
|
||||
.field("Artist", &song.title, true);
|
||||
|
||||
if let Some(note_design) = &chart.note_design {
|
||||
embed = embed.field("Note design", note_design, true);
|
||||
}
|
||||
|
||||
if let Some(pack) = &song.pack {
|
||||
embed = embed.field("Pack", pack, true);
|
||||
}
|
||||
|
||||
if icon_attachement.is_some() {
|
||||
embed = embed.thumbnail(format!("attachment://{}", &attachement_name));
|
||||
}
|
||||
|
||||
ctx.channel_id()
|
||||
.send_files(
|
||||
ctx.http(),
|
||||
icon_attachement,
|
||||
CreateMessage::new().embed(embed),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// }}}
|
|
@ -1,2 +1,27 @@
|
|||
use crate::context::{Context, Error};
|
||||
|
||||
pub mod chart;
|
||||
pub mod score;
|
||||
pub mod stats;
|
||||
|
||||
// {{{ Help
|
||||
/// Show this help menu
|
||||
#[poise::command(prefix_command, track_edits, slash_command)]
|
||||
pub async fn help(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Specific command to show help about"]
|
||||
#[autocomplete = "poise::builtins::autocomplete_command"]
|
||||
command: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
poise::builtins::help(
|
||||
ctx,
|
||||
command.as_deref(),
|
||||
poise::builtins::HelpConfiguration {
|
||||
extra_text_at_bottom: "For additional support, message @prescientmoon",
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
// }}}
|
||||
|
|
|
@ -10,27 +10,6 @@ use poise::serenity_prelude::{CreateAttachment, CreateEmbed, CreateMessage};
|
|||
use poise::{serenity_prelude as serenity, CreateReply};
|
||||
use sqlx::query;
|
||||
|
||||
// {{{ Help
|
||||
/// Show this help menu
|
||||
#[poise::command(prefix_command, track_edits, slash_command)]
|
||||
pub async fn help(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Specific command to show help about"]
|
||||
#[autocomplete = "poise::builtins::autocomplete_command"]
|
||||
command: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
poise::builtins::help(
|
||||
ctx,
|
||||
command.as_deref(),
|
||||
poise::builtins::HelpConfiguration {
|
||||
extra_text_at_bottom: "For additional support, message @prescientmoon",
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
// }}}
|
||||
// {{{ Score
|
||||
/// Score management
|
||||
#[poise::command(
|
||||
|
|
|
@ -17,9 +17,8 @@ use poise::{
|
|||
use sqlx::query_as;
|
||||
|
||||
use crate::{
|
||||
chart::Difficulty,
|
||||
context::{Context, Error},
|
||||
score::{guess_chart_name, DbPlay, Score},
|
||||
score::{guess_song_and_chart, DbPlay, Score},
|
||||
user::{discord_it_to_discord_user, User},
|
||||
};
|
||||
|
||||
|
@ -65,22 +64,7 @@ pub async fn best(
|
|||
}
|
||||
};
|
||||
|
||||
let name = name.trim();
|
||||
let (name, difficulty) = name
|
||||
.strip_suffix("PST")
|
||||
.zip(Some(Difficulty::PST))
|
||||
.or_else(|| name.strip_suffix("[PST]").zip(Some(Difficulty::PST)))
|
||||
.or_else(|| name.strip_suffix("PRS").zip(Some(Difficulty::PRS)))
|
||||
.or_else(|| name.strip_suffix("[PRS]").zip(Some(Difficulty::PRS)))
|
||||
.or_else(|| name.strip_suffix("FTR").zip(Some(Difficulty::FTR)))
|
||||
.or_else(|| name.strip_suffix("[FTR]").zip(Some(Difficulty::FTR)))
|
||||
.or_else(|| name.strip_suffix("ETR").zip(Some(Difficulty::ETR)))
|
||||
.or_else(|| name.strip_suffix("[ETR]").zip(Some(Difficulty::ETR)))
|
||||
.or_else(|| name.strip_suffix("BYD").zip(Some(Difficulty::BYD)))
|
||||
.or_else(|| name.strip_suffix("[BYD]").zip(Some(Difficulty::BYD)))
|
||||
.unwrap_or((&name, Difficulty::FTR));
|
||||
|
||||
let (song, chart) = guess_chart_name(name, &ctx.data().song_cache, Some(difficulty), true)?;
|
||||
let (song, chart) = guess_song_and_chart(&ctx.data(), &name)?;
|
||||
|
||||
let play = query_as!(
|
||||
DbPlay,
|
||||
|
@ -137,22 +121,7 @@ pub async fn plot(
|
|||
}
|
||||
};
|
||||
|
||||
let name = name.trim();
|
||||
let (name, difficulty) = name
|
||||
.strip_suffix("PST")
|
||||
.zip(Some(Difficulty::PST))
|
||||
.or_else(|| name.strip_suffix("[PST]").zip(Some(Difficulty::PST)))
|
||||
.or_else(|| name.strip_suffix("PRS").zip(Some(Difficulty::PRS)))
|
||||
.or_else(|| name.strip_suffix("[PRS]").zip(Some(Difficulty::PRS)))
|
||||
.or_else(|| name.strip_suffix("FTR").zip(Some(Difficulty::FTR)))
|
||||
.or_else(|| name.strip_suffix("[FTR]").zip(Some(Difficulty::FTR)))
|
||||
.or_else(|| name.strip_suffix("ETR").zip(Some(Difficulty::ETR)))
|
||||
.or_else(|| name.strip_suffix("[ETR]").zip(Some(Difficulty::ETR)))
|
||||
.or_else(|| name.strip_suffix("BYD").zip(Some(Difficulty::BYD)))
|
||||
.or_else(|| name.strip_suffix("[BYD]").zip(Some(Difficulty::BYD)))
|
||||
.unwrap_or((&name, Difficulty::FTR));
|
||||
|
||||
let (song, chart) = guess_chart_name(name, &ctx.data().song_cache, Some(difficulty), true)?;
|
||||
let (song, chart) = guess_song_and_chart(&ctx.data(), &name)?;
|
||||
|
||||
let plays = query_as!(
|
||||
DbPlay,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue