示例#1
0
        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);
            }
        }
示例#2
0
        public async Task GetNoggen([Remainder] string args = null)
        {
            var          embed            = new EmbedBuilder();
            var          sb               = new StringBuilder();
            string       title            = string.Empty;
            GuildMembers members          = null;
            string       thumbUrl         = string.Empty;
            var          guildInfo        = Context.Guild;
            string       discordGuildName = string.Empty;

            if (guildInfo == null)
            {
                discordGuildName = Context.User.Username;
                thumbUrl         = Context.User.GetAvatarUrl();
            }
            else
            {
                discordGuildName = Context.Guild.Name;
                thumbUrl         = Context.Guild.IconUrl;
            }

            var guildObject = await _wowUtils.GetGuildName(Context);

            title              = $"Top Noggenfogger Consumers in **{guildObject.guildName}**";
            embed.Title        = title;
            embed.ThumbnailUrl = thumbUrl;

            if (guildObject.guildName != null || members != null)
            {
                try
                {
                    if (args == "clear")
                    {
                        List <CharStats> statsFromDb = new List <CharStats>();

                        using (var db = new NinjaBotEntities())
                        {
                            statsFromDb = db.CharStats.Where(c => c.GuildName == guildObject.guildName).ToList();
                        }
                        if (statsFromDb != null)
                        {
                            using (var db = new NinjaBotEntities())
                            {
                                var people = db.CharStats.Where(c => c.GuildName == guildObject.guildName).ToList();
                                foreach (var person in people)
                                {
                                    db.CharStats.Remove(person);
                                }
                                await db.SaveChangesAsync();
                            }
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(guildObject.locale))
                        {
                            members = _wowApi.GetGuildMembers(guildObject.realmName, guildObject.guildName, locale: guildObject.locale, regionName: guildObject.regionName);
                        }
                        else
                        {
                            members = _wowApi.GetGuildMembers(guildObject.realmName, guildObject.guildName, regionName: guildObject.regionName);
                        }

                        var maxLevelChars            = members.members.Where(m => m.character.level == 120);
                        List <CharStats> statsFromDb = new List <CharStats>();

                        using (var db = new NinjaBotEntities())
                        {
                            statsFromDb = db.CharStats.Where(c => c.GuildName == guildObject.guildName).ToList();
                        }

                        foreach (var member in maxLevelChars)
                        {
                            var curMemberStats = new WowStats();
                            var match          = statsFromDb.Where(s => s.CharName == member.character.name).FirstOrDefault();
                            var matchTime      = DateTime.Now;

                            if (match != null)
                            {
                                matchTime = match.LastModified;
                            }
                            if (match == null || matchTime.Day != DateTime.Now.Day)
                            {
                                curMemberStats = _wowApi.GetCharStats(member.character.name, member.character.realm.slug, guildObject.locale);
                                var elixer = curMemberStats.Statistics.SubCategories[0].SubCategories[0].Statistics.Where(s => s.Name == "Elixir consumed most").FirstOrDefault();
                                using (var db = new NinjaBotEntities())
                                {
                                    db.CharStats.Add(new CharStats {
                                        CharName       = member.character.name,
                                        RealmName      = member.character.realm.slug,
                                        GuildName      = guildObject.guildName,
                                        ElixerConsumed = elixer.Highest,
                                        Quantity       = elixer.Quantity,
                                        LastModified   = DateTime.Now
                                    });
                                    await db.SaveChangesAsync();
                                }
                            }
                            else
                            {
                            }
                        }
                        if (statsFromDb.Count() == 0)
                        {
                            using (var db = new NinjaBotEntities())
                            {
                                statsFromDb = db.CharStats.Where(c => c.GuildName == guildObject.guildName).ToList();
                            }
                        }
                        if (statsFromDb.Count() > 0)
                        {
                            var candidates = statsFromDb.OrderByDescending(o => o.Quantity).Take(10).ToList();
                            if (candidates != null && candidates.Count() > 0)
                            {
                                foreach (var canditate in candidates)
                                {
                                    sb.AppendLine($":black_medium_small_square: {canditate.CharName} -> *{canditate.Quantity}*");
                                }
                            }
                        }
                        embed.Description = sb.ToString();
                        await _cc.Reply(Context, embed);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Get-Guild Error getting guild info: [{ex.Message}]");
                }
            }
        }