mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 00:38:54 +00:00
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:
parent
06cbc51c0e
commit
cf831fae87
5 changed files with 49 additions and 22 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "Inflector"
|
||||
version = "0.11.4"
|
||||
|
@ -228,9 +230,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "command_attr"
|
||||
version = "0.3.5"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fe1f0b69fde68f40ea2ee6ca8db23bc40d2e593db884659a65d8486032cc65b"
|
||||
checksum = "8a6c3666f685cb1efc0628b8c984dbad9c372d080450736c7732089c385ed81d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1485,9 +1487,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serenity"
|
||||
version = "0.10.5"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "deead3f7ecbbbe4c249e07af17686937ccb9d7fa24ca3accd1d223e369a75272"
|
||||
checksum = "6275d443266aedf2be507a245ddc23db0c07b1b99774e16f3c879e96a78b067a"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"async-tungstenite",
|
||||
|
|
|
@ -262,14 +262,36 @@ impl<'a> CollectedScore<'a> {
|
|||
bm: &BeatmapWithMode,
|
||||
content: &BeatmapContent,
|
||||
) -> 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
|
||||
.send_message(ctx.c.http(), |c| {
|
||||
c.content(match self.kind {
|
||||
ScoreType::TopRecord(_) => {
|
||||
format!("New top record from {}!", self.discord_user.mention())
|
||||
}
|
||||
ScoreType::WorldRecord(_) => {
|
||||
format!("New best score from {}!", self.discord_user.mention())
|
||||
ScoreType::WorldRecord(rank) => {
|
||||
if rank <= 100 {
|
||||
format!(
|
||||
"New leaderboard record from {}!",
|
||||
self.discord_user.mention()
|
||||
)
|
||||
} else {
|
||||
format!("New leaderboard record from **{}**!", member.distinct())
|
||||
}
|
||||
}
|
||||
})
|
||||
.embed(|e| {
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
|||
discord::oppai_cache::{BeatmapContent, BeatmapInfo, BeatmapInfoWithPP, OppaiAccuracy},
|
||||
models::{Beatmap, Mode, Mods, Rank, Score, User},
|
||||
};
|
||||
use chrono::Utc;
|
||||
use serenity::{builder::CreateEmbed, utils::MessageBuilder};
|
||||
use youmubot_prelude::*;
|
||||
|
||||
|
@ -331,7 +330,7 @@ impl<'a> ScoreEmbedBuilder<'a> {
|
|||
.description(format!(
|
||||
r#"**Beatmap**: {} - {} [{}]**{} **
|
||||
**Links**: [[Listing]]({}) [[Download]]({}) [[Bloodcat]]({})
|
||||
**Played on**: {}
|
||||
**Played**: {}
|
||||
{}"#,
|
||||
b.artist,
|
||||
b.title,
|
||||
|
@ -340,7 +339,7 @@ impl<'a> ScoreEmbedBuilder<'a> {
|
|||
b.link(),
|
||||
b.download_link(false),
|
||||
b.download_link(true),
|
||||
s.date.format("%F %T"),
|
||||
s.date.format("<t:%s:R>"),
|
||||
pp_gained.as_ref().map(|v| &v[..]).unwrap_or(""),
|
||||
))
|
||||
.image(b.cover_url())
|
||||
|
@ -384,7 +383,7 @@ pub(crate) fn user_embed(
|
|||
.url(format!("https://osu.ppy.sh/users/{}", u.id))
|
||||
.color(0xffb6c1)
|
||||
.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(
|
||||
"Performance Points",
|
||||
u.pp.map(|v| format!("{:.2}pp", v))
|
||||
|
@ -405,8 +404,9 @@ pub(crate) fn user_embed(
|
|||
.field(
|
||||
"Play count / Play time",
|
||||
format!(
|
||||
"{} ({})",
|
||||
"{} / {} hours ({})",
|
||||
grouped_number(u.play_count),
|
||||
u.played_time.as_secs() / 3600,
|
||||
Duration(u.played_time)
|
||||
),
|
||||
false,
|
||||
|
@ -442,14 +442,7 @@ pub(crate) fn user_embed(
|
|||
v.pp.unwrap() /*Top record should have pp*/
|
||||
))
|
||||
.push(" - ")
|
||||
.push_line(format!(
|
||||
"{:.1} ago",
|
||||
Duration(
|
||||
(Utc::now() - v.date)
|
||||
.to_std()
|
||||
.unwrap_or_else(|_| std::time::Duration::from_secs(1))
|
||||
)
|
||||
))
|
||||
.push_line(v.date.format("<t:%s:R>"))
|
||||
.push("on ")
|
||||
.push_line(format!(
|
||||
"[{} - {} [{}]]({})**{} **",
|
||||
|
|
|
@ -13,7 +13,7 @@ pub use mods::Mods;
|
|||
use serenity::utils::MessageBuilder;
|
||||
|
||||
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)]
|
||||
|
@ -30,7 +30,7 @@ pub enum ApprovalStatus {
|
|||
impl fmt::Display for ApprovalStatus {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let ApprovalStatus::Ranked(ref d) = self {
|
||||
write!(f, "Ranked on {}", d.format("%F %T"))
|
||||
write!(f, "Ranked on {}", d.format("<t:%s>"))
|
||||
} else {
|
||||
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.
|
||||
pub fn short_link(&self, override_mode: Option<Mode>, mods: Option<Mods>) -> String {
|
||||
format!(
|
||||
|
@ -392,6 +397,11 @@ impl Beatmap {
|
|||
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)]
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2018"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
default = ["core", "osu", "codeforces"]
|
||||
default = ["core", "osu"] # codeforces disabled for now
|
||||
core = []
|
||||
osu = ["youmubot-osu"]
|
||||
codeforces = ["youmubot-cf"]
|
||||
|
|
Loading…
Add table
Reference in a new issue