# Conflicts:
#	src/bot/api.rs
#	src/requests/set_chat_title.rs
This commit is contained in:
P0lunin 2019-10-19 18:50:10 +03:00
commit 4e2dfd6b06
8 changed files with 33 additions and 27 deletions

View file

@ -358,11 +358,7 @@ impl Bot {
SendAnimation::new(self, chat_id, animation)
}
pub fn set_chat_title<C, T>(
&self,
chat_id: C,
title: T,
) -> SetChatTitle
pub fn set_chat_title<C, T>(&self, chat_id: C, title: T) -> SetChatTitle
where
C: Into<ChatId>,
T: Into<String>,

View file

@ -19,7 +19,7 @@ impl Bot {
/// use telebofr::types::File as TgFile;
/// use tokio::fs::File;
/// # use telebofr::RequestError;
/// use telebofr::bot::Bot;
/// use telebofr::Bot;
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let bot = Bot::new("TOKEN");

View file

@ -1,38 +1,44 @@
//! A Telegram bot.
use reqwest::Client;
mod api;
mod download;
/// A Telegram bot used to build requests.
#[derive(Debug, Clone)]
pub struct Bot {
token: String,
client: Client,
}
/// Constructors
impl Bot {
pub fn new(token: &str) -> Self {
pub fn new<S>(token: S) -> Self
where
S: Into<String>,
{
Bot {
token: String::from(token),
token: token.into(),
client: Client::new(),
}
}
pub fn with_client(token: &str, client: Client) -> Self {
pub fn with_client<S>(token: S, client: Client) -> Self
where
S: Into<String>,
{
Bot {
token: String::from(token),
token: token.into(),
client,
}
}
}
impl Bot {
#[inline]
pub fn token(&self) -> &str {
&self.token
}
#[inline]
pub fn client(&self) -> &Client {
&self.client
}

View file

@ -32,7 +32,7 @@ type Handlers<'a, T, E> =
///
/// Simplest example:
/// ```no_run
/// # use telebofr::bot::Bot;
/// # use telebofr::Bot;
/// use telebofr::types::Message;
/// async fn run() {
/// use std::convert::Infallible;

View file

@ -5,12 +5,13 @@ extern crate serde;
#[macro_use]
extern crate thiserror;
pub use bot::Bot;
pub use errors::{DownloadError, RequestError};
mod errors;
mod network;
pub mod bot;
mod bot;
pub mod dispatcher;
pub mod requests;
pub mod types;

View file

@ -1,4 +1,4 @@
//! Raw API functions.
//! API requests.
use async_trait::async_trait;
use serde::de::DeserializeOwned;

View file

@ -1,9 +1,11 @@
use async_trait::async_trait;
use crate::bot::Bot;
use crate::types::{ChatId, True};
use crate::requests::{Request, ResponseResult};
use crate::network;
use crate::{
bot::Bot,
network,
requests::{Request, ResponseResult},
types::{ChatId, True},
};
#[derive(Debug, Clone, Serialize)]
pub struct SetChatTitle<'a> {
@ -29,8 +31,9 @@ impl SetChatTitle<'_> {
&self.bot.client(),
&self.bot.token(),
"setChatTitle",
&self
).await
&self,
)
.await
}
}
@ -52,16 +55,16 @@ impl<'a> SetChatTitle<'a> {
}
pub fn chat_id<C>(mut self, chat_id: C) -> Self
where
C: Into<ChatId>,
where
C: Into<ChatId>,
{
self.chat_id = chat_id.into();
self
}
pub fn title<C>(mut self, title: C) -> Self
where
C: Into<String>,
where
C: Into<String>,
{
self.title = title.into();
self

View file

@ -1,4 +1,4 @@
//! Raw API structures.
//! API types.
pub use animation::*;
pub use audio::*;