make it pretty
This commit is contained in:
parent
a89496676b
commit
f34fc54b3a
@ -95,8 +95,17 @@ impl CommandHandler {
|
||||
bot: &Bot,
|
||||
message: &Message,
|
||||
) -> Result<JsonRequest<SendMessage>, Box<dyn Error + Send + Sync>> {
|
||||
if let Some(reply) = message.reply_to_message() {
|
||||
if let Some(user) = reply.from() {
|
||||
let reply = match message.reply_to_message() {
|
||||
Some(reply) => reply,
|
||||
None => {
|
||||
return Ok(self
|
||||
.send_text_reply(bot, message, BOT_TEXT_NO_TARGET.to_string())
|
||||
.await)
|
||||
}
|
||||
};
|
||||
|
||||
match reply.from() {
|
||||
Some(user) => {
|
||||
let mut vars = HashMap::new();
|
||||
let index = OsRng.gen::<usize>() % BOT_TEXT_HANGED.len();
|
||||
let text = BOT_TEXT_HANGED[index];
|
||||
@ -110,15 +119,10 @@ impl CommandHandler {
|
||||
Ok(self
|
||||
.send_text_reply(bot, reply, escape(&text.format(&vars).unwrap()))
|
||||
.await)
|
||||
} else {
|
||||
Ok(self
|
||||
.send_text_reply(bot, message, BOT_TEXT_IS_CHANNEL.to_string())
|
||||
.await)
|
||||
}
|
||||
} else {
|
||||
Ok(self
|
||||
.send_text_reply(bot, message, BOT_TEXT_NO_TARGET.to_string())
|
||||
.await)
|
||||
None => Ok(self
|
||||
.send_text_reply(bot, message, BOT_TEXT_IS_CHANNEL.to_string())
|
||||
.await),
|
||||
}
|
||||
}
|
||||
|
||||
|
21
src/main.rs
21
src/main.rs
@ -38,15 +38,7 @@ async fn main() {
|
||||
let bot = Bot::new(args.tgbot_token.to_owned())
|
||||
.set_api_url(reqwest::Url::parse(&args.api_url.as_str()).unwrap());
|
||||
|
||||
match bot.get_me().send().await {
|
||||
Ok(result) => log_info_ln!(
|
||||
"connect succeed: id={}, botname=\"{}\"",
|
||||
result.id,
|
||||
result.username()
|
||||
),
|
||||
Err(error) => log_panic!("{}", error),
|
||||
}
|
||||
|
||||
get_me(&bot).await;
|
||||
register_commands(&bot).await;
|
||||
|
||||
Commands::repl(bot, move |bot: Bot, message: Message, cmd: Commands| {
|
||||
@ -71,3 +63,14 @@ async fn register_commands(bot: &Bot) {
|
||||
log_info_ln!("commands registered")
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_me(bot: &Bot) {
|
||||
match bot.get_me().send().await {
|
||||
Ok(result) => log_info_ln!(
|
||||
"connect succeed: id={}, botname=\"{}\"",
|
||||
result.id,
|
||||
result.username()
|
||||
),
|
||||
Err(error) => log_panic!("{}", error),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user