mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 15:49:27 +01:00
Import bot::Bot into lib.rs
This commit is contained in:
parent
715298c713
commit
6f4bd19382
8 changed files with 27 additions and 33 deletions
|
@ -8,13 +8,12 @@ use crate::{
|
||||||
SendAnimation, SendAudio, SendChatAction, SendContact, SendDocument,
|
SendAnimation, SendAudio, SendChatAction, SendContact, SendDocument,
|
||||||
SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll,
|
SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll,
|
||||||
SendVenue, SendVideo, SendVideoNote, SendVoice, SetChatDescription,
|
SendVenue, SendVideo, SendVideoNote, SendVoice, SetChatDescription,
|
||||||
SetChatStickerSet, StopMessageLiveLocation, UnbanChatMember,
|
SetChatStickerSet, SetChatTitle, StopMessageLiveLocation,
|
||||||
UnpinChatMessage, SetChatTitle
|
UnbanChatMember, UnpinChatMessage,
|
||||||
},
|
},
|
||||||
types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
|
types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Telegram functions
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
pub fn get_me(&self) -> GetMe {
|
pub fn get_me(&self) -> GetMe {
|
||||||
GetMe::new(self)
|
GetMe::new(self)
|
||||||
|
@ -357,11 +356,7 @@ impl Bot {
|
||||||
SendAnimation::new(self, chat_id, animation)
|
SendAnimation::new(self, chat_id, animation)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_chat_title<C, T>(
|
pub fn set_chat_title<C, T>(&self, chat_id: C, title: T) -> SetChatTitle
|
||||||
&self,
|
|
||||||
chat_id: C,
|
|
||||||
title: T,
|
|
||||||
) -> SetChatTitle
|
|
||||||
where
|
where
|
||||||
C: Into<ChatId>,
|
C: Into<ChatId>,
|
||||||
T: Into<String>,
|
T: Into<String>,
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl Bot {
|
||||||
/// use telebofr::types::File as TgFile;
|
/// use telebofr::types::File as TgFile;
|
||||||
/// use tokio::fs::File;
|
/// use tokio::fs::File;
|
||||||
/// # use telebofr::RequestError;
|
/// # use telebofr::RequestError;
|
||||||
/// use telebofr::bot::Bot;
|
/// use telebofr::Bot;
|
||||||
///
|
///
|
||||||
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
/// let bot = Bot::new("TOKEN");
|
/// let bot = Bot::new("TOKEN");
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
//! A Telegram bot.
|
|
||||||
|
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod download;
|
mod download;
|
||||||
|
|
||||||
|
/// A Telegram bot used to build requests.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
token: String,
|
token: String,
|
||||||
|
|
|
@ -32,7 +32,7 @@ type Handlers<'a, T, E> =
|
||||||
///
|
///
|
||||||
/// Simplest example:
|
/// Simplest example:
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use telebofr::bot::Bot;
|
/// # use telebofr::Bot;
|
||||||
/// use telebofr::types::Message;
|
/// use telebofr::types::Message;
|
||||||
/// async fn run() {
|
/// async fn run() {
|
||||||
/// use std::convert::Infallible;
|
/// use std::convert::Infallible;
|
||||||
|
|
|
@ -5,12 +5,13 @@ extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate thiserror;
|
extern crate thiserror;
|
||||||
|
|
||||||
|
pub use bot::Bot;
|
||||||
pub use errors::{DownloadError, RequestError};
|
pub use errors::{DownloadError, RequestError};
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
mod network;
|
mod network;
|
||||||
|
|
||||||
pub mod bot;
|
mod bot;
|
||||||
pub mod dispatcher;
|
pub mod dispatcher;
|
||||||
pub mod requests;
|
pub mod requests;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Raw API functions.
|
//! API requests.
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use crate::bot::Bot;
|
use crate::{
|
||||||
use crate::types::{ChatId, True};
|
bot::Bot,
|
||||||
use crate::requests::{Request, ResponseResult};
|
network,
|
||||||
use crate::network;
|
requests::{Request, ResponseResult},
|
||||||
|
types::{ChatId, True},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct SetChatTitle<'a> {
|
pub struct SetChatTitle<'a> {
|
||||||
|
@ -29,20 +31,17 @@ impl SetChatTitle<'_> {
|
||||||
&self.bot.client(),
|
&self.bot.client(),
|
||||||
&self.bot.token(),
|
&self.bot.token(),
|
||||||
"SetChatTitle",
|
"SetChatTitle",
|
||||||
&self
|
&self,
|
||||||
).await
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SetChatTitle<'a> {
|
impl<'a> SetChatTitle<'a> {
|
||||||
pub(crate) fn new<C, T>(
|
pub(crate) fn new<C, T>(bot: &'a Bot, chat_id: C, title: T) -> Self
|
||||||
bot: &'a Bot,
|
where
|
||||||
chat_id: C,
|
C: Into<ChatId>,
|
||||||
title: T
|
T: Into<String>,
|
||||||
) -> Self
|
|
||||||
where
|
|
||||||
C: Into<ChatId>,
|
|
||||||
T: Into<String>,
|
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
bot,
|
bot,
|
||||||
|
@ -52,16 +51,16 @@ impl<'a> SetChatTitle<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||||
where
|
where
|
||||||
C: Into<ChatId>,
|
C: Into<ChatId>,
|
||||||
{
|
{
|
||||||
self.chat_id = chat_id.into();
|
self.chat_id = chat_id.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title<C>(mut self, title: C) -> Self
|
pub fn title<C>(mut self, title: C) -> Self
|
||||||
where
|
where
|
||||||
C: Into<String>,
|
C: Into<String>,
|
||||||
{
|
{
|
||||||
self.title = title.into();
|
self.title = title.into();
|
||||||
self
|
self
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Raw API structures.
|
//! API types.
|
||||||
|
|
||||||
pub use animation::*;
|
pub use animation::*;
|
||||||
pub use audio::*;
|
pub use audio::*;
|
||||||
|
|
Loading…
Add table
Reference in a new issue