public async Task SetRegionCommand(CommandContext ctx, string region, [RemainingText] string account)
        {
            Region reg;

            var parsed = Enum.TryParse(region, true, out reg);

            if (parsed == false)
            {
                await ctx.Channel.SendMessageAsync($"Could not parse region. Possible values: {string.Join(", ", Enum.GetNames(typeof(Region)))}");

                return;
            }
            using (var db = new DatabaseDbContext())
            {
                var acc = db.ValorantAccount.FirstOrDefault(acc => acc.DisplayName == account);
                if (acc == null)
                {
                    await ctx.Channel.SendMessageAsync("Cannot find specified account");

                    return;
                }

                acc.Region = reg;
                db.Update(acc);
                await db.SaveChangesAsync();

                await ctx.Channel.SendMessageAsync("Region updated");
            }
        }
Пример #2
0
 public async Task AddLastAccountMatch(ValorantAccount account, List <RankInfo> history)
 {
     using (var db = new DatabaseDbContext())
     {
         foreach (var rankInfo in history)
         {
             if (account.RankInfos.Any(info => info.DateTime == rankInfo.DateTime) == false)
             {
                 account.RankInfos.Add(rankInfo);
             }
         }
         db.Update(account);
         await db.SaveChangesAsync();
     }
 }
Пример #3
0
        public async Task <bool> LinkAccountToDiscordUser(ValorantAccount accountToAdd, DiscordUser user)
        {
            bool result = true;

            using (var db = new DatabaseDbContext())
            {
                var dbUser = db.DiscordUsers.Include(u => u.ValorantAccounts).SingleOrDefault(u => u.ID == user.Id);
                if (dbUser == null)
                {
                    dbUser = new DbDiscordUser()
                    {
                        ID   = user.Id,
                        Name = user.Username
                    };
                    await db.DiscordUsers.AddAsync(dbUser);

                    await db.SaveChangesAsync();
                }

                var valorantAccount = dbUser.ValorantAccounts.FirstOrDefault(a => a.Subject == accountToAdd.Subject);
                if (valorantAccount == null)
                {
                    dbUser.ValorantAccounts.Add(accountToAdd);
                    db.Update(dbUser);
                }
                else
                {
                    accountToAdd.ID = valorantAccount.ID;
                    result          = false;
                    db.Update(accountToAdd);
                }

                await db.SaveChangesAsync();
            }
            return(result);
        }
Пример #4
0
        public async Task RankCommand(CommandContext ctx, DiscordUser discordUser = null)
        {
            LogCommandExecuted(ctx);
            discordUser ??= ctx.User;

            using (var db = new DatabaseDbContext())
            {
                var user = await db.DiscordUsers.Include(user => user.ValorantAccounts)
                           .FirstOrDefaultAsync(user => user.ID == discordUser.Id);

                if (user == null || user.ValorantAccounts.Count == 0)
                {
                    await ctx.Channel.SendMessageAsync("You have no connected accounts");

                    Logger.LogInformation($"User {discordUser.Username} has no ValorantAccounts connected");
                    return;
                }

                var embed = new DiscordEmbedBuilder().WithTitle($"List of {user.Name} accounts");
                foreach (var valorantAccount in user.ValorantAccounts.OrderByDescending(val => val.Rank)
                         .ThenByDescending(val => val.RankProgress))
                {
                    var playerRank = await ValorantApiService.GetPlayerRank(valorantAccount.Region.ToString(), valorantAccount.Subject);

                    valorantAccount.UpdateRank(playerRank);

                    var playerIDs = await ValorantApiService.GetPlayerIds(valorantAccount.Region.ToString(), valorantAccount.Subject);

                    if (playerIDs != null)
                    {
                        valorantAccount.DisplayName = $"{playerIDs.Name}#{playerIDs.Tag}";
                    }

                    var guildEmote = ctx.Guild.Emojis.FirstOrDefault(emote =>
                                                                     emote.Value.Name == valorantAccount.RankName.Replace(" ", ""));
                    embed.AddField("Name", valorantAccount.DisplayName, true);
                    embed.AddField("Rank", $"{guildEmote.Value}{valorantAccount.RankName}", true); //todo: add emoji
                    embed.AddField("Progress", $"{valorantAccount.RankProgress} / 100", true);


                    db.Update(valorantAccount);
                }

                await ctx.Channel.SendMessageAsync(embed : embed.Build());

                await db.SaveChangesAsync();
            }
        }
Пример #5
0
 public async Task AsignAccountToGuild(ValorantAccount accountToAssign, ulong guildId)
 {
     using (var db = new DatabaseDbContext())
     {
         var guild = accountToAssign.RegisteredGuilds.FirstOrDefault(g => g.GuildID == guildId);
         if (guild == null)
         {
             accountToAssign.RegisteredGuilds.Add(new RegisteredGuild()
             {
                 GuildID         = guildId,
                 ValorantAccount = accountToAssign
             });
             db.Update(accountToAssign);
             await db.SaveChangesAsync();
         }
     }
 }
Пример #6
0
        public async Task RankCommand(CommandContext ctx, [RemainingText] string account)
        {
            LogCommandExecuted(ctx);

            using (var db = new DatabaseDbContext())
            {
                var acc = db.ValorantAccount.FirstOrDefault(acc => acc.DisplayName == account);

                if (acc == null)
                {
                    await ctx.Channel.SendMessageAsync($"Cannot find account {account}");

                    Logger.LogInformation($"Account {account} not found");
                    return;
                }

                var embed = new DiscordEmbedBuilder().WithTitle($"Rank of {account}");

                var playerRank = await ValorantApiService.GetPlayerRank(acc.Region.ToString(), acc.Subject);

                acc.UpdateRank(playerRank);

                var playerIDs = await ValorantApiService.GetPlayerIds(acc.Region.ToString(), acc.Subject);

                if (playerIDs != null)
                {
                    acc.DisplayName = $"{playerIDs.Name}#{playerIDs.Tag}";
                }

                var guildEmote = ctx.Guild.Emojis.FirstOrDefault(emote =>
                                                                 emote.Value.Name == acc.RankName.Replace(" ", ""));
                embed.AddField("Name", acc.DisplayName, true);
                embed.AddField("Rank", $"{guildEmote.Value}{acc.RankName}", true); //todo: add emoji
                embed.AddField("Progress", $"{acc.RankProgress} / 100", true);


                db.Update(acc);

                await ctx.Channel.SendMessageAsync(embed : embed.Build());

                await db.SaveChangesAsync();
            }
        }
Пример #7
0
        public string UpdateDoctors(DoctorRequest request)
        {
            var update_doctor = new Doctor
            {
                Id        = request.IdDoctor,
                FirstName = request.FirstName,
                LastName  = request.LastName,
                Email     = request.Email
            };

            _context.Update(update_doctor);
            try
            {
                _context.Entry(update_doctor).State = EntityState.Modified;
                _context.SaveChanges();
            }
            catch (Exception)
            {
                return(null);
            }
            return("A doctor has been successfully updated");
        }
        private async Task Update()
        {
            using (var db = new DatabaseDbContext())
            {
                var accounts = db.ValorantAccount.Include(acc => acc.DbDiscordUser)
                               .Include(acc => acc.RegisteredGuilds).Include(acc => acc.RankInfos).ToList();

                var valorantAccount = accounts[_currentAccount];
                Logger.LogInformation($"Running RankChecker on player {valorantAccount.DisplayName}");

                _currentAccount++;
                if (_currentAccount >= accounts.Count)
                {
                    _currentAccount = 0;
                }

                var playerRank = await _valorantApiService.GetPlayerRank(valorantAccount.Region.ToString(), valorantAccount.Subject);

                if (playerRank == null)
                {
                    Logger.LogError("Could not update playerRank");
                    return;
                }

                foreach (var valorantAccountRegisteredGuild in valorantAccount.RegisteredGuilds)
                {
                    var guildConfig = db.GuildConfigs.FirstOrDefault(guild =>
                                                                     guild.Guild == valorantAccountRegisteredGuild.GuildID && guild.UpdatesChannel != null);
                    if (guildConfig != null)
                    {
                        var channel = await _botService.DiscordClient.GetChannelAsync(guildConfig.UpdatesChannel.Value);

                        if (channel != null)
                        {
                            if (playerRank.RankInt < valorantAccount.Rank)
                            {
                                await channel.SendMessageAsync(
                                    $"Account {valorantAccount.DisplayName} has been downgraded to {playerRank.RankString} . Current progress: {playerRank.Progress} / 100");
                            }

                            if (playerRank.RankInt > valorantAccount.Rank)
                            {
                                await channel.SendMessageAsync(
                                    $"Account {valorantAccount.DisplayName} has been promoted to {playerRank.RankString} ! Current progress: {playerRank.Progress} / 100");
                            }

                            if (playerRank.LastMatch != null)
                            {
                                var dt = DateTimeOffset.FromUnixTimeMilliseconds(playerRank.LastMatch.MatchStartTime)
                                         .DateTime;
                                var info = new RankInfo
                                {
                                    DateTime        = dt,
                                    Progress        = (int)playerRank.LastMatch.RankedRatingAfterUpdate,
                                    RankInt         = (int)playerRank.LastMatch.TierAfterUpdate,
                                    ValorantAccount = valorantAccount
                                };

                                if (info.Progress != 0 || info.RankInt != 0)
                                {
                                    if (valorantAccount.RankInfos.Any(rankInfo => rankInfo.DateTime == info.DateTime) ==
                                        false)
                                    {
                                        valorantAccount.RankInfos.Add(info);
                                    }
                                    db.Update(valorantAccount);
                                    await db.SaveChangesAsync();
                                }
                            }
                            else
                            {
                            }


                            var playerRankChanged = playerRank.RankInt != valorantAccount.Rank;
                            if (playerRankChanged)
                            {
                                valorantAccount.UpdateRank(playerRank);
                                db.Update(valorantAccount);
                                await db.SaveChangesAsync();
                            }
                        }
                    }
                }
            }
        }