updated "Program_ListenUpdates" example

This commit is contained in:
Wizou 2023-05-27 18:05:24 +02:00
parent b282d2e007
commit 7feb4a40ec
5 changed files with 13 additions and 9 deletions

4
.github/dev.yml vendored
View file

@ -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

View file

@ -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.

View file

@ -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)

View file

@ -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();
}
}

View file

@ -6721,7 +6721,7 @@ namespace TL
{
/// <summary>Button ID, to be passed to <see cref="SchemaExtensions.Messages_SendBotRequestedPeer">Messages_SendBotRequestedPeer</see>.</summary>
public int button_id;
/// <summary>Filtering criteria to use for the peer selection list shown to the user.</summary>
/// <summary>Filtering criteria to use for the peer selection list shown to the user. <br/>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.</summary>
public RequestPeerType peer_type;
}
@ -6842,7 +6842,7 @@ namespace TL
/// <summary>Programming language of the code</summary>
public string language;
}
/// <summary>Message entity representing a <a href="https://google.com">text url</a>: for in-text urls like <a href="https://google.com">https://google.com</a> use <see cref="MessageEntityUrl"/>. <para>See <a href="https://corefork.telegram.org/constructor/messageEntityTextUrl"/></para></summary>
/// <summary>Message entity representing a <a href="https://google.com">text url</a>: for in-text urls like <a href="https://google.com">https://google.com</a> use <see cref="MessageEntityUrl"/>. <para>See <a href="https://corefork.telegram.org/constructor/messageEntityTextUrl"/></para></summary>
[TLDef(0x76A6D327, inheritBefore = true)]
public class MessageEntityTextUrl : MessageEntity
{