public Search(PageService ps) { _pageService = ps; _characterIndex = new DbCharacterIndex( ConfigUtils.GetCurrentDatabase(Constants.ProductionConfig)); _seriesIndex = new DbSeriesIndex( ConfigUtils.GetCurrentDatabase(Constants.ProductionConfig)); }
public async Task InSeriesAsync(string seriesName = null) { if (string.IsNullOrEmpty(seriesName)) { await ReplyAsync("Usage: oka.in_series series_name"); return; } if (!_pageService.HandlerAdded) { Context.Client.ReactionAdded += ReactionAdded_Event; _pageService.HandlerAdded = true; } DbSeriesIndex seriesIndex = _seriesIndex; DbCharacterIndex charIndex = _characterIndex; using (MySqlConnection charConn = _characterIndex.GetConnection()) using (MySqlConnection seriesConn = _seriesIndex.GetConnection()) { int id; string tag; string seriesNameEscaped; if (int.TryParse(seriesName, out id)) { tag = seriesIndex.LookupTagById(id, seriesConn); if (!string.IsNullOrEmpty(tag)) { seriesName = tag; } } seriesName = TagParser.Format(seriesName); seriesNameEscaped = TagParser.EscapeUnderscore(seriesName); List <string> characters = seriesIndex.CharactersInSeries(seriesName, seriesConn); if (characters.Count > 0) { if (characters.Count < MaxSearchResults) { List <TagData> characterData = charIndex.LookupTagData(characters, charConn); pages = TagParser.CompileSuggestions(characterData, EmbedBuilder.MaxFieldCount); EmbedBuilder embed = BuildSuggestionsEmbed(pages); if (embed != null) { var toSend = await Context.Channel.SendMessageAsync(embed : embed.Build()); ulong msgId = toSend.Id; PageData pageData = new PageData(pages); _pageService.AddLimited(msgId, pageData); await toSend.AddReactionAsync(Constants.PageBack); await toSend.AddReactionAsync(Constants.PageForward); await toSend.AddReactionAsync(Constants.SortAlphabetical); await toSend.AddReactionAsync(Constants.SortNumerical); await toSend.AddReactionAsync(Constants.ChangeOrder); } } else { await ReplyAsync(ExcessiveResults.Replace("%", seriesNameEscaped)); } } else { await ReplyAsync(NoResults.Replace("%", seriesNameEscaped)); } } }