Пример #1
0
        public async Task <Option <List <Marriage> > > GetAllMarriagesOfUser(ulong userId)
        => await _soraTransactor.DoAsync(async context =>
        {
            var marriages = await context.Marriages.Where(x => x.Partner1Id == userId || x.Partner2Id == userId)
                            .ToListAsync().ConfigureAwait(false);

            if (marriages.Count == 0)
            {
                return(Option.None <List <Marriage> >());
            }

            return(marriages);
        }).ConfigureAwait(false);
Пример #2
0
        public async Task <Option <List <Reminder> > > GetUserReminders(ulong userId)
        => await _soraTransactor.DoAsync(async context =>
        {
            var rems = await context.Reminders
                       .Where(x => x.UserId == userId)
                       .ToListAsync()
                       .ConfigureAwait(false);

            if (rems == null || rems.Count == 0)
            {
                return(Option.None <List <Reminder> >());
            }

            return(rems);
        }).ConfigureAwait(false);
Пример #3
0
        public async Task <Option <List <WaifuRequest> > > GetUserWaifuRequests(ulong userId)
        => await _soraTransactor.DoAsync <Option <List <WaifuRequest> > >(async context =>
        {
            var requests = await context.WaifuRequests
                           .Where(x => x.UserId == userId)
                           .ToListAsync()
                           .ConfigureAwait(false);

            if (requests.Count == 0)
            {
                return(Option.None <List <WaifuRequest> >());
            }

            return(requests);
        }).ConfigureAwait(false);
Пример #4
0
        public async Task <Option <Afk> > GetUserAfk(ulong userId)
        => await _soraTransactor.DoAsync(async context =>
        {
            var afk = await context.Afks.FindAsync(userId).ConfigureAwait(false);
            if (afk == null)
            {
                return(Option.None <Afk>());
            }

            return(afk);
        }).ConfigureAwait(false);
Пример #5
0
        public async Task <Option <ProfileImageGenDto> > GetProfileStatistics(ulong userId, ulong guildId)
        {
            return(await _soraTransactor.DoAsync <Option <ProfileImageGenDto> >(async context =>
            {
                var user = await context.Users.FindAsync(userId).ConfigureAwait(false);
                if (user == null)
                {
                    return Option.None <ProfileImageGenDto>();
                }

                var globalRank = await context.Users
                                 .Where(u => u.Exp > user.Exp)
                                 .CountAsync()
                                 .ConfigureAwait(false);

                var guildUser = await context.GuildUsers
                                .FirstOrDefaultAsync(x => x.UserId == userId && x.GuildId == guildId)
                                .ConfigureAwait(false) ?? new GuildUser(0, 0, 0); // Just so we have default values to work with

                var localRank = await context.GuildUsers
                                .CountAsync(g => g.GuildId == guildId && g.Exp > guildUser.Exp)
                                .ConfigureAwait(false);

                var clan = await context.ClanMembers
                           .Where(x => x.UserId == userId)
                           .Select(x => x.Clan)
                           .FirstOrDefaultAsync();

                _log.LogInformation($"Clan was {clan?.Name}");

                return new ProfileImageGenDto()
                {
                    GlobalExp = user.Exp,
                    GlobalRank = globalRank + 1,
                    HasCustomBg = user.HasCustomProfileBg,
                    LocalExp = guildUser.Exp,
                    LocalRank = localRank + 1,
                    ClanName = clan?.Name
                };
            }).ConfigureAwait(false));
        }
Пример #6
0
 public async Task <Option <Clan> > GetClanById(int clanId)
 {
     return(await _soraTransactor.DoAsync(async context =>
     {
         var clan = await context.Clans.FindAsync(clanId).ConfigureAwait(false);
         return clan ?? Option.None <Clan>();
     }));
 }
Пример #7
0
 public async Task <Option <StarboardMessage> > GetStarboardMessage(ulong messageId)
 => await _soraTransactor.DoAsync(async context =>
 {
     var msg = await context.StarboardMessages.FindAsync(messageId).ConfigureAwait(false);
     return(msg == null ? Option.None <StarboardMessage>() : msg);
 }).ConfigureAwait(false);
Пример #8
0
 public async Task <string> GetGuildPrefix(ulong id)
 => await _soraTransactor.DoAsync(async context =>
                                  await context.Guilds.Where(g => g.Id == id).Select(x => x.Prefix).FirstOrDefaultAsync()
                                  ).ConfigureAwait(false);
Пример #9
0
 public async Task <bool> CheckIfRoleAlreadyExists(ulong roleId)
 => await _soraTransactor.DoAsync(async context =>
                                  await context.Sars.CountAsync(x => x.RoleId == roleId) == 1
                                  ).ConfigureAwait(false);
Пример #10
0
 public async Task <List <Waifu> > GetAllWaifus()
 => await _soraTransactor
 .DoAsync(async context => await context.Waifus.ToListAsync().ConfigureAwait(false))
 .ConfigureAwait(false);