Hot fixes

This commit is contained in:
Temirkhan Myrzamadi 2020-02-11 19:12:14 +06:00
parent d803d8197a
commit 4b0dea21f1
3 changed files with 12 additions and 13 deletions

View file

@ -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<Message>| async move {
ctx.reply("pong").await
Dispatcher::<RequestError>::new(Bot::new("MyAwesomeToken"))
.message_handler(&|ctx: DispatcherHandlerCtx<Message>| async move {
ctx.answer("pong").send().await?;
Ok(())
})
.dispatch()
.await;

View file

@ -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<S>(token: S) -> Self
pub fn new<S>(token: S) -> Arc<Self>
where
S: Into<String>,
{
Bot {
token: token.into(),
client: Client::new(),
}
Self::with_client(token, Client::new())
}
pub fn with_client<S>(token: S, client: Client) -> Self
pub fn with_client<S>(token: S, client: Client) -> Arc<Self>
where
S: Into<String>,
{
Bot {
Arc::new(Bot {
token: token.into(),
client,
}
})
}
}

View file

@ -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<Bot>) -> Self {
Self {
bot: Arc::new(bot),
bot,
handlers_error_handler: Box::new(LoggingErrorHandler::new(
"An error from a Dispatcher's handler",
)),