Inheritance: TeleSharp.TL.TLObject
Example #1
0
        //**********************************************************//
        //**                 Below is Members routines            **//
        //**********************************************************//

        // Return members list from specified group Name
        private static TLVector <TLAbsUser> GetGroupMembers(string gname, string ufile = null)
        {
            long hash = 0;
            int  gid  = GetGroupIdByName(gname, out hash);

            TeleSharp.TL.Messages.TLChatFull ch = GetGroupFullById(gid, hash);

            if (0 == hash && MembersLogAndSave(ch.Users, ufile, gname))
            {
                return(ch.Users);
            }

            int offset = 0;
            TLChannelParticipants ps    = null;
            TLVector <TLAbsUser>  users = new TLVector <TLAbsUser>();

            do
            {
                ps = client.GetChannelParticipants(gid, hash, offset, 5000).GetAwaiter().GetResult();
                foreach (TLUser u in ps.Users)
                {
                    users.Add(u);
                }
                offset += ps.Users.Count;
            } while (users.Count < ps.Count && 0 != ps.Users.Count);

            MembersLogAndSave(users, ufile, gname);
            return(users);
        }
        private static bool CheckIfOurBotIsPresent(TLChatFull x)
        {
            if (x == null)
            {
                return(false);
            }

            if (x.Users == null)
            {
                return(false);
            }

            if (x.Users.Count == 0)
            {
                return(false);
            }

            foreach (var u in x.Users)
            {
                if (u is TLUser u2)
                {
                    if (string.IsNullOrEmpty(u2.Username) == false)
                    {
                        if (u2.Username.ToLower() == "polinetwork3bot")
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Возвращает код-во людей
        /// </summary>
        /// <param name="channelName"></param>
        /// <returns>Получение кол-во людей (int) в канале  , если что-то пошло не так вернет -1</returns>
        public async Task <Int32> GetCountParticipantsChannelandSuperGroup(String channelName)
        {
            if (client == null)
            {
                return(-1);
            }
            TLAbsDialogs dialogs_temp = await client.GetUserDialogsAsync();

            TLDialogsSlice dialogs = dialogs_temp as TLDialogsSlice;

            TeleSharp.TL.Messages.TLChatFull res = new TeleSharp.TL.Messages.TLChatFull();
            try
            {
                TLChannel channelInfo = (await client.SendRequestAsync <TeleSharp.TL.Contacts.TLResolvedPeer>(
                                             new TeleSharp.TL.Contacts.TLRequestResolveUsername
                {
                    Username = channelName
                }).ConfigureAwait(false)).Chats.Last() as TeleSharp.TL.TLChannel;

                TLRequestGetFullChannel req = new TLRequestGetFullChannel()
                {
                    Channel = new TLInputChannel()
                    {
                        AccessHash = channelInfo.AccessHash.Value, ChannelId = channelInfo.Id
                    }
                };

                res = await client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(req);
            }
            catch
            {
                return(-1);
            }
            return((res.FullChat as TLChannelFull).ParticipantsCount.Value);
        }
Example #4
0
        public async Task <UserSearchResult> GetUsersOld(TelegramClient client)
        {
            UserSearchResult searchResult = new UserSearchResult()
            {
                TlUsers = new List <TLUser>(), Users = new List <UserModel>()
            };

            try
            {
                dynamic dialogs;
                try
                {
                    dialogs = (TLDialogs)await client.GetUserDialogsAsync();
                }
                catch (Exception ex)
                {
                    dialogs = (TLDialogsSlice)await client.GetUserDialogsAsync();

                    Logger.Error(ex);
                }

                foreach (TLAbsChat element in dialogs.Chats)
                {
                    if (element is TLChat)
                    {
                        TLChat chat    = element as TLChat;
                        var    request = new TLRequestGetFullChat()
                        {
                            ChatId = chat.Id
                        };

                        TeleSharp.TL.Messages.TLChatFull chatFull = await client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(request);

                        foreach (var absUser in chatFull.Users)
                        {
                            TLUser user = absUser as TLUser;

                            if (!user.Bot && !user.Deleted && !user.Self)
                            {
                                searchResult.TlUsers.Add(user);

                                var customeUser = _userService.CreateCustomUserModel(user);
                                searchResult.Users.Add(customeUser);
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(searchResult);
        }
Example #5
0
        public async Task <TLVector <TLAbsUser> > GetMembers(int chatId)
        {
            await client.ConnectAsync();

            TLRequestGetFullChat req = new TLRequestGetFullChat
            {
                chat_id = chatId
            };

            TLChatFull result = await client.SendRequestAsync <TLChatFull>(req);

            return(result.users);
        }
Example #6
0
        // Get extended group info (yo collect chat users, channel participants, access hash)
        private static TeleSharp.TL.Messages.TLChatFull GetGroupFullById(int id, long hash)
        {
            TeleSharp.TL.Messages.TLChatFull ch = null;

            if (0 == hash)
            {
                ch = client.GetFullChatAsync(id).GetAwaiter().GetResult();
            }
            if (null != ch)
            {
                return(ch);
            }

            return(client.GetFullChannelAsync(id, hash).GetAwaiter().GetResult());
        }
        public async Task <bool> CheckUriChannel(long accessHash, int id)
        {
            try
            {
                TLChatFull chan = await _client.SendRequestAsync <TLChatFull>(new TLRequestGetFullChannel()
                {
                    Channel = new TLInputChannel()
                    {
                        ChannelId = id, AccessHash = accessHash
                    }
                });

                return(true);
            }
            catch (Exception)
            {
            }
            return(false);
        }
        public async Task <List <TLUser> > GetUsers(TelegramClient client)
        {
            var usersList = new List <TLUser>();

            try
            {
                var dialogs = (TLDialogs)await client.GetUserDialogsAsync();

                //var dialogs2 = (TLDialogsSlice)await client.GetUserDialogsAsync();

                foreach (TLAbsChat element in dialogs.Chats)
                {
                    if (element is TLChat) //chats with permissions
                    {
                        TLChat chat    = element as TLChat;
                        var    request = new TLRequestGetFullChat()
                        {
                            ChatId = chat.Id
                        };

                        TeleSharp.TL.Messages.TLChatFull chatFull = await client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(request);

                        foreach (var absUser in chatFull.Users)
                        {
                            TLUser user = absUser as TLUser;

                            if (!user.Bot)
                            {
                                usersList.Add(user);
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(usersList);
        }
        private static async Task <Tuple <bool?, DateTime?> > CheckIfOurBotIsPresent2Async(TLInputChannel x5,
                                                                                           TelegramBotAbstract telegramBotAbstract)
        {
            if (id_of_chats_we_know_are_ok.ContainsKey(x5.ChannelId))
            {
                return(new Tuple <bool?, DateTime?>(id_of_chats_we_know_are_ok[x5.ChannelId], null));
            }

            TLAbsInputChannel channel = new TLInputChannel {
                ChannelId = x5.ChannelId, AccessHash = x5.AccessHash
            };
            TLChatFull x = null;

            try
            {
                x = await telegramBotAbstract._userbotClient.getFullChat(channel);
            }
            catch (Exception e)
            {
                ;

                if (e is FloodException eflood)
                {
                    ;

                    var untilWhen = GetUntilWhenWeCanMakeRequests(eflood);
                    return(new Tuple <bool?, DateTime?>(null, untilWhen));
                }
            }

            var isOurBotPresent = CheckIfOurBotIsPresent(x);

            if (isOurBotPresent)
            {
                id_of_chats_we_know_are_ok[x5.ChannelId] = true;
            }

            return(new Tuple <bool?, DateTime?>(isOurBotPresent, null));
        }
        private static async Task <Tuple <bool?, DateTime?> > CheckIfOurBotIsPresent3Async(TLChat x5,
                                                                                           TelegramBotAbstract telegramBotAbstract)
        {
            if (id_of_chats_we_know_are_ok.ContainsKey(x5.Id))
            {
                return(new Tuple <bool?, DateTime?>(id_of_chats_we_know_are_ok[x5.Id], null));
            }

            TLChatFull x = null;

            try
            {
                x = await telegramBotAbstract._userbotClient.Messages_getFullChat(x5.Id);
            }
            catch (Exception e)
            {
                if (e is FloodException floodException)
                {
                    var untilWhen = GetUntilWhenWeCanMakeRequests(floodException);
                    return(new Tuple <bool?, DateTime?>(null, untilWhen));
                }
            }

            if (x == null)
            {
                return(new Tuple <bool?, DateTime?>(false, null));
            }
            ;

            var r = CheckIfOurBotIsPresent(x);

            if (r)
            {
                id_of_chats_we_know_are_ok[x5.Id] = r;
            }

            return(new Tuple <bool?, DateTime?>(r, null));
        }
Example #11
0
 public override void DeserializeResponse(BinaryReader br)
 {
     Response = (TLChatFull)ObjectUtils.DeserializeObject(br);
 }
Example #12
0
 public override void deserializeResponse(BinaryReader br)
 {
     Response = (Messages.TLChatFull)ObjectUtils.DeserializeObject(br);
 }
        private static async Task <Tuple <bool?, DateTime?> > FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot4(
            TLChat x5, TLAbsInputPeer u, TelegramBotAbstract telegramBotAbstract)
        {
            if (x5 == null)
            {
                return(null);
            }

            ;

            ;

            if (x5.MigratedTo == null)
            {
                var r4 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot6Async(x5, u, telegramBotAbstract);

                return(r4);
            }

            var            x6 = x5.MigratedTo;
            TLInputChannel x8 = null;

            if (x6 is TLInputChannel x7)
            {
                x8 = x7;
            }
            else
            {
                ;
                return(null);
            }

            if (x5.MigratedTo == null)
            {
                return(null);
            }

            TLAbsInputChannel channel = x8;
            TLChatFull        x       = null;

            var channel2 = GetChannel(channel);

            if (channel2 == null)
            {
                return(new Tuple <bool?, DateTime?>(false, null));
            }

            var isOurBotPresent2 = await CheckIfOurBotIsPresent2Async(channel2, telegramBotAbstract);

            if (isOurBotPresent2 == null)
            {
                return(new Tuple <bool?, DateTime?>(false, null));
            }

            if (isOurBotPresent2.Item2 != null)
            {
                return(new Tuple <bool?, DateTime?>(null, isOurBotPresent2.Item2));
            }

            if (isOurBotPresent2.Item1 != null && isOurBotPresent2.Item1.Value)
            {
                return(new Tuple <bool?, DateTime?>(true, null));
            }

            var r3 = await InsertOurBotAsyncChat(x5, u, x8.AccessHash, telegramBotAbstract);

            return(new Tuple <bool?, DateTime?>(r3, null));
        }
        public static async Task <ModelParserInfo> ParserInfoAboutChannelAndSuperGroup(String channelName, TLSharp.Core.TelegramClient client, Int32 countMessageParse = 200)
        {
            ModelParserInfo info   = new ModelParserInfo();
            ChannelInfo     result = new ChannelInfo();

            List <Int32> AverageViews = new List <Int32>();
            TLChannel    channelInfo;

            if (client == null)
            {
                return(null);
            }
            var            dialogs_temp = client.GetUserDialogsAsync().GetAwaiter().GetResult();
            TLDialogsSlice dialogs      = dialogs_temp as TLDialogsSlice;

            TeleSharp.TL.Messages.TLChatFull res = new TeleSharp.TL.Messages.TLChatFull();

            channelInfo = (client.SendRequestAsync <TeleSharp.TL.Contacts.TLResolvedPeer>(
                               new TeleSharp.TL.Contacts.TLRequestResolveUsername
            {
                Username = channelName
            }).ConfigureAwait(false)).GetAwaiter().GetResult().Chats.Last() as TeleSharp.TL.TLChannel;

            TLRequestGetFullChannel req = new TLRequestGetFullChannel()
            {
                Channel = new TLInputChannel()
                {
                    AccessHash = channelInfo.AccessHash.Value, ChannelId = channelInfo.Id
                }
            };

            res = client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(req).GetAwaiter().GetResult();
            Int32 offset = 0;

            result.Channel   = channelInfo;
            result.ChatFull  = res;
            info.ChannelInfo = result;
            info.CountPeople = (res.FullChat as TLChannelFull).ParticipantsCount.Value;
            info.Avatar      = (res.FullChat as TLChannelFull).ChatPhoto as TLPhoto;
            info.About       = (res.FullChat as TLChannelFull).About;
            TLChannelMessages       temp = new TLChannelMessages();
            TLVector <TLAbsMessage> msgs = new TLVector <TLAbsMessage>();

            do
            {
                try
                {
                    temp = client.SendRequestAsync <TLChannelMessages>
                               (new TLRequestGetHistory()
                    {
                        Peer = new TLInputPeerChannel()
                        {
                            ChannelId = result.Channel.Id, AccessHash = (long)result.Channel.AccessHash
                        },
                        Limit     = 500,
                        AddOffset = offset,
                        OffsetId  = 0
                    }).GetAwaiter().GetResult();
                    msgs = temp.Messages;
                }
                catch
                {
                    await Task.Delay(3000);
                }
                if (countMessageParse != 0)
                {
                    offset            = temp.Count - countMessageParse;
                    countMessageParse = 0;
                }
                if (temp.Count > offset || temp.Count == 0)
                {
                    offset += msgs.Count;
                    foreach (var msg in msgs)
                    {
                        if (msg is TLMessage)
                        {
                            TLMessage sms = msg as TLMessage;
                            if (sms.Views != null)
                            {
                                AverageViews.Add(sms.Views.Value);
                            }
                            info.CountMessage++;
                            if (sms.Media != null)
                            {
                                info.CountMediaFiles++;

                                if (sms.Media is TLMessageMediaDocument)
                                {
                                    info.ChannelParserMediaInfo.CountVideo++;
                                }
                                else if (sms.Media is TLMessageMediaPhoto)
                                {
                                    info.ChannelParserMediaInfo.CountPhoto++;
                                }
                                else if (sms.Media is TLMessageMediaWebPage)
                                {
                                    info.ChannelParserMediaInfo.CountWebPag++;
                                }
                                else if (sms.Media is TLMessageMediaContact)
                                {
                                    info.ChannelParserMediaInfo.CountContact++;
                                }
                            }
                        }
                        if (msg is TLMessageService)
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    break;
                }
            } while (temp.Count > offset || temp.Count == 0);

            if (AverageViews.Count != 0)
            {
                info.AverageViews = AverageViews.Sum() / AverageViews.Count;
            }

            return(info);
        }