diff --git a/examples/ping_pong_bot/src/main.rs b/examples/ping_pong_bot/src/main.rs index d8eb2abb..5aa70401 100644 --- a/examples/ping_pong_bot/src/main.rs +++ b/examples/ping_pong_bot/src/main.rs @@ -6,9 +6,10 @@ async fn main() { pretty_env_logger::init(); log::info!("Starting the ping-pong bot!"); - Dispatcher::new(Bot::new("MyAwesomeToken")) - .message_handler(|ctx: HandlerCtx| async move { - ctx.reply("pong").await + Dispatcher::::new(Bot::new("MyAwesomeToken")) + .message_handler(&|ctx: DispatcherHandlerCtx| async move { + ctx.answer("pong").send().await?; + Ok(()) }) .dispatch() .await; diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 5e26de9e..0dbd9d89 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -1,4 +1,5 @@ use reqwest::Client; +use std::sync::Arc; mod api; mod download; @@ -11,24 +12,21 @@ pub struct Bot { } impl Bot { - pub fn new(token: S) -> Self + pub fn new(token: S) -> Arc where S: Into, { - Bot { - token: token.into(), - client: Client::new(), - } + Self::with_client(token, Client::new()) } - pub fn with_client(token: S, client: Client) -> Self + pub fn with_client(token: S, client: Client) -> Arc where S: Into, { - Bot { + Arc::new(Bot { token: token.into(), client, - } + }) } } diff --git a/src/dispatching/dispatcher.rs b/src/dispatching/dispatcher.rs index 00b62163..ba2e4ee1 100644 --- a/src/dispatching/dispatcher.rs +++ b/src/dispatching/dispatcher.rs @@ -53,9 +53,9 @@ where { /// Constructs a new dispatcher with this `bot`. #[must_use] - pub fn new(bot: Bot) -> Self { + pub fn new(bot: Arc) -> Self { Self { - bot: Arc::new(bot), + bot, handlers_error_handler: Box::new(LoggingErrorHandler::new( "An error from a Dispatcher's handler", )),