Rename command and add Markdown backed caption

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-02-20 22:49:14 +05:30
parent 9a61b8bf50
commit a7cb0a0939
No known key found for this signature in database
GPG Key ID: B7843F823355E9B9
1 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
use teloxide::types::InputFile;
use teloxide::types::{InputFile, ParseMode};
use teloxide::{prelude::*, utils::command::BotCommand};
use lazy_static::lazy_static;
@ -19,23 +19,23 @@ enum Command {
#[command(description = "display this text.")]
Help,
#[command(description = "Return a random picture")]
Pic,
Random,
}
async fn get_random_file() -> String {
let num = thread_rng().gen_range(0, *FILE_COUNT);
FILES.get(num).unwrap().clone()
FILES.get(thread_rng().gen_range(0, *FILE_COUNT)).unwrap().clone()
}
async fn answer(cx: DispatcherHandlerCx<Message>, command: Command) -> ResponseResult<()> {
match command {
Command::Help => cx.answer(Command::descriptions()).send().await?,
Command::Pic => {
cx.answer_photo(InputFile::url(format!(
"{}/{}",
*BASE_URL,
get_random_file().await
)))
Command::Random => {
let file = get_random_file().await;
let link = format!("{}/{}", *BASE_URL, file);
cx.answer_photo(InputFile::url(&link))
.caption(format!("[{}]({})", &file.replace(".jpg", ""), link))
.parse_mode(ParseMode::MarkdownV2)
.reply_to_message_id(cx.update.id)
.send()
.await?
}