Exemplo n.º 1
0
        /// <summary>
        /// returns a FileDescriptor object which contains info about a file and can be used to download the file
        /// </summary>
        /// <param name="fileId"></param>
        /// <returns></returns>
        public FileDescriptor GetFile(string fileId)
        {
            Require(fileId);

            var id    = new QueryStringParameter("file_id", fileId);
            var reply = _communicator.GetReply <GetFileReply>("getFile", id);

            if (reply.Ok)
            {
                return(reply.File);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// returns the profile photos of a user in different qualities
        /// </summary>
        /// <returns>A list of Photosize arrays, where each list element contains different qualities of the photo in an array</returns>
        public IList <PhotoSize[]> GetUserProfilePhotos(User user, int maxPhotos = int.MaxValue)
        {
            Require(user);

            var parameters = new List <QueryStringParameter>
            {
                new QueryStringParameter("user_id", user.Id.ToString()),
            };

            long offset            = 0;
            long stepsize          = 100;
            var  offsetParameter   = new QueryStringParameter("offset", offset.ToString());
            var  stepSizeParameter = new QueryStringParameter("limit", maxPhotos < stepsize ? maxPhotos.ToString() : stepsize.ToString());


            parameters.Add(offsetParameter);
            parameters.Add(stepSizeParameter);

            long totalCount;
            var  photos = new List <PhotoSize[]>();

            do
            {
                var reply = _communicator.GetReply <GetUserProfilePhotosReply>("getUserProfilePhotos", parameters.ToArray());
                if (!reply.Ok)
                {
                    return(null);
                }

                totalCount = reply.UserProfilePhotos.TotalCount;
                photos.AddRange(reply.UserProfilePhotos.Photos);

                offset += stepsize;
                offsetParameter.Value = offset.ToString();
                if (totalCount - offset < stepsize)
                {
                    stepSizeParameter.Value = (totalCount - offset).ToString();
                }
            }while ((offset <= totalCount) && (offset <= maxPhotos));

            return(photos);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets all unconfirmed updates the bot has received
        /// - when called the first time, it gets all unconfirmed messages the bot has received
        /// - subsequent calls confirm previous update, so after that, it will only get new updates (and confirm old ones)
        ///
        /// </summary>
        /// <param name="peek">when set, the bot will not confirm updates, so that they will also be kept on the server</param>
        /// <returns>a list of Messages</returns>
        ///
        public IList <Update> GetUpdates(bool peek = false)
        {
            QueryStringParameter requestlimit = new QueryStringParameter("limit", Constants.RequestLimit.ToString());

            UpdateReply reply;

            if (_updateOffset != 0 && !peek)
            {
                QueryStringParameter offset = new QueryStringParameter("offset", _updateOffset.ToString());
                reply = _communicator.GetReply <UpdateReply>("getUpdates", requestlimit, offset);
            }
            else
            {
                reply = _communicator.GetReply <UpdateReply>("getUpdates", requestlimit);
            }

            //set offset for next pull
            if (reply.Updates.Length > 0)
            {
                _updateOffset = reply.Updates[reply.Updates.Length - 1].UpdateId + 1;
            }

            return(new List <Update>(reply.Updates));
        }