private static Embed CreateSingleShardsCardEmbedOutput(ShardsCard card, bool small) { EmbedBuilder builder = new EmbedBuilder(); if (small) { builder.WithUrl(card.ImageURL); builder.WithThumbnailUrl(card.ThumbnailURL); builder.WithTitle(card.Name); string types = string.Empty; if (card.Subtypes.Count > 0) { for (int i = 0; i < card.Subtypes.Count; i++) { types += card.Subtypes[i]; if (i < card.Subtypes.Count - 1) { types += ", "; } } } else { types = card.CardType; } builder.AddField(types, card.FullText.Replace("<b>", "**") .Replace("</b>", "**") .Replace("<lb>", "\n") .Replace("<i>", "*") .Replace("</i>", "*"), false); builder.WithFooter(string.Format("Copies: {0}", card.NumCopies)); } else { builder.WithImageUrl(card.ImageURL); } return(builder.WithColor(new Color(112, 141, 241)).Build()); }
public static Embed ProcessShardsCommand(string searchedCard, bool small = false) { Embed embed; List <ShardsCard> matchingCards = new List <ShardsCard>(); string sqlCards = "SELECT DISTINCT * FROM ShardsCards WHERE Name LIKE '%" + searchedCard.Replace("\'", "\'\'") + "%'"; string sqlSubTypes = "SELECT DISTINCT SubType FROM ShardsSubtypes WHERE Code = @code"; SQLiteCommand command = new SQLiteCommand(sqlCards, Program.dbConnection); SQLiteDataReader reader = command.ExecuteReader(); SQLiteCommand subtypeCommand = new SQLiteCommand(sqlSubTypes, Program.dbConnection); SQLiteDataReader subtypeReader; List <string> subtypes; ShardsCard card; while (reader.Read()) { card = new ShardsCard { Code = Convert.ToString(reader["Code"]), SetNumber = Convert.ToInt16(reader["SetNumber"]), Name = Convert.ToString(reader["Name"]), CardType = Convert.ToString(reader["CardType"]), NumCopies = Convert.ToInt16(reader["NumCopies"]), FullText = Convert.ToString(reader["FullText"]), Cost = Convert.ToString(reader["Cost"]), Victory = Convert.ToString(reader["Victory"]), ThumbnailURL = Convert.ToString(reader["ThumbnailURL"]), ImageURL = Convert.ToString(reader["ImageURL"]) }; subtypeCommand.Parameters.Add("@code", System.Data.DbType.String).Value = card.Code; subtypeReader = subtypeCommand.ExecuteReader(); subtypes = new List <string>(); while (subtypeReader.Read()) { subtypes.Add(Convert.ToString(subtypeReader["SubType"])); } subtypeReader.Close(); card.Subtypes = subtypes; subtypeCommand.Parameters.Clear(); matchingCards.Add(card); } if (matchingCards.Count == 0) { embed = new EmbedBuilder().WithColor(new Color(112, 141, 241)).WithTitle(string.Format("Couldn't find a cardname containing \"{0}\"", searchedCard)).Build(); } else if (matchingCards.Count == 1) { embed = CreateSingleShardsCardEmbedOutput(matchingCards[0], small); } else { int exactMatchIndex = -1; for (int i = 0; i < matchingCards.Count; i++) { if (matchingCards[i].Name.Equals(searchedCard, StringComparison.OrdinalIgnoreCase)) { exactMatchIndex = i; break; } } if (exactMatchIndex >= 0) { embed = CreateSingleShardsCardEmbedOutput(matchingCards[exactMatchIndex], small); } else { embed = CreateMultipleShardsCardEmbedOutput(matchingCards); } } return(embed); }