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

Commit

Permalink
feat: only cure users on name change
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 21, 2022
1 parent 5519bb2 commit 1f5063b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/events/guild_member_addition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use super::*;
use crate::utils::decancer::cure;

pub async fn guild_member_addition(ctx: &serenity::Context, new_member: &serenity::Member) {
cure(ctx, new_member).await;
}
cure(ctx, &None, new_member).await;
}
4 changes: 2 additions & 2 deletions src/events/guild_member_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::utils::decancer::cure;

pub async fn guild_member_update(
ctx: &serenity::Context,
_old_if_available: &Option<serenity::Member>,
old_if_available: &Option<serenity::Member>,
new: &serenity::Member,
) {
cure(ctx, new).await;
cure(ctx, old_if_available, new).await;
}
21 changes: 17 additions & 4 deletions src/utils/decancer.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
use ::decancer::Decancer;
use tracing::{error, info};
use tracing::{error, info, trace};

use super::*;

const DECANCER: Decancer = Decancer::new();

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

if let Some(old) = old_if_available {
if old.display_name().to_string() == name {
trace!(
"Skipping decancer for {} because their name hasn't changed",
member.user.tag()
);
return;
}
}

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

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

if name.to_lowercase() == cured_name {
Expand Down

0 comments on commit 1f5063b

Please sign in to comment.