mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 00:38:54 +00:00
Only announce new records when stats were not recorded
This commit is contained in:
parent
a4407df97c
commit
6e6821510d
1 changed files with 36 additions and 29 deletions
|
@ -118,36 +118,37 @@ impl Announcer {
|
||||||
last_update: now,
|
last_update: now,
|
||||||
};
|
};
|
||||||
let last = user.modes.insert(mode, stats);
|
let last = user.modes.insert(mode, stats);
|
||||||
let last_update = last.as_ref().map(|v| v.last_update);
|
|
||||||
|
|
||||||
// broadcast
|
// broadcast
|
||||||
let mention = user.user_id;
|
let mention = user.user_id;
|
||||||
let broadcast_to = broadcast_to.clone();
|
let broadcast_to = broadcast_to.clone();
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
let env = env.clone();
|
let env = env.clone();
|
||||||
spawn_future(async move {
|
if let Some(last) = last {
|
||||||
let top = top
|
spawn_future(async move {
|
||||||
.into_iter()
|
let top = top
|
||||||
.enumerate()
|
.into_iter()
|
||||||
.filter(|(_, s)| Self::is_announceable_date(s.date, last_update, now))
|
.enumerate()
|
||||||
.map(|(rank, score)| {
|
.filter(|(_, s)| Self::is_announceable_date(s.date, last.last_update, now))
|
||||||
CollectedScore::from_top_score(&u, score, mode, rank as u8)
|
.map(|(rank, score)| {
|
||||||
});
|
CollectedScore::from_top_score(&u, score, mode, rank as u8 + 1)
|
||||||
let recents = events
|
});
|
||||||
.into_iter()
|
let recents = events
|
||||||
.map(|e| CollectedScore::from_event(&env.client, &u, e))
|
.into_iter()
|
||||||
.collect::<FuturesUnordered<_>>()
|
.map(|e| CollectedScore::from_event(&env.client, &u, e))
|
||||||
.filter_map(|v| future::ready(v.pls_ok()))
|
.collect::<FuturesUnordered<_>>()
|
||||||
.collect::<Vec<_>>()
|
.filter_map(|v| future::ready(v.pls_ok()))
|
||||||
.await
|
.collect::<Vec<_>>()
|
||||||
.into_iter();
|
.await
|
||||||
top.chain(recents)
|
.into_iter();
|
||||||
.map(|v| v.send_message(&ctx, &env, mention, &broadcast_to))
|
top.chain(recents)
|
||||||
.collect::<FuturesUnordered<_>>()
|
.map(|v| v.send_message(&ctx, &env, mention, &broadcast_to))
|
||||||
.filter_map(|v| future::ready(v.pls_ok().map(|_| ())))
|
.collect::<FuturesUnordered<_>>()
|
||||||
.collect::<()>()
|
.filter_map(|v| future::ready(v.pls_ok().map(|_| ())))
|
||||||
.await
|
.collect::<()>()
|
||||||
});
|
.await
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
user.failures = 0;
|
user.failures = 0;
|
||||||
user
|
user
|
||||||
|
@ -155,10 +156,10 @@ impl Announcer {
|
||||||
|
|
||||||
fn is_announceable_date(
|
fn is_announceable_date(
|
||||||
s: DateTime<Utc>,
|
s: DateTime<Utc>,
|
||||||
last_update: Option<DateTime<Utc>>,
|
last_update: impl Into<Option<DateTime<Utc>>>,
|
||||||
now: DateTime<Utc>,
|
now: DateTime<Utc>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
(match last_update {
|
(match last_update.into() {
|
||||||
Some(lu) => s > lu,
|
Some(lu) => s > lu,
|
||||||
None => true,
|
None => true,
|
||||||
}) && s <= now
|
}) && s <= now
|
||||||
|
@ -303,11 +304,17 @@ impl<'a> CollectedScore<'a> {
|
||||||
&ctx,
|
&ctx,
|
||||||
CreateMessage::new()
|
CreateMessage::new()
|
||||||
.content(match self.kind {
|
.content(match self.kind {
|
||||||
ScoreType::TopRecord(_) => {
|
ScoreType::TopRecord(rank) => {
|
||||||
format!("New top record from {}!", mention.mention())
|
if rank <= 25 {
|
||||||
|
format!("New leaderboard record from {}!", mention.mention())
|
||||||
|
} else {
|
||||||
|
format!("New leaderboard record from **{}**!", member.distinct())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ScoreType::WorldRecord(rank) => {
|
ScoreType::WorldRecord(rank) => {
|
||||||
if rank <= 100 {
|
if (self.mode == Mode::Std && rank <= 100)
|
||||||
|
|| (self.mode != Mode::Std && rank <= 50)
|
||||||
|
{
|
||||||
format!("New leaderboard record from {}!", mention.mention())
|
format!("New leaderboard record from {}!", mention.mention())
|
||||||
} else {
|
} else {
|
||||||
format!("New leaderboard record from **{}**!", member.distinct())
|
format!("New leaderboard record from **{}**!", member.distinct())
|
||||||
|
|
Loading…
Add table
Reference in a new issue