Merge pull request #40 from async-telegram-bot/add_methods_to_bot

Add some methods to `Bot`
This commit is contained in:
Temirkhan Myrzamadi 2019-10-07 15:48:27 +06:00 committed by GitHub
commit 1812ab10bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 195 additions and 3 deletions

View file

@ -3,9 +3,12 @@ use crate::{
requests::{
ChatId, EditMessageLiveLocation, ForwardMessage, GetFile, GetMe,
SendAudio, SendLocation, SendMediaGroup, SendMessage, SendPhoto,
StopMessageLiveLocation,
StopMessageLiveLocation, AnswerPreCheckoutQuery, AnswerShippingQuery,
KickChatMember, PinChatMessage, PromoteChatMember, RestrictChatMember,
SendChatAction, SendContact, SendPoll, SendVenue, SendVideoNote,
SendVoice, UnbanChatMember, UnpinChatMessage, ChatAction
},
types::{InputFile, InputMedia},
types::{InputFile, InputMedia, ChatPermissions},
};
/// Telegram functions
@ -110,4 +113,193 @@ impl Bot {
{
GetFile::new(self.ctx(), file_id.into())
}
pub fn answer_pre_checkout_query<I, O>(
&self,
pre_checkout_query_id: I,
ok: O,
) -> AnswerPreCheckoutQuery
where
I: Into<String>,
O: Into<bool>
{
AnswerPreCheckoutQuery::new(
self.ctx(),
pre_checkout_query_id.into(),
ok.into(),
)
}
pub fn answer_shipping_query<I, O>(
&self,
shipping_query_id: I,
ok: O,
) -> AnswerShippingQuery
where
I: Into<String>,
O: Into<bool>
{
AnswerShippingQuery::new(
self.ctx(),
shipping_query_id.into(),
ok.into()
)
}
pub fn kick_chat_member<C, U>(
&self,
chat_id: C,
user_id: U,
) -> KickChatMember
where
C: Into<ChatId>,
U: Into<i32>,
{
KickChatMember::new(self.ctx(), chat_id.into(), user_id.into())
}
pub fn pin_chat_message<C, M>(
&self,
chat_id: C,
message_id: M
) -> PinChatMessage
where
C: Into<ChatId>,
M: Into<i32>,
{
PinChatMessage::new(self.ctx(), chat_id.into(), message_id.into())
}
pub fn promote_chat_member<C, U>(
&self,
chat_id: C,
user_id: U,
) -> PromoteChatMember
where
C: Into<ChatId>,
U: Into<i32>,
{
PromoteChatMember::new(self.ctx(), chat_id.into(), user_id.into())
}
pub fn restrict_chat_member<C, U, P>(
&self,
chat_id: C,
user_id: U,
permissions: P
) -> RestrictChatMember
where
C: Into<ChatId>,
U: Into<i32>,
P: Into<ChatPermissions>
{
RestrictChatMember::new(
self.ctx(),
chat_id.into(),
user_id.into(),
permissions.into(),
)
}
pub fn send_chat_action<C, A>(&self, chat_id: C, action: A) -> SendChatAction
where
C: Into<ChatId>,
A: Into<ChatAction>,
{
SendChatAction::new(self.ctx(), chat_id.into(), action.into())
}
pub fn send_contact<C, P, F>(
&self,
chat_id: C,
phone_number: P,
first_name: F,
) -> SendContact
where
C: Into<ChatId>,
P: Into<String>,
F: Into<String>
{
SendContact::new(
self.ctx(),
chat_id.into(),
phone_number.into(),
first_name.into(),
)
}
pub fn send_poll<C, Q, O>(
&self,
chat_id: C,
question: Q,
options: O,
) -> SendPoll
where
C: Into<ChatId>,
Q: Into<String>,
O: Into<Vec<String>>
{
SendPoll::new(
self.ctx(),
chat_id.into(),
question.into(),
options.into(),
)
}
pub fn send_venue<C, Lt, Lg, T, A>(
&self,
chat_id: C,
latitude: Lt,
longitude: Lg,
title: T,
address: A,
) -> SendVenue
where
C: Into<ChatId>,
Lt: Into<f64>,
Lg: Into<f64>,
T: Into<String>,
A: Into<String>,
{
SendVenue::new(
self.ctx(),
chat_id.into(),
latitude.into(),
longitude.into(),
title.into(),
address.into(),
)
}
pub fn send_video_note<C, V>(&self, chat_id: C, video_note: V) -> SendVideoNote
where
C: Into<ChatId>,
V: Into<String>, // TODO: InputFile
{
SendVideoNote::new(self.ctx(), chat_id.into(), video_note.into())
}
pub fn send_voice<C, V>(&self, chat_id: C, voice: V) -> SendVoice
where
C: Into<ChatId>,
V: Into<String>, // TODO: InputFile
{
SendVoice::new(self.ctx(), chat_id.into(), voice.into())
}
pub fn unban_chat_member<C, U>(&self, chat_id: C, user_id: U) -> UnbanChatMember
where
C: Into<ChatId>,
U: Into<i32>,
{
UnbanChatMember::new(self.ctx(), chat_id.into(), user_id.into())
}
pub fn unpin_chat_message<C>(&self, chat_id: C) -> UnpinChatMessage
where
C: Into<ChatId>,
{
UnpinChatMessage::new(self.ctx(), chat_id.into())
}
}

View file

@ -14,7 +14,7 @@ pub use self::{
kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage,
promote_chat_member::PromoteChatMember,
restrict_chat_member::RestrictChatMember, send_animation::SendAnimation,
send_audio::SendAudio, send_chat_action::SendChatAction,
send_audio::SendAudio, send_chat_action::{SendChatAction, ChatAction},
send_contact::SendContact, send_document::SendDocument,
send_location::SendLocation, send_media_group::SendMediaGroup,
send_message::SendMessage, send_photo::SendPhoto, send_poll::SendPoll,