Fix invalid usernames
This commit is contained in:
+19
-7
@@ -24,6 +24,7 @@ use twilight_model::{
|
||||
id::Id,
|
||||
user::User as TwilightUser,
|
||||
};
|
||||
use twilight_validate::request::{ValidationError, ValidationErrorType, webhook_username};
|
||||
|
||||
use crate::{
|
||||
colors::AvatarColorFetchingRequest,
|
||||
@@ -1912,14 +1913,25 @@ impl<'a> Object<'a> for Participant {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_name_valid(name: String) -> String {
|
||||
if name.len() == 1 {
|
||||
format!("{name}-")
|
||||
} else if name.len() > 80 {
|
||||
format!("{name:.80}")
|
||||
} else {
|
||||
name
|
||||
fn make_name_valid(mut name: String) -> String {
|
||||
if let Err(error) = webhook_username(&name) {
|
||||
match error.kind() {
|
||||
ValidationErrorType::WebhookUsername { len, substring } => {
|
||||
if let Some(len) = len {
|
||||
if *len < 2 {
|
||||
name = format!("{name}--");
|
||||
} else {
|
||||
name = format!("{name:.80}");
|
||||
}
|
||||
} else {
|
||||
name = "Invalid name".into();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
name
|
||||
}
|
||||
|
||||
impl Participant {
|
||||
|
||||
Reference in New Issue
Block a user