mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +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,
|
||||
Dispatcher, UpdateWithCx,
|
||||
},
|
||||
error_handlers::{LoggingErrorHandler, OnError},
|
||||
error_handlers::LoggingErrorHandler,
|
||||
types::Message,
|
||||
Bot,
|
||||
};
|
||||
use std::{convert::Infallible, fmt::Debug, future::Future};
|
||||
use std::{convert::Infallible, fmt::Debug, future::Future, sync::Arc};
|
||||
|
||||
/// 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
|
||||
/// [`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
|
||||
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
|
||||
D: Default + Send + 'static,
|
||||
Fut: Future<Output = Result<DialogueStage<D>, HandlerE>> + Send + Sync + 'static,
|
||||
Result<DialogueStage<D>, HandlerE>: OnError<HandlerE>,
|
||||
HandlerE: Debug + Send,
|
||||
Fut: Future<Output = DialogueStage<D>> + Send + Sync + 'static,
|
||||
{
|
||||
let cloned_bot = bot.clone();
|
||||
|
||||
dialogues_repl_with_listener(
|
||||
bot,
|
||||
bot_name,
|
||||
handler,
|
||||
update_listeners::polling_default(cloned_bot),
|
||||
)
|
||||
.await;
|
||||
dialogues_repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot)).await;
|
||||
}
|
||||
|
||||
/// Like [`dialogue_repl`], but with a custom [`UpdateListener`].
|
||||
|
@ -55,25 +47,30 @@ where
|
|||
/// [`Dispatcher`]: crate::dispatching::Dispatcher
|
||||
/// [`dialogue_repl`]: crate::dispatching::repls::dialogue_repl()
|
||||
/// [`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_name: &'static str,
|
||||
handler: H,
|
||||
listener: L,
|
||||
) where
|
||||
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + '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,
|
||||
ListenerE: Debug + Send + 'a,
|
||||
Result<DialogueStage<D>, HandlerE>: OnError<HandlerE>,
|
||||
HandlerE: Debug + Send,
|
||||
{
|
||||
Dispatcher::new(todo!())
|
||||
.messages_handler(DialogueDispatcher::new(|x| async move {
|
||||
// let dialogue = dialogue.expect("std::convert::Infallible");
|
||||
// handler(cx, dialogue).await.log_on_error().await
|
||||
}))
|
||||
let handler = Arc::new(handler);
|
||||
|
||||
Dispatcher::new(bot)
|
||||
.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(
|
||||
listener,
|
||||
LoggingErrorHandler::with_custom_text("An error from the update listener"),
|
||||
|
|
|
@ -43,7 +43,8 @@
|
|||
|
||||
pub use bot::{Bot, BotBuilder};
|
||||
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};
|
||||
|
||||
|
|
Loading…
Reference in a new issue