Extract FavouriteMusic into favourite_music.rs (examples/dialogue_bot)

This commit is contained in:
Temirkhan Myrzamadi 2020-05-24 18:39:41 +06:00
parent c9393aa5d6
commit 572d41fbf8
4 changed files with 31 additions and 29 deletions

View 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"),
])
}
}

View file

@ -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 {

View file

@ -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>

View file

@ -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;