mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Added better error messages to .clubapply
This commit is contained in:
@@ -231,10 +231,16 @@ public partial class Xp
|
|||||||
return;
|
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())));
|
await ReplyConfirmLocalizedAsync(strs.club_applied(Format.Bold(club.ToString())));
|
||||||
else
|
else if (result == ClubApplyResult.Banned)
|
||||||
await ReplyErrorLocalizedAsync(strs.club_apply_error);
|
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]
|
[Cmd]
|
||||||
|
@@ -118,18 +118,22 @@ public class ClubService : INService, IClubService
|
|||||||
return club is not null;
|
return club is not null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ApplyToClub(IUser user, ClubInfo club)
|
public ClubApplyResult ApplyToClub(IUser user, ClubInfo club)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
using var uow = _db.GetDbContext();
|
||||||
var du = uow.GetOrCreateUser(user);
|
var du = uow.GetOrCreateUser(user);
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
|
|
||||||
if (du.Club is not null
|
//user banned or a member of a club, or already applied,
|
||||||
|| club.Bans.Any(x => x.UserId == du.Id)
|
// or doesn't min minumum level requirement, can't apply
|
||||||
|| club.Applicants.Any(x => x.UserId == du.Id))
|
if (du.Club is not null)
|
||||||
//user banned or a member of a club, or already applied,
|
return ClubApplyResult.AlreadyInAClub;
|
||||||
// or doesn't min minumum level requirement, can't apply
|
|
||||||
return false;
|
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
|
var app = new ClubApplicants
|
||||||
{
|
{
|
||||||
@@ -138,9 +142,8 @@ public class ClubService : INService, IClubService
|
|||||||
};
|
};
|
||||||
|
|
||||||
uow.Set<ClubApplicants>().Add(app);
|
uow.Set<ClubApplicants>().Add(app);
|
||||||
|
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
return true;
|
return ClubApplyResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AcceptApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser)
|
public bool AcceptApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser)
|
||||||
|
@@ -10,7 +10,7 @@ public interface IClubService
|
|||||||
ClubInfo? GetClubByMember(IUser user);
|
ClubInfo? GetClubByMember(IUser user);
|
||||||
Task<bool> SetClubIconAsync(ulong ownerUserId, string? url);
|
Task<bool> SetClubIconAsync(ulong ownerUserId, string? url);
|
||||||
bool GetClubByName(string clubName, out ClubInfo club);
|
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);
|
bool AcceptApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser);
|
||||||
ClubInfo? GetClubWithBansAndApplications(ulong ownerUserId);
|
ClubInfo? GetClubWithBansAndApplications(ulong ownerUserId);
|
||||||
bool LeaveClub(IUser user);
|
bool LeaveClub(IUser user);
|
||||||
@@ -20,4 +20,13 @@ public interface IClubService
|
|||||||
bool UnBan(ulong ownerUserId, string userName, out ClubInfo club);
|
bool UnBan(ulong ownerUserId, string userName, out ClubInfo club);
|
||||||
bool Kick(ulong kickerId, string userName, out ClubInfo club);
|
bool Kick(ulong kickerId, string userName, out ClubInfo club);
|
||||||
List<ClubInfo> GetClubLeaderboardPage(int page);
|
List<ClubInfo> GetClubLeaderboardPage(int page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ClubApplyResult
|
||||||
|
{
|
||||||
|
Success,
|
||||||
|
|
||||||
|
AlreadyInAClub,
|
||||||
|
Banned,
|
||||||
|
InsufficientLevel
|
||||||
}
|
}
|
@@ -837,13 +837,15 @@
|
|||||||
"server_leaderboard": "Server XP Leaderboard",
|
"server_leaderboard": "Server XP Leaderboard",
|
||||||
"global_leaderboard": "Global XP Leaderboard",
|
"global_leaderboard": "Global XP Leaderboard",
|
||||||
"modified": "Modified server XP of the user {0} by {1}",
|
"modified": "Modified server XP of the user {0} by {1}",
|
||||||
|
"club_insuff_lvl": "You're insufficient level to join that club.",
|
||||||
|
"club_join_banned": "You're banned from that club.",
|
||||||
|
"club_already_in": "You are already a member of a club.",
|
||||||
"club_create_error_name": "Failed creating the club. A club with that name already exists.",
|
"club_create_error_name": "Failed creating the club. A club with that name already exists.",
|
||||||
"club_create_error": "Failed creating the club. Make sure you're above level 5 and not a member of a club already.",
|
"club_create_error": "Failed creating the club. Make sure you're above level 5 and not a member of a club already.",
|
||||||
"club_name_too_long": "Club name is too long.",
|
"club_name_too_long": "Club name is too long.",
|
||||||
"club_created": "Club {0} successfully created!",
|
"club_created": "Club {0} successfully created!",
|
||||||
"club_not_exists": "That club doesn't exist.",
|
"club_not_exists": "That club doesn't exist.",
|
||||||
"club_applied": "You've applied for membership in {0} club.",
|
"club_applied": "You've applied for membership in {0} club.",
|
||||||
"club_apply_error": "Error applying. You are either already a member of the club, or you don't meet the minimum level requirement, or you've been banned from this one.",
|
|
||||||
"club_accepted": "Accepted user {0} to the club.",
|
"club_accepted": "Accepted user {0} to the club.",
|
||||||
"club_accept_error": "User not found",
|
"club_accept_error": "User not found",
|
||||||
"club_left": "You've left the club.",
|
"club_left": "You've left the club.",
|
||||||
|
Reference in New Issue
Block a user