diff --git a/.gitignore b/.gitignore index 282b562..0dc12eb 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,4 @@ dmypy.json *.pyi !*.example.jsonc *.epub +!*.schema.json diff --git a/schema/base64.schema.json b/schema/base64.schema.json new file mode 100644 index 0000000..5f664bb --- /dev/null +++ b/schema/base64.schema.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "https://github.com/lifegpc/pythonscript/raw/master/schema/base64.schema.json", + "type": "string", + "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" +} diff --git a/schema/tdlib.schema.json b/schema/tdlib.schema.json new file mode 100644 index 0000000..e312d5e --- /dev/null +++ b/schema/tdlib.schema.json @@ -0,0 +1,95 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "https://github.com/lifegpc/pythonscript/raw/master/schema/tdlib.schema.json", + "title": "Tdlib", + "description": "Tdlib settings", + "type": "object", + "properties": { + "bot_encryption_key": { + "$ref": "base64.schema.json", + "description": "Encryption key to check or set up for bot. Need base64 encoded.", + "minLength": 4 + }, + "bot_token": { + "description": "Bot Token, which can be obtained with @BotFather .", + "type": "string" + }, + "BotTdlibParameters": { + "$ref": "tdlib_parameters.schema.json", + "description": "Same as TdlibParameters, but when creating a bot session, these parameters will override parameters in TdlibParameters", + "required": [ + "database_directory" + ] + }, + "encryption_key": { + "$ref": "base64.schema.json", + "description": "Encryption key to check or set up. Need base64 encoded.", + "minLength": 4 + }, + "phone_number": { + "description": "User's phone number", + "type": "string", + "pattern": "^\\+?[0-9]+$" + }, + "proxy": { + "description": "Proxy settings.", + "type": "object", + "properties": { + "port": { + "description": "The port of the proxy.", + "type": "number" + }, + "server": { + "description": "The server address of the proxy.", + "type": "string" + }, + "type": { + "description": "The type of the proxy.", + "type": "object", + "properties": { + "@type": { + "description": "The type of the proxy type. Support proxyTypeHttp, proxyTypeSocks5, proxyTypeMtproto.", + "type": "string", + "enum": ["proxyTypeHttp", "proxyTypeSocks5", "proxyTypeMtproto"] + }, + "http_only": { + "description": "Pass true if the proxy supports only HTTP requests and doesn't support transparent TCP connections via HTTP CONNECT method. Supported if @type is proxyTypeHttp.", + "type": "boolean", + "default": false + }, + "password": { + "description": "The password to authenticate. Supported if @type is proxyTypeHttp or proxyTypeSocks5", + "type": "string" + }, + "secret": { + "description": "The proxy's secret in hexadecimal encoding. Supported if @type is proxyTypeMtproto.", + "type": "string", + "pattern": "^[0-9a-fA-F]+$" + }, + "username": { + "description": "The username to authenticate. Supported if @type is proxyTypeHttp or proxyTypeSocks5", + "type": "string" + } + } + } + }, + "required": [ + "port", + "server", + "type" + ] + }, + "TdlibParameters": { + "$ref": "tdlib_parameters.schema.json", + "required": [ + "api_hash", + "api_id" + ] + } + }, + "required": [ + "encryption_key", + "phone_number", + "TdlibParameters" + ] +} diff --git a/schema/tdlib_parameters.schema.json b/schema/tdlib_parameters.schema.json new file mode 100644 index 0000000..dcd638e --- /dev/null +++ b/schema/tdlib_parameters.schema.json @@ -0,0 +1,81 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "https://github.com/lifegpc/pythonscript/raw/master/schema/tdlib_parameters.schema.json", + "title": "Tdlib Parameters", + "description": "Parameters of tdlib. Detailed information is availabled on https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1tdlib_parameters.html", + "type": "object", + "properties": { + "api_hash": { + "description": "Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org.", + "type": "string" + }, + "api_id": { + "description": "Application identifier for Telegram API access, which can be obtained at https://my.telegram.org .", + "type": "number", + "maximum": 2147483647, + "minimum": -2147483648 + }, + "application_version": { + "description": "Application version; must be non-empty.", + "type": "string", + "default": "1.0.0" + }, + "database_directory": { + "description": "The path to the directory for the persistent database; if empty, the current working directory will be used.", + "type": "string" + }, + "device_model": { + "description": "Model of the device the application is being run on; must be non-empty.", + "type": "string", + "default": "Desktop" + }, + "enable_storage_optimizer": { + "description": "If set to true, old files will automatically be deleted.", + "type": "string", + "default": true + }, + "files_directory": { + "description": "The path to the directory for storing files; if empty, database_directory will be used.", + "type": "string" + }, + "ignore_file_names": { + "description": "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.", + "type": "boolean", + "default": false + }, + "system_language_code": { + "description": "IETF language tag of the user's operating system language; must be non-empty.", + "type": "string", + "default": "en" + }, + "system_version": { + "description": "Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib.", + "type": "string" + }, + "use_chat_info_database": { + "description": "If set to true, the library will maintain a cache of users, basic groups, supergroups, channels and secret chats. Implies use_file_database.", + "type": "boolean", + "default": false + }, + "use_file_database": { + "description": "If set to true, information about downloaded and uploaded files will be saved between application restarts.", + "type": "boolean", + "default": false + }, + "use_message_database": { + "description": "If set to true, the library will maintain a cache of chats and messages. Implies use_chat_info_database.", + "type": "boolean", + "default": false + }, + "use_secret_chats": { + "description": "If set to true, support for secret chats will be enabled.", + "type": "boolean", + "default": true + }, + "use_test_dc": { + "description": "If set to true, the Telegram test environment will be used instead of the production environment.", + "type": "boolean", + "default": false + } + } +} diff --git a/tdlib.example.jsonc b/tdlib.example.jsonc index 0df1666..ed070f8 100644 --- a/tdlib.example.jsonc +++ b/tdlib.example.jsonc @@ -1,11 +1,12 @@ { + "$schema": "schema/tdlib.schema.json", "TdlibParameters": { // Detailed information is availabled on https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1tdlib_parameters.html "api_id": 12345678, // Application identifier for Telegram API access, which can be obtained at https://my.telegram.org. "api_hash": "1234567890abcdef0123456789abcdef", // Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org. "database_directory": "/path/to/database", // Optional. The path to the directory for the persistent database; if empty, the current working directory will be used. "use_message_database": false // Optional. If set to true, the library will maintain a cache of chats and messages. Warn: TdLib do not provide a function to optimize database. }, - "encryption_key": "Base64 encoded's key", // Encryption key to check or set up. Need base64 encoded. + "encryption_key": "AA==", // Encryption key to check or set up. Need base64 encoded. "proxy": { // Optional. Specify proxy "server": "127.0.0.1", "port": 1080, @@ -21,6 +22,6 @@ "BotTdlibParameters": { // Optional. Same as TdlibParameters, but when creating a bot session, these parameters will override parameters in TdlibParameters "database_directory": "/path/to/botdatabase" }, - "bot_encryption_key": "Base64 encoded's key", // Optional. Encryption key to check or set up for bot. Need base64 encoded. + "bot_encryption_key": "AA==", // Optional. Encryption key to check or set up for bot. Need base64 encoded. "bot_token": "12345678:235zoHFG" // Optional. Bot Token, which can be obtained with @BotFather }