Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: allow ascii only names
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 21, 2022
1 parent e20e5b1 commit 3f05f8c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utils/decancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ use super::*;
const DECANCER: Decancer = Decancer::new();

pub async fn cure(ctx: &serenity::Context, member: &serenity::Member) {
let display_name = member.display_name();
let name = display_name.to_string();
println!("Curing {}", member.display_name());
let name = member.display_name().to_string();

let cured_user_name = DECANCER.cure(&name);
let mut cured_name = DECANCER
.cure(&name)
.replace(|c: char| !(c == ' ' || c.is_ascii_alphanumeric()), "");

if name.to_lowercase() == cured_user_name {
if cured_name.len() == 0 {
cured_name = "ReVanced user" .to_string();
}

if name.to_lowercase() == cured_name {
return; // username is already cured
}

match member
.guild_id
.edit_member(&ctx.http, member.user.id, |edit_member| {
edit_member.nickname(cured_user_name)
edit_member.nickname(cured_name)
})
.await
{
Expand Down

0 comments on commit 3f05f8c

Please sign in to comment.