Fix the docs

This commit is contained in:
Temirkhan Myrzamadi 2020-02-07 06:03:33 +06:00
parent 375f09df18
commit d4170725aa
10 changed files with 83 additions and 91 deletions

View file

@ -2,10 +2,10 @@ use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
types::Me,
Bot,
};
use serde::Serialize;
use crate::types::Me;
/// A simple method for testing your bot's auth token. Requires no parameters.
///

View file

@ -4,10 +4,9 @@ use super::BotWrapper;
use crate::{
net,
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
types::{ChatId, Message, PollType, ReplyMarkup},
Bot,
};
use crate::types::PollType;
/// Use this method to send a native poll.
///
@ -106,7 +105,7 @@ impl<'a> SendPoll<'a> {
self
}
/// True, if the poll needs to be anonymous, defaults to True
/// `true`, if the poll needs to be anonymous, defaults to `true`.
pub fn is_anonymous<T>(mut self, val: T) -> Self
where
T: Into<bool>,
@ -115,14 +114,16 @@ impl<'a> SendPoll<'a> {
self
}
/// Poll type, “quiz” or “regular”, defaults to “regular”
pub fn poll_type(mut self, val: PollType) -> Self
{
/// Poll type, `quiz` or `regular`, defaults to `regular`.
pub fn poll_type(mut self, val: PollType) -> Self {
self.poll_type = Some(val);
self
}
/// True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
/// `true`, if the poll allows multiple answers, ignored for polls in quiz
/// mode.
///
/// Defaults to `false`.
pub fn allows_multiple_answers<T>(mut self, val: T) -> Self
where
T: Into<bool>,
@ -131,7 +132,8 @@ impl<'a> SendPoll<'a> {
self
}
/// 0-based identifier of the correct answer option, required for polls in quiz mode
/// 0-based identifier of the correct answer option, required for polls in
/// quiz mode.
pub fn correct_option_id<T>(mut self, val: T) -> Self
where
T: Into<i32>,
@ -140,7 +142,9 @@ impl<'a> SendPoll<'a> {
self
}
/// Pass True, if the poll needs to be immediately closed. This can be useful for poll preview.
/// Pass `true`, if the poll needs to be immediately closed.
///
/// This can be useful for poll preview.
pub fn is_closed<T>(mut self, val: T) -> Self
where
T: Into<bool>,
@ -149,8 +153,9 @@ impl<'a> SendPoll<'a> {
self
}
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
/// Sends the message [silently].
///
/// Users will receive a notification with no sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self {

View file

@ -1,6 +1,6 @@
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use crate::types::{True, KeyboardButtonPollType};
use crate::types::{KeyboardButtonPollType, True};
/// This object represents one button of the reply keyboard. For filter text
/// buttons String can be used instead of this object to specify text of the
@ -28,24 +28,26 @@ pub struct KeyboardButton {
pub enum ButtonRequest {
Location,
Contact,
KeyboardButtonPollType(KeyboardButtonPollType)
KeyboardButtonPollType(KeyboardButtonPollType),
}
/// Helper struct for (de)serializing [`ButtonRequest`](ButtonRequest)
#[serde_with_macros::skip_serializing_none]
#[derive(Serialize, Deserialize)]
struct RawRequest {
/// Optional. If True, the user's phone number will be sent as a contact
/// when the button is pressed. Available in private chats only
/// If `true`, the user's phone number will be sent as a contact
/// when the button is pressed. Available in private chats only.
#[serde(rename = "request_contact")]
contact: Option<True>,
/// Optional. If True, the user's current location will be sent when the
/// button is pressed. Available in private chats only
/// If `true`, the user's current location will be sent when the
/// button is pressed. Available in private chats only.
#[serde(rename = "request_location")]
location: Option<True>,
/// Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only
/// If specified, the user will be asked to create a poll and
/// send it to the bot when the button is pressed. Available in private
/// chats only.
#[serde(rename = "request_poll")]
poll: Option<KeyboardButtonPollType>,
}
@ -72,7 +74,8 @@ impl<'de> Deserialize<'de> for ButtonRequest {
location: Some(_), ..
} => Ok(Self::Location),
RawRequest {
poll: Some(poll_type), ..
poll: Some(poll_type),
..
} => Ok(Self::KeyboardButtonPollType(poll_type)),
_ => Err(D::Error::custom(
"Either one of `request_contact` and `request_location` \
@ -103,9 +106,9 @@ impl Serialize for ButtonRequest {
Self::KeyboardButtonPollType(poll_type) => RawRequest {
contact: None,
location: None,
poll: Some(poll_type.clone())
poll: Some(poll_type.clone()),
}
.serialize(serializer)
.serialize(serializer),
}
}
}

View file

@ -2,5 +2,5 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct KeyboardButtonPollType {
poll_type: String
}
poll_type: String,
}

View file

@ -63,9 +63,9 @@ pub use passport_data::*;
pub use passport_element_error::*;
pub use passport_file::*;
pub use photo_size::*;
pub use poll_type::*;
pub use poll_answer::*;
pub use poll::*;
pub use poll_answer::*;
pub use poll_type::*;
pub use pre_checkout_query::*;
pub use reply_keyboard_markup::*;
pub use reply_keyboard_remove::*;

View file

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::types::PollType;
use serde::{Deserialize, Serialize};
/// This object contains information about a poll.
///
@ -30,10 +30,10 @@ pub struct Poll {
/// True, if the poll allows multiple answers
pub allows_multiple_answers: bool,
/// 0-based identifier of the correct answer option. Available only for polls
/// in the quiz mode, which are closed, or was sent (not forwarded) by the bot
/// or to the private chat with the bot.
pub correct_option_id: Option<i32>
/// 0-based identifier of the correct answer option. Available only for
/// polls in the quiz mode, which are closed, or was sent (not
/// forwarded) by the bot or to the private chat with the bot.
pub correct_option_id: Option<i32>,
}
/// This object contains information about one answer option in a poll.

View file

@ -1,14 +1,16 @@
use serde::{Deserialize, Serialize};
use crate::types::User;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct PollAnswer {
/// Unique poll identifier
/// Unique poll identifier.
pub poll_id: String,
/// The user, who changed the answer to the poll
/// The user, who changed the answer to the poll.
pub user: User,
/// 0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote.
/// 0-based identifiers of answer options, chosen by the user.
///
/// May be empty if the user retracted their vote.
pub option_ids: Vec<i32>,
}
}

View file

@ -5,4 +5,4 @@ use serde::{Deserialize, Serialize};
pub enum PollType {
Quiz,
Regular,
}
}

View file

@ -2,7 +2,10 @@
use serde::{Deserialize, Serialize};
use crate::types::{CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll, PreCheckoutQuery, ShippingQuery, User, Sender, Chat, PollAnswer};
use crate::types::{
CallbackQuery, Chat, ChosenInlineResult, InlineQuery, Message, Poll,
PollAnswer, PreCheckoutQuery, Sender, ShippingQuery, User,
};
/// This [object] represents an incoming update.
///
@ -69,65 +72,40 @@ pub enum UpdateKind {
/// polls, which are sent by the bot.
Poll(Poll),
/// A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.
PollAnswer(PollAnswer)
/// A user changed their answer in a non-anonymous poll. Bots receive new
/// votes only in polls that were sent by the bot itself.
PollAnswer(PollAnswer),
}
impl Update {
pub fn user(&self) -> Option<&User> {
match &self.kind {
UpdateKind::Message(m) => {
match m.from() {
Some(Sender::User(user)) => Some(user),
_ => None,
}
}
UpdateKind::EditedMessage(m) => {
match m.from() {
Some(Sender::User(user)) => Some(user),
_ => None,
}
}
UpdateKind::CallbackQuery(query) => {
Some(&query.from)
}
UpdateKind::ChosenInlineResult(chosen) => {
Some(&chosen.from)
}
UpdateKind::InlineQuery(query) => {
Some(&query.from)
}
UpdateKind::ShippingQuery(query) => {
Some(&query.from)
}
UpdateKind::PreCheckoutQuery(query) => {
Some(&query.from)
}
UpdateKind::PollAnswer(answer) => {
Some(&answer.user)
}
_ => None
UpdateKind::Message(m) => match m.from() {
Some(Sender::User(user)) => Some(user),
_ => None,
},
UpdateKind::EditedMessage(m) => match m.from() {
Some(Sender::User(user)) => Some(user),
_ => None,
},
UpdateKind::CallbackQuery(query) => Some(&query.from),
UpdateKind::ChosenInlineResult(chosen) => Some(&chosen.from),
UpdateKind::InlineQuery(query) => Some(&query.from),
UpdateKind::ShippingQuery(query) => Some(&query.from),
UpdateKind::PreCheckoutQuery(query) => Some(&query.from),
UpdateKind::PollAnswer(answer) => Some(&answer.user),
_ => None,
}
}
pub fn chat(&self) -> Option<&Chat> {
match &self.kind {
UpdateKind::Message(m) => {
Some(&m.chat)
}
UpdateKind::EditedMessage(m) => {
Some(&m.chat)
}
UpdateKind::ChannelPost(p) => {
Some(&p.chat)
}
UpdateKind::EditedChannelPost(p) => {
Some(&p.chat)
}
UpdateKind::CallbackQuery(q) => {
Some(&q.message.as_ref()?.chat)
}
_ => None
UpdateKind::Message(m) => Some(&m.chat),
UpdateKind::EditedMessage(m) => Some(&m.chat),
UpdateKind::ChannelPost(p) => Some(&p.chat),
UpdateKind::EditedChannelPost(p) => Some(&p.chat),
UpdateKind::CallbackQuery(q) => Some(&q.message.as_ref()?.chat),
_ => None,
}
}
}

View file

@ -46,19 +46,23 @@ impl User {
}
}
/// Returned only in GetMe
/// Returned only in [`Bot::get_me`].
///
/// [`Bot::get_me`]: crate::Bot::get_me
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Me {
#[serde(flatten)]
pub user: User,
/// True, if the bot can be invited to groups.
/// `true`, if the bot can be invited to groups.
pub can_join_groups: bool,
/// True, if [privacy mode](https://core.telegram.org/bots#privacy-mode) is disabled for the bot.
/// `true`, if [privacy mode] is disabled for the bot.
///
/// [privacy mode]: https://core.telegram.org/bots#privacy-mode
pub can_read_all_group_messages: bool,
/// True, if the bot supports inline queries.
/// `true`, if the bot supports inline queries.
pub supports_inline_queries: bool,
}