Skip to content

Commit

Permalink
Merge pull request #50 from CyberLions/admin-tools
Browse files Browse the repository at this point in the history
Update admin tools
  • Loading branch information
bman46 authored Aug 6, 2023
2 parents 36a6220 + 2025c7e commit a78330a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CCSODiscordBot/CCSODiscordBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
<Folder Include="Modules\SSOCommands\Configuration\" />
<Folder Include="Modules\SSOCommands\UserCommands\" />
<Folder Include="Services\ExceptionHandling\" />
<Folder Include="Modules\UserManagement\AdminCommands\" />
</ItemGroup>
<ItemGroup>
<None Remove="Services\ExceptionHandling\" />
<None Remove="Modules\UserManagement\AdminCommands\" />
</ItemGroup>
<ItemGroup>
<None Update="Modules\Memes\Media\simpy.png">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AdminSlashCommands(IUserRepository iUserRepository, IGuildRepository iGui
[SlashCommand("verify-remove-user", "Remove the verification status from a user.")]
[DefaultMemberPermissions(GuildPermission.Administrator)]
[EnabledInDm(false)]
public async Task VerifyRemoveUser([Summary("User", "The user to remove verification status from.")] SocketGuildUser user, [Summary("Confirm", "True to confirm you would like to proceed with this action.")] bool confirm)
public async Task VerifyRemoveUser([Summary("User", "The user to remove verification status from.")] SocketGuildUser user, [Summary("Confirm", "True to confirm you would like to proceed with this action.")] bool confirm = false)
{
await Context.Interaction.DeferAsync(true);

Expand All @@ -43,7 +43,7 @@ public async Task VerifyRemoveUser([Summary("User", "The user to remove verifica
[SlashCommand("verify-remove-group", "Remove the verification status from all users in a group.")]
[DefaultMemberPermissions(GuildPermission.Administrator)]
[EnabledInDm(false)]
public async Task VerifyRemoveGroup([Summary("Group", "The group to remove verification status' from.")] SocketRole group, [Summary("Confirm", "True to confirm you would like to proceed with this action.")] bool confirm)
public async Task VerifyRemoveGroup([Summary("Group", "The group to remove verification status' from.")] SocketRole group, [Summary("Confirm", "True to confirm you would like to proceed with this action.")] bool confirm = false)
{
await Context.Interaction.DeferAsync(true);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Net.Mail;
using System.Text.RegularExpressions;
using CCSODiscordBot.Services.Database.Repository;
using Discord;
using Discord.Interactions;
using Google.Api;

namespace CCSODiscordBot.Modules.UserManagement.AdminCommands
{
public class UnverifyPSUAliasAccounts : InteractionModuleBase<ShardedInteractionContext>
{
private readonly IUserRepository _iUserRepository;
public UnverifyPSUAliasAccounts(IUserRepository iUserRepository)
{
_iUserRepository = iUserRepository;
}
[SlashCommand("verify-remove-alias", "Remove the verification status from all users with a PSU alias account.")]
[DefaultMemberPermissions(GuildPermission.Administrator)]
[EnabledInDm(false)]
public async Task VerifyRemoveAlias([Summary("Confirm", "Confirm that you would like to proceed.")] bool confirm = false)
{
await Context.Interaction.DeferAsync(true);

if (!confirm)
{
await Context.Interaction.FollowupAsync("Command aborted. Confirm param must be true.");
return;
}

// Log this event:
Console.WriteLine(Context.User.Id + " removed all PSU alias accounts verification status.");

var users = await _iUserRepository.GetByLinqAsync(x => x.DiscordGuildID == Context.Guild.Id && x.Verified);
int count = 0;


// Parse all users and check email
foreach(var user in users)
{
MailAddress? email = null;
// Handle null emails:
if (user.Email != null)
{
email = new MailAddress(user.Email);
}
// Check email compliance status:
if (email == null || !email.Host.EndsWith("psu.edu") || !Regex.Match(email.User, @"^[a-zA-Z]{3}\d+$").Success)
{
// Email does not match requirements. Remove verification
user.Verified = false;
await _iUserRepository.UpdateUserAsync(user);
count++;
}
}
// Notify user of status
await Context.Interaction.FollowupAsync("Removed "+count+" user's verification status.");
}
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Net.Mail;
using System.Text.RegularExpressions;
using CCSODiscordBot.Modules.Embeds.Modals;
using CCSODiscordBot.Services.Database.DataTables;
using CCSODiscordBot.Services.Database.Repository;
using CCSODiscordBot.Services.Email;
using Discord;
using Discord.Interactions;

namespace CCSODiscordBot.Modules.UserManagement.Modals
Expand Down

0 comments on commit a78330a

Please sign in to comment.