From d923b2a04e635f9c445357822f8fd96e2346c9c4 Mon Sep 17 00:00:00 2001 From: akorchyn Date: Mon, 28 Oct 2024 17:34:18 +0200 Subject: [PATCH] updated messages with reward info --- Messages.staging.toml | 4 ++-- Messages.toml | 4 ++-- bot/src/messages.rs | 46 ++++++++++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Messages.staging.toml b/Messages.staging.toml index 0764a20..7b54694 100644 --- a/Messages.staging.toml +++ b/Messages.staging.toml @@ -49,7 +49,7 @@ For contributors: - Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username}) For maintainers: -- Score pull requests that participate in the Race of Sloths +- Score pull requests that participate in the Race of Sloths and receive a reward - Engage contributors with fair scoring and fast responses so they keep their streaks - Promote the Race to the point where the Race starts promoting you - Grow the community of your contributors @@ -251,7 +251,7 @@ For contributors: - Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username}) For maintainers: -- Score pull requests that participate in the Race of Sloths +- Score pull requests that participate in the Race of Sloths and receive a reward - Engage contributors with fair scoring and fast responses so they keep their streaks - Promote the Race to the point where the Race starts promoting you - Grow the community of your contributors diff --git a/Messages.toml b/Messages.toml index 00455b1..707b533 100644 --- a/Messages.toml +++ b/Messages.toml @@ -47,7 +47,7 @@ For contributors: - Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username}) For maintainers: -- Score pull requests that participate in the Race of Sloths +- Score pull requests that participate in the Race of Sloths and receive a reward - Engage contributors with fair scoring and fast responses so they keep their streaks - Promote the Race to the point where the Race starts promoting you - Grow the community of your contributors @@ -251,7 +251,7 @@ For contributors: - Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username}) For maintainers: -- Score pull requests that participate in the Race of Sloths +- Score pull requests that participate in the Race of Sloths and receive a reward - Engage contributors with fair scoring and fast responses so they keep their streaks - Promote the Race to the point where the Race starts promoting you - Grow the community of your contributors diff --git a/bot/src/messages.rs b/bot/src/messages.rs index 110092a..254c7e4 100644 --- a/bot/src/messages.rs +++ b/bot/src/messages.rs @@ -2,7 +2,7 @@ use rand::seq::SliceRandom; use rand::thread_rng; use serde::{Deserialize, Serialize}; use shared::github::PrMetadata; -use shared::{PRInfo, TimePeriod, User}; +use shared::{PRInfo, Score, TimePeriod, User}; use std::collections::{HashMap, HashSet}; use std::fs; use std::ops::Add; @@ -387,18 +387,19 @@ impl MessageLoader { anyhow::anyhow!("Constraint violation: final_data is None for executed PR") })?; message.push_str("\n\n"); - message.push_str(&self.final_message(final_data)?) + message.push_str(&self.final_message(final_data, bot_name, check_info.votes.clone())?) } else if !check_info.votes.is_empty() { let score = check_info.average_score(); message.push_str("\n\n"); let rating = rating_breakthrough(score * 10, score, 0, 0, 0); - let final_common = self.get_message(MsgCategory::RatingMessagesCommon).format( - [("score", score.to_string()), ("rating", rating)] - .into_iter() - .collect(), + let rating_message = self.rating_message( + score.to_string(), + rating, + check_info.votes.clone(), + bot_name, )?; message.push_str("\n\n"); - message.push_str(&final_common); + message.push_str(&rating_message); } message.push_str("\n"); @@ -406,6 +407,29 @@ impl MessageLoader { Ok(message) } + fn rating_message( + &self, + score: String, + rating: String, + scorers: Vec, + bot_name: &str, + ) -> anyhow::Result { + let mut message = self + .get_message(MsgCategory::RatingMessagesCommon) + .format([("score", score), ("rating", rating)].into_iter().collect())?; + + for scorer in scorers { + if scorer.user != bot_name { + message.push_str(&format!( + "\n@{} received 25 Sloth Points for reviewing and scoring this pull request.", + bot_name + )); + } + } + + Ok(message) + } + fn user_specific_message(&self, user: &User) -> String { let timestamp = chrono::Utc::now().timestamp_nanos_opt().unwrap_or_default() as u64; let current_period = TimePeriod::Month.time_string(timestamp); @@ -484,6 +508,8 @@ impl MessageLoader { total_lifetime_percent, pr_number_this_week, }: FinalMessageData, + bot_name: &str, + scorers: Vec, ) -> anyhow::Result { let rating = rating_breakthrough( total_rating, @@ -492,11 +518,7 @@ impl MessageLoader { monthly_streak_bonus, total_lifetime_percent, ); - let final_common = self.get_message(MsgCategory::RatingMessagesCommon).format( - [("score", score.to_string()), ("rating", rating)] - .into_iter() - .collect(), - )?; + let final_common = self.rating_message(score.to_string(), rating, scorers, bot_name)?; let optional_message = if lifetime_percent_reward > 0 && total_lifetime_percent > 5 { let rank: &str = match total_lifetime_percent {