mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 08:48: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},
|
models::{Beatmap, Difficulty, Mode, Mods, Rank, Score, User},
|
||||||
};
|
};
|
||||||
use serenity::{
|
use serenity::{
|
||||||
|
all::CreateAttachment,
|
||||||
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
utils::MessageBuilder,
|
utils::MessageBuilder,
|
||||||
};
|
};
|
||||||
|
@ -63,7 +64,7 @@ pub fn beatmap_offline_embed(
|
||||||
b: &'_ crate::discord::oppai_cache::BeatmapContent,
|
b: &'_ crate::discord::oppai_cache::BeatmapContent,
|
||||||
m: Mode,
|
m: Mode,
|
||||||
mods: Mods,
|
mods: Mods,
|
||||||
) -> Result<CreateEmbed> {
|
) -> Result<(CreateEmbed, Vec<CreateAttachment>)> {
|
||||||
let bm = b.content.clone();
|
let bm = b.content.clone();
|
||||||
let metadata = b.metadata.clone();
|
let metadata = b.metadata.clone();
|
||||||
let (info, pp) = b.get_possible_pp_with(m, mods)?;
|
let (info, pp) = b.get_possible_pp_with(m, mods)?;
|
||||||
|
@ -107,29 +108,37 @@ pub fn beatmap_offline_embed(
|
||||||
total_length,
|
total_length,
|
||||||
}
|
}
|
||||||
.apply_mods(mods, info.stars);
|
.apply_mods(mods, info.stars);
|
||||||
Ok(
|
let mut embed = CreateEmbed::new()
|
||||||
CreateEmbed::new()
|
.title(beatmap_title(
|
||||||
.title(beatmap_title(
|
&metadata.artist,
|
||||||
&metadata.artist,
|
&metadata.title,
|
||||||
&metadata.title,
|
&metadata.version,
|
||||||
&metadata.version,
|
mods,
|
||||||
mods,
|
))
|
||||||
))
|
.author({
|
||||||
.author({
|
CreateEmbedAuthor::new(&metadata.creator)
|
||||||
CreateEmbedAuthor::new(&metadata.creator)
|
.url(format!("https://osu.ppy.sh/users/{}", metadata.creator))
|
||||||
.url(format!("https://osu.ppy.sh/users/{}", metadata.creator))
|
})
|
||||||
})
|
.color(0xffb6c1)
|
||||||
.color(0xffb6c1)
|
.field(
|
||||||
.field(
|
"Calculated pp",
|
||||||
"Calculated pp",
|
format!(
|
||||||
format!(
|
"95%: **{:.2}**pp, 98%: **{:.2}**pp, 99%: **{:.2}**pp, 100%: **{:.2}**pp",
|
||||||
"95%: **{:.2}**pp, 98%: **{:.2}**pp, 99%: **{:.2}**pp, 100%: **{:.2}**pp",
|
pp[0], pp[1], pp[2], pp[3]
|
||||||
pp[0], pp[1], pp[2], pp[3]
|
),
|
||||||
),
|
false,
|
||||||
false,
|
)
|
||||||
)
|
.field("Information", diff.format_info(m, mods, None), false);
|
||||||
.field("Information", diff.format_info(m, mods, None), false), // .description(beatmap_description(b))
|
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
|
// Some helper functions here
|
||||||
|
|
|
@ -101,16 +101,45 @@ pub fn dot_osu_hook<'a>(
|
||||||
osu_embeds.extend(osz_embeds);
|
osu_embeds.extend(osz_embeds);
|
||||||
|
|
||||||
if !osu_embeds.is_empty() {
|
if !osu_embeds.is_empty() {
|
||||||
msg.channel_id
|
let embed_len = osu_embeds.len();
|
||||||
.send_message(
|
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,
|
ctx,
|
||||||
CreateMessage::new()
|
msg,
|
||||||
.reference_message(msg)
|
std::time::Duration::from_secs(180),
|
||||||
.content(format!("{} attached beatmaps found", osu_embeds.len()))
|
|
||||||
.add_embeds(osu_embeds),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.pls_ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue