Ejemplo n.º 1
0
        /// <summary>
        /// Get authentication phonenumber main chats
        /// </summary>
        /// <returns>A list which contains tdpi.Chat instnaces</returns>
        public async Task <List <tdapi.Chat> > GetMainChatList()
        {
            List <tdapi.Chat> res = new List <tdapi.Chat>();
            long offsetorder      = long.MaxValue;
            long offsetid         = 0;
            int  max = 100000;

            while (true)
            {
                Responseobject GetChatListresponse = await ExecuteCommandAsync(new tdapi.GetChats(null, offsetorder, offsetid, max), new tdapi.Chats());

                if (GetChatListresponse.response == enums.Response.Success)
                {
                    tdapi.Chats chats = GetChatListresponse.responseobject as tdapi.Chats;
                    if (chats.ChatIds.Length > 0)
                    {
                        foreach (long item in chats.ChatIds)
                        {
                            Responseobject GetChatresponse = await ExecuteCommandAsync(new tdapi.GetChat(item), new tdapi.Chat());

                            if (GetChatresponse.response == enums.Response.Success)
                            {
                                res.Add(GetChatresponse.responseobject as tdapi.Chat);
                            }
                            else
                            {
                                hpcore.addlog("[GetMainChatList][GetChatresponse] - " + GetChatListresponse.responseobject);
                            }
                        }
                        if (res.Count > 0)
                        {
                            tdapi.Chat last = res.Last();
                            offsetid    = last.Id;
                            offsetorder = last.Positions.FirstOrDefault(Func => Func.List is tdapi.ChatListMain).Order;
                        }
                        hpcore.addlog($"[GetMainChatList] - gathered {res.Count:n0}");
                    }
                    else
                    {
                        hpcore.addlog($"[GetMainChatList] - finished, total {res.Count:n0}");
                        break;
                    }
                }
                else
                {
                    hpcore.addlog("[GetMainChatList][GetChatListresponse] - " + GetChatListresponse.responseobject);
                    break;
                }
            }
            res = res
                  .GroupBy(func => func.Id)
                  .Select(func => func.First())
                  .Distinct()
                  .ToList();
            mainchatslist = res;
            return(mainchatslist);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// returns a specified super group members if possible
        /// </summary>
        /// <param name="groupidentifier">target super group search query</param>
        /// <param name="istitle">true if query contains in target group title</param>
        /// <returns>A list which contains tdpi.User instnaces</returns>
        public async Task <List <tdapi.User> > GetSuperGroupUsers(string groupidentifier, bool istitle = false)
        {
            List <tdapi.User> res = new List <tdapi.User>();

            if (istitle)
            {
                if (mainchatslist is null)
                {
                    await GetMainChatList();
                }
                tdapi.Chat target = mainchatslist.FirstOrDefault(Func => Func.Title.ToLower().IndexOf(groupidentifier.ToLower()) >= 0);
                if (target != null)
                {
                    res = await GetSuperGroupUsers(target.Id);
                }
                else
                {
                    hpcore.addlog("[GetSuperGroupUsers][searchmainchatlist] - chat not found");
                }
            }
            else
            {
                Responseobject search = await ExecuteCommandAsync(new tdapi.SearchPublicChat(groupidentifier));

                if (search.response == enums.Response.Success)
                {
                    tdapi.Chat target = search.responseobject as tdapi.Chat;
                    res = await GetSuperGroupUsers(target.Id);
                }
                else
                {
                    hpcore.addlog("[GetSuperGroupUsers][search] - " + search);
                }
            }
            return(res);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a user in specified super group
        /// </summary>
        /// <param name="user">target user tdapi.User instnace</param>
        /// <param name="target">target group tdapi.Chat instnace</param>
        /// <param name="addall">if true, user will be added even if its blocked, or last seen long time ago</param>
        public async Task <(enums.Response response, object obj)> AddChatMember(tdapi.User user, tdapi.Chat target, bool addall = false)
        {
            enums.Response res = new enums.Response();
            object         obj = null;

            if (user.Username is null || user.Username.Length <= 0)
            {
                res = enums.Response.Failed;
                obj = new tdapi.Error()
                {
                    Message = "User username cannot be empty"
                };
            }
Ejemplo n.º 4
0
        /// <summary>
        /// returns a specified super group members if possible
        /// </summary>
        /// <param name="supergroupid">target super group identifier</param>
        /// <returns>A list which contains tdpi.User instnaces</returns>
        public async Task <List <tdapi.User> > GetSuperGroupUsers(long supergroupid)
        {
            hpcore.addlog("[GetSuperGroupUsers] - gathering " + supergroupid);
            List <tdapi.User>       res                       = new List <tdapi.User>();
            List <tdapi.ChatMember> chatmemberslist           = new List <tdapi.ChatMember>();
            Responseobject          GetSuperGroupChatresponse = await ExecuteCommandAsync(new tdapi.GetChat(supergroupid), new tdapi.Chat());

            if (GetSuperGroupChatresponse.response == enums.Response.Success)
            {
                tdapi.Chat groupchat = GetSuperGroupChatresponse.responseobject as tdapi.Chat;
                if (groupchat.Type is tdapi.ChatTypeSupergroup supergroupchat)
                {
                    Responseobject GetSupergroupFullInforesponse = await ExecuteCommandAsync(new tdapi.GetSupergroupFullInfo(supergroupchat.SupergroupId), new tdapi.SupergroupFullInfo());

                    if (GetSupergroupFullInforesponse.response == enums.Response.Success)
                    {
                        tdapi.SupergroupFullInfo supergroupFullInfo = GetSupergroupFullInforesponse.responseobject as tdapi.SupergroupFullInfo;
                        if (supergroupFullInfo.CanGetMembers)
                        {
                            int max = 200;
                            while (true)
                            {
                                Responseobject GetSuperGroupMemberresponse = await ExecuteCommandAsync(new tdapi.GetSupergroupMembers(supergroupchat.SupergroupId, null, chatmemberslist.Count, max), new tdapi.ChatMembers());

                                if (GetSuperGroupMemberresponse.response == enums.Response.Success)
                                {
                                    tdapi.ChatMembers members = GetSuperGroupMemberresponse.responseobject as tdapi.ChatMembers;
                                    if (members.Members.Length > 0)
                                    {
                                        foreach (tdapi.ChatMember item in members.Members)
                                        {
                                            chatmemberslist.Add(item);
                                        }
                                        hpcore.addlog($"[GetSuperGroupMemberresponse] - gathered {chatmemberslist.Count:n0}");
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    hpcore.addlog("[GetSuperGroupMemberresponse] - " + GetSuperGroupMemberresponse.responseobject);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        hpcore.addlog($"[GetSuperGroupUsers][GetSupergroupFullInforesponse] - response is {GetSupergroupFullInforesponse.responseobject}");
                    }
                }
                else
                {
                    hpcore.addlog($"[GetSuperGroupUsers][GetSupergroupChatresponse] - target group is {groupchat.Type.GetType()}");
                }
            }
            else
            {
                hpcore.addlog($"[GetSuperGroupUsers][GetSupergroupChatresponse] - response is {GetSuperGroupChatresponse}");
            }
            if (chatmemberslist.Count > 0)
            {
                hpcore.addlog($"[GetSuperGroupUsers][GetUser] -  for {chatmemberslist.Count:n0}");
                List <Task> tklist = new List <Task>();
                foreach (tdapi.ChatMember item in chatmemberslist)
                {
                    tklist.Add(Task.Run(async() =>
                    {
                        Responseobject itemuser = await ExecuteCommandAsync(new tdapi.GetUser(item.UserId), new tdapi.User());
                        if (itemuser.response == enums.Response.Success)
                        {
                            lock (lockerobject)
                            {
                                res.Add(itemuser.responseobject as tdapi.User);
                            }
                        }
                    }));
                }
                await Task.WhenAll(tklist);
            }

            return(res
                   .GroupBy(func => func.Id)
                   .Select(func => func.First())
                   .Distinct()
                   .ToList());
        }