Add util function for captions
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
054e413099
commit
448fabe013
|
@ -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()
|
||||
|
|
|
@ -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"\_")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue