InputPeer.ID & MessageBase.ToString helpers.

Publish pre-releases on nuget now
This commit is contained in:
Wizou 2022-11-20 17:15:57 +01:00
parent adf6134911
commit fd593b429a
7 changed files with 57 additions and 31 deletions

8
.github/dev.yml vendored
View file

@ -25,14 +25,14 @@ steps:
includesymbols: true includesymbols: true
versioningScheme: 'byEnvVar' versioningScheme: 'byEnvVar'
versionEnvVar: 'Build.BuildNumber' 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"' # buildProperties: 'NoWarn="0419;1573;1591";AllowedOutputExtensionsInPackageBuildOutputFolder=".dll;.xml;.pdb"'
- task: NuGetCommand@2 - task: NuGetCommand@2
inputs: inputs:
command: 'push' command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.*upkg' packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
publishPackageMetadata: true publishPackageMetadata: true
nuGetFeedType: 'internal' nuGetFeedType: 'external'
publishVstsFeed: 'WTelegramClient/WTelegramClient' publishFeedCredentials: 'nuget.org'

View file

@ -88,12 +88,14 @@ foreach (Dialog dialog in dialogs.dialogs)
case User user when user.IsActive: Console.WriteLine("User " + user); break; case User user when user.IsActive: Console.WriteLine("User " + user); break;
case ChatBase chat when chat.IsActive: Console.WriteLine(chat); 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.* Notes:
See also the `Main` method in [Examples/Program_ListenUpdates.cs](Examples/Program_ListenUpdates.cs). - 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)`
<a name="list-chats"></a> <a name="list-chats"></a>
### List all chats (groups/channels NOT users) that we joined and send a message to one ### List all chats (groups/channels NOT users) that we joined and send a message to one

18
FAQ.md
View file

@ -283,15 +283,15 @@ Here are the recommended actions to fix your problem:
- Save, close Notepad and reopen your project in Visual Studio - 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: - If you still have issues on some `foreach` constructs, add this class somewhere in your project:
```csharp ```csharp
static class Extensions static class Extensions
{ {
public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> tuple, out T1 key, out T2 value) public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> tuple, out T1 key, out T2 value)
{ {
key = tuple.Key; key = tuple.Key;
value = tuple.Value; 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. Also, remember to add a `using TL;` at the top of your files to have access to all the Telegram API methods.

View file

@ -1,7 +1,7 @@
[![NuGet version](https://img.shields.io/nuget/v/WTelegramClient?color=00508F)](https://www.nuget.org/packages/WTelegramClient/) [![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) [![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) [![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) [![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) [![Donate](https://img.shields.io/badge/Help_this_project:-Donate-ff4444)](http://t.me/WTelegramBot?start=donate)

View file

@ -15,29 +15,48 @@ namespace TL
InputPeer ToInputPeer(); 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 partial class InputPeerChat
{ {
/// <summary>⚠ Only for small private Chat. Chat groups of type Channel must use InputPeerChannel. See <see href="https://github.com/wiz0u/WTelegramClient/blob/master/README.md#terminology">Terminology</see> in README</summary> /// <summary>⚠ Only for small private Chat. Chat groups of type Channel must use InputPeerChannel. See <see href="https://github.com/wiz0u/WTelegramClient/blob/master/README.md#terminology">Terminology</see> in README</summary>
/// <param name="chat_id">Chat identifier</param> /// <param name="chat_id">Chat identifier</param>
public InputPeerChat(long chat_id) => this.chat_id = chat_id; public InputPeerChat(long chat_id) => this.chat_id = chat_id;
internal InputPeerChat() { } internal InputPeerChat() { }
public override long ID => chat_id;
} }
partial class InputPeerUser partial class InputPeerUser
{ {
/// <param name="user_id">User identifier</param> /// <param name="user_id">User identifier</param>
/// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="User"/> constructor</param> /// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="User"/> structure</param>
public InputPeerUser(long user_id, long access_hash) { this.user_id = user_id; this.access_hash = access_hash; } public InputPeerUser(long user_id, long access_hash) { this.user_id = user_id; this.access_hash = access_hash; }
internal InputPeerUser() { } internal InputPeerUser() { }
public static implicit operator InputUser(InputPeerUser user) => new(user.user_id, user.access_hash); public static implicit operator InputUser(InputPeerUser user) => new(user.user_id, user.access_hash);
public override long ID => user_id;
} }
partial class InputPeerChannel partial class InputPeerChannel
{ {
/// <param name="channel_id">Channel identifier</param> /// <param name="channel_id">Channel identifier</param>
/// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="Channel"/> constructor</param> /// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="Channel"/> structure</param>
public InputPeerChannel(long channel_id, long access_hash) { this.channel_id = channel_id; this.access_hash = access_hash; } public InputPeerChannel(long channel_id, long access_hash) { this.channel_id = channel_id; this.access_hash = access_hash; }
internal InputPeerChannel() { } internal InputPeerChannel() { }
public static implicit operator InputChannel(InputPeerChannel channel) => new(channel.channel_id, channel.access_hash); 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; } } partial class InputUserBase { public abstract long? UserId { get; } }
@ -48,7 +67,7 @@ namespace TL
public override long? UserId => user_id; public override long? UserId => user_id;
public static InputUserSelf Self => new(); public static InputUserSelf Self => new();
/// <param name="user_id">User identifier</param> /// <param name="user_id">User identifier</param>
/// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="User"/> constructor</param> /// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="User"/> structure</param>
public InputUser(long user_id, long access_hash) { this.user_id = user_id; this.access_hash = access_hash; } public InputUser(long user_id, long access_hash) { this.user_id = user_id; this.access_hash = access_hash; }
internal InputUser() { } internal InputUser() { }
public static implicit operator InputPeerUser(InputUser user) => new(user.user_id, user.access_hash); public static implicit operator InputPeerUser(InputUser user) => new(user.user_id, user.access_hash);
@ -138,8 +157,8 @@ namespace TL
} }
/// <remarks>a <c>null</c> value means <a href="https://corefork.telegram.org/constructor/userStatusEmpty">userStatusEmpty</a> = last seen a long time ago, more than a month (this is also always shown to blocked users)</remarks> /// <remarks>a <c>null</c> value means <a href="https://corefork.telegram.org/constructor/userStatusEmpty">userStatusEmpty</a> = last seen a long time ago, more than a month (this is also always shown for blocked/deleted users)</remarks>
partial class UserStatus { /// <summary>An estimation of the number of days ago the user was last seen (online=0, recently=1, lastWeek=5, lastMonth=20)<br/><see cref="UserStatus"/> = <c>null</c> means a long time ago, more than a month (this is also always shown to blocked users)</summary> partial class UserStatus { /// <summary>An estimation of the number of days ago the user was last seen (online=0, recently=1, lastWeek=5, lastMonth=20)<br/><see cref="UserStatus"/> = <c>null</c> means a long time ago, more than a month (this is also always shown for blocked/deleted users)</summary>
public abstract TimeSpan LastSeenAgo { get; } } public abstract TimeSpan LastSeenAgo { get; } }
partial class UserStatusOnline { public override TimeSpan LastSeenAgo => TimeSpan.Zero; } 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); } 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<ChatParticipantBase>(); } partial class ChatParticipantsForbidden { public override ChatParticipantBase[] Participants => Array.Empty<ChatParticipantBase>(); }
partial class ChatParticipants { public override ChatParticipantBase[] Participants => participants; } 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 { ///<summary>Use this helper method to send a copy of the media without downloading it</summary> partial class MessageMedia { ///<summary>Use this helper method to send a copy of the media without downloading it</summary>
///<remarks>Quiz poll may need to be voted before obtaining the correct answers. Dice will not replicate same value. TTL ignored<br/>May return <see langword="null"/> for Invoice and other unsupported media types</remarks> ///<remarks>Quiz poll may need to be voted before obtaining the correct answers. Dice will not replicate same value. TTL ignored<br/>May return <see langword="null"/> for Invoice and other unsupported media types</remarks>
public virtual InputMedia ToInputMedia() => null; } public virtual InputMedia ToInputMedia() => null; }
@ -463,7 +486,7 @@ namespace TL
partial class InputChannel partial class InputChannel
{ {
/// <param name="channel_id">Channel identifier</param> /// <param name="channel_id">Channel identifier</param>
/// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="Channel"/> constructor</param> /// <param name="access_hash">⚠ <b>REQUIRED FIELD</b>. See FAQ for how to obtain it<br/><strong>access_hash</strong> value from the <see cref="Channel"/> structure</param>
public InputChannel(long channel_id, long access_hash) { this.channel_id = channel_id; this.access_hash = access_hash; } public InputChannel(long channel_id, long access_hash) { this.channel_id = channel_id; this.access_hash = access_hash; }
internal InputChannel() { } internal InputChannel() { }
public static implicit operator InputPeerChannel(InputChannel channel) => new(channel.channel_id, channel.access_hash); public static implicit operator InputPeerChannel(InputChannel channel) => new(channel.channel_id, channel.access_hash);

View file

@ -36,7 +36,7 @@ namespace TL
public abstract partial class InputPeer : IObject { } public abstract partial class InputPeer : IObject { }
/// <summary>Defines the current user. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerSelf"/></para></summary> /// <summary>Defines the current user. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerSelf"/></para></summary>
[TLDef(0x7DA07EC9)] [TLDef(0x7DA07EC9)]
public class InputPeerSelf : InputPeer { } public partial class InputPeerSelf : InputPeer { }
/// <summary>Defines a chat for further interaction. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerChat"/></para></summary> /// <summary>Defines a chat for further interaction. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerChat"/></para></summary>
[TLDef(0x35A95CB9)] [TLDef(0x35A95CB9)]
public partial class InputPeerChat : InputPeer public partial class InputPeerChat : InputPeer
@ -64,7 +64,7 @@ namespace TL
} }
/// <summary>Defines a <a href="https://corefork.telegram.org/api/min">min</a> user that was seen in a certain message of a certain chat. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerUserFromMessage"/></para></summary> /// <summary>Defines a <a href="https://corefork.telegram.org/api/min">min</a> user that was seen in a certain message of a certain chat. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerUserFromMessage"/></para></summary>
[TLDef(0xA87B0A1C)] [TLDef(0xA87B0A1C)]
public class InputPeerUserFromMessage : InputPeer public partial class InputPeerUserFromMessage : InputPeer
{ {
/// <summary>The chat where the user was seen</summary> /// <summary>The chat where the user was seen</summary>
public InputPeer peer; public InputPeer peer;
@ -75,7 +75,7 @@ namespace TL
} }
/// <summary>Defines a <a href="https://corefork.telegram.org/api/min">min</a> channel that was seen in a certain message of a certain chat. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerChannelFromMessage"/></para></summary> /// <summary>Defines a <a href="https://corefork.telegram.org/api/min">min</a> channel that was seen in a certain message of a certain chat. <para>See <a href="https://corefork.telegram.org/constructor/inputPeerChannelFromMessage"/></para></summary>
[TLDef(0xBD2A0840)] [TLDef(0xBD2A0840)]
public class InputPeerChannelFromMessage : InputPeer public partial class InputPeerChannelFromMessage : InputPeer
{ {
/// <summary>The chat where the channel's message was seen</summary> /// <summary>The chat where the channel's message was seen</summary>
public InputPeer peer; public InputPeer peer;
@ -1496,7 +1496,7 @@ namespace TL
} }
/// <summary>Empty constructor, non-existent message. <para>See <a href="https://corefork.telegram.org/constructor/messageEmpty"/></para></summary> /// <summary>Empty constructor, non-existent message. <para>See <a href="https://corefork.telegram.org/constructor/messageEmpty"/></para></summary>
[TLDef(0x90A6CA84)] [TLDef(0x90A6CA84)]
public class MessageEmpty : MessageBase public partial class MessageEmpty : MessageBase
{ {
/// <summary>Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a></summary> /// <summary>Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a></summary>
public Flags flags; public Flags flags;
@ -1518,7 +1518,7 @@ namespace TL
} }
/// <summary>A message <para>See <a href="https://corefork.telegram.org/constructor/message"/></para></summary> /// <summary>A message <para>See <a href="https://corefork.telegram.org/constructor/message"/></para></summary>
[TLDef(0x38116EE0)] [TLDef(0x38116EE0)]
public class Message : MessageBase public partial class Message : MessageBase
{ {
/// <summary>Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a></summary> /// <summary>Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a></summary>
public Flags flags; public Flags flags;
@ -1632,7 +1632,7 @@ namespace TL
} }
/// <summary>Indicates a service message <para>See <a href="https://corefork.telegram.org/constructor/messageService"/></para></summary> /// <summary>Indicates a service message <para>See <a href="https://corefork.telegram.org/constructor/messageService"/></para></summary>
[TLDef(0x2B085862)] [TLDef(0x2B085862)]
public class MessageService : MessageBase public partial class MessageService : MessageBase
{ {
/// <summary>Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a></summary> /// <summary>Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a></summary>
public Flags flags; public Flags flags;

View file

@ -42,7 +42,8 @@
<None Include="..\logo.png" Link="Data\logo.png" Pack="true" PackagePath="\" /> <None Include="..\logo.png" Link="Data\logo.png" Pack="true" PackagePath="\" />
</ItemGroup> </ItemGroup>
<!--<ItemGroup> <!-- Disabled because SourceLink navigation prevents a clear display of the API
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>--> </ItemGroup>-->