Skip to content

Commit

Permalink
Merge pull request #24 from eclipserporg/feature/member_roles
Browse files Browse the repository at this point in the history
[Content Creator] Added content creator role synchronization vai the …
  • Loading branch information
Osvaldon authored Feb 4, 2024
2 parents 8a58021 + d688713 commit 9278994
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
25 changes: 15 additions & 10 deletions DiscordBot.App/Controllers/DiscordController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,35 +105,40 @@ public async Task PostUpdateMemberRoles(DiscordMemberRolesDto memberRoles)

foreach (var member in members)
{
var hasVIP = memberRoles.MemberRolesVIP.TryGetValue(member.Id, out var roleVIP);
var hasDonator = memberRoles.MemberRolesDonator.TryGetValue(member.Id, out var roleDonator);
var isVIP = memberRoles.MemberRolesVIP.TryGetValue(member.Id, out var roleVIP);
var isDonator = memberRoles.MemberRolesDonator.TryGetValue(member.Id, out var roleDonator);
var isContentCreator = memberRoles.ContentCreatorMemberIds.Contains(member.Id);

foreach (var role in member.Roles)
{
if (memberRoles.RolesVIP.Contains(role.Id) && (!hasVIP || role.Id != roleVIP))
{
if (memberRoles.RolesVIP.Contains(role.Id) && (!isVIP || role.Id != roleVIP))
await member.RevokeRoleAsync(role);
}

if (memberRoles.RolesDonator.Contains(role.Id) && (!hasDonator || role.Id != roleDonator))
{
if (memberRoles.RolesDonator.Contains(role.Id) && (!isDonator || role.Id != roleDonator))
await member.RevokeRoleAsync(role);
}

if (!isContentCreator && role.Id == _discordService.CreatorRole.Id)
await member.RevokeRoleAsync(_discordService.CreatorRole);
}

if (hasVIP && !member.Roles.Any((role) => role.Id == roleVIP))
if (isVIP && !member.Roles.Any((role) => role.Id == roleVIP))
{
var role = _discordService.Guild.GetRole(roleVIP);
if (role != null)
await member.GrantRoleAsync(role);
}

if (hasDonator && !member.Roles.Any((role) => role.Id == roleDonator))
if (isDonator && !member.Roles.Any((role) => role.Id == roleDonator))
{
var role = _discordService.Guild.GetRole(roleDonator);
if (role != null)
await member.GrantRoleAsync(role);
}

if (isContentCreator && !member.Roles.Any((role) => role.Id == _discordService.CreatorRole.Id))
{
await member.GrantRoleAsync(_discordService.CreatorRole);
}
}
}
}
5 changes: 5 additions & 0 deletions DiscordBot.Data/Models/DiscordMemberRolesDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public class DiscordMemberRolesDto
/// A collection of donator Discord member ids and their role ids.
/// </summary>
public Dictionary<ulong, ulong> MemberRolesDonator { get; set; } = new();

/// <summary>
/// A collection of content creator Discord member ids.
/// </summary
public HashSet<ulong> ContentCreatorMemberIds { get; set; } = new();
}

0 comments on commit 9278994

Please sign in to comment.