mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-20 13:59:00 +01:00
Use std::error::Error
instead of anyhow
in the examples
This commit is contained in:
parent
f5653c747d
commit
3075dfd8ac
2 changed files with 6 additions and 10 deletions
|
@ -89,7 +89,6 @@ bincode = { version = "1.3", optional = true }
|
||||||
rand = "0.8.3"
|
rand = "0.8.3"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
once_cell = "1.9.0"
|
once_cell = "1.9.0"
|
||||||
anyhow = "1.0.52"
|
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
tokio = { version = "1.8", features = ["fs", "rt-multi-thread", "macros"] }
|
tokio = { version = "1.8", features = ["fs", "rt-multi-thread", "macros"] }
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
use teloxide::{dispatching::dialogue::InMemStorage, macros::DialogueState, prelude::*};
|
use teloxide::{dispatching::dialogue::InMemStorage, macros::DialogueState, prelude::*};
|
||||||
|
|
||||||
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
|
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
#[derive(DialogueState, Clone)]
|
#[derive(DialogueState, Clone)]
|
||||||
#[handler_out(anyhow::Result<()>)]
|
#[handler_out(HandlerResult)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
#[handler(handle_start)]
|
#[handler(handle_start)]
|
||||||
Start,
|
Start,
|
||||||
|
@ -59,11 +60,7 @@ async fn main() {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_start(
|
async fn handle_start(bot: AutoSend<Bot>, msg: Message, dialogue: MyDialogue) -> HandlerResult {
|
||||||
bot: AutoSend<Bot>,
|
|
||||||
msg: Message,
|
|
||||||
dialogue: MyDialogue,
|
|
||||||
) -> 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(())
|
||||||
|
@ -73,7 +70,7 @@ async fn handle_receive_full_name(
|
||||||
bot: AutoSend<Bot>,
|
bot: AutoSend<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
dialogue: MyDialogue,
|
dialogue: MyDialogue,
|
||||||
) -> anyhow::Result<()> {
|
) -> HandlerResult {
|
||||||
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?;
|
||||||
|
@ -92,7 +89,7 @@ async fn handle_receive_age(
|
||||||
msg: Message,
|
msg: Message,
|
||||||
dialogue: MyDialogue,
|
dialogue: MyDialogue,
|
||||||
(full_name,): (String,), // Available from `State::ReceiveAge`.
|
(full_name,): (String,), // Available from `State::ReceiveAge`.
|
||||||
) -> anyhow::Result<()> {
|
) -> HandlerResult {
|
||||||
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?;
|
||||||
|
@ -111,7 +108,7 @@ async fn handle_receive_location(
|
||||||
msg: Message,
|
msg: Message,
|
||||||
dialogue: MyDialogue,
|
dialogue: MyDialogue,
|
||||||
(full_name, age): (String, u8), // Available from `State::ReceiveLocation`.
|
(full_name, age): (String, u8), // Available from `State::ReceiveLocation`.
|
||||||
) -> anyhow::Result<()> {
|
) -> HandlerResult {
|
||||||
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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue