private static async Task <Tuple <TLAbsUpdates, Exception> > PromoteToAdminAsync(TLAbsInputUser u2,
                                                                                         TLInputChannel channel, TelegramBotAbstract telegramBotAbstract)
        {
            TLAbsUpdates r2 = null;

            try
            {
                TLAbsChannelParticipantRole role = new TLChannelRoleEditor();
                r2 = await telegramBotAbstract._userbotClient.ChannelsEditAdmin(channel, u2, role);
            }
            catch (Exception e2)
            {
                ;

                try
                {
                    TLAbsChannelParticipantRole role2 = new TLChannelRoleModerator();
                    r2 = await telegramBotAbstract._userbotClient.ChannelsEditAdmin(channel, u2, role2);
                }
                catch (Exception e3)
                {
                    try
                    {
                        var r3 = await telegramBotAbstract._userbotClient.Messages_EditChatAdmin(channel.ChannelId, u2,
                                                                                                 true);

                        if (r3 == false)
                        {
                            return(new Tuple <TLAbsUpdates, Exception>(null, e3));
                        }
                    }
                    catch (Exception e4)
                    {
                        ;

                        return(new Tuple <TLAbsUpdates, Exception>(null, e4));
                    }

                    return(new Tuple <TLAbsUpdates, Exception>(null, e3));
                }

                return(new Tuple <TLAbsUpdates, Exception>(null, e2));
            }

            ;

            return(new Tuple <TLAbsUpdates, Exception>(r2, null));
        }
Пример #2
0
        public async Task <bool> EditChannelUserRole(int channelId, long channelHash, int userId, long userHash, RoleEnum role)
        {
            await client.ConnectAsync();

            TLAbsChannelParticipantRole channelRole;

            switch (role)
            {
            case RoleEnum.None:
                channelRole = new TLChannelRoleEmpty();
                break;

            case RoleEnum.Editor:
                channelRole = new TLChannelRoleEditor();
                break;

            case RoleEnum.Mod:
                channelRole = new TLChannelRoleModerator();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(role), role, null);
            }

            var request = new TLRequestEditAdmin
            {
                channel = new TLInputChannel
                {
                    access_hash = channelHash,
                    channel_id  = channelId
                },
                user_id = new TLInputUser
                {
                    access_hash = userHash,
                    user_id     = userId
                },
                role = channelRole
            };

            return(await client.SendRequestAsync <bool>(request));
        }