public async Task RemoveChar(string charName = null) { var embed = new EmbedBuilder(); var sb = new StringBuilder(); if (charName != null) { try { WowMChar charMatch = null; using (var db = new NinjaBotEntities()) { charMatch = db.WowMChar.Where(d => d.DiscordUserId == (long)Context.User.Id && d.ServerId == (long)Context.Guild.Id && charName.ToLower() == d.CharName.ToLower()).FirstOrDefault(); if (charMatch != null) { db.WowMChar.Remove(charMatch); await db.SaveChangesAsync(); sb.AppendLine($"Character [**{charMatch.CharName}**] successfully removed!"); embed.WithColor(0, 255, 0); } else { sb.AppendLine($"Could not find [**{charName}**]!"); embed.WithColor(255, 0, 0); } } } catch { } } else { embed.WithColor(255, 0, 0); sb.AppendLine("Please specify a character name!"); using (var db = new NinjaBotEntities()) { var chars = db.WowMChar.Where(d => d.DiscordUserId == (long)Context.User.Id && d.ServerId == (long)Context.Guild.Id).ToList(); if (chars != null && chars.Count > 0) { sb.AppendLine($"Your character's names are:"); foreach (var character in chars) { sb.AppendLine($":white_medium_small_square: [**{character.CharName}**]"); } } } } embed.ThumbnailUrl = Context.User.GetAvatarUrl(); embed.Title = "Character Removal"; embed.Description = sb.ToString(); await _cc.Reply(Context, embed); }
public async Task FindChar(string charName = null) { var sb = new StringBuilder(); var embed = new EmbedBuilder(); embed.Title = $"Character Finder"; if (charName != null) { embed.Title = $"Character Finder [{charName}]"; WowMChar findMe = null; using (var db = new NinjaBotEntities()) { findMe = db.WowMChar.Where(d => d.ServerId == (long)Context.Guild.Id && d.CharName.ToLower().Contains(charName.ToLower())).FirstOrDefault(); if (findMe != null) { var fb = new StringBuilder(); string square = ":white_small_square:"; fb.AppendLine($"{square} ilvl [**{findMe.ItemLevel}**]"); fb.AppendLine($"{square} traits [**{findMe.Traits}**]"); if (!string.IsNullOrEmpty(findMe.ClassName)) { fb.AppendLine($"{square} class [**{findMe.ClassName}**]"); } else { fb.AppendLine($"{square} class [**much empty**]"); } if (!string.IsNullOrEmpty(findMe.MainSpec)) { fb.AppendLine($"{square} ms [**{findMe.MainSpec}**]"); } else { fb.AppendLine($"{square} ms [**much empty**]"); } if (!string.IsNullOrEmpty(findMe.OffSpec)) { fb.AppendLine($"{square} os [**{findMe.OffSpec}**]"); } else { fb.AppendLine($"{square} os [**much empty**]"); } string foundCharName = string.Empty; if (findMe.IsMain) { foundCharName = $"{findMe.CharName} [main]"; } else { foundCharName = $"{findMe.CharName} [alt]"; } embed.WithFields( new EmbedFieldBuilder { Name = foundCharName, Value = fb.ToString(), IsInline = true } ); var belongsTo = await Context.Guild.GetUserAsync((ulong)findMe.DiscordUserId); sb.AppendLine($"This character belongs to [**{belongsTo.Username}**]"); embed.WithColor(0, 200, 100); embed.ThumbnailUrl = belongsTo.GetAvatarUrl(); } else { sb.AppendLine($"Sorry {Context.User.Mention}, no results :("); embed.WithColor(255, 100, 0); } } } else { embed.WithColor(255, 0, 0); sb.AppendLine("You must specify a character name!"); } embed.Description = sb.ToString(); embed.WithFooter( new EmbedFooterBuilder { Text = $"Lookup performed by [{Context.User.Username}]", IconUrl = Context.User.GetAvatarUrl() } ); await _cc.Reply(Context, embed); }