Ejemplo n.º 1
0
        public static async Task <string> ConstructCaptionTextAsync(string _text, List <SearchModel> searches, IInstaApi api)
        {
            var text = _text + Environment.NewLine;

            foreach (var search in searches)
            {
                if (search.InHashtags)
                {
                    foreach (var inString in search.GetInStrings())
                    {
                        if (inString.StartsWith("#") && inString.Length > 1)
                        {
                            var _hashtag = await api.SearchHashtag(inString.Substring(1, inString.Length - 1));

                            if (_hashtag.Succeeded)
                            {
                                if (_hashtag.Value.Count > 0)
                                {
                                    var hashtag = _hashtag.Value.First(_h => _h.MediaCount == _hashtag.Value.Max(h => h.MediaCount));

                                    text += $"#{hashtag.Name} ";
                                }
                            }
                        }
                    }
                }

                text += Environment.NewLine;

                if (search.InUsers)
                {
                    foreach (var inString in search.GetInStrings())
                    {
                        if (inString.StartsWith("@") && inString.Length > 1)
                        {
                            var _user = await api.SearchUsersAsync(inString.Substring(1, inString.Length - 1));

                            if (_user.Succeeded)
                            {
                                if (_user.Value.Count > 0)
                                {
                                    text += $"@{_user.Value.First().UserName} ";
                                }
                            }
                        }
                    }
                }
            }


            return(text);
        }