Files
desubot/src/commands.rs
2020-12-07 15:55:25 +03:00

35 lines
1.2 KiB
Rust

use crate::db;
use html_escape::encode_text;
use telegram_bot::prelude::*;
use telegram_bot::{Api, Error, Message, ParseMode, };
pub(crate) async fn here(api: Api, message: Message) -> Result<(), Error> {
let members: Vec<telegram_bot::User> = db::get_members(message.chat.id()).unwrap();
for u in &members {
debug!("Found user {:?}", u);
}
let mut msg = "<b>I summon you</b>, ".to_string();
for user in members {
let mention = match user.username {
Some(username) => format!("@{}", username),
_ => format!(
"<a href=\"tg://user?id={}\">{}</a>",
encode_text(&user.id.to_string()),
encode_text(&user.first_name)
),
};
msg = format!("{} {}", msg, mention);
}
match api
.send(message.text_reply(msg).parse_mode(ParseMode::Html))
.await
{
Ok(_) => debug!("@here command sent to {}", message.from.id),
Err(_) => warn!("@here command sent failed to {}", message.from.id),
}
//api.send(message.chat.text("Text to message chat")).await?;
//api.send(message.from.text("Private text")).await?;
Ok(())
}