Skip to content

Commit

Permalink
Merge pull request #37 from kozalosev/bugfix/dod/inactive_winners
Browse files Browse the repository at this point in the history
Bugfixes: inactive DoD winners, mentions, zero withheld caption
  • Loading branch information
Leonid Kozarin authored Aug 22, 2024
2 parents 237a465 + 02b1516 commit 3c72d4b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ commands:
empty: "No one is in the game yet :("
dod:
description: "Elect the Dick of a Day"
result: "The Dick of the Day is <b>%{name}</b>!\n\nHis dick has become longer for <b>%{growth} cm</b> and is <b>%{length}</b> cm long now."
result: "The Dick of the Day is <b><a href=\"tg://user?id=%{uid}\">%{name}</a></b>!\n\nHis dick has become longer for <b>%{growth} cm</b> and is <b>%{length}</b> cm long now."
position: "His position in the top is <b>%{pos}</b>."
already_chosen: "The Dick of the Day has been already chosen for today! It's <b>%{name}</b>."
no_candidates: "There is no candidates for election. In this chat nobody is in the game yet 😢"
Expand Down
2 changes: 1 addition & 1 deletion locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ commands:
empty: "Никто пока не участвует в игре :("
dod:
description: "Выбор Писюна Дня"
result: "Пам-пам-пам! Писюн Дня — <b>%{name}</b>!\n\nЕго пиписик вырос на <b>%{growth} см</b> и теперь длиной <b>%{length}</b> см."
result: "Пам-пам-пам! Писюн Дня — <b><a href=\"tg://user?id=%{uid}\">%{name}</a></b>!\n\nЕго пиписик вырос на <b>%{growth} см</b> и теперь длиной <b>%{length}</b> см."
position: "Он занимает <b>%{pos}</b> место в топе."
already_chosen: "Писюн Дня уже был выбран на сегодня! Это <b>%{name}</b>."
no_candidates: "Не из кого выбирать: в этом чате ещё никто не участвует в игре 😢"
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/dod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) async fn dick_of_day_impl(repos: &repo::Repositories, incr: Increment
let main_part = match dod_result {
Ok(Some(repo::GrowthResult{ new_length, pos_in_top })) => {
let answer = t!("commands.dod.result", locale = &lang_code,
name = winner.name.escaped(), growth = increment.total, length = new_length);
uid = winner.uid, name = winner.name.escaped(), growth = increment.total, length = new_length);
let perks_part = increment.perks_part_of_answer(&lang_code);
if let Some(pos) = pos_in_top {
let position = t!("commands.dod.position", locale = &lang_code, pos = pos);
Expand Down
1 change: 1 addition & 0 deletions src/handlers/pvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ async fn pvp_impl_attack(p: BattleParams, initiator: UserId, acceptor: UserInfo,
let (winner_res, withheld_part) = pay_for_loan_if_needed(&p, winner, bet).await
.inspect_err(|e| log::error!("couldn't pay for a loan from a battle award: {e}"))
.ok().flatten()
.filter(|(_, withheld)| *withheld > 0)
.map(|(res, withheld)| {
let withheld_part = format!("\n\n{}", t!("commands.pvp.results.withheld", locale = &p.lang_code, payout = withheld));
(res, withheld_part)
Expand Down
13 changes: 13 additions & 0 deletions src/repo/test/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ async fn get_random_active_member() {
.expect("no active member");
assert_eq!(user.uid, UID);
assert_eq!(user.name.value_ref(), NAME);

// check inactive member is not found
sqlx::query!("DROP TRIGGER IF EXISTS trg_check_and_update_dicks_timestamp ON Dicks")
.execute(&db)
.await.expect("couldn't drop the trigger");
sqlx::query!("UPDATE Dicks SET updated_at = '1997-01-01' WHERE chat_id = (SELECT id FROM Chats WHERE chat_id = $1) AND uid = $2", CHAT_ID, UID)
.execute(&db)
.await.expect("couldn't reset the updated_at column");

let user = users.get_random_active_member(&chat_id)
.await
.expect("couldn't fetch Some(User)");
assert!(user.is_none());
}

fn check_user_with_name(user: &repo::User, name: &str) {
Expand Down
2 changes: 1 addition & 1 deletion src/repo/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repository!(Users,
"SELECT u.uid, name, u.created_at FROM Users u
JOIN Dicks d ON u.uid = d.uid
JOIN Chats c ON d.chat_id = c.id
WHERE c.chat_id = $1::bigint OR c.chat_instance = $1::text
WHERE (c.chat_id = $1::bigint OR c.chat_instance = $1::text)
AND updated_at > current_timestamp - interval '1 week'
ORDER BY random() LIMIT 1",
chat_id.value() as String)
Expand Down

0 comments on commit 3c72d4b

Please sign in to comment.