Skip to content

Commit

Permalink
Merge pull request #8 from CyberLions/C-roles
Browse files Browse the repository at this point in the history
Add role selector
  • Loading branch information
bman46 authored Aug 18, 2022
2 parents eec89f0 + 420db4d commit 1316c30
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CCSODiscordBot/CCSODiscordBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<None Remove="Services\Email\" />
<None Remove="Modules\UserManagement\AccountVerification\" />
<None Remove="Modules\ServerConfig\" />
<None Remove="Modules\UserManagement\RoleSelect\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.7.2" />
Expand Down Expand Up @@ -58,6 +59,7 @@
<Folder Include="Services\Email\" />
<Folder Include="Modules\UserManagement\AccountVerification\" />
<Folder Include="Modules\ServerConfig\" />
<Folder Include="Modules\UserManagement\RoleSelect\" />
</ItemGroup>
<ItemGroup>
<None Update="Modules\Memes\Media\simpy.png">
Expand Down
6 changes: 3 additions & 3 deletions CCSODiscordBot/Modules/Roles/ComponentRespond.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ public async Task ProtectedRoleButton(ulong roleId)
// Ensure role exists and isnt null:
if (role is null)
{
await FollowupAsync("Role cannot be found. Contact an admin.");
await FollowupAsync("Role cannot be found. Contact an admin.", ephemeral: true);
throw new NullReferenceException("Role button role cannot be found and is null.");
}
// Ensure user is a SocketGuildUser.
if (user is null)
{
await FollowupAsync("User cannot be found. Contact an admin.");
await FollowupAsync("User cannot be found. Contact an admin.", ephemeral: true);
throw new NullReferenceException("User is not guild user.");
}
// Check for verification:
var dbUser = await _IUserRepository.GetByDiscordIdAsync(Context.User.Id, Context.Guild.Id);
if (!dbUser.verified)
{
await FollowupAsync("Error: You need to have a verified PSU email to add this role.");
await FollowupAsync("Error: You need to have a verified PSU email to add this role.", ephemeral: true);
return;
}
// Get user's roles:
Expand Down
29 changes: 29 additions & 0 deletions CCSODiscordBot/Modules/UserManagement/RoleSelect/SlashCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using CCSODiscordBot.Services.Database.Repository;
using Discord;
using Discord.Interactions;
using Discord.WebSocket;

namespace CCSODiscordBot.Modules.UserManagement.RoleSelect
{
public class SlashCommand : InteractionModuleBase<ShardedInteractionContext>
{
private readonly IGuildRepository _iGuildRepository;
public SlashCommand(IGuildRepository guildRepository)
{
_iGuildRepository = guildRepository;
}

[SlashCommand("roleselection", "Add embed for role selection.")]
[EnabledInDm(false)]
[DefaultMemberPermissions(GuildPermission.Administrator)]
public async Task RoleSelection([Summary(description: "The channel to post the role embed in.")] SocketTextChannel channel)
{
await Context.Interaction.DeferAsync(true);

var dbGuild = await _iGuildRepository.GetByDiscordIdAsync(Context.Guild.Id);
await channel.SendMessageAsync(embed: RolePrompt.RolePromptEmbeds.Embeds(true, dbGuild.ClassStandings, dbGuild.InterestRoles).Build(), components: RolePrompt.RolePromptComponents.BtnComponent(true, dbGuild.ClassStandings, dbGuild.InterestRoles).Build());
}
}
}

0 comments on commit 1316c30

Please sign in to comment.