Updated Xp module
This commit is contained in:
parent
b2b8e4c3d3
commit
624171c35f
3 changed files with 53 additions and 37 deletions
|
@ -123,6 +123,8 @@ public partial class Xp
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
var rank = await _service.GetClubRankAsync(club.Id);
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
.Items(allUsers)
|
.Items(allUsers)
|
||||||
|
@ -135,6 +137,7 @@ public partial class Xp
|
||||||
.WithDescription(GetText(strs.level_x(lvl.Level + $" ({club.Xp} xp)")))
|
.WithDescription(GetText(strs.level_x(lvl.Level + $" ({club.Xp} xp)")))
|
||||||
.AddField(GetText(strs.desc),
|
.AddField(GetText(strs.desc),
|
||||||
string.IsNullOrWhiteSpace(club.Description) ? "-" : club.Description)
|
string.IsNullOrWhiteSpace(club.Description) ? "-" : club.Description)
|
||||||
|
.AddField(GetText(strs.rank), $"#{rank}", true)
|
||||||
.AddField(GetText(strs.owner), club.Owner.ToString(), true)
|
.AddField(GetText(strs.owner), club.Owner.ToString(), true)
|
||||||
// .AddField(GetText(strs.level_req), club.MinimumLevelReq.ToString(), true)
|
// .AddField(GetText(strs.level_req), club.MinimumLevelReq.ToString(), true)
|
||||||
.AddField(GetText(strs.members),
|
.AddField(GetText(strs.members),
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ClubService : IEService, IClubService
|
||||||
if (club is null)
|
if (club is null)
|
||||||
return ToggleAdminResult.NotOwner;
|
return ToggleAdminResult.NotOwner;
|
||||||
|
|
||||||
if(!club.Members.Contains(adminUser))
|
if (!club.Members.Contains(adminUser))
|
||||||
return ToggleAdminResult.TargetNotMember;
|
return ToggleAdminResult.TargetNotMember;
|
||||||
|
|
||||||
var newState = adminUser.IsClubAdmin = !adminUser.IsClubAdmin;
|
var newState = adminUser.IsClubAdmin = !adminUser.IsClubAdmin;
|
||||||
|
@ -134,6 +134,18 @@ public class ClubService : IEService, IClubService
|
||||||
return club is not null;
|
return club is not null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> GetClubRankAsync(int clubId)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
|
var rank = await uow.Clubs
|
||||||
|
.ToLinqToDBTable()
|
||||||
|
.Where(x => x.Xp > (uow.Clubs.First(c => c.Id == clubId).Xp))
|
||||||
|
.CountAsyncLinqToDB();
|
||||||
|
|
||||||
|
return rank + 1;
|
||||||
|
}
|
||||||
|
|
||||||
public ClubApplyResult ApplyToClub(IUser user, ClubInfo club)
|
public ClubApplyResult ApplyToClub(IUser user, ClubInfo club)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
using var uow = _db.GetDbContext();
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace EllieBot.Modules.Xp.Services;
|
||||||
public interface IClubService
|
public interface IClubService
|
||||||
{
|
{
|
||||||
Task<ClubCreateResult> CreateClubAsync(IUser user, string clubName);
|
Task<ClubCreateResult> CreateClubAsync(IUser user, string clubName);
|
||||||
OneOf<ClubInfo,ClubTransferError> TransferClub(IUser from, IUser newOwner);
|
OneOf<ClubInfo, ClubTransferError> TransferClub(IUser from, IUser newOwner);
|
||||||
Task<ToggleAdminResult> ToggleAdminAsync(IUser owner, IUser toAdmin);
|
Task<ToggleAdminResult> ToggleAdminAsync(IUser owner, IUser toAdmin);
|
||||||
ClubInfo? GetClubByMember(IUser user);
|
ClubInfo? GetClubByMember(IUser user);
|
||||||
Task<SetClubIconResult> SetClubIconAsync(ulong ownerUserId, string? url);
|
Task<SetClubIconResult> SetClubIconAsync(ulong ownerUserId, string? url);
|
||||||
|
@ -23,6 +23,7 @@ public interface IClubService
|
||||||
ClubKickResult Kick(ulong kickerId, string userName, out ClubInfo club);
|
ClubKickResult Kick(ulong kickerId, string userName, out ClubInfo club);
|
||||||
List<ClubInfo> GetClubLeaderboardPage(int page);
|
List<ClubInfo> GetClubLeaderboardPage(int page);
|
||||||
Task<ClubRenameResult> RenameClubAsync(ulong userId, string clubName);
|
Task<ClubRenameResult> RenameClubAsync(ulong userId, string clubName);
|
||||||
|
Task<int> GetClubRankAsync(int clubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ClubApplyResult
|
public enum ClubApplyResult
|
||||||
|
|
Loading…
Reference in a new issue