From d68871351a78aa3f25023bd49faf4903108cb3d2 Mon Sep 17 00:00:00 2001 From: Osvaldon Date: Sun, 4 Feb 2024 20:03:25 +0200 Subject: [PATCH] [Content Creator] Added content creator role synchronization vai the game server. --- .../Controllers/DiscordController.cs | 25 +++++++++++-------- .../Models/DiscordMemberRolesDto.cs | 5 ++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/DiscordBot.App/Controllers/DiscordController.cs b/DiscordBot.App/Controllers/DiscordController.cs index 0693401..3d17757 100644 --- a/DiscordBot.App/Controllers/DiscordController.cs +++ b/DiscordBot.App/Controllers/DiscordController.cs @@ -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); + } } } } \ No newline at end of file diff --git a/DiscordBot.Data/Models/DiscordMemberRolesDto.cs b/DiscordBot.Data/Models/DiscordMemberRolesDto.cs index 6f1da4a..1442e82 100644 --- a/DiscordBot.Data/Models/DiscordMemberRolesDto.cs +++ b/DiscordBot.Data/Models/DiscordMemberRolesDto.cs @@ -27,4 +27,9 @@ public class DiscordMemberRolesDto /// A collection of donator Discord member ids and their role ids. /// public Dictionary MemberRolesDonator { get; set; } = new(); + + /// + /// A collection of content creator Discord member ids. + /// ContentCreatorMemberIds { get; set; } = new(); }