Add util function for captions

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-02-23 12:15:43 +05:30
parent 054e413099
commit 448fabe013
No known key found for this signature in database
GPG Key ID: B7843F823355E9B9
2 changed files with 6 additions and 6 deletions

View File

@ -8,7 +8,7 @@ use rand::{thread_rng, Rng};
use std::env;
use walkdir::WalkDir;
use utils::escape_markdown_str;
use utils::file_name_to_label;
use utils::join_results_to_string;
lazy_static! {
@ -52,11 +52,7 @@ async fn answer(
let file = get_random_file();
let link = format!("{}/{}", *BASE_URL, file);
cx.answer_photo(InputFile::url(&link))
.caption(format!(
"[{}]({})",
&escape_markdown_str(file).replace(".jpg", ""),
link
))
.caption(format!("[{}]({})", &file_name_to_label(file), link))
.parse_mode(ParseMode::MarkdownV2)
.reply_to_message_id(cx.update.id)
.send()

View File

@ -1,3 +1,7 @@
pub(crate) fn file_name_to_label(msg: String) -> String {
escape_markdown_str(msg).replace(r"\_", " ").replace(".jpg", "")
}
pub(crate) fn escape_markdown_str(msg: String) -> String {
msg.replace("_", r"\_")
}