示例#1
0
        private static void GetPostText(List <Command> sanitizedNames)
        {
            foreach (Command c in sanitizedNames)
            {
                string command = c.Request;
                switch (c.Type)
                {
                case SearchUrl:     //Actually, search by url will use the id, sneaky.
                    var    s     = c.Request.Split('/').ToList();
                    int    index = s.FindIndex(x => x == "story") + 1;
                    string id    = s[index];
                    c.Response = StoryIdLookup(id);
                    break;

                case SearchId:
                    c.Response = StoryIdLookup(c.Request);
                    break;

                case SearchName:
                    string          res          = BotClient.GetStringAsync(Constants.StoryQueryUrl($"?query={command}&")).Result;
                    StoryData.Story searchResult = JsonConvert.DeserializeObject <StoryData.Story>(res);
                    c.Response = searchResult;
                    break;
                }
            }
        }
示例#2
0
        private static string GetAuthorUsername(StoryData.Story s)
        {
            string authorId = s.data.First().relationships.author.data.id;

            var authorName = s.included.First(x => x.id == authorId && x.type == "user").attributes.name;

            return(authorName);
        }
示例#3
0
        private static StoryData.Story StoryIdLookup(string id)
        {
            string queryUrl = Constants.StoryQueryUrl($"/{id}?");
            string res      = BotClient.GetStringAsync(queryUrl).Result;

            StoryData.StorySingle searchResult =
                JsonConvert.DeserializeObject <StoryData.StorySingle>(res);
            StoryData.Story r = new StoryData.Story
            {
                data = new StoryData.Datum[1]
            };
            r.data[0]  = searchResult.data;
            r.included = searchResult.included;
            return(r);
        }
示例#4
0
        private static string GenerateTags(StoryData.Story relationshipsTags)
        {
            List <string> tagIds =
                relationshipsTags.data.First().relationships.tags.data.Select(datum1 => datum1.id).ToList();
            List <string> tagNames = new List <string>();

            foreach (string tagId in tagIds)
            {
                string tagName =
                    relationshipsTags.included.First(x => x.id == tagId && x.type == "story_tag").attributes.name;
                tagNames.Add(tagName);
            }

            string builtTagLineContent = string.Join("`, `", tagNames);

            builtTagLineContent = "`" + builtTagLineContent + "`";
            return(builtTagLineContent);
        }