osu! best minor fixes (#16)

- Bump serenity version
- Now no longer pings unless the play is within top 100
- Parse numbers in bold as well
- Use relative time syntax in embeds
This commit is contained in:
Natsu Kagami 2021-10-23 14:33:32 -04:00 committed by GitHub
parent 06cbc51c0e
commit cf831fae87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 22 deletions

10
Cargo.lock generated
View file

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3
[[package]] [[package]]
name = "Inflector" name = "Inflector"
version = "0.11.4" version = "0.11.4"
@ -228,9 +230,9 @@ dependencies = [
[[package]] [[package]]
name = "command_attr" name = "command_attr"
version = "0.3.5" version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fe1f0b69fde68f40ea2ee6ca8db23bc40d2e593db884659a65d8486032cc65b" checksum = "8a6c3666f685cb1efc0628b8c984dbad9c372d080450736c7732089c385ed81d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1485,9 +1487,9 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.10.5" version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "deead3f7ecbbbe4c249e07af17686937ccb9d7fa24ca3accd1d223e369a75272" checksum = "6275d443266aedf2be507a245ddc23db0c07b1b99774e16f3c879e96a78b067a"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",

View file

@ -262,14 +262,36 @@ impl<'a> CollectedScore<'a> {
bm: &BeatmapWithMode, bm: &BeatmapWithMode,
content: &BeatmapContent, content: &BeatmapContent,
) -> Result<Message> { ) -> Result<Message> {
let guild = match channel.to_channel(&ctx.c).await?.guild() {
Some(gc) => gc.guild_id,
None => {
eprintln!("Not a guild channel: {}", channel);
return Err(Error::msg("Trying to announce to a non-server channel"));
}
};
let member = match guild.member(&ctx.c, self.discord_user).await {
Ok(mem) => mem,
Err(e) => {
eprintln!("Cannot get member {}: {}", self.discord_user, e);
return Err(e.into());
}
};
let m = channel let m = channel
.send_message(ctx.c.http(), |c| { .send_message(ctx.c.http(), |c| {
c.content(match self.kind { c.content(match self.kind {
ScoreType::TopRecord(_) => { ScoreType::TopRecord(_) => {
format!("New top record from {}!", self.discord_user.mention()) format!("New top record from {}!", self.discord_user.mention())
} }
ScoreType::WorldRecord(_) => { ScoreType::WorldRecord(rank) => {
format!("New best score from {}!", self.discord_user.mention()) if rank <= 100 {
format!(
"New leaderboard record from {}!",
self.discord_user.mention()
)
} else {
format!("New leaderboard record from **{}**!", member.distinct())
}
} }
}) })
.embed(|e| { .embed(|e| {

View file

@ -3,7 +3,6 @@ use crate::{
discord::oppai_cache::{BeatmapContent, BeatmapInfo, BeatmapInfoWithPP, OppaiAccuracy}, discord::oppai_cache::{BeatmapContent, BeatmapInfo, BeatmapInfoWithPP, OppaiAccuracy},
models::{Beatmap, Mode, Mods, Rank, Score, User}, models::{Beatmap, Mode, Mods, Rank, Score, User},
}; };
use chrono::Utc;
use serenity::{builder::CreateEmbed, utils::MessageBuilder}; use serenity::{builder::CreateEmbed, utils::MessageBuilder};
use youmubot_prelude::*; use youmubot_prelude::*;
@ -331,7 +330,7 @@ impl<'a> ScoreEmbedBuilder<'a> {
.description(format!( .description(format!(
r#"**Beatmap**: {} - {} [{}]**{} ** r#"**Beatmap**: {} - {} [{}]**{} **
**Links**: [[Listing]]({}) [[Download]]({}) [[Bloodcat]]({}) **Links**: [[Listing]]({}) [[Download]]({}) [[Bloodcat]]({})
**Played on**: {} **Played**: {}
{}"#, {}"#,
b.artist, b.artist,
b.title, b.title,
@ -340,7 +339,7 @@ impl<'a> ScoreEmbedBuilder<'a> {
b.link(), b.link(),
b.download_link(false), b.download_link(false),
b.download_link(true), b.download_link(true),
s.date.format("%F %T"), s.date.format("<t:%s:R>"),
pp_gained.as_ref().map(|v| &v[..]).unwrap_or(""), pp_gained.as_ref().map(|v| &v[..]).unwrap_or(""),
)) ))
.image(b.cover_url()) .image(b.cover_url())
@ -384,7 +383,7 @@ pub(crate) fn user_embed(
.url(format!("https://osu.ppy.sh/users/{}", u.id)) .url(format!("https://osu.ppy.sh/users/{}", u.id))
.color(0xffb6c1) .color(0xffb6c1)
.thumbnail(format!("https://a.ppy.sh/{}", u.id)) .thumbnail(format!("https://a.ppy.sh/{}", u.id))
.description(format!("Member since **{}**", u.joined.format("%F %T"))) .description(format!("Member since **{}**", u.joined.format("<t:%s:R>")))
.field( .field(
"Performance Points", "Performance Points",
u.pp.map(|v| format!("{:.2}pp", v)) u.pp.map(|v| format!("{:.2}pp", v))
@ -405,8 +404,9 @@ pub(crate) fn user_embed(
.field( .field(
"Play count / Play time", "Play count / Play time",
format!( format!(
"{} ({})", "{} / {} hours ({})",
grouped_number(u.play_count), grouped_number(u.play_count),
u.played_time.as_secs() / 3600,
Duration(u.played_time) Duration(u.played_time)
), ),
false, false,
@ -442,14 +442,7 @@ pub(crate) fn user_embed(
v.pp.unwrap() /*Top record should have pp*/ v.pp.unwrap() /*Top record should have pp*/
)) ))
.push(" - ") .push(" - ")
.push_line(format!( .push_line(v.date.format("<t:%s:R>"))
"{:.1} ago",
Duration(
(Utc::now() - v.date)
.to_std()
.unwrap_or_else(|_| std::time::Duration::from_secs(1))
)
))
.push("on ") .push("on ")
.push_line(format!( .push_line(format!(
"[{} - {} [{}]]({})**{} **", "[{} - {} [{}]]({})**{} **",

View file

@ -13,7 +13,7 @@ pub use mods::Mods;
use serenity::utils::MessageBuilder; use serenity::utils::MessageBuilder;
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref EVENT_RANK_REGEX: Regex = Regex::new(r#"^.+achieved rank #(\d+) on .+\((.+)\)$"#).unwrap(); static ref EVENT_RANK_REGEX: Regex = Regex::new(r#"^.+achieved .*rank #(\d+).* on .+\((.+)\)$"#).unwrap();
} }
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
@ -30,7 +30,7 @@ pub enum ApprovalStatus {
impl fmt::Display for ApprovalStatus { impl fmt::Display for ApprovalStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let ApprovalStatus::Ranked(ref d) = self { if let ApprovalStatus::Ranked(ref d) = self {
write!(f, "Ranked on {}", d.format("%F %T")) write!(f, "Ranked on {}", d.format("<t:%s>"))
} else { } else {
write!(f, "{:?}", self) write!(f, "{:?}", self)
} }
@ -371,6 +371,11 @@ impl Beatmap {
} }
} }
/// Returns a direct link to the download (if you have supporter!)
pub fn osu_direct_link(&self) -> String {
format!("osu://b/{}", self.beatmapset_id)
}
/// Return a parsable short link. /// Return a parsable short link.
pub fn short_link(&self, override_mode: Option<Mode>, mods: Option<Mods>) -> String { pub fn short_link(&self, override_mode: Option<Mode>, mods: Option<Mods>) -> String {
format!( format!(
@ -392,6 +397,11 @@ impl Beatmap {
self.beatmapset_id self.beatmapset_id
) )
} }
/// Link to the cover thumbnail of the beatmap.
pub fn thumbnail_url(&self) -> String {
format!("https://b.ppy.sh/thumb/{}l.jpg", self.beatmapset_id)
}
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]

View file

@ -6,7 +6,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]
default = ["core", "osu", "codeforces"] default = ["core", "osu"] # codeforces disabled for now
core = [] core = []
osu = ["youmubot-osu"] osu = ["youmubot-osu"]
codeforces = ["youmubot-cf"] codeforces = ["youmubot-cf"]