From 10c159b2d333f33596e8bf009a3e9a8df4e09a74 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sat, 24 Sep 2022 15:30:43 +0200 Subject: [PATCH] implicit operator InputDialogPeer from InputPeer --- src/Client.Helpers.cs | 35 +++++++++++++---------------------- src/TL.Helpers.cs | 5 +++++ src/TL.Schema.cs | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Client.Helpers.cs b/src/Client.Helpers.cs index 796d9a0..bd5be12 100644 --- a/src/Client.Helpers.cs +++ b/src/Client.Helpers.cs @@ -574,25 +574,26 @@ namespace WTelegram } } + private const string OnlyChatChannel = "This method works on Chat & Channel only"; public Task AddChatUser(InputPeer peer, InputUserBase user, int fwd_limit = int.MaxValue) => peer switch { InputPeerChat chat => this.Messages_AddChatUser(chat.chat_id, user, fwd_limit), InputPeerChannel channel => this.Channels_InviteToChannel(channel, new[] { user }), - _ => throw new ArgumentException("This method works on Chat & Channel only"), + _ => throw new ArgumentException(OnlyChatChannel), }; public Task DeleteChatUser(InputPeer peer, InputUser user) => peer switch { InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, user, true), InputPeerChannel channel => this.Channels_EditBanned(channel, user, new ChatBannedRights { flags = ChatBannedRights.Flags.view_messages }), - _ => throw new ArgumentException("This method works on Chat & Channel only"), + _ => throw new ArgumentException(OnlyChatChannel), }; public Task LeaveChat(InputPeer peer) => peer switch { InputPeerChat chat => this.Messages_DeleteChatUser(chat.chat_id, InputUser.Self, true), InputPeerChannel channel => this.Channels_LeaveChannel(channel), - _ => throw new ArgumentException("This method works on Chat & Channel only"), + _ => throw new ArgumentException(OnlyChatChannel), }; public async Task EditChatAdmin(InputPeer peer, InputUserBase user, bool is_admin) @@ -607,7 +608,7 @@ namespace WTelegram return await this.Channels_EditAdmin(channel, user, new ChatAdminRights { flags = is_admin ? (ChatAdminRights.Flags)0x8BF : 0 }, null); default: - throw new ArgumentException("This method works on Chat & Channel only"); + throw new ArgumentException(OnlyChatChannel); } } @@ -615,21 +616,21 @@ namespace WTelegram { InputPeerChat chat => this.Messages_EditChatPhoto(chat.chat_id, photo), InputPeerChannel channel => this.Channels_EditPhoto(channel, photo), - _ => throw new ArgumentException("This method works on Chat & Channel only"), + _ => throw new ArgumentException(OnlyChatChannel), }; public Task EditChatTitle(InputPeer peer, string title) => peer switch { InputPeerChat chat => this.Messages_EditChatTitle(chat.chat_id, title), InputPeerChannel channel => this.Channels_EditTitle(channel, title), - _ => throw new ArgumentException("This method works on Chat & Channel only"), + _ => throw new ArgumentException(OnlyChatChannel), }; public Task GetFullChat(InputPeer peer) => peer switch { InputPeerChat chat => this.Messages_GetFullChat(chat.chat_id), InputPeerChannel channel => this.Channels_GetFullChannel(channel), - _ => throw new ArgumentException("This method works on Chat & Channel only"), + _ => throw new ArgumentException(OnlyChatChannel), }; public async Task DeleteChat(InputPeer peer) @@ -643,25 +644,15 @@ namespace WTelegram case InputPeerChannel channel: return await this.Channels_DeleteChannel(channel); default: - throw new ArgumentException("This method works on Chat & Channel only"); + throw new ArgumentException(OnlyChatChannel); } } - public async Task GetMessages(InputPeer peer, params InputMessage[] id) - { - if (peer is InputPeerChannel channel) - return await this.Channels_GetMessages(channel, id); - else - return await this.Messages_GetMessages(id); - } + public Task GetMessages(InputPeer peer, params InputMessage[] id) + => peer is InputPeerChannel channel ? this.Channels_GetMessages(channel, id) : this.Messages_GetMessages(id); - public async Task DeleteMessages(InputPeer peer, params int[] id) - { - if (peer is InputPeerChannel channel) - return await this.Channels_DeleteMessages(channel, id); - else - return await this.Messages_DeleteMessages(id); - } + public Task DeleteMessages(InputPeer peer, params int[] id) + => peer is InputPeerChannel channel ? this.Channels_DeleteMessages(channel, id) : this.Messages_DeleteMessages(id); #endregion } } diff --git a/src/TL.Helpers.cs b/src/TL.Helpers.cs index 507a5fa..2dd18f4 100644 --- a/src/TL.Helpers.cs +++ b/src/TL.Helpers.cs @@ -524,6 +524,11 @@ namespace TL public static implicit operator InputMessage(int id) => new InputMessageID() { id = id }; } + partial class InputDialogPeerBase + { + public static implicit operator InputDialogPeerBase(InputPeer peer) => new InputDialogPeer() { peer = peer }; + } + partial class SecureFile { public static implicit operator InputSecureFile(SecureFile file) => new() { id = file.id, access_hash = file.access_hash }; diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index 5a5e58a..77dcc85 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -10033,7 +10033,7 @@ namespace TL } /// Peer, or all peers in a certain folder Derived classes: , See - public abstract class InputDialogPeerBase : IObject { } + public abstract partial class InputDialogPeerBase : IObject { } /// A peer See [TLDef(0xFCAAFEB7)] public class InputDialogPeer : InputDialogPeerBase