Exemplo n.º 1
0
        public async Task <string> GetXivDB(string name, string world, bool api)
        {
            if (api == true)
            {
                var url    = new Uri($"https://api.xivdb.com/search?one=characters&string={name}&pretty=1");
                var client = HTTPHelpers.NewClient();

                string responseBody = await client.GetStringAsync(url);

                var xivdbCharacters = JsonConvert.DeserializeObject <CharacterSearch>(responseBody);

                var results = from charResult in xivdbCharacters.characters.results
                              where charResult.name.ToLower() == name.ToLower() && charResult.server == world
                              select charResult;

                string playerLink = "";

                if (results.Count() > 0)
                {
                    playerLink = results.First().url_api;
                }
                else
                {
                    return("!@invalid");
                }

                return(playerLink);
            }
            else
            {
                var url = new Uri($"https://api.xivdb.com/search?one=characters&string={name}&pretty=1");
                //https://api.xivdb.com/search?one=characters&string=knightin_Rustyarmour&pretty=1
                var client = HTTPHelpers.NewClient();

                //http://api.xivdb.com/character/6248857/knightin+rustyarmour/excalibur


                string responseBody = await client.GetStringAsync(url);

                var xivdbCharacters = JsonConvert.DeserializeObject <CharacterSearch>(responseBody);

                var results = from charResult in xivdbCharacters.characters.results
                              where charResult.name.ToLower() == name.ToLower() && charResult.server == world
                              select charResult;

                string playerLink = "";

                if (results.Count() > 0)
                {
                    playerLink = results.First().url_xivdb;
                }
                else
                {
                    return("!@invalid");
                }

                return(playerLink);
            }
        }
Exemplo n.º 2
0
        public async Task SendProfileDM(ulong Id)
        {
            Console.WriteLine($"type: {Context.Channel.GetType().Name}");
            var context = Context;

            Console.WriteLine($"does the players profile exist: {Player.DoesProfileExist(Id)}");
            if (!Player.DoesProfileExist(Id))
            {
                await Context.User.SendMessageAsync($"Profile for user <@{Id}> does not exist, please run the following command.\n!n assign `server` `character name`");

                throw new Exception("");
            }
            var player = Player.Load(Id);

            if (player.xivdbURL == "" || player.xivdbURL.Length == 0 || player.xivdbURL == null)
            {
                player.xivdbURL = GetXivDB(player.playerName, player.world, false).Result.ToString();
                if (player.xivdbURL == "!@invalid")
                {
                    //await SendProfileNoXIVDB(Id);
                    throw new Exception("Invalid XIVDB api url");
                }
            }

            if (player.xivdbURL_API == "" || player.xivdbURL_API.Length == 0 || player.xivdbURL_API == null)
            {
                player.xivdbURL_API = GetXivDB(player.playerName, player.world, true).Result.ToString();
                if (player.xivdbURL_API == "!@invalid")
                {
                    await ReplyAsync("Character API URL not found at XIVDB");

                    //await SendProfileNoXIVDB(Id);
                    throw new Exception("Invalid XIVDB api url");
                }
            }

            Console.WriteLine($"xivdb: {player.xivdbURL}\napi: {player.xivdbURL_API}");

            var client = HTTPHelpers.NewClient();

            string responseBody = await client.GetStringAsync(player.xivdbURL_API);

            var xivdbCharacter = JsonConvert.DeserializeObject <XivDB.XIVDBCharacter>(responseBody);

            var raidJobs = "";

            foreach (var job in player.jobs)
            {
                if (raidJobs.Contains(job.name) == false)
                {
                    raidJobs += $" - **{job.name}**\n" +
                                $"    •  Historical DPS: {job.historical_dps}\n" +
                                $"    •  Historic Best : {Math.Round(job.historical_percent, 1)}%\n";
                }
            }



            try {
                //foreach (var job in xivdbCharacter.data.classjobs.class_jobs) {
                //jobs += $"{job.name} - {job.level}";
                //}
            } catch {
                Console.WriteLine($"classjobs is null: {xivdbCharacter.data.classjobs.class_jobs == null}");
            }

            var clears = "";

            foreach (var clear in player.GetClearedFights(context))
            {
                if (!clear.ToLower().Contains("byakko"))
                {
                    clears += $" - {clear}\n";
                }
                else
                {
                    clears += $"\n{clear}\n";
                }
            }



            var reply = $"**Best DPS:** {player.bestDps}\n" +
                        $"**Avg Best %:** {Math.Round(player.bestPercent, 1)}%\n\n" +
                        $"__**Raid Jobs**__\n" +
                        $"{raidJobs}\n" +
                        $"__**Clears**__\n" +
                        $"{clears}\n" +
                        $""; //+
            //$"__**Jobs**__\n" +
            //$"{jobs}";
            //Console.WriteLine(reply);



            var embed = new EmbedBuilder()
                        .WithTitle($"{xivdbCharacter.name} - {xivdbCharacter.data.title}")
                        .WithUrl(player.xivdbURL)
                        .WithThumbnailUrl(xivdbCharacter.avatar)
                        .WithImageUrl(xivdbCharacter.portrait)
                        .WithFooter(new EmbedFooterBuilder()
                                    .WithText($"{player.dc} - {player.world} | {xivdbCharacter.data.race}"))
                        .WithColor(new Color(102, 255, 222))
                        .WithDescription(reply)
                        .Build();


            await Context.User.SendMessageAsync("", embed : embed);
        }
Exemplo n.º 3
0
        public async Task ViewNonProfile(string server, [Remainder] string name)
        {
            var player = await GetParseNoID(server, name);

            if (player == null)
            {
                Console.WriteLine("Player not found");
                await ReplyAsync("Sorry, the player you're looking for does not exist or has changed his name or is not on the specified server or datacenter.");
            }

            if (player.xivdbURL == "" || player.xivdbURL.Length == 0 || player.xivdbURL == null)
            {
                player.xivdbURL = GetXivDB(player.playerName, player.world, false).Result.ToString();
                if (player.xivdbURL == "!@invalid")
                {
                    await SendProfileNoXIVDB(0);

                    return;
                }
            }

            if (player.xivdbURL_API == "" || player.xivdbURL_API.Length == 0 || player.xivdbURL_API == null)
            {
                player.xivdbURL_API = GetXivDB(player.playerName, player.world, true).Result.ToString();
                if (player.xivdbURL_API == "!@invalid")
                {
                    await Context.User.SendMessageAsync("Character API URL not found at XIVDB");
                    await SendProfileNoXIVDB(0);

                    return;
                }
            }

            Console.WriteLine($"xivdb: {player.xivdbURL}\napi: {player.xivdbURL_API}");
            player.GetClearedFights();
            var client = HTTPHelpers.NewClient();

            string responseBody = await client.GetStringAsync(player.xivdbURL_API);

            var xivdbCharacter = JsonConvert.DeserializeObject <XivDB.XIVDBCharacter>(responseBody);

            var raidJobs = "";

            foreach (var job in player.jobs)
            {
                if (raidJobs.Contains(job.name) == false)
                {
                    raidJobs += $" - **{job.name}**\n" +
                                $"    •  Historical DPS: {job.historical_dps}\n" +
                                $"    •  Historic Best : {Math.Round(job.historical_percent, 1)}%\n";
                }
            }



            try {
                //foreach (var job in xivdbCharacter.data.classjobs.class_jobs) {
                //jobs += $"{job.name} - {job.level}";
                //}
            } catch {
                Console.WriteLine($"classjobs is null: {xivdbCharacter.data.classjobs.class_jobs == null}");
            }

            var clears = "";

            foreach (var clear in player.GetClearedFights(Context))
            {
                //if(clear.ToLower().Contains("byakko")){
                clears += $" - {clear}\n";
                //}
            }



            var reply = $"**Best DPS:** {player.bestDps}\n" +
                        $"**Avg Best %:** {Math.Round(player.bestPercent, 1)}%\n\n" +
                        $"__**Raid Jobs**__\n" +
                        $"{raidJobs}\n" +
                        $"__**Clears**__\n" +
                        $"{clears}\n" +
                        $""; //+
            //$"__**Jobs**__\n" +
            //$"{jobs}";
            //Console.WriteLine(reply);


            var embed = new EmbedBuilder()
                        .WithTitle($"{xivdbCharacter.name} - {xivdbCharacter.data.title}")
                        .WithUrl(player.xivdbURL)
                        .WithThumbnailUrl(xivdbCharacter.avatar)
                        .WithImageUrl(xivdbCharacter.portrait)
                        .WithFooter(new EmbedFooterBuilder()
                                    .WithText($"{player.dc} - {player.world} | {xivdbCharacter.data.race}"))
                        .WithColor(new Color(102, 255, 222))
                        .WithDescription(reply)
                        .Build();


            if (Context.Channel.GetType().Name == "SocketDMChannel")
            {
                await Context.User.SendMessageAsync("", embed : embed);
            }
            else
            {
                await ReplyAsync("", embed : embed);
            }
        }
Exemplo n.º 4
0
        public async Task <Player> GetParseNoID(string server, [Remainder] string name)
        {
            Console.WriteLine("\n ");
            var roles       = GetRoles();
            var jobslist    = new List <Nero.job>();
            var worlds      = Nero.Worlds.GetWorlds();
            var worldResult = from wrld in worlds
                              where wrld.Name.ToLower().Contains(server.ToLower())
                              select wrld;
            var        world       = worldResult.First();
            var        url         = new Uri($"https://www.fflogs.com/v1/parses/character/{name}/{world.Name}/{world.Region}/?api_key={Configuration.Load().FFLogsKey}");
            var        trialUrl    = new Uri($"https://www.fflogs.com/v1/parses/character/{name}/{world.Name}/{world.Region}/?api_key=7bd977bcb89a89934dc26a137b6d2b24&zone=15&zone=15");
            var        ultimateUrl = new Uri($"https://www.fflogs.com/v1/parses/character/{name}/{world.Name}/{world.Region}/?api_key=7bd977bcb89a89934dc26a137b6d2b24&zone=15&zone=19");
            HttpClient client      = HTTPHelpers.NewClient();

            var player = new Player(0, name, world.DC, world.Name);

            try
            {
                Console.WriteLine($"FFlogs URl: {url}");
                string responseBody = await client.GetStringAsync(url);

                string trialResponseBody = await client.GetStringAsync(trialUrl);

                string ultimateResponseBody = await client.GetStringAsync(ultimateUrl);

                var parses         = JsonConvert.DeserializeObject <List <Nero.Parses> >(responseBody);
                var trialParses    = JsonConvert.DeserializeObject <List <Nero.Parses> >(trialResponseBody);
                var ultimateParses = JsonConvert.DeserializeObject <List <Nero.Parses> >(ultimateResponseBody);
                parses.AddRange(trialParses);
                parses.AddRange(ultimateParses);


                // instantiate best% and bestdps
                double bestPercent = 0.0;
                double bestDps     = 0.0;

                foreach (var parse in parses)
                {
                    bool cleared    = false;
                    int  specAmount = 0;
                    if (parse.kill > 0)
                    {
                        cleared = true;
                    }
                    List <job> specs = new List <job>();

                    foreach (var spec in parse.specs)
                    {
                        if (parse.name != "Kefka")
                        {
                            Console.WriteLine($"parse fight: {parse.name}, spec name: {spec.spec}, spec hist %: {spec.best_historical_percent}, spec dps: {spec.best_persecondamount}");
                            specs.Add(new job(spec.spec, spec.best_historical_percent, spec.best_persecondamount));
                            if (spec.best_persecondamount >= bestDps)
                            {
                                bestDps = spec.best_persecondamount;
                            }

                            if (spec.best_historical_percent >= bestPercent)
                            {
                                bestPercent = spec.best_historical_percent;
                            }



                            specAmount++;
                        }
                    }
                    player.AddFight(cleared, parse.kill, specAmount, specs, parse.name, bestDps, bestPercent);
                    bestPercent = 0.0;
                    bestDps     = 0.0;
                }

                //ulong ffxivrecruiterID = 142476055482073089;
                //ulong testhouseID = 286211518691934210;

                //if (Context.Guild.Id == ffxivrecruiterID || Context.Guild.Id == testhouseID) {
                //await AssignRolesAsync(roles, user, player);
                //}

                return(player);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException caught");
                Console.WriteLine($"Message: {e.Message}");
            }
            client.Dispose();
            return(null);
        }