From 7ced354cac84144dd84f9fa17b0e675a5075948e Mon Sep 17 00:00:00 2001 From: Pascal Pomper Date: Thu, 5 Dec 2024 23:14:24 +0100 Subject: [PATCH] Fix incorrect role assignments for loved mappers Fixes #35 --- src/Numerous.Bot/Discord/OsuVerifier.cs | 24 ++++++++++++++++++++---- src/Numerous.Bot/Web/Osu/Extensions.cs | 18 ++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Numerous.Bot/Discord/OsuVerifier.cs b/src/Numerous.Bot/Discord/OsuVerifier.cs index 8b2823e..b1e4b26 100644 --- a/src/Numerous.Bot/Discord/OsuVerifier.cs +++ b/src/Numerous.Bot/Discord/OsuVerifier.cs @@ -12,6 +12,7 @@ using Numerous.Common.Enums; using Numerous.Database.Context; using Numerous.Database.Dtos; +using osu.Game.Beatmaps; using Serilog; namespace Numerous.Bot.Discord; @@ -58,7 +59,7 @@ public async Task AssignAllRolesAsync(SocketGuild guild, CancellationToken ct = if (await UserIsVerifiedAsync(guildUser, osuUsers)) { - await Task.Delay(2000, ct); + await Task.Delay(5000, ct); } } } @@ -194,10 +195,25 @@ role is not null } } + var isRanked = + osuUser.HasRankedSets() + || (osuUser.HasLeaderboardGds() + && (await osuApi.GetUserBeatmapsetsAsync(osuUser.Id, ApiBeatmapType.Guest)) + .Any(s => s.Ranked == BeatmapOnlineStatus.Ranked) + ); + await Task.WhenAll( - AssignRoleAsync(mappings, OsuUserGroup.UnrankedMapper, osuUser.IsUnrankedMapper()), - AssignRoleAsync(mappings, OsuUserGroup.RankedMapper, osuUser.IsRankedMapper()), - AssignRoleAsync(mappings, OsuUserGroup.ProjectLoved, osuUser.IsLovedMapper()) + AssignRoleAsync(mappings, OsuUserGroup.UnrankedMapper, osuUser.IsMapper() && !isRanked), + AssignRoleAsync(mappings, OsuUserGroup.RankedMapper, isRanked), + AssignRoleAsync( + mappings, + OsuUserGroup.LovedMapper, + osuUser.HasLovedSets() + || (osuUser.HasLeaderboardGds() + && (await osuApi.GetUserBeatmapsetsAsync(osuUser.Id, ApiBeatmapType.Guest)) + .Any(s => s.Ranked == BeatmapOnlineStatus.Loved) + ) + ) ); return; diff --git a/src/Numerous.Bot/Web/Osu/Extensions.cs b/src/Numerous.Bot/Web/Osu/Extensions.cs index ffb1d23..de23b3e 100644 --- a/src/Numerous.Bot/Web/Osu/Extensions.cs +++ b/src/Numerous.Bot/Web/Osu/Extensions.cs @@ -9,21 +9,23 @@ namespace Numerous.Bot.Web.Osu; public static class Extensions { - public static bool IsRankedMapper(this ApiOsuUser user) + public static bool HasRankedSets(this ApiOsuUser user) { - return user.RankedBeatmapsetCount > 0 - || user.GuestBeatmapsetCount > 0; + return user.RankedBeatmapsetCount > 0; } - public static bool IsLovedMapper(this ApiOsuUser user) + public static bool HasLeaderboardGds(this ApiOsuUser user) + { + return user.GuestBeatmapsetCount > 0; + } + + public static bool HasLovedSets(this ApiOsuUser user) { return user.LovedBeatmapsetCount > 0; } - public static bool IsUnrankedMapper(this ApiOsuUser user) + public static bool IsMapper(this ApiOsuUser user) { - return - (user.GraveyardBeatmapsetCount > 0 || user.PendingBeatmapsetCount > 0) - && !user.IsRankedMapper(); + return user.GraveyardBeatmapsetCount > 0 || user.PendingBeatmapsetCount > 0; } }