mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
Small refinements
This commit is contained in:
parent
b255dfaf61
commit
71f38bcb92
6 changed files with 34 additions and 35 deletions
|
@ -53,8 +53,7 @@ serde_with_macros = "1.1.0"
|
||||||
redis = { version = "0.16.0", optional = true }
|
redis = { version = "0.16.0", optional = true }
|
||||||
serde_cbor = { version = "0.11.1", optional = true }
|
serde_cbor = { version = "0.11.1", optional = true }
|
||||||
bincode = { version = "1.3.1", optional = true }
|
bincode = { version = "1.3.1", optional = true }
|
||||||
#frunk = { git = "https://github.com/Hirrolot/frunk", branch = "append-to-hlist", optional = true }
|
frunk = { git = "https://github.com/Hirrolot/frunk", branch = "append-to-hlist", optional = true }
|
||||||
frunk = { path = "../../Desktop/frunk", optional = true }
|
|
||||||
|
|
||||||
#teloxide-macros = "0.3.1"
|
#teloxide-macros = "0.3.1"
|
||||||
teloxide-macros = { git = "http://github.com/teloxide/teloxide-macros", branch = "master" }
|
teloxide-macros = { git = "http://github.com/teloxide/teloxide-macros", branch = "master" }
|
||||||
|
|
19
README.md
19
README.md
|
@ -295,6 +295,8 @@ Finally, the `main` function looks like this:
|
||||||
```rust
|
```rust
|
||||||
// Imports are omitted...
|
// Imports are omitted...
|
||||||
|
|
||||||
|
type In = DialogueWithCx<Message, Dialogue, Infallible>;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
teloxide::enable_logging!();
|
teloxide::enable_logging!();
|
||||||
|
@ -303,17 +305,12 @@ async fn main() {
|
||||||
let bot = Bot::from_env();
|
let bot = Bot::from_env();
|
||||||
|
|
||||||
Dispatcher::new(bot)
|
Dispatcher::new(bot)
|
||||||
.messages_handler(DialogueDispatcher::new(
|
.messages_handler(DialogueDispatcher::new(|input: In| async move {
|
||||||
|input: DialogueWithCx<Message, Dialogue, Infallible>| async move {
|
// No panic because of std::convert::Infallible.
|
||||||
// Unwrap without panic because of std::convert::Infallible.
|
let (cx, dialogue) = input.unpack();
|
||||||
input
|
|
||||||
.dialogue
|
dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||||
.unwrap()
|
}))
|
||||||
.react(input.cx)
|
|
||||||
.await
|
|
||||||
.expect("Something wrong with the bot!")
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.dispatch()
|
.dispatch()
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,15 @@ edition = "2018"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
tokio = "0.2.9"
|
tokio = "0.2.9"
|
||||||
|
|
||||||
frunk = { path = "../../../../Desktop/frunk" }
|
frunk = { git = "https://github.com/Hirrolot/frunk", branch = "append-to-hlist" }
|
||||||
frunk_core = { path = "../../../../Desktop/frunk/core" }
|
frunk-core = { git = "https://github.com/Hirrolot/frunk/tree/master/core", branch = "append-to-hlist" }
|
||||||
|
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
smart-default = "0.6.0"
|
smart-default = "0.6.0"
|
||||||
derive_more = "0.99.9"
|
derive_more = "0.99.9"
|
||||||
teloxide = { path = "../../", features = ["frunk"] }
|
teloxide = { path = "../../", features = ["frunk"] }
|
||||||
#teloxide-macros = { git = "http://github.com/teloxide/teloxide-macros", branch = "master" }
|
teloxide-macros = { git = "http://github.com/teloxide/teloxide-macros", branch = "master" }
|
||||||
teloxide-macros = { path = "../../../teloxide-macros" }
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
|
@ -2,13 +2,16 @@
|
||||||
//
|
//
|
||||||
// # Example
|
// # Example
|
||||||
// ```
|
// ```
|
||||||
// - Let's start our test! How many days per week are there?
|
// - Hey
|
||||||
// - 7
|
// - Let's start! What's your full name?
|
||||||
// - 10*5 = ?
|
// - Gandalf the Grey
|
||||||
// - 50
|
// - How old are you?
|
||||||
// - What's an alternative name of Gandalf?
|
// - 223
|
||||||
// - Mithrandir
|
// - What's your location?
|
||||||
// - Congratulations! You've successfully passed the test!
|
// - Middle-earth
|
||||||
|
// - Full name: Gandalf the Grey
|
||||||
|
// Age: 223
|
||||||
|
// Location: Middle-earth
|
||||||
// ```
|
// ```
|
||||||
|
|
||||||
#![allow(clippy::trivial_regex)]
|
#![allow(clippy::trivial_regex)]
|
||||||
|
@ -32,6 +35,8 @@ use states::*;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
|
|
||||||
|
type In = DialogueWithCx<Message, Dialogue, Infallible>;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
run().await;
|
run().await;
|
||||||
|
@ -44,17 +49,12 @@ async fn run() {
|
||||||
let bot = Bot::from_env();
|
let bot = Bot::from_env();
|
||||||
|
|
||||||
Dispatcher::new(bot)
|
Dispatcher::new(bot)
|
||||||
.messages_handler(DialogueDispatcher::new(
|
.messages_handler(DialogueDispatcher::new(|input: In| async move {
|
||||||
|input: DialogueWithCx<Message, Dialogue, Infallible>| async move {
|
// No panic because of std::convert::Infallible.
|
||||||
// Unwrap without panic because of std::convert::Infallible.
|
let (cx, dialogue) = input.unpack();
|
||||||
input
|
|
||||||
.dialogue
|
dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||||
.unwrap()
|
}))
|
||||||
.react(input.cx)
|
|
||||||
.await
|
|
||||||
.expect("Something wrong with the bot!")
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.dispatch()
|
.dispatch()
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ async fn run() {
|
||||||
Dispatcher::new(bot)
|
Dispatcher::new(bot)
|
||||||
.messages_handler(DialogueDispatcher::with_storage(
|
.messages_handler(DialogueDispatcher::with_storage(
|
||||||
|input: In| async move {
|
|input: In| async move {
|
||||||
|
// No panic because of std::convert::Infallible.
|
||||||
let (cx, dialogue) = input.unpack();
|
let (cx, dialogue) = input.unpack();
|
||||||
|
|
||||||
dialogue
|
dialogue
|
||||||
|
|
|
@ -15,6 +15,9 @@ pub struct DialogueWithCx<Upd, D, E> {
|
||||||
|
|
||||||
impl<Upd, D, E> DialogueWithCx<Upd, D, E> {
|
impl<Upd, D, E> DialogueWithCx<Upd, D, E> {
|
||||||
/// Returns the inner `UpdateWithCx<Upd>` and an unwrapped dialogue.
|
/// Returns the inner `UpdateWithCx<Upd>` and an unwrapped dialogue.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
/// If `self.dialogue` is `Err`.
|
||||||
pub fn unpack(self) -> (UpdateWithCx<Upd>, D)
|
pub fn unpack(self) -> (UpdateWithCx<Upd>, D)
|
||||||
where
|
where
|
||||||
E: Debug,
|
E: Debug,
|
||||||
|
|
Loading…
Add table
Reference in a new issue