private async Task <Tuple <bool, Post> > NSFWengine(string search, NSFWType type) { int TTL = 0; var post = await _post(search, type); while (string.IsNullOrEmpty(post.OriginalUrl)) { post = await _post(search, type); TTL++; if (TTL >= 5) { await ReplyAsync("`Error! TTL > 5`"); return(new Tuple <bool, Post>(false, null)); } } return(new Tuple <bool, Post>(true, post)); }
private async Task <Post> _post(string search, NSFWType type) { IBooruAsyncLoader loader; switch (type) { case NSFWType.Dan: loader = new DanbooruLoader(Database.JSON.GetApiNamedb(), Database.JSON.GetApiKeydb(), 120); break; case NSFWType.Yre: loader = new YandereLoader(); break; default: return(null); } var spost = (string.IsNullOrEmpty(search) ? await loader.LoadPopularAsync(PopularType.Day) : await loader.LoadSearchResultAsync(search)); var post = loader.LoadPostAsync(spost.Results[_ran.Next(spost.SearchCount ?? spost.Results.Count)].Id).Result; return(post); }