Added better error messages to .clubapply

This commit is contained in:
Kwoth
2022-10-09 16:24:52 +02:00
parent 8effe817ad
commit c896a0cdb8
4 changed files with 34 additions and 14 deletions

View File

@@ -231,10 +231,16 @@ public partial class Xp
return;
}
if (_service.ApplyToClub(ctx.User, club))
var result = _service.ApplyToClub(ctx.User, club);
if (result == ClubApplyResult.Success)
await ReplyConfirmLocalizedAsync(strs.club_applied(Format.Bold(club.ToString())));
else
await ReplyErrorLocalizedAsync(strs.club_apply_error);
else if (result == ClubApplyResult.Banned)
await ReplyErrorLocalizedAsync(strs.club_join_banned);
else if (result == ClubApplyResult.InsufficientLevel)
await ReplyErrorLocalizedAsync(strs.club_insuff_lvl);
else if (result == ClubApplyResult.AlreadyInAClub)
await ReplyErrorLocalizedAsync(strs.club_already_in);
}
[Cmd]

View File

@@ -118,18 +118,22 @@ public class ClubService : INService, IClubService
return club is not null;
}
public bool ApplyToClub(IUser user, ClubInfo club)
public ClubApplyResult ApplyToClub(IUser user, ClubInfo club)
{
using var uow = _db.GetDbContext();
var du = uow.GetOrCreateUser(user);
uow.SaveChanges();
if (du.Club is not null
|| club.Bans.Any(x => x.UserId == du.Id)
|| club.Applicants.Any(x => x.UserId == du.Id))
//user banned or a member of a club, or already applied,
// or doesn't min minumum level requirement, can't apply
return false;
//user banned or a member of a club, or already applied,
// or doesn't min minumum level requirement, can't apply
if (du.Club is not null)
return ClubApplyResult.AlreadyInAClub;
if (club.Bans.Any(x => x.UserId == du.Id))
return ClubApplyResult.Banned;
if (club.Applicants.Any(x => x.UserId == du.Id))
return ClubApplyResult.InsufficientLevel;
var app = new ClubApplicants
{
@@ -138,9 +142,8 @@ public class ClubService : INService, IClubService
};
uow.Set<ClubApplicants>().Add(app);
uow.SaveChanges();
return true;
return ClubApplyResult.Success;
}
public bool AcceptApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser)

View File

@@ -10,7 +10,7 @@ public interface IClubService
ClubInfo? GetClubByMember(IUser user);
Task<bool> SetClubIconAsync(ulong ownerUserId, string? url);
bool GetClubByName(string clubName, out ClubInfo club);
bool ApplyToClub(IUser user, ClubInfo club);
ClubApplyResult ApplyToClub(IUser user, ClubInfo club);
bool AcceptApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser);
ClubInfo? GetClubWithBansAndApplications(ulong ownerUserId);
bool LeaveClub(IUser user);
@@ -20,4 +20,13 @@ public interface IClubService
bool UnBan(ulong ownerUserId, string userName, out ClubInfo club);
bool Kick(ulong kickerId, string userName, out ClubInfo club);
List<ClubInfo> GetClubLeaderboardPage(int page);
}
public enum ClubApplyResult
{
Success,
AlreadyInAClub,
Banned,
InsufficientLevel
}