From 7feb4a40ec572a4cd81468de7c51c83786a85e35 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sat, 27 May 2023 18:05:24 +0200 Subject: [PATCH] updated "Program_ListenUpdates" example --- .github/dev.yml | 4 ++-- EXAMPLES.md | 2 +- Examples/Program_ListenUpdates.cs | 10 +++++++--- src/Helpers.cs | 2 +- src/TL.Schema.cs | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/dev.yml b/.github/dev.yml index c719a3b..a0ed581 100644 --- a/.github/dev.yml +++ b/.github/dev.yml @@ -1,4 +1,4 @@ -pr: none +pr: none trigger: - master @@ -25,7 +25,7 @@ steps: includesymbols: true versioningScheme: 'byEnvVar' versionEnvVar: 'Build.BuildNumber' - buildProperties: 'NoWarn="0419;1573;1591";Version=$(Build.BuildNumber);ContinuousIntegrationBuild=true;ReleaseNotes="$(Build.SourceVersionMessage)"' + buildProperties: 'NoWarn="0419;1573;1591";Version=$(Build.BuildNumber);ContinuousIntegrationBuild=true;ReleaseNotes="$(Build.SourceVersionMessage.Replace("\"", "″"))"' # buildProperties: 'NoWarn="0419;1573;1591";AllowedOutputExtensionsInPackageBuildOutputFolder=".dll;.xml;.pdb"' - task: NuGetCommand@2 diff --git a/EXAMPLES.md b/EXAMPLES.md index 985d4f9..c0aa92c 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -197,7 +197,7 @@ See [Examples/Program_ListenUpdates.cs](https://github.com/wiz0u/WTelegramClient You have to handle `client.OnUpdate` events containing an `UpdateNewMessage`. -See the `DisplayMessage` method in [Examples/Program_ListenUpdates.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs?ts=4#L23). +See the `HandleMessage` method in [Examples/Program_ListenUpdates.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs?ts=4#L23). You can filter specific chats the message are posted in, by looking at the `Message.peer_id` field. diff --git a/Examples/Program_ListenUpdates.cs b/Examples/Program_ListenUpdates.cs index c69ebb0..baf09ca 100644 --- a/Examples/Program_ListenUpdates.cs +++ b/Examples/Program_ListenUpdates.cs @@ -36,11 +36,15 @@ namespace WTelegramClientTest private static async Task Client_OnUpdate(UpdatesBase updates) { updates.CollectUsersChats(Users, Chats); + if (updates is UpdateShortMessage usm && !Users.ContainsKey(usm.user_id)) + (await Client.Updates_GetDifference(usm.pts - usm.pts_count, usm.date, 0)).CollectUsersChats(Users, Chats); + else if (updates is UpdateShortChatMessage uscm && (!Users.ContainsKey(uscm.from_id) || !Chats.ContainsKey(uscm.chat_id))) + (await Client.Updates_GetDifference(uscm.pts - uscm.pts_count, uscm.date, 0)).CollectUsersChats(Users, Chats); foreach (var update in updates.UpdateList) switch (update) { - case UpdateNewMessage unm: await DisplayMessage(unm.message); break; - case UpdateEditMessage uem: await DisplayMessage(uem.message, true); break; + case UpdateNewMessage unm: await HandleMessage(unm.message); break; + case UpdateEditMessage uem: await HandleMessage(uem.message, true); break; // Note: UpdateNewChannelMessage and UpdateEditChannelMessage are also handled by above cases case UpdateDeleteChannelMessages udcm: Console.WriteLine($"{udcm.messages.Length} message(s) deleted in {Chat(udcm.channel_id)}"); break; case UpdateDeleteMessages udm: Console.WriteLine($"{udm.messages.Length} message(s) deleted"); break; @@ -56,7 +60,7 @@ namespace WTelegramClientTest } // in this example method, we're not using async/await, so we just return Task.CompletedTask - private static Task DisplayMessage(MessageBase messageBase, bool edit = false) + private static Task HandleMessage(MessageBase messageBase, bool edit = false) { if (edit) Console.Write("(Edit): "); switch (messageBase) diff --git a/src/Helpers.cs b/src/Helpers.cs index 6bc628d..3231d95 100644 --- a/src/Helpers.cs +++ b/src/Helpers.cs @@ -246,10 +246,10 @@ namespace WTelegram public override long Length => ContentLength ?? _innerStream.Length; public override long Position { get => _innerStream.Position; set => _innerStream.Position = value; } public override void Flush() => _innerStream.Flush(); - public override int Read(byte[] buffer, int offset, int count) => _innerStream.Read(buffer, offset, count); public override long Seek(long offset, SeekOrigin origin) => _innerStream.Seek(offset, origin); public override void SetLength(long value) => _innerStream.SetLength(value); public override void Write(byte[] buffer, int offset, int count) => _innerStream.Write(buffer, offset, count); + public override int Read(byte[] buffer, int offset, int count) => _innerStream.Read(buffer, offset, count); protected override void Dispose(bool disposing) => _innerStream.Dispose(); } } diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index 378bd19..f6b2a19 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -6721,7 +6721,7 @@ namespace TL { /// Button ID, to be passed to Messages_SendBotRequestedPeer. public int button_id; - /// Filtering criteria to use for the peer selection list shown to the user. + /// Filtering criteria to use for the peer selection list shown to the user.
The list should display all existing peers of the specified type, and should also offer an option for the user to create and immediately use a peer of the specified type, if needed.
public RequestPeerType peer_type; } @@ -6842,7 +6842,7 @@ namespace TL /// Programming language of the code public string language; } - /// Message entity representing a text url: for in-text urls like https://google.com use . See + /// Message entity representing a text url: for in-text urls like https://google.com use . See [TLDef(0x76A6D327, inheritBefore = true)] public class MessageEntityTextUrl : MessageEntity {