From fd593b429ae37c702580676788159a81c2eb546f Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sun, 20 Nov 2022 17:15:57 +0100 Subject: [PATCH] InputPeer.ID & MessageBase.ToString helpers. Publish pre-releases on nuget now --- .github/dev.yml | 8 ++++---- EXAMPLES.md | 8 +++++--- FAQ.md | 18 +++++++++--------- README.md | 2 +- src/TL.Helpers.cs | 37 ++++++++++++++++++++++++++++++------- src/TL.Schema.cs | 12 ++++++------ src/WTelegramClient.csproj | 3 ++- 7 files changed, 57 insertions(+), 31 deletions(-) diff --git a/.github/dev.yml b/.github/dev.yml index d26fff4..994f6ad 100644 --- a/.github/dev.yml +++ b/.github/dev.yml @@ -25,14 +25,14 @@ steps: includesymbols: true versioningScheme: 'byEnvVar' versionEnvVar: 'Build.BuildNumber' - buildProperties: 'NoWarn="0419;1573;1591";Version=$(Build.BuildNumber);ContinuousIntegrationBuild=true;ReleaseNotes="$(ReleaseNotes)"' + buildProperties: 'NoWarn="0419;1573;1591";Version=$(Build.BuildNumber);ContinuousIntegrationBuild=true;ReleaseNotes="$(Build.SourceVersionMessage)"' # buildProperties: 'NoWarn="0419;1573;1591";AllowedOutputExtensionsInPackageBuildOutputFolder=".dll;.xml;.pdb"' - task: NuGetCommand@2 inputs: command: 'push' - packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.*upkg' + packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg' publishPackageMetadata: true - nuGetFeedType: 'internal' - publishVstsFeed: 'WTelegramClient/WTelegramClient' + nuGetFeedType: 'external' + publishFeedCredentials: 'nuget.org' diff --git a/EXAMPLES.md b/EXAMPLES.md index d8fc6dc..1e26e97 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -88,12 +88,14 @@ foreach (Dialog dialog in dialogs.dialogs) case User user when user.IsActive: Console.WriteLine("User " + user); break; case ChatBase chat when chat.IsActive: Console.WriteLine(chat); break; } - //var latestMsg = dialogs.messages.FirstOrDefault(m => m.Peer.ID == dialog.Peer.ID && m.ID == dialog.TopMessage); + //var latestMsg = dialogs.messages.FirstOrDefault(m => m.Peer.ID == dialog.Peer.ID && m.ID == dialog.TopMessage); } ``` -*Note: the lists returned by Messages_GetAllDialogs contains the `access_hash` for those chats and users.* -See also the `Main` method in [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs). +Notes: +- The lists returned by Messages_GetAllDialogs contains the `access_hash` for those chats and users. +- See also the `Main` method in [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs). +- To retrieve the dialog information about a specific [peer](README.md#terminology), use `client.Messages_GetPeerDialogs(inputPeer)` ### List all chats (groups/channels NOT users) that we joined and send a message to one diff --git a/FAQ.md b/FAQ.md index 9a1c8d8..fcb3789 100644 --- a/FAQ.md +++ b/FAQ.md @@ -283,15 +283,15 @@ Here are the recommended actions to fix your problem: - Save, close Notepad and reopen your project in Visual Studio - If you still have issues on some `foreach` constructs, add this class somewhere in your project: ```csharp - static class Extensions - { - public static void Deconstruct(this KeyValuePair tuple, out T1 key, out T2 value) - { - key = tuple.Key; - value = tuple.Value; - } - } - ``` + static class Extensions + { + public static void Deconstruct(this KeyValuePair tuple, out T1 key, out T2 value) + { + key = tuple.Key; + value = tuple.Value; + } + } + ``` Also, remember to add a `using TL;` at the top of your files to have access to all the Telegram API methods. diff --git a/README.md b/README.md index 28e6757..d173cc5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![NuGet version](https://img.shields.io/nuget/v/WTelegramClient?color=00508F)](https://www.nuget.org/packages/WTelegramClient/) [![Build Status](https://img.shields.io/azure-devops/build/wiz0u/WTelegramClient/7)](https://dev.azure.com/wiz0u/WTelegramClient/_build?definitionId=7) [![API Layer](https://img.shields.io/badge/API_Layer-148-blueviolet)](https://corefork.telegram.org/methods) -[![dev nuget](https://img.shields.io/badge/dynamic/json?color=ffc040&label=dev%20nuget&query=%24.versions%5B0%5D&url=https%3A%2F%2Fpkgs.dev.azure.com%2Fwiz0u%2F81bd92b7-0bb9-4701-b426-09090b27e037%2F_packaging%2F46ce0497-7803-4bd4-8c6c-030583e7c371%2Fnuget%2Fv3%2Fflat2%2Fwtelegramclient%2Findex.json)](https://dev.azure.com/wiz0u/WTelegramClient/_artifacts/feed/WTelegramClient/NuGet/WTelegramClient) +[![dev nuget](https://img.shields.io/nuget/vpre/WTelegramClient?color=ffc040&label=dev%20nuget)](https://dev.azure.com/wiz0u/WTelegramClient/_artifacts/feed/WTelegramClient/NuGet/WTelegramClient) [![Support Chat](https://img.shields.io/badge/Contact_us-on_Telegram-238EC2)](https://t.me/WTelegramClient) [![Donate](https://img.shields.io/badge/Help_this_project:-Donate-ff4444)](http://t.me/WTelegramBot?start=donate) diff --git a/src/TL.Helpers.cs b/src/TL.Helpers.cs index 3bf8380..506b52d 100644 --- a/src/TL.Helpers.cs +++ b/src/TL.Helpers.cs @@ -15,29 +15,48 @@ namespace TL InputPeer ToInputPeer(); } - partial class InputPeer { public static InputPeerSelf Self => new(); } + partial class InputPeer + { + public static readonly InputPeerSelf Self = new(); + public abstract long ID { get; } + } + partial class InputPeerSelf + { + public override long ID => 0; + } partial class InputPeerChat { /// ⚠ Only for small private Chat. Chat groups of type Channel must use InputPeerChannel. See Terminology in README /// Chat identifier public InputPeerChat(long chat_id) => this.chat_id = chat_id; internal InputPeerChat() { } + public override long ID => chat_id; } partial class InputPeerUser { /// User identifier - /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the constructor + /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the structure public InputPeerUser(long user_id, long access_hash) { this.user_id = user_id; this.access_hash = access_hash; } internal InputPeerUser() { } public static implicit operator InputUser(InputPeerUser user) => new(user.user_id, user.access_hash); + public override long ID => user_id; } partial class InputPeerChannel { /// Channel identifier - /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the constructor + /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the structure public InputPeerChannel(long channel_id, long access_hash) { this.channel_id = channel_id; this.access_hash = access_hash; } internal InputPeerChannel() { } public static implicit operator InputChannel(InputPeerChannel channel) => new(channel.channel_id, channel.access_hash); + public override long ID => channel_id; + } + partial class InputPeerUserFromMessage + { + public override long ID => user_id; + } + partial class InputPeerChannelFromMessage + { + public override long ID => channel_id; } partial class InputUserBase { public abstract long? UserId { get; } } @@ -48,7 +67,7 @@ namespace TL public override long? UserId => user_id; public static InputUserSelf Self => new(); /// User identifier - /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the constructor + /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the structure public InputUser(long user_id, long access_hash) { this.user_id = user_id; this.access_hash = access_hash; } internal InputUser() { } public static implicit operator InputPeerUser(InputUser user) => new(user.user_id, user.access_hash); @@ -138,8 +157,8 @@ namespace TL } - /// a null value means userStatusEmpty = last seen a long time ago, more than a month (this is also always shown to blocked users) - partial class UserStatus { /// An estimation of the number of days ago the user was last seen (online=0, recently=1, lastWeek=5, lastMonth=20)
= null means a long time ago, more than a month (this is also always shown to blocked users)
+ /// a null value means userStatusEmpty = last seen a long time ago, more than a month (this is also always shown for blocked/deleted users) + partial class UserStatus { /// An estimation of the number of days ago the user was last seen (online=0, recently=1, lastWeek=5, lastMonth=20)
= null means a long time ago, more than a month (this is also always shown for blocked/deleted users)
public abstract TimeSpan LastSeenAgo { get; } } partial class UserStatusOnline { public override TimeSpan LastSeenAgo => TimeSpan.Zero; } partial class UserStatusOffline { public override TimeSpan LastSeenAgo => DateTime.UtcNow - new DateTime((was_online + 62135596800L) * 10000000, DateTimeKind.Utc); } @@ -218,6 +237,10 @@ namespace TL partial class ChatParticipantsForbidden { public override ChatParticipantBase[] Participants => Array.Empty(); } partial class ChatParticipants { public override ChatParticipantBase[] Participants => participants; } + partial class MessageEmpty { public override string ToString() => "(no message)"; } + partial class Message { public override string ToString() => $"{(from_id ?? peer_id)?.ID}> {message} {media}"; } + partial class MessageService { public override string ToString() => $"{(from_id ?? peer_id)?.ID} [{action.GetType().Name[13..]}]"; } + partial class MessageMedia { ///Use this helper method to send a copy of the media without downloading it ///Quiz poll may need to be voted before obtaining the correct answers. Dice will not replicate same value. TTL ignored
May return for Invoice and other unsupported media types
public virtual InputMedia ToInputMedia() => null; } @@ -463,7 +486,7 @@ namespace TL partial class InputChannel { /// Channel identifier - /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the constructor + /// REQUIRED FIELD. See FAQ for how to obtain it
access_hash value from the structure public InputChannel(long channel_id, long access_hash) { this.channel_id = channel_id; this.access_hash = access_hash; } internal InputChannel() { } public static implicit operator InputPeerChannel(InputChannel channel) => new(channel.channel_id, channel.access_hash); diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index a9026f8..4d66f08 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -36,7 +36,7 @@ namespace TL public abstract partial class InputPeer : IObject { } /// Defines the current user. See [TLDef(0x7DA07EC9)] - public class InputPeerSelf : InputPeer { } + public partial class InputPeerSelf : InputPeer { } /// Defines a chat for further interaction. See [TLDef(0x35A95CB9)] public partial class InputPeerChat : InputPeer @@ -64,7 +64,7 @@ namespace TL } /// Defines a min user that was seen in a certain message of a certain chat. See [TLDef(0xA87B0A1C)] - public class InputPeerUserFromMessage : InputPeer + public partial class InputPeerUserFromMessage : InputPeer { /// The chat where the user was seen public InputPeer peer; @@ -75,7 +75,7 @@ namespace TL } /// Defines a min channel that was seen in a certain message of a certain chat. See [TLDef(0xBD2A0840)] - public class InputPeerChannelFromMessage : InputPeer + public partial class InputPeerChannelFromMessage : InputPeer { /// The chat where the channel's message was seen public InputPeer peer; @@ -1496,7 +1496,7 @@ namespace TL } /// Empty constructor, non-existent message. See [TLDef(0x90A6CA84)] - public class MessageEmpty : MessageBase + public partial class MessageEmpty : MessageBase { /// Flags, see TL conditional fields public Flags flags; @@ -1518,7 +1518,7 @@ namespace TL } /// A message See [TLDef(0x38116EE0)] - public class Message : MessageBase + public partial class Message : MessageBase { /// Flags, see TL conditional fields public Flags flags; @@ -1632,7 +1632,7 @@ namespace TL } /// Indicates a service message See [TLDef(0x2B085862)] - public class MessageService : MessageBase + public partial class MessageService : MessageBase { /// Flags, see TL conditional fields public Flags flags; diff --git a/src/WTelegramClient.csproj b/src/WTelegramClient.csproj index 51eaaab..eccde27 100644 --- a/src/WTelegramClient.csproj +++ b/src/WTelegramClient.csproj @@ -42,7 +42,8 @@ -