Fix invalid usernames
This commit is contained in:
Generated
+1
-1
@@ -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
@@ -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"
|
||||||
|
|
||||||
|
|||||||
+18
-6
@@ -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 {
|
||||||
|
if *len < 2 {
|
||||||
|
name = format!("{name}--");
|
||||||
} else {
|
} else {
|
||||||
name
|
name = format!("{name:.80}");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
name = "Invalid name".into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Participant {
|
impl Participant {
|
||||||
|
|||||||
Reference in New Issue
Block a user