public async Task <NinjaObjects.GuildObject> GetGuildAssociation(string discordGuildName) { NinjaObjects.GuildObject guildObject = new NinjaObjects.GuildObject(); using (var db = new NinjaBotEntities()) { var foundGuild = db.WowGuildAssociations.FirstOrDefault(g => g.ServerName == discordGuildName); if (foundGuild != null) { guildObject.guildName = foundGuild.WowGuild; guildObject.realmName = foundGuild.WowRealm; guildObject.regionName = foundGuild.WowRegion; guildObject.locale = foundGuild.Locale; guildObject.realmSlug = foundGuild.LocalRealmSlug; } } return(guildObject); }
public async Task <NinjaObjects.GuildObject> GetGuildName(ICommandContext context) { NinjaObjects.GuildObject guildObject = new NinjaObjects.GuildObject(); try { if (context.Channel is IDMChannel) { guildObject = await GetGuildAssociation(context.User.Username); } else if (context.Channel is IGuildChannel) { guildObject = await GetGuildAssociation(context.Guild.Name); } _logger.LogInformation($"getGuildName: {context.Channel.Name} : {guildObject.guildName} -> {guildObject.realmName}"); } catch (Exception ex) { _logger.LogError($"getGuildName: {ex.Message}"); } return(guildObject); }
public async Task GetWowRankings(ICommandContext context, string args = null) { NinjaObjects.GuildObject guildObject = new NinjaObjects.GuildObject(); string guildName = string.Empty; string realmName = string.Empty; string regionName = "us"; if (string.IsNullOrEmpty(args)) { guildObject = await GetGuildName(context); guildName = guildObject.guildName; realmName = guildObject.realmName; regionName = guildObject.regionName; } else { if (args.Contains(',')) { switch (args.Split(',').Count()) { case 2: { realmName = args.Split(',')[0].ToString().Trim(); guildName = args.Split(',')[1].ToString().Trim(); break; } case 3: { realmName = args.Split(',')[0].ToString().Trim(); guildName = args.Split(',')[1].ToString().Trim(); regionName = args.Split(',')[2].ToString().Trim(); break; } } } else { StringBuilder sb = new StringBuilder(); var embed = new EmbedBuilder(); embed.WithColor(new Color(255, 0, 0)); embed.Title = $"Unable to find a guild/realm association!\nTry {_prefix}wow rankings Realm Name, Guild Name"; sb.AppendLine($"Command syntax: {_prefix}wow rankings realm name, guild name"); sb.AppendLine($"Command example: {_prefix}wow rankings azgalor, carebears"); embed.Description = sb.ToString(); await _cc.Reply(context, embed); return; } } if (string.IsNullOrEmpty(guildName) || string.IsNullOrEmpty(realmName)) { StringBuilder sb = new StringBuilder(); var embed = new EmbedBuilder(); embed.WithColor(new Color(255, 0, 0)); embed.Title = $"Unable to find a guild/realm association!\nTry {_prefix}wow rankings Realm Name, Guild Name"; sb.AppendLine($"Command syntax: {_prefix}wow rankings realm name, guild name"); sb.AppendLine($"Command example: {_prefix}wow rankings azgalor, carebears"); embed.Description = sb.ToString(); await _cc.Reply(context, embed); return; } try { var guildMembers = _wowApi.GetGuildMembers(realmName, guildName, regionName); int memberCount = 0; if (guildMembers != null) { guildName = guildMembers.guild.name; realmName = guildMembers.guild.realm.slug; memberCount = guildMembers.members.Count(); } var wowProgressApi = new WowProgress(); StringBuilder sb = new StringBuilder(); var embed = new EmbedBuilder(); embed.WithColor(new Color(255, 255, 0)); var ranking = wowProgressApi.GetGuildRank(guildName, realmName, regionName); var realmObject = wowProgressApi.GetRealmObject(realmName, wowProgressApi._links, regionName); var topGuilds = realmObject.OrderBy(r => r.realm_rank).Take(3); var guild = realmObject.Where(r => r.name.ToLower() == guildName.ToLower()).FirstOrDefault(); int guildRank = guild.realm_rank; var surroundingGuilds = realmObject.Where(r => r.realm_rank > (guild.realm_rank - 2) && r.realm_rank < (guild.realm_rank + 2)); embed.Title = $"__:straight_ruler:Guild ranking for **{guildName}** [**{memberCount}** members] (Score: **{ranking.score}**):straight_ruler:__"; sb.AppendLine($"Realm rank: **{ranking.realm_rank}** **|** World rank: **{ranking.world_rank}** **|** Area rank: **{ranking.area_rank}**"); sb.AppendLine(); sb.AppendLine($"__Where **{guildName}** fits in on **{realmName}**__"); foreach (var singleGuild in surroundingGuilds) { sb.AppendLine($"\t(**{singleGuild.realm_rank}**) **{singleGuild.name}** **|** World rank: **{singleGuild.world_rank}**"); } sb.AppendLine(); sb.AppendLine($"__:top:Top 3 guilds on **{realmName}**:top:__"); foreach (var topGuild in topGuilds) { sb.AppendLine($"\t(**{topGuild.realm_rank}**) **{topGuild.name}** **|** World Rank: **{topGuild.world_rank}**"); } sb.AppendLine(); sb.AppendLine("Ranking data gathered via **WoWProgress.com**"); embed.WithUrl($"{guild.url}"); embed.Description = sb.ToString(); await _cc.Reply(context, embed); } catch (Exception ex) { _logger.LogError($"{ex.Message} {ex.InnerException} {ex.Data}{ex.Source}{ex.StackTrace}"); StringBuilder sb = new StringBuilder(); var embed = new EmbedBuilder(); embed.WithColor(new Color(255, 0, 0)); embed.Title = $":frowning: Sorry, {context.User.Username}, something went wrong! Perhaps check the guild's home realm.:frowning: "; sb.AppendLine($"Command syntax: {_prefix}wow rankings realm name, guild name"); sb.AppendLine($"Command example: {_prefix}wow rankings azgalor, carebears"); embed.Description = sb.ToString(); await _cc.Reply(context, embed); } }
public async Task <GuildChar> GetCharFromArgs(string args, ICommandContext context) { string regionPattern = "^[a-z]{2}$"; string charName = string.Empty; string realmName = string.Empty; string foundRegion = string.Empty; Regex matchPattern = new Regex($@"{regionPattern}"); GuildChar guildie = null; List <FoundChar> chars; NinjaObjects.GuildObject guildObject = new NinjaObjects.GuildObject(); GuildChar charInfo = new GuildChar { realmName = string.Empty, charName = string.Empty }; int argNumber = args.Split(' ').Count(); switch (argNumber) { case 1: { charName = args.Split(' ')[0].Trim(); break; } case 2: { charName = args.Split(' ')[0].Trim(); realmName = args.Split(' ')[1].Trim(); break; } } if (argNumber > 2) { charName = args.Split(' ')[0].Replace("'", string.Empty).Trim(); realmName = string.Empty; int i = 0; do { i++; MatchCollection match = matchPattern.Matches(args.Split(' ')[i].ToLower()); if (match.Count > 0) { foundRegion = match[0].Value; break; } if (i == argNumber - 1) { realmName += $"{args.Split(' ')[i]}".Replace("\"", ""); } else { realmName += $"{args.Split(' ')[i]} ".Replace("\"", ""); } }while (i <= argNumber - 2); realmName = realmName.Trim(); } if (string.IsNullOrEmpty(realmName)) { //See if they're a guildie first try { guildObject = await GetGuildName(context); } catch (Exception ex) { _logger.LogError($"Error looking up character: {ex.Message}"); } if (guildObject.guildName != null && guildObject.realmName != null) { guildie = _wowApi.GetCharFromGuild(charName, guildObject.realmName, guildObject.guildName, guildObject.regionName); if (string.IsNullOrEmpty(guildie.charName)) { guildie = null; } } //Check to see if the character is in the guild if (guildie != null) { charName = guildie.charName; realmName = guildie.realmName; charInfo.regionName = guildie.regionName; } else { chars = _wowApi.SearchArmory(charName); if (chars != null) { charName = chars[0].charName; realmName = chars[0].realmName; } } } if (!string.IsNullOrEmpty(foundRegion)) { charInfo.regionName = foundRegion; } charInfo.charName = charName; charInfo.realmName = realmName; if (!string.IsNullOrEmpty(guildObject.locale)) { charInfo.locale = guildObject.locale; } return(charInfo); }
public async Task GetAuctionItems(string args, ICommandContext context) { try { NinjaObjects.GuildObject guildObject = new NinjaObjects.GuildObject(); string realmName = string.Empty; string regionName = "us"; if (string.IsNullOrEmpty(args)) { guildObject = await GetGuildName(context); realmName = guildObject.realmName; regionName = guildObject.regionName; } else { int i = 0; do { if (i == args.Split(' ').Count() - 1) { realmName += $"{args.Split(' ')[i]}".Replace("\"", ""); } else { realmName += $"{args.Split(' ')[i]} ".Replace("\"", ""); } i++; }while (i <= args.Split(' ').Count() - 1); realmName = realmName.Trim(); } if (string.IsNullOrEmpty(realmName)) { await _cc.Reply(context, $"Unable to find realm \nTry {_prefix}wow auctions realmName"); return; } _logger.LogInformation($"Looking up auctions for realm {realmName.ToUpper()}"); List <WowAuctions> auctions = await _wowApi.GetAuctionsByRealm(realmName.ToLower(), guildObject.regionName); StringBuilder sb = new StringBuilder(); var auctionList = GetAuctionItemIDs(); var embed = new EmbedBuilder(); embed.WithColor(new Color(0, 255, 0)); embed.Title = $":scales:Auction prices on **{realmName.ToUpper()}**"; foreach (var item in auctionList) { var auction = auctions.Where(auc => auc.AuctionItemId == item.ItemID).ToList(); long lowestPrice = GetLowestBuyoutPrice(auction.Where(r => r.AuctionBuyout != 0)); if (auction.Count() != 0) { sb.AppendLine($":black_small_square:__**{item.Name}**__ / Found **{auction.Count()}** / Lowest price **{ lowestPrice / 10000}g**"); } else { sb.AppendLine($":black_small_square:__**{item.Name}**__ / None found :("); } } sb.AppendLine(); sb.AppendLine($"Last updated: **{auctions[0].DateModified}**"); embed.Description = sb.ToString(); await _cc.Reply(context, embed); using (var db = new NinjaBotEntities()) { foreach (var item in auctionList) { var items = auctions.Where(auc => auc.AuctionItemId == item.ItemID).ToList(); long lowestPrice = GetLowestBuyoutPrice(items.Where(r => r.AuctionBuyout != 0)); long highestPrice = GetHighestBuyoutPrice(items.Where(r => r.AuctionBuyout != 0)); long averagePrice = GetAveragePrice(items.Where(r => r.AuctionBuyout != 0)); if (items.Count() > 0) { db.WowAuctionPrices.Add(new WowAuctionPrice { AuctionItemId = (long)items[0].AuctionItemId, AuctionRealm = items[0].RealmSlug, AvgPrice = averagePrice, MinPrice = lowestPrice, MaxPrice = highestPrice, Seen = items.Count() }); } } await db.SaveChangesAsync(); } } catch (Exception ex) { _logger.LogError($"Auction error: [{ex.Message}]"); await _cc.Reply(context, "Error getting auctions :("); } }