.chat_id() => .chat.id

This commit is contained in:
Hirrolot 2022-02-04 19:45:35 +06:00
parent ec9f701cf7
commit 5a00e970e4
4 changed files with 26 additions and 26 deletions

View file

@ -238,7 +238,7 @@ async fn handle_start(
msg: Message, msg: Message,
dialogue: MyDialogue, dialogue: MyDialogue,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
bot.send_message(msg.chat_id(), "Let's start! What's your full name?").await?; bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?;
dialogue.update(State::ReceiveFullName).await?; dialogue.update(State::ReceiveFullName).await?;
Ok(()) Ok(())
} }
@ -250,11 +250,11 @@ async fn handle_receive_full_name(
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match msg.text() { match msg.text() {
Some(text) => { Some(text) => {
bot.send_message(msg.chat_id(), "How old are you?").await?; bot.send_message(msg.chat.id, "How old are you?").await?;
dialogue.update(State::ReceiveAge { full_name: text.into() }).await?; dialogue.update(State::ReceiveAge { full_name: text.into() }).await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me plain text.").await?; bot.send_message(msg.chat.id, "Send me plain text.").await?;
} }
} }
@ -269,11 +269,11 @@ async fn handle_receive_age(
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match msg.text().map(|text| text.parse::<u8>()) { match msg.text().map(|text| text.parse::<u8>()) {
Some(Ok(age)) => { Some(Ok(age)) => {
bot.send_message(msg.chat_id(), "What's your location?").await?; bot.send_message(msg.chat.id, "What's your location?").await?;
dialogue.update(State::ReceiveLocation { full_name, age }).await?; dialogue.update(State::ReceiveLocation { full_name, age }).await?;
} }
_ => { _ => {
bot.send_message(msg.chat_id(), "Send me a number.").await?; bot.send_message(msg.chat.id, "Send me a number.").await?;
} }
} }
@ -289,11 +289,11 @@ async fn handle_receive_location(
match msg.text() { match msg.text() {
Some(location) => { Some(location) => {
let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location); let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location);
bot.send_message(msg.chat_id(), message).await?; bot.send_message(msg.chat.id, message).await?;
dialogue.exit().await?; dialogue.exit().await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me plain text.").await?; bot.send_message(msg.chat.id, "Send me plain text.").await?;
} }
} }

View file

@ -69,10 +69,10 @@ async fn kick_user(bot: Bot, msg: Message) -> Result<(), Box<dyn Error + Send +
match msg.reply_to_message() { match msg.reply_to_message() {
Some(replied) => { Some(replied) => {
// bot.unban_chat_member can also kicks a user from a group chat. // bot.unban_chat_member can also kicks a user from a group chat.
bot.unban_chat_member(msg.chat_id(), replied.from().unwrap().id).await?; bot.unban_chat_member(msg.chat.id, replied.from().unwrap().id).await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Use this command in reply to another message").await?; bot.send_message(msg.chat.id, "Use this command in reply to another message").await?;
} }
} }
Ok(()) Ok(())
@ -87,7 +87,7 @@ async fn mute_user(
match msg.reply_to_message() { match msg.reply_to_message() {
Some(replied) => { Some(replied) => {
bot.restrict_chat_member( bot.restrict_chat_member(
msg.chat_id(), msg.chat.id,
replied.from().expect("Must be MessageKind::Common").id, replied.from().expect("Must be MessageKind::Common").id,
ChatPermissions::empty(), ChatPermissions::empty(),
) )
@ -95,7 +95,7 @@ async fn mute_user(
.await?; .await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Use this command in a reply to another message!") bot.send_message(msg.chat.id, "Use this command in a reply to another message!")
.await?; .await?;
} }
} }
@ -111,14 +111,14 @@ async fn ban_user(
match msg.reply_to_message() { match msg.reply_to_message() {
Some(replied) => { Some(replied) => {
bot.kick_chat_member( bot.kick_chat_member(
msg.chat_id(), msg.chat.id,
replied.from().expect("Must be MessageKind::Common").id, replied.from().expect("Must be MessageKind::Common").id,
) )
.until_date(msg.date + time) .until_date(msg.date + time)
.await?; .await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Use this command in a reply to another message!") bot.send_message(msg.chat.id, "Use this command in a reply to another message!")
.await?; .await?;
} }
} }
@ -132,7 +132,7 @@ async fn action(
) -> Result<(), Box<dyn Error + Send + Sync>> { ) -> Result<(), Box<dyn Error + Send + Sync>> {
match command { match command {
Command::Help => { Command::Help => {
bot.send_message(msg.chat_id(), Command::descriptions()).await?; bot.send_message(msg.chat.id, Command::descriptions()).await?;
} }
Command::Kick => kick_user(bot, msg).await?, Command::Kick => kick_user(bot, msg).await?,
Command::Ban { time, unit } => ban_user(bot, msg, calc_restrict_time(time, unit)).await?, Command::Ban { time, unit } => ban_user(bot, msg, calc_restrict_time(time, unit)).await?,

View file

@ -64,7 +64,7 @@ async fn handle_start(
msg: Message, msg: Message,
dialogue: MyDialogue, dialogue: MyDialogue,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
bot.send_message(msg.chat_id(), "Let's start! What's your full name?").await?; bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?;
dialogue.update(State::ReceiveFullName).await?; dialogue.update(State::ReceiveFullName).await?;
Ok(()) Ok(())
} }
@ -76,11 +76,11 @@ async fn handle_receive_full_name(
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match msg.text() { match msg.text() {
Some(text) => { Some(text) => {
bot.send_message(msg.chat_id(), "How old are you?").await?; bot.send_message(msg.chat.id, "How old are you?").await?;
dialogue.update(State::ReceiveAge { full_name: text.into() }).await?; dialogue.update(State::ReceiveAge { full_name: text.into() }).await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me plain text.").await?; bot.send_message(msg.chat.id, "Send me plain text.").await?;
} }
} }
@ -95,11 +95,11 @@ async fn handle_receive_age(
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match msg.text().map(|text| text.parse::<u8>()) { match msg.text().map(|text| text.parse::<u8>()) {
Some(Ok(age)) => { Some(Ok(age)) => {
bot.send_message(msg.chat_id(), "What's your location?").await?; bot.send_message(msg.chat.id, "What's your location?").await?;
dialogue.update(State::ReceiveLocation { full_name, age }).await?; dialogue.update(State::ReceiveLocation { full_name, age }).await?;
} }
_ => { _ => {
bot.send_message(msg.chat_id(), "Send me a number.").await?; bot.send_message(msg.chat.id, "Send me a number.").await?;
} }
} }
@ -115,11 +115,11 @@ async fn handle_receive_location(
match msg.text() { match msg.text() {
Some(location) => { Some(location) => {
let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location); let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location);
bot.send_message(msg.chat_id(), message).await?; bot.send_message(msg.chat.id, message).await?;
dialogue.exit().await?; dialogue.exit().await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me plain text.").await?; bot.send_message(msg.chat.id, "Send me plain text.").await?;
} }
} }

View file

@ -43,15 +43,15 @@
//! match msg.text() { //! match msg.text() {
//! Some(number) => match number.parse::<u8>() { //! Some(number) => match number.parse::<u8>() {
//! Ok(age) => { //! Ok(age) => {
//! bot.send_message(msg.chat_id(), "What's your location?").await?; //! bot.send_message(msg.chat.id, "What's your location?").await?;
//! dialogue.update(State::ReceiveLocation { full_name, age }).await?; //! dialogue.update(State::ReceiveLocation { full_name, age }).await?;
//! } //! }
//! _ => { //! _ => {
//! bot.send_message(msg.chat_id(), "Send me a number.").await?; //! bot.send_message(msg.chat.id, "Send me a number.").await?;
//! } //! }
//! }, //! },
//! None => { //! None => {
//! bot.send_message(msg.chat_id(), "Send me a text message.").await?; //! bot.send_message(msg.chat.id, "Send me a text message.").await?;
//! } //! }
//! } //! }
//! //!
@ -76,11 +76,11 @@
//! Some(location) => { //! Some(location) => {
//! let message = //! let message =
//! format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location); //! format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location);
//! bot.send_message(msg.chat_id(), message).await?; //! bot.send_message(msg.chat.id, message).await?;
//! dialogue.exit().await?; //! dialogue.exit().await?;
//! } //! }
//! None => { //! None => {
//! bot.send_message(msg.chat_id(), "Send me a text message.").await?; //! bot.send_message(msg.chat.id, "Send me a text message.").await?;
//! } //! }
//! } //! }
//! //!