예제 #1
0
        public async Task AddAsync(RiftPendingUser pendingUser)
        {
            await DB.Users.EnsureExistsAsync(pendingUser.UserId);

            await using var context = new RiftContext();
            await context.PendingUsers.AddAsync(pendingUser);

            await context.SaveChangesAsync();
        }
예제 #2
0
        public async Task RemoveAsync(ulong userId)
        {
            await using var context = new RiftContext();
            var pendingUser = new RiftPendingUser
            {
                UserId = userId
            };

            context.PendingUsers.Remove(pendingUser);
            await context.SaveChangesAsync();
        }
예제 #3
0
        static async Task <bool> AddForApprovalAsync(RiftPendingUser pendingUser)
        {
            if (await DB.PendingUsers.IsPendingAsync(pendingUser.UserId))
            {
                return(false);
            }

            await DB.PendingUsers.AddAsync(pendingUser);

            return(true);
        }
예제 #4
0
        async Task <IonicMessage> RegisterInternalAsync(ulong userId, string region, string summonerName)
        {
            if (await DB.LeagueData.HasAsync(userId))
            {
                return(await messageService.GetMessageAsync("register-hasAcc", new FormatData(userId)));
            }

            if (await DB.PendingUsers.IsPendingAsync(userId))
            {
                return(await messageService.GetMessageAsync("register-pending", new FormatData(userId)));
            }

            (var summonerResult, var summoner) = await GetSummonerByNameAsync(region.ToLowerInvariant(), summonerName);

            if (summonerResult != RequestResult.Success)
            {
                return(await messageService.GetMessageAsync("register-namenotfound", new FormatData(userId)));
            }

            if (await DB.LeagueData.IsTakenAsync(region, summoner.Id))
            {
                return(await messageService.GetMessageAsync("register-taken", new FormatData(userId)));
            }

            var code = Helper.GenerateConfirmationCode(16);

            var pendingUser = new RiftPendingUser
            {
                UserId           = userId,
                Region           = region.ToLowerInvariant(),
                PlayerUUID       = summoner.Puuid,
                AccountId        = summoner.AccountId,
                SummonedId       = summoner.Id,
                ConfirmationCode = code,
                ExpirationTime   = DateTime.UtcNow + Settings.Economy.PendingUserLifeTime
            };

            if (!await AddForApprovalAsync(pendingUser))
            {
                return(MessageService.Error);
            }

            return(await messageService.GetMessageAsync("register-code", new FormatData(userId)
            {
                LeagueRegistration = new LeagueRegistrationData
                {
                    ConfirmationCode = code
                }
            }));
        }
예제 #5
0
        async Task PostValidateAsync(RiftPendingUser pendingUser)
        {
            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, pendingUser.UserId, out var sgUser))
            {
                return;
            }

            await DB.PendingUsers.RemoveAsync(pendingUser.UserId);

            await AssignRoleFromRankAsync(sgUser, pendingUser);

            await DB.Inventory.AddAsync(sgUser.Id, new InventoryData { Chests = 2u });

            await messageService.SendMessageAsync("register-success", Settings.ChannelId.Commands, new FormatData(pendingUser.UserId));
        }
예제 #6
0
 public async Task RemoveAsync(RiftPendingUser pendingUser)
 {
     await RemoveAsync(pendingUser.UserId);
 }