mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-18 00:08:54 +00:00
Reformat uploaded beatmap embed and send background
This commit is contained in:
parent
2315f40cf1
commit
e9a6e55569
2 changed files with 69 additions and 31 deletions
|
@ -4,6 +4,7 @@ use crate::{
|
|||
models::{Beatmap, Difficulty, Mode, Mods, Rank, Score, User},
|
||||
};
|
||||
use serenity::{
|
||||
all::CreateAttachment,
|
||||
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||
utils::MessageBuilder,
|
||||
};
|
||||
|
@ -63,7 +64,7 @@ pub fn beatmap_offline_embed(
|
|||
b: &'_ crate::discord::oppai_cache::BeatmapContent,
|
||||
m: Mode,
|
||||
mods: Mods,
|
||||
) -> Result<CreateEmbed> {
|
||||
) -> Result<(CreateEmbed, Vec<CreateAttachment>)> {
|
||||
let bm = b.content.clone();
|
||||
let metadata = b.metadata.clone();
|
||||
let (info, pp) = b.get_possible_pp_with(m, mods)?;
|
||||
|
@ -107,29 +108,37 @@ pub fn beatmap_offline_embed(
|
|||
total_length,
|
||||
}
|
||||
.apply_mods(mods, info.stars);
|
||||
Ok(
|
||||
CreateEmbed::new()
|
||||
.title(beatmap_title(
|
||||
&metadata.artist,
|
||||
&metadata.title,
|
||||
&metadata.version,
|
||||
mods,
|
||||
))
|
||||
.author({
|
||||
CreateEmbedAuthor::new(&metadata.creator)
|
||||
.url(format!("https://osu.ppy.sh/users/{}", metadata.creator))
|
||||
})
|
||||
.color(0xffb6c1)
|
||||
.field(
|
||||
"Calculated pp",
|
||||
format!(
|
||||
"95%: **{:.2}**pp, 98%: **{:.2}**pp, 99%: **{:.2}**pp, 100%: **{:.2}**pp",
|
||||
pp[0], pp[1], pp[2], pp[3]
|
||||
),
|
||||
false,
|
||||
)
|
||||
.field("Information", diff.format_info(m, mods, None), false), // .description(beatmap_description(b))
|
||||
)
|
||||
let mut embed = CreateEmbed::new()
|
||||
.title(beatmap_title(
|
||||
&metadata.artist,
|
||||
&metadata.title,
|
||||
&metadata.version,
|
||||
mods,
|
||||
))
|
||||
.author({
|
||||
CreateEmbedAuthor::new(&metadata.creator)
|
||||
.url(format!("https://osu.ppy.sh/users/{}", metadata.creator))
|
||||
})
|
||||
.color(0xffb6c1)
|
||||
.field(
|
||||
"Calculated pp",
|
||||
format!(
|
||||
"95%: **{:.2}**pp, 98%: **{:.2}**pp, 99%: **{:.2}**pp, 100%: **{:.2}**pp",
|
||||
pp[0], pp[1], pp[2], pp[3]
|
||||
),
|
||||
false,
|
||||
)
|
||||
.field("Information", diff.format_info(m, mods, None), false);
|
||||
let mut attachments = Vec::new();
|
||||
if let Some(bg) = &b.beatmap_background {
|
||||
embed = embed.thumbnail(format!("attachment://{}", bg.filename));
|
||||
attachments.push(CreateAttachment::bytes(
|
||||
bg.content.clone().into_vec(),
|
||||
bg.filename.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok((embed, attachments))
|
||||
}
|
||||
|
||||
// Some helper functions here
|
||||
|
|
|
@ -101,16 +101,45 @@ pub fn dot_osu_hook<'a>(
|
|||
osu_embeds.extend(osz_embeds);
|
||||
|
||||
if !osu_embeds.is_empty() {
|
||||
msg.channel_id
|
||||
.send_message(
|
||||
let embed_len = osu_embeds.len();
|
||||
if embed_len == 1 {
|
||||
let (embed, attachments) = osu_embeds.into_iter().next().unwrap();
|
||||
msg.channel_id
|
||||
.send_message(
|
||||
ctx,
|
||||
CreateMessage::new()
|
||||
.reference_message(msg)
|
||||
.embed(embed)
|
||||
.add_files(attachments)
|
||||
.content("Attached beatmap".to_owned()),
|
||||
)
|
||||
.await
|
||||
.pls_ok();
|
||||
} else {
|
||||
let osu_embeds = Arc::new(osu_embeds);
|
||||
paginate_reply(
|
||||
paginate_from_fn(|page, ctx, msg| {
|
||||
let osu_embeds = osu_embeds.clone();
|
||||
Box::pin(async move {
|
||||
let (embed, attachments) = &osu_embeds[page as usize];
|
||||
let mut edit = EditMessage::new()
|
||||
.content(format!("Attached beatmaps ({}/{})", page + 1, embed_len))
|
||||
.embed(embed.clone());
|
||||
for att in attachments {
|
||||
edit = edit.new_attachment(att.clone());
|
||||
}
|
||||
msg.edit(&ctx, edit).await?;
|
||||
Ok(true)
|
||||
})
|
||||
})
|
||||
.with_page_count(embed_len),
|
||||
ctx,
|
||||
CreateMessage::new()
|
||||
.reference_message(msg)
|
||||
.content(format!("{} attached beatmaps found", osu_embeds.len()))
|
||||
.add_embeds(osu_embeds),
|
||||
msg,
|
||||
std::time::Duration::from_secs(180),
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
.pls_ok();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Reference in a new issue