public async Task SendChip(SocketMessage message, string[] args) { string name = (args.Length < 2) ? args[0] : args[1]; bool exists = this.chipLibrary.TryGetValue(name.ToLower(), out Chip Value); if (exists) { await message.Channel.SendMessageAsync("```" + Value.All + "```"); //await sendChipAsEmbed(message, Value); return; } //else doesn't exist var chipList = (from kvp in chipLibrary.AsParallel(). WithMergeOptions(ParallelMergeOptions.FullyBuffered) where kvp.Key.Contains(name.ToLower()) select kvp.Value.Name).OrderBy(chip => chip).ToArray(); switch (chipList.Length) { case 0: { //no chips found //await message.Channel.SendMessageAsync("That doesn't exist"); //return; //StringSearch.compareMatch(name, chipLibrary); var res = (from kvp in chipLibrary.AsParallel().WithMergeOptions(ParallelMergeOptions.FullyBuffered) select Tuple.Create(kvp.Value.Name, StringSearch.GetDamerauLevenshteinDistance(name.ToLower(), kvp.Value.Name.ToLower()))) .OrderBy(selector => selector.Item2).Take(5); var toret = (from tup in res select tup.Item1); StringBuilder builder = new StringBuilder(); builder.Append("Did you mean: "); builder.Append(string.Join(", ", toret)); await message.Channel.SendMessageAsync(builder.ToString()); return; } case 1: { //one chip has a name that contains it this.chipLibrary.TryGetValue(chipList[0].ToLower(), out Chip foundVal); await message.Channel.SendMessageAsync("```" + foundVal.All + "```"); //await sendChipAsEmbed(message, foundVal); return; } default: { await SendStringArrayAsMessage(message, chipList); return; } } }
public async Task SendVirus(SocketMessage message, string[] args) { if (args.Length < 2) { await message.Channel.SendMessageAsync("You must specify a virus name"); return; } args = args.Skip(1).Take(args.Length - 1).ToArray(); string name = string.Join(" ", args); bool exists = this.compendium.TryGetValue(name.ToLower(), out Virus foundVirus); if (exists) { string toSend = string.Format("```{0} - CR {1}\n{2}```", foundVirus.Name, foundVirus.CR, foundVirus.Description); await message.Channel.SendMessageAsync(toSend); return; } var virusList = (from kvp in compendium.AsParallel(). WithMergeOptions(ParallelMergeOptions.FullyBuffered) where kvp.Key.Contains(name.ToLower()) select kvp.Value.Name).OrderBy(Virus => Virus).ToArray(); switch (virusList.Length) { case 0: { var res = (from kvp in compendium.AsParallel().WithMergeOptions(ParallelMergeOptions.FullyBuffered) select Tuple.Create(kvp.Value.Name, StringSearch.GetDamerauLevenshteinDistance(name.ToLower(), kvp.Value.Name.ToLower()))) .OrderBy(selector => selector.Item2).Take(5); var toret = (from tup in res select tup.Item1); StringBuilder builder = new StringBuilder(); builder.Append("Did you mean: "); builder.Append(string.Join(", ", toret)); await message.Channel.SendMessageAsync(builder.ToString()); return; } case 1: { this.compendium.TryGetValue(virusList[1].ToLower(), out foundVirus); string toSend = string.Format("```{0} - CR {1}\n{2}```", foundVirus.Name, foundVirus.CR, foundVirus.Description); await message.Channel.SendMessageAsync(toSend); return; } default: await Library.SendStringArrayAsMessage(message, virusList); return; } }
public async Task SendNCP(SocketMessage message, string[] args) { if (args.Length < 2) { await message.Channel.SendMessageAsync("You must specify an argument"); return; } args = args.Skip(1).Take(args.Length - 1).ToArray(); string name = string.Join(" ", args); bool exists = this.NCPs.TryGetValue(name.ToLower(), out NCP Value); if (exists) { await message.Channel.SendMessageAsync("```" + Value.Name + " - (" + Value.EBCost + " EB) - " + Value.Color + "\n" + Value.Description + "```"); return; } var NCPList = (from kvp in NCPs.AsParallel(). WithMergeOptions(ParallelMergeOptions.FullyBuffered) where kvp.Key.Contains(name.ToLower()) select kvp.Value.Name).OrderBy(NCP => NCP).ToArray(); switch (NCPList.Length) { case 0: { var res = (from kvp in NCPs.AsParallel().WithMergeOptions(ParallelMergeOptions.FullyBuffered) select Tuple.Create(kvp.Value.Name, StringSearch.GetDamerauLevenshteinDistance(name.ToLower(), kvp.Value.Name.ToLower()))) .OrderBy(selector => selector.Item2).Take(5); var toret = (from tup in res select tup.Item1); StringBuilder builder = new StringBuilder(); builder.Append("Did you mean: "); builder.Append(string.Join(", ", toret)); await message.Channel.SendMessageAsync(builder.ToString()); return; } case 1: { //one ncp has a name that contains it this.NCPs.TryGetValue(NCPList[0].ToLower(), out NCP foundVal); await message.Channel.SendMessageAsync("```" + foundVal.Name + " - (" + foundVal.EBCost + " EB) - " + foundVal.Color + "\n" + foundVal.Description + "```"); return; } default: { await Library.SendStringArrayAsMessage(message, NCPList); return; } } }