mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
Fix compilation
This commit is contained in:
parent
114267f14c
commit
13fb15f24e
2 changed files with 22 additions and 24 deletions
|
@ -5,11 +5,11 @@ use crate::{
|
||||||
update_listeners::UpdateListener,
|
update_listeners::UpdateListener,
|
||||||
Dispatcher, UpdateWithCx,
|
Dispatcher, UpdateWithCx,
|
||||||
},
|
},
|
||||||
error_handlers::{LoggingErrorHandler, OnError},
|
error_handlers::LoggingErrorHandler,
|
||||||
types::Message,
|
types::Message,
|
||||||
Bot,
|
Bot,
|
||||||
};
|
};
|
||||||
use std::{convert::Infallible, fmt::Debug, future::Future};
|
use std::{convert::Infallible, fmt::Debug, future::Future, sync::Arc};
|
||||||
|
|
||||||
/// A [REPL] for dialogues.
|
/// A [REPL] for dialogues.
|
||||||
///
|
///
|
||||||
|
@ -23,23 +23,15 @@ use std::{convert::Infallible, fmt::Debug, future::Future};
|
||||||
///
|
///
|
||||||
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
|
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
|
||||||
/// [`Dispatcher`]: crate::dispatching::Dispatcher
|
/// [`Dispatcher`]: crate::dispatching::Dispatcher
|
||||||
pub async fn dialogues_repl<'a, H, D, Fut, HandlerE>(bot: Bot, bot_name: &'static str, handler: H)
|
pub async fn dialogues_repl<'a, H, D, Fut>(bot: Bot, handler: H)
|
||||||
where
|
where
|
||||||
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
|
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
|
||||||
D: Default + Send + 'static,
|
D: Default + Send + 'static,
|
||||||
Fut: Future<Output = Result<DialogueStage<D>, HandlerE>> + Send + Sync + 'static,
|
Fut: Future<Output = DialogueStage<D>> + Send + Sync + 'static,
|
||||||
Result<DialogueStage<D>, HandlerE>: OnError<HandlerE>,
|
|
||||||
HandlerE: Debug + Send,
|
|
||||||
{
|
{
|
||||||
let cloned_bot = bot.clone();
|
let cloned_bot = bot.clone();
|
||||||
|
|
||||||
dialogues_repl_with_listener(
|
dialogues_repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot)).await;
|
||||||
bot,
|
|
||||||
bot_name,
|
|
||||||
handler,
|
|
||||||
update_listeners::polling_default(cloned_bot),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [`dialogue_repl`], but with a custom [`UpdateListener`].
|
/// Like [`dialogue_repl`], but with a custom [`UpdateListener`].
|
||||||
|
@ -55,25 +47,30 @@ where
|
||||||
/// [`Dispatcher`]: crate::dispatching::Dispatcher
|
/// [`Dispatcher`]: crate::dispatching::Dispatcher
|
||||||
/// [`dialogue_repl`]: crate::dispatching::repls::dialogue_repl()
|
/// [`dialogue_repl`]: crate::dispatching::repls::dialogue_repl()
|
||||||
/// [`UpdateListener`]: crate::dispatching::update_listeners::UpdateListener
|
/// [`UpdateListener`]: crate::dispatching::update_listeners::UpdateListener
|
||||||
pub async fn dialogues_repl_with_listener<'a, H, D, Fut, HandlerE, L, ListenerE>(
|
pub async fn dialogues_repl_with_listener<'a, H, D, Fut, L, ListenerE>(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
bot_name: &'static str,
|
|
||||||
handler: H,
|
handler: H,
|
||||||
listener: L,
|
listener: L,
|
||||||
) where
|
) where
|
||||||
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
|
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
|
||||||
D: Default + Send + 'static,
|
D: Default + Send + 'static,
|
||||||
Fut: Future<Output = Result<DialogueStage<D>, HandlerE>> + Send + Sync + 'static,
|
Fut: Future<Output = DialogueStage<D>> + Send + Sync + 'static,
|
||||||
L: UpdateListener<ListenerE> + Send + 'a,
|
L: UpdateListener<ListenerE> + Send + 'a,
|
||||||
ListenerE: Debug + Send + 'a,
|
ListenerE: Debug + Send + 'a,
|
||||||
Result<DialogueStage<D>, HandlerE>: OnError<HandlerE>,
|
|
||||||
HandlerE: Debug + Send,
|
|
||||||
{
|
{
|
||||||
Dispatcher::new(todo!())
|
let handler = Arc::new(handler);
|
||||||
.messages_handler(DialogueDispatcher::new(|x| async move {
|
|
||||||
// let dialogue = dialogue.expect("std::convert::Infallible");
|
Dispatcher::new(bot)
|
||||||
// handler(cx, dialogue).await.log_on_error().await
|
.messages_handler(DialogueDispatcher::new(
|
||||||
}))
|
move |DialogueWithCx { cx, dialogue }: DialogueWithCx<Message, D, Infallible>| {
|
||||||
|
let handler = Arc::clone(&handler);
|
||||||
|
|
||||||
|
async move {
|
||||||
|
let dialogue = dialogue.expect("std::convert::Infallible");
|
||||||
|
handler(cx, dialogue).await
|
||||||
|
}
|
||||||
|
},
|
||||||
|
))
|
||||||
.dispatch_with_listener(
|
.dispatch_with_listener(
|
||||||
listener,
|
listener,
|
||||||
LoggingErrorHandler::with_custom_text("An error from the update listener"),
|
LoggingErrorHandler::with_custom_text("An error from the update listener"),
|
||||||
|
|
|
@ -43,7 +43,8 @@
|
||||||
|
|
||||||
pub use bot::{Bot, BotBuilder};
|
pub use bot::{Bot, BotBuilder};
|
||||||
pub use dispatching::repls::{
|
pub use dispatching::repls::{
|
||||||
commands_repl, commands_repl_with_listener, repl, repl_with_listener,
|
commands_repl, commands_repl_with_listener, dialogues_repl, dialogues_repl_with_listener, repl,
|
||||||
|
repl_with_listener,
|
||||||
};
|
};
|
||||||
pub use errors::{ApiErrorKind, DownloadError, KnownApiErrorKind, RequestError};
|
pub use errors::{ApiErrorKind, DownloadError, KnownApiErrorKind, RequestError};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue