From 05752863bd787a4b4d313c539aa8bae8ded6f624 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Fri, 1 Apr 2022 21:48:28 +0200 Subject: [PATCH] Various minor stuff --- EXAMPLES.md | 1 + README.md | 18 +++---- src/Compat.cs | 17 ++----- src/TL.SchemaFuncs.cs | 116 ------------------------------------------ 4 files changed, 13 insertions(+), 139 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index eeba122..286de14 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -17,6 +17,7 @@ and add at least these variables with adequate value: **api_id, api_hash, phone_ Remember that these are just simple example codes that you should adjust to your needs. In real production code, you might want to properly test the success of each operation or handle exceptions. +ℹ️ WTelegramClient covers 100% of Telegram Client API, much more than the examples below: check the [full API methods list](https://corefork.telegram.org/methods)! More examples can also be found in answers to [StackOverflow questions](https://stackoverflow.com/questions/tagged/wtelegramclient). diff --git a/README.md b/README.md index f04fdb8..7530047 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## _Telegram Client API library written 100% in C# and .NET Standard_ -This ReadMe is a quick but important tutorial to learn the fundamentals about this library. Please read it all. +This ReadMe is a **quick but important tutorial** to learn the fundamentals about this library. Please read it all. >⚠️ This library relies on asynchronous C# programming (`async/await`) so make sure you are familiar with this advanced topic before proceeding. >If you are a beginner in C#, starting a project based on this library might not be a great idea. @@ -44,7 +44,7 @@ This is because WTelegramClient saves (typically in the encrypted file **bin\WTe That file path is configurable (session_pathname), and under various circumstances (changing user or server address) you may want to change it or simply delete the existing session file in order to restart the authentification process. # Non-interactive configuration -Your next step will probably be to provide a configuration to the client so that the required elements (in bold above) are not prompted through the Console but answered by your program. +Your next step will probably be to provide a configuration to the client so that the required elements are not prompted through the Console but answered by your program. To do this, you need to write a method that will provide the answers, and pass it on the constructor: ```csharp @@ -68,19 +68,19 @@ using var client = new WTelegram.Client(Config); There are other configuration items that are queried to your method but returning `null` let WTelegramClient choose a default adequate value. Those shown above are the only ones that have no default values and should be provided by your method. Returning `null` for verification_code or password will show a prompt for console apps, or an error otherwise. -Returning an empty string for verification_code requests resending the code through another method (SMS or Call). +Returning `""` for verification_code requests resending the code through another method (SMS or Call). Another simple approach is to pass `Environment.GetEnvironmentVariable` as the config callback and define the configuration items as environment variables. Undefined variables get the default `null` behavior. Finally, if you want to redirect the library logs to your logger instead of the Console, you can install a delegate in the `WTelegram.Helpers.Log` static property. -Its `int` argument is the log severity, compatible with the classic [LogLevel enum](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel) +Its `int` argument is the log severity, compatible with the [LogLevel enum](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel) # Example of API call >ℹ️ The Telegram API makes extensive usage of base and derived classes, so be ready to use the various syntaxes C# offer to check/cast base classes into the more useful derived classes (`is`, `as`, `case DerivedType` ) -All the Telegram API classes/methods are fully documented through Intellisense: Place your mouse over a class/method name, or start typing the call arguments to see a tooltip display their description, the list of derived classes and a web link to the official API page. +All the Telegram API classes/methods are fully documented through Intellisense: Place your mouse over a class/method name, or start typing the call arguments to see a tooltip displaying their description, the list of derived classes and a web link to the official API page. The Telegram [API object classes](https://corefork.telegram.org/schema) are defined in the `TL` namespace, and the [API functions](https://corefork.telegram.org/methods) are available as async methods of `Client`. @@ -121,13 +121,13 @@ In the API, Telegram uses some terms/classnames that can be confusing as they di **⚠️ Most chat groups you see are really of type `Channel`, not `Chat`!** - chats : In plural or general meaning, it means either `Chat` or `Channel` - `Peer` : Either a `Chat`, `Channel` or a private chat with a `User` -- Dialog : The current status of a chat with a `Peer` *(draft, last message, unread count, pinned...)* +- Dialog : The current status of a chat with a `Peer` *(draft, last message, unread count, pinned...)*. It represents each line from your Telegram chat list. - DC (DataCenter) : There are a few datacenters depending on where in the world the user (or an uploaded media file) is from. - Access Hash : Telegram requires you to provide a specific `access_hash` for users, channels, and other resources before interacting with them. See [FAQ #4](https://github.com/wiz0u/WTelegramClient/blob/master/FAQ.md#access-hash) to learn more about it. # Other things to know -The Client class also offers an `Update` event that is triggered when Telegram servers sends unsollicited Updates or notifications/information/status/service messages, independently of your API requests. See [Examples/Program_ListenUpdates.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs) +The Client class also offers an `Update` event that is triggered when Telegram servers sends Updates (like new messages or status), independently of your API requests. See [Examples/Program_ListenUpdates.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs) An invalid API request can result in a `RpcException` being raised, reflecting the [error code and status text](https://revgram.github.io/errors.html) of the problem. @@ -148,8 +148,8 @@ This library can be used for any Telegram scenarios including: - Download/upload of files/media - Building a full-featured interactive client -It has been tested in a Console app, [in a WinForms app](https://github.com/wiz0u/WTelegramClient/blob/master/FAQ.md#gui), [in ASP.NET webservice](https://github.com/wiz0u/WTelegramClient/blob/master/EXAMPLES.md#logging). -Secret chats (end-to-end encryption, PFS) and connection to CDN DCs have not been tested yet. +It has been tested in a Console app, [in a WinForms app](https://github.com/wiz0u/WTelegramClient/blob/master/FAQ.md#gui), +[in ASP.NET webservice](https://github.com/wiz0u/WTelegramClient/blob/master/EXAMPLES.md#logging), and in Xamarin/Android. Please don't use this library for Spam or Scam. Respect Telegram [Terms of Service](https://telegram.org/tos) as well as the [API Terms of Service](https://core.telegram.org/api/terms) or you might get banned from Telegram servers. diff --git a/src/Compat.cs b/src/Compat.cs index 5835e06..c33a9bb 100644 --- a/src/Compat.cs +++ b/src/Compat.cs @@ -29,7 +29,7 @@ namespace WTelegram return new BigInteger(data); } - internal static byte[] ToByteArray(this BigInteger bigInteger, bool isUnsigned = false, bool isBigEndian = false) + internal static byte[] ToByteArray(this BigInteger bigInteger, bool isUnsigned, bool isBigEndian) { if (!isBigEndian || !isUnsigned) throw new ArgumentException("Unexpected parameters to ToByteArray"); var result = bigInteger.ToByteArray(); @@ -50,11 +50,7 @@ namespace WTelegram public static V GetValueOrDefault(this Dictionary dictionary, K key, V defaultValue = default) => dictionary.TryGetValue(key, out V value) ? value : defaultValue; - public static void Deconstruct(this KeyValuePair kvp, out K key, out V value) - { - key = kvp.Key; - value = kvp.Value; - } + public static void Deconstruct(this KeyValuePair kvp, out K key, out V value) { key = kvp.Key; value = kvp.Value; } internal static IPEndPoint IPEndPoint_Parse(string addr) { @@ -78,14 +74,7 @@ namespace WTelegram static class Convert { internal static string ToHexString(byte[] data) => BitConverter.ToString(data).Replace("-", ""); - internal static byte[] FromHexString(string hex) - { - int NumberChars = hex.Length; - byte[] bytes = new byte[NumberChars / 2]; - for (int i = 0; i < NumberChars; i += 2) - bytes[i / 2] = System.Convert.ToByte(hex.Substring(i, 2), 16); - return bytes; - } + internal static byte[] FromHexString(string hex) => Enumerable.Range(0, hex.Length / 2).Select(i => System.Convert.ToByte(hex.Substring(i * 2, 2), 16)).ToArray(); } #endif diff --git a/src/TL.SchemaFuncs.cs b/src/TL.SchemaFuncs.cs index 0900277..e4b7c61 100644 --- a/src/TL.SchemaFuncs.cs +++ b/src/TL.SchemaFuncs.cs @@ -4572,9 +4572,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_proxy = 0x1, - /// Field has a value has_params = 0x2, } } @@ -4687,7 +4685,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_new_settings = 0x1, } } @@ -4788,11 +4785,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_first_name = 0x1, - /// Field has a value has_last_name = 0x2, - /// Field has a value has_about = 0x4, } } @@ -5061,7 +5055,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_peer = 0x1, compare_sound = 0x2, } @@ -5126,7 +5119,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_thumb = 0x1, } } @@ -5142,9 +5134,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_document = 0x4, - /// Field has a value has_settings = 0x8, } } @@ -5162,13 +5152,9 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_slug = 0x1, - /// Field has a value has_title = 0x2, - /// Field has a value has_document = 0x4, - /// Field has a value has_settings = 0x8, } } @@ -5191,11 +5177,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { dark = 0x1, - /// Field has a value has_theme = 0x2, - /// Field has a value has_format = 0x4, - /// Field has a value has_base_theme = 0x8, } } @@ -5281,9 +5264,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_encrypted_requests_disabled = 0x1, - /// Field has a value has_call_requests_disabled = 0x2, } } @@ -5442,7 +5423,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_self_expires = 0x1, background = 0x2, } @@ -5488,7 +5468,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { exclude_pinned = 0x1, - /// Field has a value has_folder_id = 0x2, } } @@ -5526,9 +5505,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_from_id = 0x1, - /// Field has a value has_top_msg_id = 0x2, } } @@ -5553,9 +5530,7 @@ namespace TL.Methods { just_clear = 0x1, revoke = 0x2, - /// Field has a value has_min_date = 0x4, - /// Field has a value has_max_date = 0x8, } } @@ -5588,7 +5563,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_top_msg_id = 0x1, } } @@ -5608,19 +5582,14 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reply_to_msg_id = 0x1, no_webpage = 0x2, - /// Field has a value has_reply_markup = 0x4, - /// Field has a value has_entities = 0x8, silent = 0x20, background = 0x40, clear_draft = 0x80, - /// Field has a value has_schedule_date = 0x400, - /// Field has a value has_send_as = 0x2000, noforwards = 0x4000, } @@ -5642,18 +5611,13 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reply_to_msg_id = 0x1, - /// Field has a value has_reply_markup = 0x4, - /// Field has a value has_entities = 0x8, silent = 0x20, background = 0x40, clear_draft = 0x80, - /// Field has a value has_schedule_date = 0x400, - /// Field has a value has_send_as = 0x2000, noforwards = 0x4000, } @@ -5675,11 +5639,9 @@ namespace TL.Methods silent = 0x20, background = 0x40, with_my_score = 0x100, - /// Field has a value has_schedule_date = 0x400, drop_author = 0x800, drop_media_captions = 0x1000, - /// Field has a value has_send_as = 0x2000, noforwards = 0x4000, } @@ -5886,7 +5848,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_entities = 0x8, } } @@ -5902,13 +5863,10 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_expire_date = 0x1, - /// Field has a value has_usage_limit = 0x2, legacy_revoke_permanent = 0x4, request_needed = 0x8, - /// Field has a value has_title = 0x10, } } @@ -5992,7 +5950,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_folder_id = 0x1, } } @@ -6042,7 +5999,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_geo_point = 0x1, } } @@ -6061,9 +6017,7 @@ namespace TL.Methods { gallery = 0x1, private_ = 0x2, - /// Field has a value has_next_offset = 0x4, - /// Field has a value has_switch_pm = 0x8, } } @@ -6082,15 +6036,12 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reply_to_msg_id = 0x1, silent = 0x20, background = 0x40, clear_draft = 0x80, - /// Field has a value has_schedule_date = 0x400, hide_via = 0x800, - /// Field has a value has_send_as = 0x2000, } } @@ -6117,15 +6068,10 @@ namespace TL.Methods [Flags] public enum Flags : uint { no_webpage = 0x2, - /// Field has a value has_reply_markup = 0x4, - /// Field has a value has_entities = 0x8, - /// Field has a value has_message = 0x800, - /// Field has a value has_media = 0x4000, - /// Field has a value has_schedule_date = 0x8000, } } @@ -6143,13 +6089,9 @@ namespace TL.Methods [Flags] public enum Flags : uint { no_webpage = 0x2, - /// Field has a value has_reply_markup = 0x4, - /// Field has a value has_entities = 0x8, - /// Field has a value has_message = 0x800, - /// Field has a value has_media = 0x4000, } } @@ -6165,10 +6107,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_data = 0x1, game = 0x2, - /// Field has a value has_password = 0x4, } } @@ -6184,10 +6124,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_message = 0x1, alert = 0x2, - /// Field has a value has_url = 0x4, } } @@ -6209,10 +6147,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reply_to_msg_id = 0x1, no_webpage = 0x2, - /// Field has a value has_entities = 0x8, } } @@ -6401,9 +6337,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_error = 0x1, - /// Field has a value has_shipping_options = 0x2, } } @@ -6417,7 +6351,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_error = 0x1, success = 0x2, } @@ -6488,14 +6421,11 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reply_to_msg_id = 0x1, silent = 0x20, background = 0x40, clear_draft = 0x80, - /// Field has a value has_schedule_date = 0x400, - /// Field has a value has_send_as = 0x2000, noforwards = 0x4000, } @@ -6635,9 +6565,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_peer = 0x2, - /// Field has a value has_url = 0x4, } } @@ -6654,9 +6582,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { write_allowed = 0x1, - /// Field has a value has_peer = 0x2, - /// Field has a value has_url = 0x4, } } @@ -6707,9 +6633,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_option = 0x1, - /// Field has a value has_offset = 0x2, } } @@ -6743,7 +6667,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_filter = 0x1, } } @@ -6856,7 +6779,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_offset_date = 0x4, revoked = 0x8, } @@ -6882,14 +6804,10 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_expire_date = 0x1, - /// Field has a value has_usage_limit = 0x2, revoked = 0x4, - /// Field has a value has_request_needed = 0x8, - /// Field has a value has_title = 0x10, } } @@ -6928,9 +6846,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { requested = 0x1, - /// Field has a value has_link = 0x2, - /// Field has a value has_q = 0x4, } } @@ -7003,7 +6919,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { approved = 0x1, - /// Field has a value has_link = 0x2, } } @@ -7032,7 +6947,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reaction = 0x1, big = 0x2, } @@ -7057,9 +6971,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_reaction = 0x1, - /// Field has a value has_offset = 0x2, } } @@ -7095,11 +7007,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_peer = 0x1, - /// Field has a value has_text = 0x2, - /// Field has a value has_from_lang = 0x4, } } @@ -7143,7 +7052,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_pts_total_limit = 0x1, } } @@ -7179,11 +7087,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_file = 0x1, - /// Field has a value has_video = 0x2, - /// Field has a value has_video_start_ts = 0x4, } } @@ -7453,7 +7358,6 @@ namespace TL.Methods { broadcast = 0x1, megagroup = 0x2, - /// Field has a value has_geo_point = 0x4, for_import = 0x8, } @@ -7576,9 +7480,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_events_filter = 0x1, - /// Field has a value has_admins = 0x2, } } @@ -7731,7 +7633,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_theme_params = 0x1, } } @@ -7771,11 +7672,8 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_requested_info_id = 0x1, - /// Field has a value has_shipping_option_id = 0x2, - /// Field has a value has_tip_amount = 0x4, } } @@ -7816,9 +7714,7 @@ namespace TL.Methods { masks = 0x1, animated = 0x2, - /// Field has a value has_thumb = 0x4, - /// Field has a value has_software = 0x8, videos = 0x10, } @@ -7958,9 +7854,7 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_title = 0x1, - /// Field has a value has_schedule_date = 0x2, rtmp_stream = 0x4, } @@ -7978,7 +7872,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { muted = 0x1, - /// Field has a value has_invite_hash = 0x2, video_stopped = 0x4, } @@ -8013,7 +7906,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_join_muted = 0x1, reset_invite_hash = 0x2, } @@ -8054,7 +7946,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { start = 0x1, - /// Field has a value has_title = 0x2, video = 0x4, } @@ -8075,17 +7966,11 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_muted = 0x1, - /// Field has a value has_volume = 0x2, - /// Field has a value has_raise_hand = 0x4, - /// Field has a value has_video_stopped = 0x8, - /// Field has a value has_video_paused = 0x10, - /// Field has a value has_presentation_paused = 0x20, } } @@ -8230,7 +8115,6 @@ namespace TL.Methods [Flags] public enum Flags : uint { - /// Field has a value has_x = 0x1, } }