Fix invalid usernames

This commit is contained in:
2025-08-25 19:50:30 -03:00
parent ca1ce13887
commit 16085b4bd8
3 changed files with 21 additions and 9 deletions
Generated
+1 -1
View File
@@ -1996,7 +1996,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
[[package]] [[package]]
name = "payphone" name = "payphone"
version = "4.4.0" version = "4.4.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "payphone" name = "payphone"
version = "4.4.0" version = "4.4.1"
edition = "2024" edition = "2024"
default-run = "payphone" default-run = "payphone"
+19 -7
View File
@@ -24,6 +24,7 @@ use twilight_model::{
id::Id, id::Id,
user::User as TwilightUser, user::User as TwilightUser,
}; };
use twilight_validate::request::{ValidationError, ValidationErrorType, webhook_username};
use crate::{ use crate::{
colors::AvatarColorFetchingRequest, colors::AvatarColorFetchingRequest,
@@ -1912,14 +1913,25 @@ impl<'a> Object<'a> for Participant {
} }
} }
fn make_name_valid(name: String) -> String { fn make_name_valid(mut name: String) -> String {
if name.len() == 1 { if let Err(error) = webhook_username(&name) {
format!("{name}-") match error.kind() {
} else if name.len() > 80 { ValidationErrorType::WebhookUsername { len, substring } => {
format!("{name:.80}") if let Some(len) = len {
} else { if *len < 2 {
name name = format!("{name}--");
} else {
name = format!("{name:.80}");
}
} else {
name = "Invalid name".into();
}
}
_ => {}
}
} }
name
} }
impl Participant { impl Participant {