diff --git a/.sqlx/query-592e4ff3dd3a6463e1b57005fb476eab7000dabb1675138b2af8148081f541b5.json b/.sqlx/query-6b411f90d3986ddaa5dcd5d118e7f1d5ab5e712c04a59749b2083884b8490e4d.json
similarity index 67%
rename from .sqlx/query-592e4ff3dd3a6463e1b57005fb476eab7000dabb1675138b2af8148081f541b5.json
rename to .sqlx/query-6b411f90d3986ddaa5dcd5d118e7f1d5ab5e712c04a59749b2083884b8490e4d.json
index 999501d..bf26f90 100644
--- a/.sqlx/query-592e4ff3dd3a6463e1b57005fb476eab7000dabb1675138b2af8148081f541b5.json
+++ b/.sqlx/query-6b411f90d3986ddaa5dcd5d118e7f1d5ab5e712c04a59749b2083884b8490e4d.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "SELECT u.uid, name, u.created_at FROM Users u\n JOIN Dicks d ON u.uid = d.uid\n JOIN Chats c ON d.chat_id = c.id\n WHERE c.chat_id = $1::bigint OR c.chat_instance = $1::text\n AND updated_at > current_timestamp - interval '1 week'\n ORDER BY random() LIMIT 1",
+ "query": "SELECT u.uid, name, u.created_at FROM Users u\n JOIN Dicks d ON u.uid = d.uid\n JOIN Chats c ON d.chat_id = c.id\n WHERE (c.chat_id = $1::bigint OR c.chat_instance = $1::text)\n AND updated_at > current_timestamp - interval '1 week'\n ORDER BY random() LIMIT 1",
"describe": {
"columns": [
{
@@ -30,5 +30,5 @@
false
]
},
- "hash": "592e4ff3dd3a6463e1b57005fb476eab7000dabb1675138b2af8148081f541b5"
+ "hash": "6b411f90d3986ddaa5dcd5d118e7f1d5ab5e712c04a59749b2083884b8490e4d"
}
diff --git a/.sqlx/query-9cfa8866550d42d7939ba4de939a5fe4afb32dc120c3974d8d2c8e2f7b36f64b.json b/.sqlx/query-9cfa8866550d42d7939ba4de939a5fe4afb32dc120c3974d8d2c8e2f7b36f64b.json
new file mode 100644
index 0000000..610fc73
--- /dev/null
+++ b/.sqlx/query-9cfa8866550d42d7939ba4de939a5fe4afb32dc120c3974d8d2c8e2f7b36f64b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE Dicks SET updated_at = '1997-01-01' WHERE chat_id = (SELECT id FROM Chats WHERE chat_id = $1) AND uid = $2",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "9cfa8866550d42d7939ba4de939a5fe4afb32dc120c3974d8d2c8e2f7b36f64b"
+}
diff --git a/locales/en.yml b/locales/en.yml
index 9295e9d..22b126e 100644
--- a/locales/en.yml
+++ b/locales/en.yml
@@ -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 %{name}!\n\nHis dick has become longer for %{growth} cm and is %{length} cm long now."
+ result: "The Dick of the Day is %{name}!\n\nHis dick has become longer for %{growth} cm and is %{length} cm long now."
position: "His position in the top is %{pos}."
already_chosen: "The Dick of the Day has been already chosen for today! It's %{name}."
no_candidates: "There is no candidates for election. In this chat nobody is in the game yet 😢"
diff --git a/locales/ru.yml b/locales/ru.yml
index 2f9de42..a016578 100644
--- a/locales/ru.yml
+++ b/locales/ru.yml
@@ -19,7 +19,7 @@ commands:
empty: "Никто пока не участвует в игре :("
dod:
description: "Выбор Писюна Дня"
- result: "Пам-пам-пам! Писюн Дня — %{name}!\n\nЕго пиписик вырос на %{growth} см и теперь длиной %{length} см."
+ result: "Пам-пам-пам! Писюн Дня — %{name}!\n\nЕго пиписик вырос на %{growth} см и теперь длиной %{length} см."
position: "Он занимает %{pos} место в топе."
already_chosen: "Писюн Дня уже был выбран на сегодня! Это %{name}."
no_candidates: "Не из кого выбирать: в этом чате ещё никто не участвует в игре 😢"
diff --git a/src/handlers/dod.rs b/src/handlers/dod.rs
index f03c3bf..074ef63 100644
--- a/src/handlers/dod.rs
+++ b/src/handlers/dod.rs
@@ -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);
diff --git a/src/handlers/pvp.rs b/src/handlers/pvp.rs
index b57cbdd..974c553 100644
--- a/src/handlers/pvp.rs
+++ b/src/handlers/pvp.rs
@@ -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)
diff --git a/src/repo/test/users.rs b/src/repo/test/users.rs
index 50ad359..782c931 100644
--- a/src/repo/test/users.rs
+++ b/src/repo/test/users.rs
@@ -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) {
diff --git a/src/repo/users.rs b/src/repo/users.rs
index ab24186..cde1e8b 100644
--- a/src/repo/users.rs
+++ b/src/repo/users.rs
@@ -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)