Example #1
0
        // Add 1 memeber to specified group Name from members.txt file
        private static int AddMemberToGroup(TLUser user, int gid, long hash)
        {
            int          ret = 0;
            TLAbsUpdates up  = null;

            try
            {
                user.Id = GetMemberIdByNickname(user);
                if (0 == hash)
                {
                    up = client.AddChatUserAsync(user.Id, gid).GetAwaiter().GetResult();
                }
                else
                {
                    up = client.InviteToChannelAsync(user.Id, gid, hash).GetAwaiter().GetResult();
                }

                if (0 != ((TLUpdates)up).Updates.Count)
                {
                    Logger.Succ("Adding user:{0} to group successful.", new string[] { userTitle(user) });
                    ret++;
                }
                else
                {
                    Logger.Warn("Adding user:{0} to group:{1} failed (USER_ALREADY_PARTICIPANT).", new string[] { userTitle(user), gid.ToString() });
                }
            } catch (Exception ex)
            {
                Logger.Warn("Adding user:{0} to group failed: {1}", new string[] { userTitle(user), ex.Message });
            }

            return(ret);
        }