Skip to content

Commit

Permalink
Merge pull request #38 from Desiders/add-support-bot-api-7.8
Browse files Browse the repository at this point in the history
Add support Bot API 7.8
  • Loading branch information
Desiders authored Aug 14, 2024
2 parents 51e0d86 + df9bc80 commit 47b7e52
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 187 deletions.
19 changes: 19 additions & 0 deletions telers/src/methods/pin_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use serde_with::skip_serializing_none;
#[skip_serializing_none]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
pub struct PinChatMessage {
/// Unique identifier of the business connection on behalf of which the message will be pinned
pub business_connection_id: Option<String>,
/// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
pub chat_id: ChatIdKind,
/// Identifier of a message to pin
Expand All @@ -25,12 +27,21 @@ impl PinChatMessage {
#[must_use]
pub fn new(chat_id: impl Into<ChatIdKind>, message_id: i64) -> Self {
Self {
business_connection_id: None,
chat_id: chat_id.into(),
message_id,
disable_notification: None,
}
}

#[must_use]
pub fn business_connection_id(self, val: impl Into<String>) -> Self {
Self {
business_connection_id: Some(val.into()),
..self
}
}

#[must_use]
pub fn chat_id(self, val: impl Into<ChatIdKind>) -> Self {
Self {
Expand All @@ -57,6 +68,14 @@ impl PinChatMessage {
}

impl PinChatMessage {
#[must_use]
pub fn business_connection_id_option(self, val: Option<impl Into<String>>) -> Self {
Self {
business_connection_id: val.map(Into::into),
..self
}
}

#[must_use]
pub fn disable_notification_option(self, val: Option<bool>) -> Self {
Self {
Expand Down
23 changes: 23 additions & 0 deletions telers/src/methods/unpin_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ use super::base::{Request, TelegramMethod};
use crate::{client::Bot, types::ChatIdKind};

use serde::Serialize;
use serde_with::skip_serializing_none;

/// Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the `can_pin_messages` administrator right in a supergroup or `can_edit_messages` administrator right in a channel.
/// # Documentation
/// <https://core.telegram.org/bots/api#unpinchatmessage>
/// # Returns
/// Returns `true` on success
#[skip_serializing_none]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
pub struct UnpinChatMessage {
/// Unique identifier of the business connection on behalf of which the message will be unpinned
pub business_connection_id: Option<String>,
/// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
pub chat_id: ChatIdKind,
/// Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
Expand All @@ -21,11 +25,20 @@ impl UnpinChatMessage {
#[must_use]
pub fn new(chat_id: impl Into<ChatIdKind>, message_id: i64) -> Self {
Self {
business_connection_id: None,
chat_id: chat_id.into(),
message_id,
}
}

#[must_use]
pub fn business_connection_id(self, val: impl Into<String>) -> Self {
Self {
business_connection_id: Some(val.into()),
..self
}
}

#[must_use]
pub fn chat_id(self, val: impl Into<ChatIdKind>) -> Self {
Self {
Expand All @@ -43,6 +56,16 @@ impl UnpinChatMessage {
}
}

impl UnpinChatMessage {
#[must_use]
pub fn business_connection_id_option(self, val: Option<impl Into<String>>) -> Self {
Self {
business_connection_id: val.map(Into::into),
..self
}
}
}

impl TelegramMethod for UnpinChatMessage {
type Method = Self;
type Return = bool;
Expand Down
189 changes: 2 additions & 187 deletions telers/src/types/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct User {
pub supports_inline_queries: Option<bool>,
/// `true`, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in [`GetMe`](crate::methods::GetMe).
pub can_connect_to_business: Option<bool>,
/// `true, if the bot has a main Web App. Returned only in [`GetMe`](crate::methods::GetMe).
pub has_main_web_app: Option<bool>,
}

impl User {
Expand All @@ -50,190 +52,3 @@ impl User {
}
}
}

impl User {
#[must_use]
pub fn new(id: i64, is_bot: bool, first_name: impl Into<String>) -> Self {
Self {
id,
is_bot,
first_name: first_name.into(),
last_name: None,
username: None,
language_code: None,
is_premium: None,
added_to_attachment_menu: None,
can_join_groups: None,
can_read_all_group_messages: None,
supports_inline_queries: None,
can_connect_to_business: None,
}
}

#[must_use]
pub fn id(self, val: i64) -> Self {
Self { id: val, ..self }
}

#[must_use]
pub fn is_bot(self, val: bool) -> Self {
Self {
is_bot: val,
..self
}
}

#[must_use]
pub fn first_name(self, val: impl Into<String>) -> Self {
Self {
first_name: val.into(),
..self
}
}

#[must_use]
pub fn last_name(self, val: impl Into<String>) -> Self {
Self {
last_name: Some(val.into()),
..self
}
}

#[must_use]
pub fn username(self, val: impl Into<String>) -> Self {
Self {
username: Some(val.into()),
..self
}
}

#[must_use]
pub fn language_code(self, val: impl Into<String>) -> Self {
Self {
language_code: Some(val.into()),
..self
}
}

#[must_use]
pub fn is_premium(self, val: bool) -> Self {
Self {
is_premium: Some(val),
..self
}
}

#[must_use]
pub fn added_to_attachment_menu(self, val: bool) -> Self {
Self {
added_to_attachment_menu: Some(val),
..self
}
}

#[must_use]
pub fn can_join_groups(self, val: bool) -> Self {
Self {
can_join_groups: Some(val),
..self
}
}

#[must_use]
pub fn can_read_all_group_messages(self, val: bool) -> Self {
Self {
can_read_all_group_messages: Some(val),
..self
}
}

#[must_use]
pub fn supports_inline_queries(self, val: bool) -> Self {
Self {
supports_inline_queries: Some(val),
..self
}
}

#[must_use]
pub fn can_connect_to_business(self, val: bool) -> Self {
Self {
can_connect_to_business: Some(val),
..self
}
}
}

impl User {
#[must_use]
pub fn last_name_option(self, val: Option<impl Into<String>>) -> Self {
Self {
last_name: val.map(Into::into),
..self
}
}

#[must_use]
pub fn username_option(self, val: Option<impl Into<String>>) -> Self {
Self {
username: val.map(Into::into),
..self
}
}

#[must_use]
pub fn language_code_option(self, val: Option<impl Into<String>>) -> Self {
Self {
language_code: val.map(Into::into),
..self
}
}

#[must_use]
pub fn is_premium_option(self, val: Option<bool>) -> Self {
Self {
is_premium: val,
..self
}
}

#[must_use]
pub fn added_to_attachment_menu_option(self, val: Option<bool>) -> Self {
Self {
added_to_attachment_menu: val,
..self
}
}

#[must_use]
pub fn can_join_groups_option(self, val: Option<bool>) -> Self {
Self {
can_join_groups: val,
..self
}
}

#[must_use]
pub fn can_read_all_group_messages_option(self, val: Option<bool>) -> Self {
Self {
can_read_all_group_messages: val,
..self
}
}

#[must_use]
pub fn supports_inline_queries_option(self, val: Option<bool>) -> Self {
Self {
supports_inline_queries: val,
..self
}
}

#[must_use]
pub fn can_connect_to_business_option(self, val: Option<bool>) -> Self {
Self {
can_connect_to_business: val,
..self
}
}
}

0 comments on commit 47b7e52

Please sign in to comment.