From b41f3cbe27e8c7af6160f5ed7ec5ca5cf5625644 Mon Sep 17 00:00:00 2001 From: fedechkin_alexey Date: Mon, 2 Sep 2019 20:51:03 +0700 Subject: [PATCH] add struct --- src/core/types/CallbackQuery.rs | 19 +++++++++++++ src/core/types/ChatMember.rs | 38 ++++++++++++++++++++++++++ src/core/types/ForceReply.rs | 13 +++++++++ src/core/types/InlineKeyboardButton.rs | 20 ++++++++++++++ src/core/types/InlineKeyboardMarkup.rs | 7 +++++ src/core/types/KeyboardButton.rs | 11 ++++++++ src/core/types/ReplyKeyboardMarkup.rs | 13 +++++++++ src/core/types/ReplyKeyboardRemove.rs | 13 +++++++++ 8 files changed, 134 insertions(+) create mode 100644 src/core/types/CallbackQuery.rs create mode 100644 src/core/types/ChatMember.rs create mode 100644 src/core/types/ForceReply.rs create mode 100644 src/core/types/InlineKeyboardButton.rs create mode 100644 src/core/types/InlineKeyboardMarkup.rs create mode 100644 src/core/types/KeyboardButton.rs create mode 100644 src/core/types/ReplyKeyboardMarkup.rs create mode 100644 src/core/types/ReplyKeyboardRemove.rs diff --git a/src/core/types/CallbackQuery.rs b/src/core/types/CallbackQuery.rs new file mode 100644 index 00000000..3fb17e76 --- /dev/null +++ b/src/core/types/CallbackQuery.rs @@ -0,0 +1,19 @@ +use serde::Deserialize; + +/// This object represents an incoming callback query from a callback button in an inline keyboard. +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct CallbackQuery { + /// Unique identifier for this query + pub id: CallbackQueryId, + /// Sender + pub from: User, + /// Message with the callback button that originated the query. + /// Note that message content and message date will not be available if the message is too old + pub message: Message, + /// Global identifier, uniquely corresponding to the chat to which the message + /// with the callback button was sent. Useful for high scores in games. + pub chat_instance: String, + /// Data associated with the callback button. Be aware that a bad client can + /// send arbitrary data in this field. + pub data: String, +} \ No newline at end of file diff --git a/src/core/types/ChatMember.rs b/src/core/types/ChatMember.rs new file mode 100644 index 00000000..1ffb0c5c --- /dev/null +++ b/src/core/types/ChatMember.rs @@ -0,0 +1,38 @@ +use serde::Deserialize; + +/// This object contains information about one member of the chat. +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct ChatMember { + /// Information about the user. + pub user: User, + /// The member's status in the chat. + pub status: ChatMemberStatus, + ///Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time + pub until_date: Option, + ///Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user + pub can_be_edited: Option, + ///Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings + pub can_change_info: Option, + ///Optional. Administrators only. True, if the administrator can post in the channel, channels only + pub can_post_messages: Option, + ///Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only + pub can_edit_messages: Option, + ///Optional. Administrators only. True, if the administrator can delete messages of other users + pub can_delete_messages: Option, + ///Optional. Administrators only. True, if the administrator can invite new users to the chat + pub can_invite_users: Option, + ///Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members + pub can_restrict_members: Option, + ///Optional. Administrators only. True, if the administrator can pin messages, supergroups only + pub can_pin_messages: Option, + ///Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user) + pub can_promote_members: Option, + ///Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues + pub can_send_messages: Option, + ///Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages + pub can_send_media_messages: Option, + ///Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages + pub can_send_other_messages: Option, + ///Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages + pub can_add_web_page_previews: Option, +} \ No newline at end of file diff --git a/src/core/types/ForceReply.rs b/src/core/types/ForceReply.rs new file mode 100644 index 00000000..6689065a --- /dev/null +++ b/src/core/types/ForceReply.rs @@ -0,0 +1,13 @@ +use serde::Deserialize; + +/// Upon receiving a message with this object, Telegram clients will +/// display a reply interface to the user (act as if the user has +/// selected the bot‘s message and tapped ’Reply'). This can be +/// extremely useful if you want to create user-friendly step-by-step +/// interfaces without having to sacrifice privacy mod +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct ForceReply { + force_reply: True, + #[serde(skip_serializing_if = "Not::not")] + selective: bool, +} \ No newline at end of file diff --git a/src/core/types/InlineKeyboardButton.rs b/src/core/types/InlineKeyboardButton.rs new file mode 100644 index 00000000..36e98256 --- /dev/null +++ b/src/core/types/InlineKeyboardButton.rs @@ -0,0 +1,20 @@ +use serde::Deserialize; + +/// This object represents one button of an inline keyboard. +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct InlineKeyboardButton { + text: String, + #[serde(flatten)] + kind: InlineKeyboardButtonKind, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)] +pub enum InlineKeyboardButtonKind { + #[serde(rename = "url")] + Url(String), // TODO(knsd): Url? + #[serde(rename = "callback_data")] + CallbackData(String), // TODO(knsd) Validate size? + // SwitchInlineQuery(String), + // SwitchInlineQueryCurrentChat(String), + // CallbackGame(CallbackGame), +} \ No newline at end of file diff --git a/src/core/types/InlineKeyboardMarkup.rs b/src/core/types/InlineKeyboardMarkup.rs new file mode 100644 index 00000000..18aafc49 --- /dev/null +++ b/src/core/types/InlineKeyboardMarkup.rs @@ -0,0 +1,7 @@ +use serde::Deserialize; + +/// This object represents an inline keyboard that appears right next to the message it belongs to. +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct InlineKeyboardMarkup { + inline_keyboard: Vec>, +} diff --git a/src/core/types/KeyboardButton.rs b/src/core/types/KeyboardButton.rs new file mode 100644 index 00000000..9021bf72 --- /dev/null +++ b/src/core/types/KeyboardButton.rs @@ -0,0 +1,11 @@ +use serde::Deserialize; + +/// This object represents one button of the reply keyboard. +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct KeyboardButton { + text: String, + #[serde(skip_serializing_if = "Not::not")] + request_contact: bool, + #[serde(skip_serializing_if = "Not::not")] + request_location: bool, +} \ No newline at end of file diff --git a/src/core/types/ReplyKeyboardMarkup.rs b/src/core/types/ReplyKeyboardMarkup.rs new file mode 100644 index 00000000..8587b805 --- /dev/null +++ b/src/core/types/ReplyKeyboardMarkup.rs @@ -0,0 +1,13 @@ +use serde::Deserialize; + +/// This object represents a custom keyboard with reply options. +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct ReplyKeyboardMarkup { + keyboard: Vec>, + #[serde(skip_serializing_if = "Not::not")] + resize_keyboard: bool, + #[serde(skip_serializing_if = "Not::not")] + one_time_keyboard: bool, + #[serde(skip_serializing_if = "Not::not")] + selective: bool, +} \ No newline at end of file diff --git a/src/core/types/ReplyKeyboardRemove.rs b/src/core/types/ReplyKeyboardRemove.rs new file mode 100644 index 00000000..6a445502 --- /dev/null +++ b/src/core/types/ReplyKeyboardRemove.rs @@ -0,0 +1,13 @@ +use serde::Deserialize; + +/// Upon receiving a message with this object, Telegram clients will remove +/// the current custom keyboard and display the default letter-keyboard. +/// By default, custom keyboards are displayed until a new keyboard is sent +/// by a bot. An exception is made for one-time keyboards that are hidden +/// immediately after the user presses a button (see ReplyKeyboardMarkup). +#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] +pub struct ReplyKeyboardRemove { + remove_keyboard: True, + #[serde(skip_serializing_if = "Not::not")] + selective: bool, +} \ No newline at end of file