-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from CyberLions/admin-tools
Update admin tools
- Loading branch information
Showing
4 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
CCSODiscordBot/Modules/UserManagement/AdminCommands/UnverifyPSUAliasAccounts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} | ||
|
6 changes: 1 addition & 5 deletions
6
CCSODiscordBot/Modules/UserManagement/NewUserInteractions/Modals/BasicInformationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters