Fix type aliases in the examples

This commit is contained in:
Hirrolot 2022-02-02 06:28:32 +06:00
parent d25efa9e14
commit d49b03edae
3 changed files with 16 additions and 17 deletions

View file

@ -19,10 +19,7 @@ use teloxide::{
prelude2::*,
};
// FIXME: naming
type MyBot = AutoSend<Bot>;
type Store = SqliteStorage<Json>;
type BotDialogue = Dialogue<State, Store>;
type BotDialogue = Dialogue<State, SqliteStorage<Json>>;
#[derive(DialogueState, Clone, serde::Serialize, serde::Deserialize)]
#[handler_out(anyhow::Result<()>)]
@ -62,7 +59,9 @@ async fn main() {
DispatcherBuilder::new(
bot,
dptree::entry().add_dialogue::<Message, Store, State>().dispatch_by::<State>(),
dptree::entry()
.add_dialogue::<Message, SqliteStorage<Json>, State>()
.dispatch_by::<State>(),
)
.dependencies(dptree::deps![storage])
.build()
@ -70,14 +69,18 @@ async fn main() {
.await;
}
async fn handle_start(bot: MyBot, mes: Message, dialogue: BotDialogue) -> anyhow::Result<()> {
async fn handle_start(
bot: AutoSend<Bot>,
mes: Message,
dialogue: BotDialogue,
) -> anyhow::Result<()> {
bot.send_message(mes.chat_id(), "Let's start! What's your full name?").await?;
dialogue.next(State::ReceiveFullName).await?;
Ok(())
}
async fn handle_receive_full_name(
bot: MyBot,
bot: AutoSend<Bot>,
mes: Message,
dialogue: BotDialogue,
) -> anyhow::Result<()> {
@ -87,7 +90,7 @@ async fn handle_receive_full_name(
}
async fn handle_receive_age(
bot: MyBot,
bot: AutoSend<Bot>,
mes: Message,
dialogue: BotDialogue,
full_name: String,
@ -105,7 +108,7 @@ async fn handle_receive_age(
}
async fn handle_receive_location(
bot: MyBot,
bot: AutoSend<Bot>,
mes: Message,
dialogue: BotDialogue,
state: ReceiveLocation,

View file

@ -2,8 +2,6 @@
use teloxide::prelude2::*;
type TeleBot = AutoSend<Bot>;
#[tokio::main]
async fn main() {
teloxide::enable_logging!();
@ -11,7 +9,7 @@ async fn main() {
let bot = Bot::from_env().auto_send();
teloxide::repls2::repl(bot, |message: Message, bot: TeleBot| async move {
teloxide::repls2::repl(bot, |message: Message, bot: AutoSend<Bot>| async move {
bot.send_dice(message.chat.id).await?;
respond(())
})

View file

@ -5,9 +5,7 @@ use teloxide::{
};
use thiserror::Error;
type Store = RedisStorage<Bincode>;
// FIXME: naming
type MyDialogue = Dialogue<BotDialogue, Store>;
type BotDialogue = Dialogue<BotDialogue, RedisStorage<Bincode>>;
type StorageError = <RedisStorage<Bincode> as Storage<BotDialogue>>::Error;
#[derive(Debug, Error)]
@ -33,7 +31,7 @@ impl Default for BotDialogue {
async fn handle_message(
bot: AutoSend<Bot>,
mes: Message,
dialogue: MyDialogue,
dialogue: BotDialogue,
) -> Result<(), Error> {
match mes.text() {
None => {
@ -81,7 +79,7 @@ async fn main() {
let storage = RedisStorage::open("redis://127.0.0.1:6379", Bincode).await.unwrap();
let handler = dptree::entry()
.add_dialogue::<Message, Store, BotDialogue>()
.add_dialogue::<Message, RedisStorage<Bincode>, BotDialogue>()
.branch(dptree::endpoint(handle_message));
DispatcherBuilder::new(bot, handler)