Skip to content

Commit

Permalink
Fix incorrect role assignments for loved mappers (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasi4K5 authored Dec 5, 2024
2 parents d993cb6 + 7ced354 commit e0fe521
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
24 changes: 20 additions & 4 deletions src/Numerous.Bot/Discord/OsuVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 10 additions & 8 deletions src/Numerous.Bot/Web/Osu/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit e0fe521

Please sign in to comment.