Skip to content

Commit

Permalink
clear roles when member is inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
loukylor committed Dec 29, 2024
1 parent 28b4fb4 commit 3e1f71c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions TrickFireDiscordBot/Services/RoleSyncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Task<PaginatedList<Page>> nextPageQuery(string? cursor) =>
}
if (!dryRun && !member.Roles.Contains(inactiveRole))
{
await member.GrantRoleAsync(inactiveRole);
await member.ModifyAsync(model => model.Roles = new List<DiscordRole>() { inactiveRole });
await Task.Delay(1000);
}
logger.LogInformation("{}, ({})", member.DisplayName, member.Username);
Expand Down Expand Up @@ -144,6 +144,13 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
int highestRole = discordService.MainGuild.CurrentMember.Roles.Max(role => role.Position);
await member.ModifyAsync(model =>
{
DiscordRole? inactiveRole = newRoles.FirstOrDefault(role => role.Id == options.Value.InactiveRoleId);
if (inactiveRole is not null)
{
model.Roles = new List<DiscordRole>() { inactiveRole };
return;
}

List<DiscordRole> rolesWithLeadership = new(newRoles);
foreach (DiscordRole role in member.Roles.Where(role => role.Position >= highestRole))
{
Expand Down Expand Up @@ -194,15 +201,18 @@ await member.ModifyAsync(model =>

private async Task<IEnumerable<DiscordRole>> GetRoles(Page notionPage)
{
List<DiscordRole> roles = [];
HashSet<DiscordRole> roles = [];

DiscordRole? activeRole = GetActiveRole(notionPage);
if (activeRole is not null)
{
roles.Add(activeRole);
}

roles.AddRange(await GetTeams(notionPage));
foreach (DiscordRole role in await GetTeams(notionPage))
{
roles.Add(role);
}

MultiSelectPropertyValue positions = (notionPage.Properties[options.Value.ClubPositionsPropertyName]
as MultiSelectPropertyValue)!;
Expand Down

0 comments on commit 3e1f71c

Please sign in to comment.