mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	Removed ambiguity in clubban and clubunban error messages
This commit is contained in:
		@@ -294,13 +294,20 @@ public partial class Xp
 | 
			
		||||
        [Priority(0)]
 | 
			
		||||
        public Task ClubBan([Leftover] string userName)
 | 
			
		||||
        {
 | 
			
		||||
            if (_service.Ban(ctx.User.Id, userName, out var club))
 | 
			
		||||
            var result = _service.Ban(ctx.User.Id, userName, out var club);
 | 
			
		||||
            if (result == ClubBanResult.Success)
 | 
			
		||||
            {
 | 
			
		||||
                return ReplyConfirmLocalizedAsync(strs.club_user_banned(Format.Bold(userName),
 | 
			
		||||
                    Format.Bold(club.ToString())));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ReplyErrorLocalizedAsync(strs.club_user_ban_fail);
 | 
			
		||||
            if (result == ClubBanResult.Unbannable)
 | 
			
		||||
                return ReplyErrorLocalizedAsync(strs.club_ban_fail_unbannable);
 | 
			
		||||
 | 
			
		||||
            if (result == ClubBanResult.WrongUser)
 | 
			
		||||
                return ReplyErrorLocalizedAsync(strs.club_ban_fail_user_not_found);
 | 
			
		||||
 | 
			
		||||
            return ReplyErrorLocalizedAsync(strs.club_admin_perms);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
@@ -312,13 +319,20 @@ public partial class Xp
 | 
			
		||||
        [Priority(0)]
 | 
			
		||||
        public Task ClubUnBan([Leftover] string userName)
 | 
			
		||||
        {
 | 
			
		||||
            if (_service.UnBan(ctx.User.Id, userName, out var club))
 | 
			
		||||
            var result = _service.UnBan(ctx.User.Id, userName, out var club);
 | 
			
		||||
            
 | 
			
		||||
            if (result == ClubUnbanResult.Success)
 | 
			
		||||
            {
 | 
			
		||||
                return ReplyConfirmLocalizedAsync(strs.club_user_unbanned(Format.Bold(userName),
 | 
			
		||||
                    Format.Bold(club.ToString())));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ReplyErrorLocalizedAsync(strs.club_user_unban_fail);
 | 
			
		||||
            if (result == ClubUnbanResult.WrongUser)
 | 
			
		||||
            {
 | 
			
		||||
                return ReplyErrorLocalizedAsync(strs.club_unban_fail_user_not_found);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ReplyErrorLocalizedAsync(strs.club_admin_perms);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
 
 | 
			
		||||
@@ -216,23 +216,23 @@ public class ClubService : INService, IClubService
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public bool Ban(ulong bannerId, string userName, out ClubInfo club)
 | 
			
		||||
    public ClubBanResult Ban(ulong bannerId, string userName, out ClubInfo club)
 | 
			
		||||
    {
 | 
			
		||||
        using var uow = _db.GetDbContext();
 | 
			
		||||
        club = uow.Clubs.GetByOwnerOrAdmin(bannerId);
 | 
			
		||||
        if (club is null)
 | 
			
		||||
            return false;
 | 
			
		||||
            return ClubBanResult.NotOwnerOrAdmin;
 | 
			
		||||
 | 
			
		||||
        var usr = club.Members.FirstOrDefault(x => x.ToString().ToUpperInvariant() == userName.ToUpperInvariant())
 | 
			
		||||
                  ?? club.Applicants
 | 
			
		||||
                         .FirstOrDefault(x => x.User.ToString().ToUpperInvariant() == userName.ToUpperInvariant())
 | 
			
		||||
                         ?.User;
 | 
			
		||||
        if (usr is null)
 | 
			
		||||
            return false;
 | 
			
		||||
            return ClubBanResult.WrongUser;
 | 
			
		||||
 | 
			
		||||
        if (club.OwnerId == usr.Id
 | 
			
		||||
            || (usr.IsClubAdmin && club.Owner.UserId != bannerId)) // can't ban the owner kek, whew
 | 
			
		||||
            return false;
 | 
			
		||||
            return ClubBanResult.Unbannable;
 | 
			
		||||
 | 
			
		||||
        club.Bans.Add(new()
 | 
			
		||||
        {
 | 
			
		||||
@@ -247,24 +247,24 @@ public class ClubService : INService, IClubService
 | 
			
		||||
 | 
			
		||||
        uow.SaveChanges();
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
        return ClubBanResult.Success;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public bool UnBan(ulong ownerUserId, string userName, out ClubInfo club)
 | 
			
		||||
    public ClubUnbanResult UnBan(ulong ownerUserId, string userName, out ClubInfo club)
 | 
			
		||||
    {
 | 
			
		||||
        using var uow = _db.GetDbContext();
 | 
			
		||||
        club = uow.Clubs.GetByOwnerOrAdmin(ownerUserId);
 | 
			
		||||
        if (club is null)
 | 
			
		||||
            return false;
 | 
			
		||||
            return ClubUnbanResult.NotOwnerOrAdmin;
 | 
			
		||||
 | 
			
		||||
        var ban = club.Bans.FirstOrDefault(x => x.User.ToString().ToUpperInvariant() == userName.ToUpperInvariant());
 | 
			
		||||
        if (ban is null)
 | 
			
		||||
            return false;
 | 
			
		||||
            return ClubUnbanResult.WrongUser;
 | 
			
		||||
 | 
			
		||||
        club.Bans.Remove(ban);
 | 
			
		||||
        uow.SaveChanges();
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
        return ClubUnbanResult.Success;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public bool Kick(ulong kickerId, string userName, out ClubInfo club)
 | 
			
		||||
@@ -298,4 +298,20 @@ public class ClubService : INService, IClubService
 | 
			
		||||
        using var uow = _db.GetDbContext();
 | 
			
		||||
        return uow.Clubs.GetClubLeaderboardPage(page);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public enum ClubUnbanResult
 | 
			
		||||
{
 | 
			
		||||
   Success,
 | 
			
		||||
   NotOwnerOrAdmin,
 | 
			
		||||
   WrongUser
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public enum ClubBanResult
 | 
			
		||||
{
 | 
			
		||||
    Success,
 | 
			
		||||
    NotOwnerOrAdmin,
 | 
			
		||||
    WrongUser,
 | 
			
		||||
    Unbannable,
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
@@ -16,8 +16,8 @@ public interface IClubService
 | 
			
		||||
    bool LeaveClub(IUser user);
 | 
			
		||||
    bool SetDescription(ulong userId, string? desc);
 | 
			
		||||
    bool Disband(ulong userId, out ClubInfo club);
 | 
			
		||||
    bool Ban(ulong bannerId, string userName, out ClubInfo club);
 | 
			
		||||
    bool UnBan(ulong ownerUserId, string userName, out ClubInfo club);
 | 
			
		||||
    ClubBanResult Ban(ulong bannerId, string userName, out ClubInfo club);
 | 
			
		||||
    ClubUnbanResult UnBan(ulong ownerUserId, string userName, out ClubInfo club);
 | 
			
		||||
    bool Kick(ulong kickerId, string userName, out ClubInfo club);
 | 
			
		||||
    List<ClubInfo> GetClubLeaderboardPage(int page);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -854,9 +854,11 @@
 | 
			
		||||
  "club_user_not_in_club": "{0} is not in a club.",
 | 
			
		||||
  "club_user_kick_fail": "Error kicking. You're either not the club owner, or that user is not in your club.",
 | 
			
		||||
  "club_user_banned": "Banned user {0} from {1} club.",
 | 
			
		||||
  "club_user_ban_fail": "Failed to ban. You're either not the club owner, or that user is not in your club or applied to it.",
 | 
			
		||||
  "club_admin_perms": "You must be a club admin or owner in order to perform this action.",
 | 
			
		||||
  "club_ban_fail_user_not_found": "That user is not in your club or applied to it.",
 | 
			
		||||
  "club_ban_fail_unbannable": "Only the club owner can ban club admins.",
 | 
			
		||||
  "club_user_unbanned": "Unbanned user {0} in {1} club.",
 | 
			
		||||
  "club_user_unban_fail": "Failed to unban. You're either not the club owner, or that user is not in your club or applied to it.",
 | 
			
		||||
  "club_unban_fail_user_not_found": "That user is not banned in this club.",
 | 
			
		||||
  "club_desc_update": "Club Description Updated",
 | 
			
		||||
  "club_desc_update_failed": "Failed changing club description.",
 | 
			
		||||
  "club_disbanded": "Club {0} has been disbanded",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user