mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 08:34:27 -05:00 
			
		
		
		
	.clubinfo performance improvement and fixed an issue with cyrillic clubs not showing up at all even with correct capitalization
This commit is contained in:
		@@ -26,10 +26,17 @@ public static class ClubExtensions
 | 
			
		||||
        => Include(clubs).FirstOrDefault(c => c.Users.Any(u => u.UserId == userId));
 | 
			
		||||
 | 
			
		||||
    public static ClubInfo GetByName(this DbSet<ClubInfo> clubs, string name, int discrim)
 | 
			
		||||
        => Include(clubs).FirstOrDefault(c => c.Name.ToUpper() == name.ToUpper() && c.Discrim == discrim);
 | 
			
		||||
        => Include(clubs)
 | 
			
		||||
            .FirstOrDefault(c => EF.Functions.Collate(c.Name, "NOCASE") == EF.Functions.Collate(name, "NOCASE")
 | 
			
		||||
                                 && c.Discrim == discrim);
 | 
			
		||||
 | 
			
		||||
    public static int GetNextDiscrim(this DbSet<ClubInfo> clubs, string name)
 | 
			
		||||
        => Include(clubs).Where(x => x.Name.ToUpper() == name.ToUpper()).Select(x => x.Discrim).DefaultIfEmpty().Max()
 | 
			
		||||
        => Include(clubs)
 | 
			
		||||
           .Where(x =>
 | 
			
		||||
               EF.Functions.Collate(x.Name, "NOCASE") == EF.Functions.Collate(name, "NOCASE"))
 | 
			
		||||
           .Select(x => x.Discrim)
 | 
			
		||||
           .DefaultIfEmpty()
 | 
			
		||||
           .Max()
 | 
			
		||||
           + 1;
 | 
			
		||||
 | 
			
		||||
    public static List<ClubInfo> GetClubLeaderboardPage(this DbSet<ClubInfo> clubs, int page)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
#nullable disable
 | 
			
		||||
using NadekoBot.Db.Models;
 | 
			
		||||
using NadekoBot.Modules.Xp.Services;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Xp;
 | 
			
		||||
@@ -76,37 +77,8 @@ public partial class Xp
 | 
			
		||||
            await ReplyConfirmLocalizedAsync(strs.club_icon_set);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [Priority(1)]
 | 
			
		||||
        public async partial Task ClubInformation(IUser user = null)
 | 
			
		||||
        private async Task InternalClubInfoAsync(ClubInfo club)
 | 
			
		||||
        {
 | 
			
		||||
            user ??= ctx.User;
 | 
			
		||||
            var club = _service.GetClubByMember(user);
 | 
			
		||||
            if (club is null)
 | 
			
		||||
            {
 | 
			
		||||
                await ErrorLocalizedAsync(strs.club_user_not_in_club(Format.Bold(user.ToString())));
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            await ClubInformation(club.ToString());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [Priority(0)]
 | 
			
		||||
        public async partial Task ClubInformation([Leftover] string clubName = null)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(clubName))
 | 
			
		||||
            {
 | 
			
		||||
                await ClubInformation(ctx.User);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!_service.GetClubByName(clubName, out var club))
 | 
			
		||||
            {
 | 
			
		||||
                await ReplyErrorLocalizedAsync(strs.club_not_exists);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var lvl = new LevelStats(club.Xp);
 | 
			
		||||
            var users = club.Users.OrderByDescending(x =>
 | 
			
		||||
            {
 | 
			
		||||
@@ -153,6 +125,40 @@ public partial class Xp
 | 
			
		||||
                10);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [Priority(1)]
 | 
			
		||||
        public async partial Task ClubInformation(IUser user = null)
 | 
			
		||||
        {
 | 
			
		||||
            user ??= ctx.User;
 | 
			
		||||
            var club = _service.GetClubByMember(user);
 | 
			
		||||
            if (club is null)
 | 
			
		||||
            {
 | 
			
		||||
                await ErrorLocalizedAsync(strs.club_user_not_in_club(Format.Bold(user.ToString())));
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            await InternalClubInfoAsync(club);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [Priority(0)]
 | 
			
		||||
        public async partial Task ClubInformation([Leftover] string clubName = null)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(clubName))
 | 
			
		||||
            {
 | 
			
		||||
                await ClubInformation(ctx.User);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!_service.GetClubByName(clubName, out var club))
 | 
			
		||||
            {
 | 
			
		||||
                await ReplyErrorLocalizedAsync(strs.club_not_exists);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            await InternalClubInfoAsync(club);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        public partial Task ClubBans(int page = 1)
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user