mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +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]
|
#[macro_use]
|
||||||
extern crate frunk;
|
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::{
|
mod favourite_music;
|
||||||
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"),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dialogue states.
|
// Dialogue states.
|
||||||
|
|
||||||
|
@ -92,12 +71,13 @@ type Dialogue = Coprod!(
|
||||||
|
|
||||||
wrap_dialogue!(
|
wrap_dialogue!(
|
||||||
Wrapper(Dialogue),
|
Wrapper(Dialogue),
|
||||||
default { Self(Dialogue::inject(StartState)) }
|
default Self(Dialogue::inject(StartState))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Transition functions.
|
// Transition functions.
|
||||||
|
|
||||||
type Cx<State> = DialogueDispatcherHandlerCx<Message, State, Infallible>;
|
type Cx<State> =
|
||||||
|
DialogueDispatcherHandlerCx<Message, State, std::convert::Infallible>;
|
||||||
type Res = ResponseResult<DialogueStage<Wrapper>>;
|
type Res = ResponseResult<DialogueStage<Wrapper>>;
|
||||||
|
|
||||||
async fn start(cx: Cx<StartState>) -> Res {
|
async fn start(cx: Cx<StartState>) -> Res {
|
||||||
|
|
|
@ -79,7 +79,7 @@ macro_rules! dispatch {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! wrap_dialogue {
|
macro_rules! wrap_dialogue {
|
||||||
($name:ident($dialogue:ident), default {$default_block:expr}) => {
|
($name:ident($dialogue:ident), default $default_block:expr) => {
|
||||||
struct $name($dialogue);
|
struct $name($dialogue);
|
||||||
|
|
||||||
impl teloxide::dispatching::dialogue::DialogueWrapper<$dialogue>
|
impl teloxide::dispatching::dialogue::DialogueWrapper<$dialogue>
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub use crate::{
|
||||||
up, wrap_dialogue, Bot, RequestError,
|
up, wrap_dialogue, Bot, RequestError,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use tokio::sync::mpsc::UnboundedReceiver;
|
|
||||||
pub use frunk::Coproduct;
|
pub use frunk::Coproduct;
|
||||||
|
pub use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
|
||||||
pub use futures::StreamExt;
|
pub use futures::StreamExt;
|
||||||
|
|
Loading…
Add table
Reference in a new issue