Skip to content

Commit

Permalink
Add member role upon verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
bman46 committed Aug 20, 2022
1 parent 1e3ac11 commit 7ab63d9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CCSODiscordBot/Modules/ServerConfig/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}

/// <summary>
/// Function to create a new guild in the DB
Expand All @@ -200,6 +223,7 @@ private async Task<Guild> CreateNewGuild(SocketGuild newGuild)

return guild;
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions CCSODiscordBot/Services/Database/DataTables/Guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BtnRole>? ClassStandings { get; set; }

Expand Down

0 comments on commit 7ab63d9

Please sign in to comment.