From 7ab63d9991e51ba0919c73d365c39a329d938edd Mon Sep 17 00:00:00 2001 From: Brendan McShane Date: Sat, 20 Aug 2022 10:24:24 -0400 Subject: [PATCH] Add member role upon verification. --- .../Modules/ServerConfig/SlashCommands.cs | 24 +++++++++++++++++++ .../AccountVerification/SlashCommands.cs | 6 +++++ .../Services/Database/DataTables/Guild.cs | 3 +++ 3 files changed, 33 insertions(+) diff --git a/CCSODiscordBot/Modules/ServerConfig/SlashCommands.cs b/CCSODiscordBot/Modules/ServerConfig/SlashCommands.cs index 6d9a77b..5b78cf0 100644 --- a/CCSODiscordBot/Modules/ServerConfig/SlashCommands.cs +++ b/CCSODiscordBot/Modules/ServerConfig/SlashCommands.cs @@ -178,6 +178,29 @@ public async Task AddInterest(SocketRole role, string name, string description) // Notify user: await Context.Interaction.FollowupAsync("Settings updated!"); } + [SlashCommand("setmemberrole", "Sets the role granted to verified members.")] + [EnabledInDm(false)] + [DefaultMemberPermissions(GuildPermission.Administrator)] + public async Task SetMemberRole(SocketRole role) + { + await Context.Interaction.DeferAsync(true); + + Guild guild = await _iGuildRepository.GetByDiscordIdAsync(Context.Guild.Id); + // Check for new server: + if (guild == null) + { + // Create new + guild = await CreateNewGuild(Context.Guild); + } + // Set role: + guild.VerifiedMemberRole = role.Id; + + // Update DB: + await _iGuildRepository.UpdateGuildAsync(guild); + + // Notify user: + await Context.Interaction.FollowupAsync("Settings updated!"); + } /// /// Function to create a new guild in the DB @@ -200,6 +223,7 @@ private async Task CreateNewGuild(SocketGuild newGuild) return guild; } + } } diff --git a/CCSODiscordBot/Modules/UserManagement/AccountVerification/SlashCommands.cs b/CCSODiscordBot/Modules/UserManagement/AccountVerification/SlashCommands.cs index 72ac042..3ff4976 100644 --- a/CCSODiscordBot/Modules/UserManagement/AccountVerification/SlashCommands.cs +++ b/CCSODiscordBot/Modules/UserManagement/AccountVerification/SlashCommands.cs @@ -41,6 +41,12 @@ public async Task Verify([Summary("Code", "The code sent to your email.")][MinVa user.VerificationNumber = null; await _IUserRepository.UpdateUserAsync(user); var guild = await _IGuildRepository.GetByDiscordIdAsync(Context.Guild.Id); + // Set member role: + if(guild.VerifiedMemberRole != null) + { + await Context.Guild.GetUser(Context.User.Id).AddRoleAsync((ulong) guild.VerifiedMemberRole); + } + // Ensure guild has set up standings and/or interest roles if (guild.ClassStandings?.Count > 0 || guild.InterestRoles?.Count > 0) { diff --git a/CCSODiscordBot/Services/Database/DataTables/Guild.cs b/CCSODiscordBot/Services/Database/DataTables/Guild.cs index 4f28407..391b070 100644 --- a/CCSODiscordBot/Services/Database/DataTables/Guild.cs +++ b/CCSODiscordBot/Services/Database/DataTables/Guild.cs @@ -20,6 +20,9 @@ public class Guild [BsonElement("welcomeChannel")] public ulong WelcomeChannel { get; set; } + [BsonElement("memberRole")] + public ulong? VerifiedMemberRole { get; set; } + [BsonElement("standings")] public List? ClassStandings { get; set; }