Skip to content

Commit

Permalink
Merge pull request #5 from kozalosev/bugfix/0.1.4
Browse files Browse the repository at this point in the history
- Fix English translation
- Make the limit of tops configurable
- Fix incorrect top position
- Fix import of names ending with "..."
  • Loading branch information
Leonid Kozarin authored Oct 21, 2023
2 parents 9b57e61 + f5a6969 commit 1d4d635
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GROWTH_MAX=10
GROW_SHRINK_RATIO=0.5
GROWTH_DOD_BONUS_MAX=5
NEWCOMERS_GRACE_DAYS=7
TOP_LIMIT=10

# to enable Webhook Mode, set to a correct URL, proxied by a reverse proxy server
#WEBHOOK_URL=https://your.domain/DickGrowerBot/webhook
14 changes: 7 additions & 7 deletions locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
commands:
grow:
result: "Your dick has been grown by <b>%{incr} cm</b> and now it is <b>%{length} cm</b> long.\nYour position in the top is <b>%{pos}</b>."
tomorrow: "Your dick has been already grown today."
result: "Your dick has grown by <b>%{incr} cm</b> and now it is <b>%{length} cm</b> long.\nYour position in the top is <b>%{pos}</b>."
tomorrow: "You have already played with your dick today."
top:
title: "Top of the biggest dicks:"
line: "%{n}|<b>%{name}</b> — <b>%{length}</b> cm"
Expand All @@ -13,7 +13,7 @@ commands:
import:
result:
titles:
imported: "The following users were imported:"
imported: "The following users have been imported:"
already_present: "The following users were already imported earlier:"
not_found: "The following users are not in the game yet:"
line:
Expand All @@ -29,16 +29,16 @@ commands:
promo:
success:
template: "You has activated this promo code successfully! %{ending}"
singular: "Your dick in one chat was grown by %{growth} cm"
plural: "Your dicks in %{affected_chats} chats were grown by %{growth} cm"
singular: "Your dick has grown by %{growth} cm in one chat."
plural: "Your dick has grown by %{growth} cm in %{affected_chats} chats!"
errors:
no_promo: "I'm so sorry but this promo code either does not exist at all, or expired, or exhausted 😞"
already_activated: "It seems you had already used this promocode earlier 🤨"
already_activated: "It seems you already used this promocode earlier 🤨"
no_dicks: "It seems you don't have any dicks yet. 🤔 Right now is the time to add me into a chat and execute the <code>/grow</code> command!"
titles:
greeting: "Hello"
time_till_next_day:
none: " Come back tomorrow!"
some: "\n\nThe next attempt in <b>%{hours}</b>h <b>%{minutes}</b>m."
some: "\nNext attempt in <b>%{hours}</b>h <b>%{minutes}</b>m."
errors:
not_group_chat: "This bot is supposed to do its mission in group chats only! <i>(for the testing period: in a specific list of chats)</i>"
2 changes: 1 addition & 1 deletion locales/ru.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
commands:
grow:
result: "Твоя пися выросла на %{incr} см и теперь её длина составляет %{length} см.\nТы занимаешь %{pos} место в топе."
tomorrow: "Ты уже растил пиписю сегодня."
tomorrow: "Ты уже играл с пиписей сегодня."
top:
title: "Топ самых больших пиписек:"
line: "%{n}|<b>%{name}</b> — <b>%{length}</b> см"
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct AppConfig {
pub grow_shrink_ratio: f32,
pub dod_bonus_range: RangeInclusive<u32>,
pub newcomers_grace_days: u32,
pub top_limit: u32,
}

#[derive(Clone)]
Expand All @@ -26,11 +27,13 @@ impl AppConfig {
let grow_shrink_ratio = get_value_or_default("GROW_SHRINK_RATIO", 0.5);
let max_dod_bonus = get_value_or_default("GROWTH_DOD_BONUS_MAX", 5);
let newcomers_grace_days = get_value_or_default("NEWCOMERS_GRACE_DAYS", 7);
let top_limit = get_value_or_default("TOP_LIMIT", 10);
Self {
growth_range: min..=max,
grow_shrink_ratio,
dod_bonus_range: 1..=max_dod_bonus,
newcomers_grace_days,
top_limit,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/dick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub async fn dick_cmd_handler(bot: Bot, msg: Message, cmd: DickCommands,

let lang_code = ensure_lang_code(msg.from());
let title = t!("commands.top.title", locale = &lang_code);
let lines = repos.dicks.get_top(msg.chat.id)
let lines = repos.dicks.get_top(msg.chat.id, config.top_limit)
.await?
.iter().enumerate()
.map(|(i, d)| {
Expand Down
12 changes: 7 additions & 5 deletions src/handlers/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{metrics, repo};
const ORIGINAL_BOT_USERNAMES: [&str; 2] = ["pipisabot", "kraft28_bot"];

static TOP_LINE_REGEXP: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"\d{1,3}((\. )|\|)(?<name>.+)(\.{3})? — (?<length>\d+) см.")
Regex::new(r"\d{1,3}((\. )|\|)(?<name>.+?)(\.{3})? — (?<length>\d+) см.")
.expect("TOP_LINE_REGEXP is invalid")
});

Expand Down Expand Up @@ -116,19 +116,21 @@ pub async fn import_cmd_handler(bot: Bot, msg: Message, repos: repo::Repositorie
metrics::CMD_IMPORT.finished();
let imported = r.imported.into_iter()
.map(|u| t!("commands.import.result.line.imported",
name = u.name, length = u.length,
name = teloxide::utils::html::escape(&u.name),
length = u.length,
locale = &lang_code))
.collect::<Vec<String>>()
.join("\n");
let already_present = r.already_present.into_iter()
.map(|u| t!("commands.import.result.line.already_present",
name = u.name, length = u.length,
name = teloxide::utils::html::escape(&u.name),
length = u.length,
locale = &lang_code))
.collect::<Vec<String>>()
.join("\n");
let not_found = r.not_found.into_iter()
.map(|name| t!("commands.import.result.line.not_found",
name = name,
name = teloxide::utils::html::escape(&name),
locale = &lang_code))
.collect::<Vec<String>>()
.join("\n");
Expand Down Expand Up @@ -199,7 +201,7 @@ async fn check_and_parse_message(bot: &Bot, msg: &Message) -> Result<ParseResult
}

fn check_reply_source_and_text(reply: &Message) -> Option<ParseResult> {
reply.from().clone()
reply.from().as_ref()
.filter(|u| u.is_bot)
.and_then(|u| u.username.as_ref())
.filter(|name| ORIGINAL_BOT_USERNAMES.contains(&name.as_ref()))
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod tests {
fn get_time_till_next_day_string() {
let expected = "<b>1</b>h <b>49</b>m.";
let actual = date::get_time_till_next_day_string("en");
let actual = &actual[expected.len()+1..];
let actual = &actual[actual.len()-expected.len()..];
assert_eq!(expected, actual)
}
}
16 changes: 7 additions & 9 deletions src/repo/dicks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ repository!(Dicks,
Ok(GrowthResult { new_length, pos_in_top })
}
,
pub async fn get_top(&self, chat_id: ChatId) -> anyhow::Result<Vec<Dick>, sqlx::Error> {
sqlx::query_as::<_, Dick>("SELECT length, name as owner_name FROM dicks d JOIN users u ON u.uid = d.uid WHERE chat_id = $1 ORDER BY length DESC LIMIT 10")
pub async fn get_top(&self, chat_id: ChatId, limit: u32) -> anyhow::Result<Vec<Dick>, sqlx::Error> {
sqlx::query_as::<_, Dick>("SELECT length, name as owner_name FROM dicks d JOIN users u ON u.uid = d.uid WHERE chat_id = $1 ORDER BY length DESC LIMIT $2")
.bind(chat_id.0)
.bind(limit as i32)
.fetch_all(&self.pool)
.await
}
Expand All @@ -47,13 +48,10 @@ repository!(Dicks,
}
,
async fn get_position_in_top(&self, chat_id: ChatId, uid: i64) -> anyhow::Result<i64> {
sqlx::query("
WITH top AS (
SELECT chat_id, uid, length FROM dicks WHERE chat_id = $1
) SELECT
ROW_NUMBER() OVER(ORDER BY top.length DESC) as position
FROM top
WHERE uid = $2")
sqlx::query("SELECT position FROM (
SELECT uid, ROW_NUMBER() OVER (ORDER BY length DESC) AS position
FROM dicks WHERE chat_id = $1) AS _
WHERE uid = $2")
.bind(chat_id.0)
.bind(uid)
.fetch_one(&self.pool)
Expand Down

0 comments on commit 1d4d635

Please sign in to comment.