private async Task PrintItemsAsync(string itemName, IReadOnlyList <ComboItem> strings) { const int minLength = 2; if (itemName.Length <= minLength) { await ReplyAsync($"Please enter a search term longer than {minLength} characters.").ConfigureAwait(false); return; } var exact = ItemUtil.GetItem(itemName, strings); if (!exact.IsNone) { var msg = $"{exact.ItemId:X4} {itemName}"; await ReplyAsync(Format.Code(msg)).ConfigureAwait(false); return; } var matches = ItemUtil.GetItemsMatching(itemName, strings).ToArray(); var result = string.Join(Environment.NewLine, matches.Select(z => $"{z.Value:X4} {z.Text}")); if (result.Length == 0) { await ReplyAsync("No matches found.").ConfigureAwait(false); return; } const int maxLength = 500; if (result.Length > maxLength) { var ordered = matches.OrderBy(z => LevenshteinDistance.Compute(z.Text, itemName)); result = string.Join(Environment.NewLine, ordered.Select(z => $"{z.Value:X4} {z.Text}")); result = result.Substring(0, maxLength) + "...[truncated]"; } await ReplyAsync(Format.Code(result)).ConfigureAwait(false); }
private async Task PrintItemsAsync(string itemName, IReadOnlyList <ComboItem> strings) { const int minLength = 2; if (itemName.Length <= minLength) { await ReplyAsync($"Please enter a search term longer than {minLength} characters.").ConfigureAwait(false); return; } foreach (var item in strings) { if (!string.Equals(item.Text, itemName, StringComparison.OrdinalIgnoreCase)) { continue; } if (!DropUtil.InvertedRecipeDictionary.TryGetValue((ushort)item.Value, out var recipeID)) { await ReplyAsync("Requested item is not a DIY recipe.").ConfigureAwait(false); return; } var msg = $"{item.Value:X4} {item.Text}: Recipe order code: 0{recipeID:X3}000016A2"; await ReplyAsync(Format.Code(msg)).ConfigureAwait(false); return; } var items = ItemUtil.GetItemsMatching(itemName, strings).ToArray(); var matches = new List <string>(); foreach (var item in items) { if (!DropUtil.InvertedRecipeDictionary.TryGetValue((ushort)item.Value, out var recipeID)) { continue; } var msg = $"{item.Value:X4} {item.Text}: Recipe order code: 0{recipeID:X3}000016A2"; matches.Add(msg); } var result = string.Join(Environment.NewLine, matches); if (result.Length == 0) { await ReplyAsync("No matches found.").ConfigureAwait(false); return; } const int maxLength = 500; if (result.Length > maxLength) { result = result.Substring(0, maxLength) + "...[truncated]"; } await ReplyAsync(Format.Code(result)).ConfigureAwait(false); }