mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Extract FavouriteMusic into favourite_music.rs (examples/dialogue_bot)
This commit is contained in:
parent
c9393aa5d6
commit
572d41fbf8
4 changed files with 31 additions and 29 deletions
22
examples/dialogue_bot/src/favourite_music.rs
Normal file
22
examples/dialogue_bot/src/favourite_music.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use parse_display::{Display, FromStr};
|
||||
|
||||
use teloxide::types::{KeyboardButton, ReplyKeyboardMarkup};
|
||||
|
||||
#[derive(Copy, Clone, Display, FromStr)]
|
||||
pub enum FavouriteMusic {
|
||||
Rock,
|
||||
Metal,
|
||||
Pop,
|
||||
Other,
|
||||
}
|
||||
|
||||
impl FavouriteMusic {
|
||||
pub fn markup() -> ReplyKeyboardMarkup {
|
||||
ReplyKeyboardMarkup::default().append_row(vec![
|
||||
KeyboardButton::new("Rock"),
|
||||
KeyboardButton::new("Metal"),
|
||||
KeyboardButton::new("Pop"),
|
||||
KeyboardButton::new("Other"),
|
||||
])
|
||||
}
|
||||
}
|
|
@ -20,33 +20,12 @@
|
|||
#[macro_use]
|
||||
extern crate frunk;
|
||||
|
||||
use std::convert::Infallible;
|
||||
use parse_display::Display;
|
||||
|
||||
use parse_display::{Display, FromStr};
|
||||
use favourite_music::FavouriteMusic;
|
||||
use teloxide::prelude::*;
|
||||
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
types::{KeyboardButton, ReplyKeyboardMarkup},
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Display, FromStr)]
|
||||
enum FavouriteMusic {
|
||||
Rock,
|
||||
Metal,
|
||||
Pop,
|
||||
Other,
|
||||
}
|
||||
|
||||
impl FavouriteMusic {
|
||||
fn markup() -> ReplyKeyboardMarkup {
|
||||
ReplyKeyboardMarkup::default().append_row(vec![
|
||||
KeyboardButton::new("Rock"),
|
||||
KeyboardButton::new("Metal"),
|
||||
KeyboardButton::new("Pop"),
|
||||
KeyboardButton::new("Other"),
|
||||
])
|
||||
}
|
||||
}
|
||||
mod favourite_music;
|
||||
|
||||
// Dialogue states.
|
||||
|
||||
|
@ -92,12 +71,13 @@ type Dialogue = Coprod!(
|
|||
|
||||
wrap_dialogue!(
|
||||
Wrapper(Dialogue),
|
||||
default { Self(Dialogue::inject(StartState)) }
|
||||
default Self(Dialogue::inject(StartState))
|
||||
);
|
||||
|
||||
// Transition functions.
|
||||
|
||||
type Cx<State> = DialogueDispatcherHandlerCx<Message, State, Infallible>;
|
||||
type Cx<State> =
|
||||
DialogueDispatcherHandlerCx<Message, State, std::convert::Infallible>;
|
||||
type Res = ResponseResult<DialogueStage<Wrapper>>;
|
||||
|
||||
async fn start(cx: Cx<StartState>) -> Res {
|
||||
|
|
|
@ -79,7 +79,7 @@ macro_rules! dispatch {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! wrap_dialogue {
|
||||
($name:ident($dialogue:ident), default {$default_block:expr}) => {
|
||||
($name:ident($dialogue:ident), default $default_block:expr) => {
|
||||
struct $name($dialogue);
|
||||
|
||||
impl teloxide::dispatching::dialogue::DialogueWrapper<$dialogue>
|
||||
|
|
|
@ -16,7 +16,7 @@ pub use crate::{
|
|||
up, wrap_dialogue, Bot, RequestError,
|
||||
};
|
||||
|
||||
pub use tokio::sync::mpsc::UnboundedReceiver;
|
||||
pub use frunk::Coproduct;
|
||||
pub use tokio::sync::mpsc::UnboundedReceiver;
|
||||
|
||||
pub use futures::StreamExt;
|
||||
|
|
Loading…
Reference in a new issue