1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! Make cool Telegram bots with Rust easily. Here is a simple echo bot:
//!
//! ```no_run
//! use tbot::prelude::*;
//!
//! let mut bot = tbot::bot!("BOT_TOKEN").event_loop();
//!
//! bot.text(|context| {
//!     let reply = context
//!         .send_message(&context.text.value)
//!         .into_future()
//!         .map_err(|err| {
//!             dbg!(err);
//!         });
//!
//!     tbot::spawn(reply);
//! });
//!
//! bot.polling().start();
//! ```
//!
//! If you're new to `tbot`, we recommend you go through the [tutorial] first.
//! We also have several [How-to guides][how-to] with snippets to solve your
//! problems.
//!
//! If you have a question, ask it in [our group] on Telegram. If you find
//! a bug, fill an issue on either our [GitLab] or [GitHub] repository.
//!
//! [our group]: t.me/tbot_group
//! [tutorial]: https://gitlab.com/SnejUgal/tbot/wikis/Tutorial
//! [how-to]: https://gitlab.com/SnejUgal/tbot/wikis/How-to
//! [GitLab]: https://gitlab.com/SnejUgal/tbot
//! [GitHub]: https://github.com/SnejUgal/tbot

#![deny(
    future_incompatible,
    nonstandard_style,
    missing_docs,
    clippy::all,
    clippy::pedantic,
    clippy::nursery,
    clippy::cargo
)]
#![allow(clippy::multiple_crate_versions)] // can't do much

mod bot;
mod download_file;
mod internal;
mod multipart;
mod token;

pub mod connectors;
pub mod contexts;
pub mod errors;
pub mod event_loop;
pub mod methods;
pub mod types;

use serde::{Deserialize, Serialize};
pub use {bot::*, event_loop::EventLoop, token::*};
use {download_file::download_file, multipart::*, prelude::*};

/// A wrapper around `tokio::run` without `F::Item: ()`.
///
/// When calling an API method, you'll most likely throw away its result.
/// However, `tokio` requires that `F::Item` be `()`. `tbot` provides
/// a thin wrapper around `tokio::run` that maps `F::Item` to `()`.
/// On the other hand, `tbot` still requires that you handle possible errors
/// properly before running a future.
pub fn run<F>(future: F)
where
    F: futures::Future<Error = ()> + Send + 'static,
{
    tokio::run(future.map(|_| ()));
}

/// A wrapper around `tokio::spawn` without `F::Item: ()`.
///
/// When calling an API method, you'll most likely throw away its result.
/// However, `tokio` requires that `F::Item` be `()`. `tbot` provides
/// a thin wrapper around `tokio::spawn` that maps `F::Item` to `()`.
/// On the other hand, `tbot` still requires that you handle possible errors
/// properly before running a future.
pub fn spawn<F>(future: F) -> tokio::executor::Spawn
where
    F: futures::Future<Error = ()> + Send + 'static,
{
    tokio::spawn(future.map(|_| ()))
}

pub mod prelude {
    //! Traits needed when working with `tbot`.
    pub use super::contexts::traits::*;
    pub use futures::Future;
    pub use futures::IntoFuture;
}