diff options
author | syn <isaqtm@gmail.com> | 2021-02-11 04:17:36 +0300 |
---|---|---|
committer | syn <isaqtm@gmail.com> | 2021-02-11 04:17:36 +0300 |
commit | 089c71ac47fde2d22432da7e91e332b8cfe384d7 (patch) | |
tree | 256b31bb67a3fdfe0b11afbbd8573491acd60b2f | |
parent | fe72c896a648cfff14bc1b606bcc486ccba0fc22 (diff) | |
download | tdlib-autogen-089c71ac47fde2d22432da7e91e332b8cfe384d7.tar.gz |
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/core.rs | 1164 | ||||
-rw-r--r-- | src/lib.rs | 22 | ||||
-rw-r--r-- | src/makefile | 2 | ||||
-rw-r--r-- | src/targets/core.json | 20 | ||||
-rw-r--r-- | src/targets/messaging.json | 20 | ||||
-rw-r--r-- | src/util.py | 70 |
7 files changed, 1289 insertions, 11 deletions
@@ -15,3 +15,5 @@ chrono = "0.4" tdlib-rs = { version = "0.1", path = "../tdlib-rs" } +[features] +core = [] diff --git a/src/core.rs b/src/core.rs new file mode 100644 index 0000000..e0f8477 --- /dev/null +++ b/src/core.rs @@ -0,0 +1,1164 @@ + +#![allow(unused)] +use serde::Deserializer; +use tdlib_rs::client::ClientLike; + +use super::{deserialize_i64_0, deserialize_i64_1}; +use serde_derive::{Deserialize, Serialize}; +use serde_json::{json, Value as SerdeJsonValue}; +use tdlib_rs::client::ResponseFuture; +use tdlib_rs::Client; + +#[doc = "An object of this type can be returned on every function call, in case of an error"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Error { + #[doc = "Error code; subject to future changes. If the error code is 406, the error message must not be processed in any way and must not be displayed to the user"] + pub code: i32, + #[doc = "Error message; subject to future changes"] + pub message: String, +} +#[doc = "An object of this type is returned on a successful function call for certain functions"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Ok {} +#[doc = "Contains parameters for TDLib initialization"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct TdlibParameters { + #[doc = "If set to true, the Telegram test environment will be used instead of the production environment"] + pub use_test_dc: bool, + #[doc = "The path to the directory for the persistent database; if empty, the current working directory will be used"] + pub database_directory: String, + #[doc = "The path to the directory for storing files; if empty, database_directory will be used"] + pub files_directory: String, + #[doc = "If set to true, information about downloaded and uploaded files will be saved between application restarts"] + pub use_file_database: bool, + #[doc = "If set to true, the library will maintain a cache of users, basic groups, supergroups, channels and secret chats. Implies use_file_database"] + pub use_chat_info_database: bool, + #[doc = "If set to true, the library will maintain a cache of chats and messages. Implies use_chat_info_database"] + pub use_message_database: bool, + #[doc = "If set to true, support for secret chats will be enabled"] + pub use_secret_chats: bool, + #[doc = "Application identifier for Telegram API access, which can be obtained at https://my.telegram.org"] + pub api_id: i32, + #[doc = "Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org"] + pub api_hash: String, + #[doc = "IETF language tag of the user's operating system language; must be non-empty"] + pub system_language_code: String, + #[doc = "Model of the device the application is being run on; must be non-empty"] + pub device_model: String, + #[doc = "Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib"] + pub system_version: String, + #[doc = "Application version; must be non-empty"] + pub application_version: String, + #[doc = "If set to true, old files will automatically be deleted"] + pub enable_storage_optimizer: bool, + #[doc = "If set to true, original file names will be ignored. Otherwise, downloaded files will be saved under names as close as possible to the original name"] + pub ignore_file_names: bool, +} +#[doc = "TDLib needs an encryption key to decrypt the local database "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct AuthorizationStateWaitEncryptionKey { + #[doc = "True, if the database is currently encrypted"] + pub is_encrypted: bool, +} +#[doc = "TDLib needs the user's authentication code to authorize "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct AuthorizationStateWaitCode { + #[doc = "Information about the authorization code that was sent"] + pub code_info: SerdeJsonValue, +} +#[doc = "The user needs to confirm authorization on another logged in device by scanning a QR code with the provided link "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct AuthorizationStateWaitOtherDeviceConfirmation { + #[doc = "A tg:// URL for the QR code. The link will be updated frequently"] + pub link: String, +} +#[doc = "The user is unregistered and need to accept terms of service and enter their first name and last name to finish registration "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct AuthorizationStateWaitRegistration { + #[doc = "Telegram terms of service"] + pub terms_of_service: SerdeJsonValue, +} +#[doc = "The user has been authorized, but needs to enter a password to start using the application "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct AuthorizationStateWaitPassword { + #[doc = "Hint for the password; may be empty "] + pub password_hint: String, + #[doc = "True, if a recovery email address has been set up"] + pub has_recovery_email_address: bool, + #[doc = "Pattern of the email address to which the recovery email was sent; empty until a recovery email has been sent"] + pub recovery_email_address_pattern: String, +} +#[doc = "Represents a user"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct User { + #[doc = "User identifier"] + pub id: i32, + #[doc = "First name of the user"] + pub first_name: String, + #[doc = "Last name of the user"] + pub last_name: String, + #[doc = "Username of the user"] + pub username: String, + #[doc = "Phone number of the user"] + pub phone_number: String, + #[doc = "Current online status of the user"] + pub status: UserStatus, + #[doc = "Profile photo of the user; may be null"] + pub profile_photo: SerdeJsonValue, + #[doc = "The user is a contact of the current user"] + pub is_contact: bool, + #[doc = "The user is a contact of the current user and the current user is a contact of the user"] + pub is_mutual_contact: bool, + #[doc = "True, if the user is verified"] + pub is_verified: bool, + #[doc = "True, if the user is Telegram support account"] + pub is_support: bool, + #[doc = "If non-empty, it contains a human-readable description of the reason why access to this user must be restricted"] + pub restriction_reason: String, + #[doc = "True, if many users reported this user as a scam"] + pub is_scam: bool, + #[doc = "If false, the user is inaccessible, and the only information known about the user is inside this class. It can't be passed to any method except GetUser"] + pub have_access: bool, + #[doc = "Type of the user"] + #[serde(rename = "type")] + pub type_: SerdeJsonValue, + #[doc = "IETF language tag of the user's language; only available to bots"] + pub language_code: Option<String>, +} +#[doc = "Describes a message"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Message { + #[doc = "Message identifier; unique for the chat to which the message belongs"] + pub id: i64, + #[doc = "The sender of the message"] + pub sender: SerdeJsonValue, + #[doc = "Chat identifier"] + pub chat_id: i64, + #[doc = "Information about the sending state of the message; may be null"] + pub sending_state: SerdeJsonValue, + #[doc = "Information about the scheduling state of the message; may be null"] + pub scheduling_state: SerdeJsonValue, + #[doc = "True, if the message is outgoing"] + pub is_outgoing: bool, + #[doc = "True, if the message is pinned"] + pub is_pinned: bool, + #[doc = "True, if the message can be edited. For live location and poll messages this fields shows whether editMessageLiveLocation or stopPoll can be used with this message by the application"] + pub can_be_edited: bool, + #[doc = "True, if the message can be forwarded"] + pub can_be_forwarded: bool, + #[doc = "True, if the message can be deleted only for the current user while other users will continue to see it"] + pub can_be_deleted_only_for_self: bool, + #[doc = "True, if the message can be deleted for all users"] + pub can_be_deleted_for_all_users: bool, + #[doc = "True, if the message statistics are available"] + pub can_get_statistics: bool, + #[doc = "True, if the message thread info is available"] + pub can_get_message_thread: bool, + #[doc = "True, if the message is a channel post. All messages to channels are channel posts, all other messages are not channel posts"] + pub is_channel_post: bool, + #[doc = "True, if the message contains an unread mention for the current user"] + pub contains_unread_mention: bool, + #[doc = "Point in time (Unix timestamp) when the message was sent"] + pub date: i32, + #[doc = "Point in time (Unix timestamp) when the message was last edited"] + pub edit_date: i32, + #[doc = "Information about the initial message sender; may be null"] + pub forward_info: SerdeJsonValue, + #[doc = "Information about interactions with the message; may be null"] + pub interaction_info: SerdeJsonValue, + #[doc = "If non-zero, the identifier of the chat to which the replied message belongs; Currently, only messages in the Replies chat can have different reply_in_chat_id and chat_id"] + pub reply_in_chat_id: i64, + #[doc = "If non-zero, the identifier of the message this message is replying to; can be the identifier of a deleted message"] + pub reply_to_message_id: i64, + #[doc = "If non-zero, the identifier of the message thread the message belongs to; unique within the chat to which the message belongs"] + pub message_thread_id: i64, + #[doc = "For self-destructing messages, the message's TTL (Time To Live), in seconds; 0 if none. TDLib will send updateDeleteMessages or updateMessageContent once the TTL expires"] + pub ttl: i32, + #[doc = "Time left before the message expires, in seconds"] + pub ttl_expires_in: f64, + #[doc = "If non-zero, the user identifier of the bot through which this message was sent"] + pub via_bot_user_id: i32, + #[doc = "For channel posts and anonymous group messages, optional author signature"] + pub author_signature: String, + #[doc = "Unique identifier of an album this message belongs to. Only photos and videos can be grouped together in albums"] + #[serde(deserialize_with = "deserialize_i64_0")] + pub media_album_id: i64, + #[doc = "If non-empty, contains a human-readable description of the reason why access to this message must be restricted"] + pub restriction_reason: String, + #[doc = "Content of the message"] + pub content: SerdeJsonValue, + #[doc = "Reply markup for the message; may be null"] + pub reply_markup: SerdeJsonValue, +} +#[doc = "A chat. (Can be a private chat, basic group, supergroup, or secret chat)"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Chat { + #[doc = "Chat unique identifier"] + pub id: i64, + #[doc = "Type of the chat"] + #[serde(rename = "type")] + pub type_: SerdeJsonValue, + #[doc = "Chat title"] + pub title: String, + #[doc = "Chat photo; may be null"] + pub photo: SerdeJsonValue, + #[doc = "Actions that non-administrator chat members are allowed to take in the chat"] + pub permissions: SerdeJsonValue, + #[doc = "Last message in the chat; may be null"] + pub last_message: Option<Message>, + #[doc = "Positions of the chat in chat lists"] + pub positions: SerdeJsonValue, + #[doc = "True, if the chat is marked as unread"] + pub is_marked_as_unread: bool, + #[doc = "True, if the chat is blocked by the current user and private messages from the chat can't be received"] + pub is_blocked: bool, + #[doc = "True, if the chat has scheduled messages"] + pub has_scheduled_messages: bool, + #[doc = "True, if the chat messages can be deleted only for the current user while other users will continue to see the messages"] + pub can_be_deleted_only_for_self: bool, + #[doc = "True, if the chat messages can be deleted for all users"] + pub can_be_deleted_for_all_users: bool, + #[doc = "True, if the chat can be reported to Telegram moderators through reportChat"] + pub can_be_reported: bool, + #[doc = "Default value of the disable_notification parameter, used when a message is sent to the chat"] + pub default_disable_notification: bool, + #[doc = "Number of unread messages in the chat"] + pub unread_count: i32, + #[doc = "Identifier of the last read incoming message"] + pub last_read_inbox_message_id: i64, + #[doc = "Identifier of the last read outgoing message"] + pub last_read_outbox_message_id: i64, + #[doc = "Number of unread messages with a mention/reply in the chat"] + pub unread_mention_count: i32, + #[doc = "Notification settings for this chat"] + pub notification_settings: SerdeJsonValue, + #[doc = "Describes actions which should be possible to do through a chat action bar; may be null"] + pub action_bar: SerdeJsonValue, + #[doc = "Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat"] + pub reply_markup_message_id: i64, + #[doc = "A draft of a message in the chat; may be null"] + pub draft_message: SerdeJsonValue, + #[doc = "Contains application-specific data associated with the chat. (For example, the chat scroll position or local chat notification settings can be stored here.) Persistent if the message database is used"] + pub client_data: String, +} +#[doc = "The user is online "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UserStatusOnline { + #[doc = "Point in time (Unix timestamp) when the user's online status will expire"] + pub expires: i32, +} +#[doc = "The user is offline "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UserStatusOffline { + #[doc = "Point in time (Unix timestamp) when the user was last online"] + pub was_online: i32, +} +#[doc = "Contains settings for the authentication of the user's phone number"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct PhoneNumberAuthenticationSettings { + #[doc = "Pass true if the authentication code may be sent via flash call to the specified phone number"] + pub allow_flash_call: bool, + #[doc = "Pass true if the authenticated phone number is used on the current device"] + pub is_current_phone_number: bool, + #[doc = "For official applications only. True, if the application can use Android SMS Retriever API (requires Google Play Services >= 10.2) to automatically receive the authentication code from the SMS. See https://developers.google.com/identity/sms-retriever/ for more details"] + pub allow_sms_retriever_api: bool, +} +#[doc = "The user authorization state has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateAuthorizationState { + #[doc = "New authorization state"] + pub authorization_state: AuthorizationState, +} +#[doc = "A new message was received; can also be an outgoing message "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewMessage { + #[doc = "The new message"] + pub message: Message, +} +#[doc = "A request to send a message has reached the Telegram server. This doesn't mean that the message will be sent successfully or even that the send message request will be processed. This update will be sent only if the option \"use_quick_ack\" is set to true. This update may be sent multiple times for the same message"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageSendAcknowledged { + #[doc = "The chat identifier of the sent message "] + pub chat_id: i64, + #[doc = "A temporary message identifier"] + pub message_id: i64, +} +#[doc = "A message has been successfully sent "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageSendSucceeded { + #[doc = "Information about the sent message. Usually only the message identifier, date, and content are changed, but almost all other fields can also change "] + pub message: Message, + #[doc = "The previous temporary message identifier"] + pub old_message_id: i64, +} +#[doc = "A message failed to send. Be aware that some messages being sent can be irrecoverably deleted, in which case updateDeleteMessages will be received instead of this update"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageSendFailed { + #[doc = "Contains information about the message which failed to send "] + pub message: Message, + #[doc = "The previous temporary message identifier "] + pub old_message_id: i64, + #[doc = "An error code "] + pub error_code: i32, + #[doc = "Error message"] + pub error_message: String, +} +#[doc = "The message content has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageContent { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Message identifier "] + pub message_id: i64, + #[doc = "New message content"] + pub new_content: SerdeJsonValue, +} +#[doc = "A message was edited. Changes in the message content will come in a separate updateMessageContent "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageEdited { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Message identifier "] + pub message_id: i64, + #[doc = "Point in time (Unix timestamp) when the message was edited "] + pub edit_date: i32, + #[doc = "New message reply markup; may be null"] + pub reply_markup: SerdeJsonValue, +} +#[doc = "The message pinned state was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageIsPinned { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The message identifier "] + pub message_id: i64, + #[doc = "True, if the message is pinned"] + pub is_pinned: bool, +} +#[doc = "The information about interactions with a message has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageInteractionInfo { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Message identifier "] + pub message_id: i64, + #[doc = "New information about interactions with the message; may be null"] + pub interaction_info: SerdeJsonValue, +} +#[doc = "The message content was opened. Updates voice note messages to \"listened\", video note messages to \"viewed\" and starts the TTL timer for self-destructing messages "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageContentOpened { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Message identifier"] + pub message_id: i64, +} +#[doc = "A message with an unread mention was read "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageMentionRead { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Message identifier "] + pub message_id: i64, + #[doc = "The new number of unread mention messages left in the chat"] + pub unread_mention_count: i32, +} +#[doc = "A message with a live location was viewed. When the update is received, the application is supposed to update the live location"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateMessageLiveLocationViewed { + #[doc = "Identifier of the chat with the live location message "] + pub chat_id: i64, + #[doc = "Identifier of the message with live location"] + pub message_id: i64, +} +#[doc = "A new chat has been loaded/created. This update is guaranteed to come before the chat identifier is returned to the application. The chat field changes will be reported through separate updates "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewChat { + #[doc = "The chat"] + pub chat: Chat, +} +#[doc = "The title of a chat was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatTitle { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new chat title"] + pub title: String, +} +#[doc = "A chat photo was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatPhoto { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new chat photo; may be null"] + pub photo: SerdeJsonValue, +} +#[doc = "Chat permissions was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatPermissions { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new chat permissions"] + pub permissions: SerdeJsonValue, +} +#[doc = "The last message of a chat was changed. If last_message is null, then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatLastMessage { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new last message in the chat; may be null "] + pub last_message: Option<Message>, + #[doc = "The new chat positions in the chat lists"] + pub positions: SerdeJsonValue, +} +#[doc = "The position of a chat in a chat list has changed. Instead of this update updateChatLastMessage or updateChatDraftMessage might be sent "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatPosition { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "New chat position. If new order is 0, then the chat needs to be removed from the list"] + pub position: SerdeJsonValue, +} +#[doc = "A chat was marked as unread or was read "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatIsMarkedAsUnread { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "New value of is_marked_as_unread"] + pub is_marked_as_unread: bool, +} +#[doc = "A chat was blocked or unblocked "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatIsBlocked { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "New value of is_blocked"] + pub is_blocked: bool, +} +#[doc = "A chat's has_scheduled_messages field has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatHasScheduledMessages { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "New value of has_scheduled_messages"] + pub has_scheduled_messages: bool, +} +#[doc = "The value of the default disable_notification parameter, used when a message is sent to the chat, was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatDefaultDisableNotification { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new default_disable_notification value"] + pub default_disable_notification: bool, +} +#[doc = "Incoming messages were read or number of unread messages has been changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatReadInbox { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Identifier of the last read incoming message "] + pub last_read_inbox_message_id: i64, + #[doc = "The number of unread messages left in the chat"] + pub unread_count: i32, +} +#[doc = "Outgoing messages were read "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatReadOutbox { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Identifier of last read outgoing message"] + pub last_read_outbox_message_id: i64, +} +#[doc = "The chat unread_mention_count has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatUnreadMentionCount { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The number of unread mention messages left in the chat"] + pub unread_mention_count: i32, +} +#[doc = "Notification settings for a chat were changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatNotificationSettings { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new notification settings"] + pub notification_settings: SerdeJsonValue, +} +#[doc = "Notification settings for some type of chats were updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateScopeNotificationSettings { + #[doc = "Types of chats for which notification settings were updated "] + pub scope: SerdeJsonValue, + #[doc = "The new notification settings"] + pub notification_settings: SerdeJsonValue, +} +#[doc = "The chat action bar was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatActionBar { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new value of the action bar; may be null"] + pub action_bar: SerdeJsonValue, +} +#[doc = "The default chat reply markup was changed. Can occur because new messages with reply markup were received or because an old reply markup was hidden by the user"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatReplyMarkup { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat"] + pub reply_markup_message_id: i64, +} +#[doc = "A chat draft has changed. Be aware that the update may come in the currently opened chat but with old content of the draft. If the user has changed the content of the draft, this update shouldn't be applied "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatDraftMessage { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "The new draft message; may be null "] + pub draft_message: SerdeJsonValue, + #[doc = "The new chat positions in the chat lists"] + pub positions: SerdeJsonValue, +} +#[doc = "The list of chat filters or a chat filter has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatFilters { + #[doc = "The new list of chat filters"] + pub chat_filters: SerdeJsonValue, +} +#[doc = "The number of online group members has changed. This update with non-zero count is sent only for currently opened chats. There is no guarantee that it will be sent just after the count has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateChatOnlineMemberCount { + #[doc = "Identifier of the chat "] + pub chat_id: i64, + #[doc = "New number of online members in the chat, or 0 if unknown"] + pub online_member_count: i32, +} +#[doc = "A notification was changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNotification { + #[doc = "Unique notification group identifier "] + pub notification_group_id: i32, + #[doc = "Changed notification"] + pub notification: SerdeJsonValue, +} +#[doc = "A list of active notifications in a notification group has changed"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNotificationGroup { + #[doc = "Unique notification group identifier"] + pub notification_group_id: i32, + #[doc = "New type of the notification group"] + #[serde(rename = "type")] + pub type_: SerdeJsonValue, + #[doc = "Identifier of a chat to which all notifications in the group belong"] + pub chat_id: i64, + #[doc = "Chat identifier, which notification settings must be applied to the added notifications"] + pub notification_settings_chat_id: i64, + #[doc = "True, if the notifications should be shown without sound"] + pub is_silent: bool, + #[doc = "Total number of unread notifications in the group, can be bigger than number of active notifications"] + pub total_count: i32, + #[doc = "List of added group notifications, sorted by notification ID "] + pub added_notifications: SerdeJsonValue, + #[doc = "Identifiers of removed group notifications, sorted by notification ID"] + pub removed_notification_ids: Vec<i32>, +} +#[doc = "Contains active notifications that was shown on previous application launches. This update is sent only if the message database is used. In that case it comes once before any updateNotification and updateNotificationGroup update "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateActiveNotifications { + #[doc = "Lists of active notification groups"] + pub groups: SerdeJsonValue, +} +#[doc = "Describes whether there are some pending notification updates. Can be used to prevent application from killing, while there are some pending notifications"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateHavePendingNotifications { + #[doc = "True, if there are some delayed notification updates, which will be sent soon"] + pub have_delayed_notifications: bool, + #[doc = "True, if there can be some yet unreceived notifications, which are being fetched from the server"] + pub have_unreceived_notifications: bool, +} +#[doc = "Some messages were deleted "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateDeleteMessages { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "Identifiers of the deleted messages"] + pub message_ids: Vec<i64>, + #[doc = "True, if the messages are permanently deleted by a user (as opposed to just becoming inaccessible)"] + pub is_permanent: bool, + #[doc = "True, if the messages are deleted only from the cache and can possibly be retrieved again in the future"] + pub from_cache: bool, +} +#[doc = "User activity in the chat has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUserChatAction { + #[doc = "Chat identifier "] + pub chat_id: i64, + #[doc = "If not 0, a message thread identifier in which the action was performed "] + pub message_thread_id: i64, + #[doc = "Identifier of a user performing an action "] + pub user_id: i32, + #[doc = "The action description"] + pub action: SerdeJsonValue, +} +#[doc = "The user went online or offline "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUserStatus { + #[doc = "User identifier "] + pub user_id: i32, + #[doc = "New status of the user"] + pub status: UserStatus, +} +#[doc = "Some data of a user has changed. This update is guaranteed to come before the user identifier is returned to the application "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUser { + #[doc = "New data about the user"] + pub user: User, +} +#[doc = "Some data of a basic group has changed. This update is guaranteed to come before the basic group identifier is returned to the application "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateBasicGroup { + #[doc = "New data about the group"] + pub basic_group: SerdeJsonValue, +} +#[doc = "Some data of a supergroup or a channel has changed. This update is guaranteed to come before the supergroup identifier is returned to the application "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateSupergroup { + #[doc = "New data about the supergroup"] + pub supergroup: SerdeJsonValue, +} +#[doc = "Some data of a secret chat has changed. This update is guaranteed to come before the secret chat identifier is returned to the application "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateSecretChat { + #[doc = "New data about the secret chat"] + pub secret_chat: SerdeJsonValue, +} +#[doc = "Some data from userFullInfo has been changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUserFullInfo { + #[doc = "User identifier "] + pub user_id: i32, + #[doc = "New full information about the user"] + pub user_full_info: SerdeJsonValue, +} +#[doc = "Some data from basicGroupFullInfo has been changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateBasicGroupFullInfo { + #[doc = "Identifier of a basic group "] + pub basic_group_id: i32, + #[doc = "New full information about the group"] + pub basic_group_full_info: SerdeJsonValue, +} +#[doc = "Some data from supergroupFullInfo has been changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateSupergroupFullInfo { + #[doc = "Identifier of the supergroup or channel "] + pub supergroup_id: i32, + #[doc = "New full information about the supergroup"] + pub supergroup_full_info: SerdeJsonValue, +} +#[doc = "Service notification from the server. Upon receiving this the application must show a popup with the content of the notification"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateServiceNotification { + #[doc = "Notification type. If type begins with \"AUTH_KEY_DROP_\", then two buttons \"Cancel\" and \"Log out\" should be shown under notification; if user presses the second, all local data should be destroyed using Destroy method"] + #[serde(rename = "type")] + pub type_: String, + #[doc = "Notification content"] + pub content: SerdeJsonValue, +} +#[doc = "Information about a file was updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateFile { + #[doc = "New data about the file"] + pub file: SerdeJsonValue, +} +#[doc = "The file generation process needs to be started by the application"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateFileGenerationStart { + #[doc = "Unique identifier for the generation process"] + #[serde(deserialize_with = "deserialize_i64_0")] + pub generation_id: i64, + #[doc = "The path to a file from which a new file is generated; may be empty"] + pub original_path: String, + #[doc = "The path to a file that should be created and where the new file should be generated"] + pub destination_path: String, + #[doc = "String specifying the conversion applied to the original file. If conversion is \"#url#\" than original_path contains an HTTP/HTTPS URL of a file, which should be downloaded by the application"] + pub conversion: String, +} +#[doc = "File generation is no longer needed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateFileGenerationStop { + #[doc = "Unique identifier for the generation process"] + #[serde(deserialize_with = "deserialize_i64_0")] + pub generation_id: i64, +} +#[doc = "New call was created or information about a call was updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateCall { + #[doc = "New data about a call"] + pub call: SerdeJsonValue, +} +#[doc = "New call signaling data arrived "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewCallSignalingData { + #[doc = "The call identifier "] + pub call_id: i32, + #[doc = "The data"] + pub data: String, +} +#[doc = "Some privacy setting rules have been changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUserPrivacySettingRules { + #[doc = "The privacy setting "] + pub setting: SerdeJsonValue, + #[doc = "New privacy rules"] + pub rules: SerdeJsonValue, +} +#[doc = "Number of unread messages in a chat list has changed. This update is sent only if the message database is used "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUnreadMessageCount { + #[doc = "The chat list with changed number of unread messages"] + pub chat_list: SerdeJsonValue, + #[doc = "Total number of unread messages "] + pub unread_count: i32, + #[doc = "Total number of unread messages in unmuted chats"] + pub unread_unmuted_count: i32, +} +#[doc = "Number of unread chats, i.e. with unread messages or marked as unread, has changed. This update is sent only if the message database is used"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUnreadChatCount { + #[doc = "The chat list with changed number of unread messages"] + pub chat_list: SerdeJsonValue, + #[doc = "Approximate total number of chats in the chat list"] + pub total_count: i32, + #[doc = "Total number of unread chats "] + pub unread_count: i32, + #[doc = "Total number of unread unmuted chats"] + pub unread_unmuted_count: i32, + #[doc = "Total number of chats marked as unread "] + pub marked_as_unread_count: i32, + #[doc = "Total number of unmuted chats marked as unread"] + pub marked_as_unread_unmuted_count: i32, +} +#[doc = "An option changed its value "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateOption { + #[doc = "The option name "] + pub name: String, + #[doc = "The new option value"] + pub value: SerdeJsonValue, +} +#[doc = "A sticker set has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateStickerSet { + #[doc = "The sticker set"] + pub sticker_set: SerdeJsonValue, +} +#[doc = "The list of installed sticker sets was updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateInstalledStickerSets { + #[doc = "True, if the list of installed mask sticker sets was updated "] + pub is_masks: bool, + #[doc = "The new list of installed ordinary sticker sets"] + #[serde(deserialize_with = "deserialize_i64_1")] + pub sticker_set_ids: Vec<i64>, +} +#[doc = "The list of trending sticker sets was updated or some of them were viewed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateTrendingStickerSets { + #[doc = "The prefix of the list of trending sticker sets with the newest trending sticker sets"] + pub sticker_sets: SerdeJsonValue, +} +#[doc = "The list of recently used stickers was updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateRecentStickers { + #[doc = "True, if the list of stickers attached to photo or video files was updated, otherwise the list of sent stickers is updated "] + pub is_attached: bool, + #[doc = "The new list of file identifiers of recently used stickers"] + pub sticker_ids: Vec<i32>, +} +#[doc = "The list of favorite stickers was updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateFavoriteStickers { + #[doc = "The new list of file identifiers of favorite stickers"] + pub sticker_ids: Vec<i32>, +} +#[doc = "The list of saved animations was updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateSavedAnimations { + #[doc = "The new list of file identifiers of saved animations"] + pub animation_ids: Vec<i32>, +} +#[doc = "The selected background has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateSelectedBackground { + #[doc = "True, if background for dark theme has changed "] + pub for_dark_theme: bool, + #[doc = "The new selected background; may be null"] + pub background: SerdeJsonValue, +} +#[doc = "Some language pack strings have been updated "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateLanguagePackStrings { + #[doc = "Localization target to which the language pack belongs "] + pub localization_target: String, + #[doc = "Identifier of the updated language pack "] + pub language_pack_id: String, + #[doc = "List of changed language pack strings"] + pub strings: SerdeJsonValue, +} +#[doc = "The connection state has changed. This update must be used only to show a human-readable description of the connection state "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateConnectionState { + #[doc = "The new connection state"] + pub state: SerdeJsonValue, +} +#[doc = "New terms of service must be accepted by the user. If the terms of service are declined, then the deleteAccount method should be called with the reason \"Decline ToS update\" "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateTermsOfService { + #[doc = "Identifier of the terms of service "] + pub terms_of_service_id: String, + #[doc = "The new terms of service"] + pub terms_of_service: SerdeJsonValue, +} +#[doc = "The list of users nearby has changed. The update is guaranteed to be sent only 60 seconds after a successful searchChatsNearby request "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateUsersNearby { + #[doc = "The new list of users nearby"] + pub users_nearby: SerdeJsonValue, +} +#[doc = "The list of supported dice emojis has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateDiceEmojis { + #[doc = "The new list of supported dice emojis"] + pub emojis: Vec<String>, +} +#[doc = "The parameters of animation search through GetOption(\"animation_search_bot_username\") bot has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateAnimationSearchParameters { + #[doc = "Name of the animation search provider "] + pub provider: String, + #[doc = "The new list of emojis suggested for searching"] + pub emojis: Vec<String>, +} +#[doc = "The list of suggested to the user actions has changed "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateSuggestedActions { + #[doc = "Added suggested actions "] + pub added_actions: SerdeJsonValue, + #[doc = "Removed suggested actions"] + pub removed_actions: SerdeJsonValue, +} +#[doc = "A new incoming inline query; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewInlineQuery { + #[doc = "Unique query identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub id: i64, + #[doc = "Identifier of the user who sent the query "] + pub sender_user_id: i32, + #[doc = "User location; may be null"] + pub user_location: SerdeJsonValue, + #[doc = "Text of the query "] + pub query: String, + #[doc = "Offset of the first entry to return"] + pub offset: String, +} +#[doc = "The user has chosen a result of an inline query; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewChosenInlineResult { + #[doc = "Identifier of the user who sent the query "] + pub sender_user_id: i32, + #[doc = "User location; may be null"] + pub user_location: SerdeJsonValue, + #[doc = "Text of the query "] + pub query: String, + #[doc = "Identifier of the chosen result "] + pub result_id: String, + #[doc = "Identifier of the sent inline message, if known"] + pub inline_message_id: String, +} +#[doc = "A new incoming callback query; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewCallbackQuery { + #[doc = "Unique query identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub id: i64, + #[doc = "Identifier of the user who sent the query"] + pub sender_user_id: i32, + #[doc = "Identifier of the chat where the query was sent "] + pub chat_id: i64, + #[doc = "Identifier of the message, from which the query originated"] + pub message_id: i64, + #[doc = "Identifier that uniquely corresponds to the chat to which the message was sent "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub chat_instance: i64, + #[doc = "Query payload"] + pub payload: SerdeJsonValue, +} +#[doc = "A new incoming callback query from a message sent via a bot; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewInlineCallbackQuery { + #[doc = "Unique query identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub id: i64, + #[doc = "Identifier of the user who sent the query "] + pub sender_user_id: i32, + #[doc = "Identifier of the inline message, from which the query originated"] + pub inline_message_id: String, + #[doc = "An identifier uniquely corresponding to the chat a message was sent to "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub chat_instance: i64, + #[doc = "Query payload"] + pub payload: SerdeJsonValue, +} +#[doc = "A new incoming shipping query; for bots only. Only for invoices with flexible price "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewShippingQuery { + #[doc = "Unique query identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub id: i64, + #[doc = "Identifier of the user who sent the query "] + pub sender_user_id: i32, + #[doc = "Invoice payload "] + pub invoice_payload: String, + #[doc = "User shipping address"] + pub shipping_address: SerdeJsonValue, +} +#[doc = "A new incoming pre-checkout query; for bots only. Contains full information about a checkout "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewPreCheckoutQuery { + #[doc = "Unique query identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub id: i64, + #[doc = "Identifier of the user who sent the query "] + pub sender_user_id: i32, + #[doc = "Currency for the product price "] + pub currency: String, + #[doc = "Total price for the product, in the minimal quantity of the currency"] + pub total_amount: i64, + #[doc = "Invoice payload "] + pub invoice_payload: String, + #[doc = "Identifier of a shipping option chosen by the user; may be empty if not applicable "] + pub shipping_option_id: String, + #[doc = "Information about the order; may be null"] + pub order_info: SerdeJsonValue, +} +#[doc = "A new incoming event; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewCustomEvent { + #[doc = "A JSON-serialized event"] + pub event: String, +} +#[doc = "A new incoming query; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateNewCustomQuery { + #[doc = "The query identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub id: i64, + #[doc = "JSON-serialized query data "] + pub data: String, + #[doc = "Query timeout"] + pub timeout: i32, +} +#[doc = "A poll was updated; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdatePoll { + #[doc = "New data about the poll"] + pub poll: SerdeJsonValue, +} +#[doc = "A user changed the answer to a poll; for bots only "] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdatePollAnswer { + #[doc = "Unique poll identifier "] + #[serde(deserialize_with = "deserialize_i64_0")] + pub poll_id: i64, + #[doc = "The user, who changed the answer to the poll "] + pub user_id: i32, + #[doc = "0-based identifiers of answer options, chosen by the user"] + pub option_ids: Vec<i32>, +} +#[doc = "Represents the current authorization state of the TDLib client"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub enum AuthorizationState { + AuthorizationStateWaitTdlibParameters, + AuthorizationStateWaitEncryptionKey(AuthorizationStateWaitEncryptionKey), + AuthorizationStateWaitPhoneNumber, + AuthorizationStateWaitCode(AuthorizationStateWaitCode), + AuthorizationStateWaitOtherDeviceConfirmation(AuthorizationStateWaitOtherDeviceConfirmation), + AuthorizationStateWaitRegistration(AuthorizationStateWaitRegistration), + AuthorizationStateWaitPassword(AuthorizationStateWaitPassword), + AuthorizationStateReady, + AuthorizationStateLoggingOut, + AuthorizationStateClosing, + AuthorizationStateClosed, +} +#[doc = "Describes the last time the user was online"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub enum UserStatus { + UserStatusEmpty, + UserStatusOnline(UserStatusOnline), + UserStatusOffline(UserStatusOffline), + UserStatusRecently, + UserStatusLastWeek, + UserStatusLastMonth, +} +#[doc = "Contains notifications about data changes"] +#[derive(Serialize, Deserialize, Clone, Debug)] +pub enum Update { + UpdateAuthorizationState(UpdateAuthorizationState), + UpdateNewMessage(UpdateNewMessage), + UpdateMessageSendAcknowledged(UpdateMessageSendAcknowledged), + UpdateMessageSendSucceeded(UpdateMessageSendSucceeded), + UpdateMessageSendFailed(UpdateMessageSendFailed), + UpdateMessageContent(UpdateMessageContent), + UpdateMessageEdited(UpdateMessageEdited), + UpdateMessageIsPinned(UpdateMessageIsPinned), + UpdateMessageInteractionInfo(UpdateMessageInteractionInfo), + UpdateMessageContentOpened(UpdateMessageContentOpened), + UpdateMessageMentionRead(UpdateMessageMentionRead), + UpdateMessageLiveLocationViewed(UpdateMessageLiveLocationViewed), + UpdateNewChat(UpdateNewChat), + UpdateChatTitle(UpdateChatTitle), + UpdateChatPhoto(UpdateChatPhoto), + UpdateChatPermissions(UpdateChatPermissions), + UpdateChatLastMessage(UpdateChatLastMessage), + UpdateChatPosition(UpdateChatPosition), + UpdateChatIsMarkedAsUnread(UpdateChatIsMarkedAsUnread), + UpdateChatIsBlocked(UpdateChatIsBlocked), + UpdateChatHasScheduledMessages(UpdateChatHasScheduledMessages), + UpdateChatDefaultDisableNotification(UpdateChatDefaultDisableNotification), + UpdateChatReadInbox(UpdateChatReadInbox), + UpdateChatReadOutbox(UpdateChatReadOutbox), + UpdateChatUnreadMentionCount(UpdateChatUnreadMentionCount), + UpdateChatNotificationSettings(UpdateChatNotificationSettings), + UpdateScopeNotificationSettings(UpdateScopeNotificationSettings), + UpdateChatActionBar(UpdateChatActionBar), + UpdateChatReplyMarkup(UpdateChatReplyMarkup), + UpdateChatDraftMessage(UpdateChatDraftMessage), + UpdateChatFilters(UpdateChatFilters), + UpdateChatOnlineMemberCount(UpdateChatOnlineMemberCount), + UpdateNotification(UpdateNotification), + UpdateNotificationGroup(UpdateNotificationGroup), + UpdateActiveNotifications(UpdateActiveNotifications), + UpdateHavePendingNotifications(UpdateHavePendingNotifications), + UpdateDeleteMessages(UpdateDeleteMessages), + UpdateUserChatAction(UpdateUserChatAction), + UpdateUserStatus(UpdateUserStatus), + UpdateUser(UpdateUser), + UpdateBasicGroup(UpdateBasicGroup), + UpdateSupergroup(UpdateSupergroup), + UpdateSecretChat(UpdateSecretChat), + UpdateUserFullInfo(UpdateUserFullInfo), + UpdateBasicGroupFullInfo(UpdateBasicGroupFullInfo), + UpdateSupergroupFullInfo(UpdateSupergroupFullInfo), + UpdateServiceNotification(UpdateServiceNotification), + UpdateFile(UpdateFile), + UpdateFileGenerationStart(UpdateFileGenerationStart), + UpdateFileGenerationStop(UpdateFileGenerationStop), + UpdateCall(UpdateCall), + UpdateNewCallSignalingData(UpdateNewCallSignalingData), + UpdateUserPrivacySettingRules(UpdateUserPrivacySettingRules), + UpdateUnreadMessageCount(UpdateUnreadMessageCount), + UpdateUnreadChatCount(UpdateUnreadChatCount), + UpdateOption(UpdateOption), + UpdateStickerSet(UpdateStickerSet), + UpdateInstalledStickerSets(UpdateInstalledStickerSets), + UpdateTrendingStickerSets(UpdateTrendingStickerSets), + UpdateRecentStickers(UpdateRecentStickers), + UpdateFavoriteStickers(UpdateFavoriteStickers), + UpdateSavedAnimations(UpdateSavedAnimations), + UpdateSelectedBackground(UpdateSelectedBackground), + UpdateLanguagePackStrings(UpdateLanguagePackStrings), + UpdateConnectionState(UpdateConnectionState), + UpdateTermsOfService(UpdateTermsOfService), + UpdateUsersNearby(UpdateUsersNearby), + UpdateDiceEmojis(UpdateDiceEmojis), + UpdateAnimationSearchParameters(UpdateAnimationSearchParameters), + UpdateSuggestedActions(UpdateSuggestedActions), + UpdateNewInlineQuery(UpdateNewInlineQuery), + UpdateNewChosenInlineResult(UpdateNewChosenInlineResult), + UpdateNewCallbackQuery(UpdateNewCallbackQuery), + UpdateNewInlineCallbackQuery(UpdateNewInlineCallbackQuery), + UpdateNewShippingQuery(UpdateNewShippingQuery), + UpdateNewPreCheckoutQuery(UpdateNewPreCheckoutQuery), + UpdateNewCustomEvent(UpdateNewCustomEvent), + UpdateNewCustomQuery(UpdateNewCustomQuery), + UpdatePoll(UpdatePoll), + UpdatePollAnswer(UpdatePollAnswer), +} +pub trait ClientExt: ClientLike { + #[doc = "Returns the current authorization state; this is an offline request. For informational purposes only. Use updateAuthorizationState instead to maintain the current authorization state. Can be called before initialization"] + fn get_authorization_state(&self) -> ResponseFuture<AuthorizationState> { + self.send(json!({ + "@type": "getAuthorizationState" + })) + } + #[doc = "Sets the parameters for TDLib initialization. Works only when the current authorization state is authorizationStateWaitTdlibParameters "] + #[doc = " \n\n"] + #[doc = "parameters: "] + #[doc = " * `parameters`: Parameters"] + fn set_tdlib_parameters(&self, parameters: TdlibParameters) -> ResponseFuture<Ok> { + self.send(json!({ + "parameters": parameters, + "@type": "setTdlibParameters" + })) + } + #[doc = "Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber, \nor if there is no pending authentication query and the current authorization state is authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword"] + #[doc = " \n\n"] + #[doc = "parameters: "] + #[doc = " * `phone_number`: The phone number of the user, in international format "] + #[doc = " * `settings`: Settings for the authentication of the user's phone number"] + fn set_authentication_phone_number( + &self, + phone_number: String, + settings: PhoneNumberAuthenticationSettings, + ) -> ResponseFuture<Ok> { + self.send(json!({ + "phone_number": phone_number, + "settings": settings, + "@type": "setAuthenticationPhoneNumber" + })) + } + #[doc = "Checks the authentication code. Works only when the current authorization state is authorizationStateWaitCode "] + #[doc = " \n\n"] + #[doc = "parameters: "] + #[doc = " * `code`: The verification code received via SMS, Telegram message, phone call, or flash call"] + fn check_authentication_code(&self, code: String) -> ResponseFuture<Ok> { + self.send(json!({ + "code": code, + "@type": "checkAuthenticationCode" + })) + } + #[doc = "Checks the authentication password for correctness. Works only when the current authorization state is authorizationStateWaitPassword "] + #[doc = " \n\n"] + #[doc = "parameters: "] + #[doc = " * `password`: The password to check"] + fn check_authentication_password(&self, password: String) -> ResponseFuture<Ok> { + self.send(json!({ + "password": password, + "@type": "checkAuthenticationPassword" + })) + } + #[doc = "Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain "] + #[doc = " \n\n"] + #[doc = "parameters: "] + #[doc = " * `new_encryption_key`: New encryption key"] + fn set_database_encryption_key(&self, new_encryption_key: String) -> ResponseFuture<Ok> { + self.send(json!({ + "new_encryption_key": new_encryption_key, + "@type": "setDatabaseEncryptionKey" + })) + } + #[doc = "Returns network data usage statistics. Can be called before authorization "] + #[doc = " \n\n"] + #[doc = "parameters: "] + #[doc = " * `only_current`: If true, returns only data for the current library launch"] + #[doc = " \n\n"] + #[doc = "Return type: `NetworkStatistics`"] + fn get_network_statistics(&self, only_current: bool) -> ResponseFuture<SerdeJsonValue> { + self.send(json!({ + "only_current": only_current, + "@type": "getNetworkStatistics" + })) + } +} @@ -17,19 +17,23 @@ pub fn deserialize_i64_1<'de, D: Deserializer<'de>>(deserializer: D) -> std::res .map_err(serde::de::Error::custom) } -pub mod generated; +pub mod core; +pub use crate::core::*; -pub use generated::*; +//pub mod messaging; +//pub use crate::messaging::*; + +impl ClientExt for Client {} impl std::fmt::Display for UserStatus { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - UserStatus::UserStatusEmpty => write!(f, "seen never"), - UserStatus::UserStatusOnline(online) => write!(f, "online. expires: {}", fmt_date(online.expires)), - UserStatus::UserStatusOffline(offline) => write!(f, "online. expires: {}", fmt_date(offline.was_online)), - UserStatus::UserStatusRecently => write!(f, "seen recently"), - UserStatus::UserStatusLastWeek => write!(f, "seen last week"), - UserStatus::UserStatusLastMonth => write!(f, "seen last month"), + UserStatus::UserStatusEmpty => write!(f, "never"), + UserStatus::UserStatusOnline(online) => write!(f, "online until {}", fmt_date(online.expires)), + UserStatus::UserStatusOffline(offline) => write!(f, "online until {}", fmt_date(offline.was_online)), + UserStatus::UserStatusRecently => write!(f, "recently"), + UserStatus::UserStatusLastWeek => write!(f, "last week"), + UserStatus::UserStatusLastMonth => write!(f, "last month"), } } } @@ -39,5 +43,3 @@ fn fmt_date(date: i32) -> String { let dt: chrono::DateTime<chrono::Local> = chrono::Local.timestamp(date as i64, 0); format!("{}", dt) } - -impl ClientExt for Client {} diff --git a/src/makefile b/src/makefile index 4899cc2..79b4489 100644 --- a/src/makefile +++ b/src/makefile @@ -9,7 +9,7 @@ core: venv $(PYTHON) generate.py --target targets/core.json | rustfmt > core.rs messaging: venv - $(PYTHON) generate.py | rustfmt > messaging.rs + $(PYTHON) generate.py --target targets/messaging.json | rustfmt > messaging.rs venv: [ -d $(VENV) ] || (python3 -m venv $(DEFAULT_ENV) && VIRTUAL_ENV=$(VENV) $(VENV)/bin/pip install lark-parser) diff --git a/src/targets/core.json b/src/targets/core.json new file mode 100644 index 0000000..5e8b0bf --- /dev/null +++ b/src/targets/core.json @@ -0,0 +1,20 @@ +[ + "User", + "Chat", + "Message", + "Error", + "Ok", + "TdlibParameters", + "PhoneNumberAuthenticationSettings", + + "set_tdlib_parameters", + "get_network_statistics", + "get_authorization_state", + "set_database_encryption_key", + "set_authentication_phone_number", + "check_authentication_code", + "check_authentication_password", + "AuthorizationState", + "Update", + "UserStatus" +] diff --git a/src/targets/messaging.json b/src/targets/messaging.json new file mode 100644 index 0000000..5e8b0bf --- /dev/null +++ b/src/targets/messaging.json @@ -0,0 +1,20 @@ +[ + "User", + "Chat", + "Message", + "Error", + "Ok", + "TdlibParameters", + "PhoneNumberAuthenticationSettings", + + "set_tdlib_parameters", + "get_network_statistics", + "get_authorization_state", + "set_database_encryption_key", + "set_authentication_phone_number", + "check_authentication_code", + "check_authentication_password", + "AuthorizationState", + "Update", + "UserStatus" +] diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000..9eee425 --- /dev/null +++ b/src/util.py @@ -0,0 +1,70 @@ +import re +from lark import Token + +# https://stackoverflow.com/a/1176023/6938271 +MIXED_2_SNAKE_CASE = re.compile(r'(?<!^)(?=[A-Z])') + +ENUM_EXCLUDE_ALWAYS = [ + 'JsonValue' +] + +BOXED_TYPES = [ + 'RichText', + 'PageBlock' +] + +STRUCT_EXCLUDE_ALWAYS = [ + 'JsonValueNull', + 'JsonValueBoolean', + 'JsonValueNumber', + 'JsonValueString', + 'JsonValueArray', + 'JsonValueObject' +] + +def to_snake_case(ident): + return MIXED_2_SNAKE_CASE.sub('_', ident).lower() + +def to_camel_case(ident): + if len(ident) == 0: + return '' + return ident[0].upper() + ident[1:] + +def escape_doc(doc): + return doc.translate(str.maketrans({"\"": '\\"', "\\": "\\\\"})).replace('\n', ' \\n') + +SCALAR_MAPPING = { + 'string': ('String', False), + 'int32': ('i32', False), + 'int53': ('i64', False), + 'int64': ('i64', True), + 'double': ('f64', False), + 'bytes': ('String', False), + 'Bool': ('bool', False), +} + +def type_is_scalar(name): + return name in SCALAR_MAPPING + +def convert_scalar_name(name): + return SCALAR_MAPPING[name] + + +def parse_param(raw_type) -> tuple: # rusty_name: str, inner: str, deserializer: Optional[int] + if isinstance(raw_type, Token): + if type_is_scalar(raw_type): + scalar, deserialize = convert_scalar_name(raw_type) + if deserialize: + return scalar, scalar, 0 + else: + return scalar, scalar, None + else: + rusty_type = to_camel_case(raw_type) + if rusty_type in BOXED_TYPES: + return f'Box<{rusty_type}>', rusty_type, None + return rusty_type, rusty_type, None + else: + inner_full, inner_inner, deserializer = parse_param(raw_type.children[0]) + if deserializer is not None: + deserializer += 1 + return f'Vec<{inner_full}>', inner_inner, deserializer |