mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
system refs now first parse for a user ref
This commit is contained in:
parent
b3fdaec68c
commit
960f735db9
1 changed files with 20 additions and 16 deletions
|
|
@ -139,23 +139,10 @@ impl Parameter {
|
|||
ParameterKind::MemberRefs => Ok(ParameterValue::MemberRefs(
|
||||
input.split(' ').map(|s| s.trim().to_string()).collect(),
|
||||
)),
|
||||
ParameterKind::SystemRef => Ok(ParameterValue::SystemRef(input.into())),
|
||||
ParameterKind::UserRef => {
|
||||
if let Ok(user_id) = input.parse::<u64>() {
|
||||
return Ok(ParameterValue::UserRef(user_id));
|
||||
}
|
||||
|
||||
static RE: std::sync::LazyLock<Regex> =
|
||||
std::sync::LazyLock::new(|| Regex::new(r"<@!?(\\d{17,19})>").unwrap());
|
||||
if let Some(captures) = RE.captures(&input) {
|
||||
return captures[1]
|
||||
.parse::<u64>()
|
||||
.map(|id| ParameterValue::UserRef(id))
|
||||
.map_err(|_| SmolStr::new("invalid user ID"));
|
||||
}
|
||||
|
||||
Err(SmolStr::new("invalid user ID"))
|
||||
ParameterKind::SystemRef => {
|
||||
Ok(parse_user_ref(input).unwrap_or(ParameterValue::SystemRef(input.into())))
|
||||
}
|
||||
ParameterKind::UserRef => parse_user_ref(input),
|
||||
ParameterKind::MemberPrivacyTarget => MemberPrivacyTargetKind::from_str(input)
|
||||
.map(|target| ParameterValue::MemberPrivacyTarget(target.as_ref().into())),
|
||||
ParameterKind::GroupPrivacyTarget => GroupPrivacyTargetKind::from_str(input)
|
||||
|
|
@ -328,6 +315,23 @@ impl<P: Into<Parameter>> From<Skip<P>> for Parameter {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_user_ref(input: &str) -> Result<ParameterValue, SmolStr> {
|
||||
if let Ok(user_id) = input.parse::<u64>() {
|
||||
return Ok(ParameterValue::UserRef(user_id));
|
||||
}
|
||||
|
||||
static RE: std::sync::LazyLock<Regex> =
|
||||
std::sync::LazyLock::new(|| Regex::new(r"<@!?(\\d{17,19})>").unwrap());
|
||||
if let Some(captures) = RE.captures(&input) {
|
||||
return captures[1]
|
||||
.parse::<u64>()
|
||||
.map(|id| ParameterValue::UserRef(id))
|
||||
.map_err(|_| SmolStr::new("invalid user ID"));
|
||||
}
|
||||
|
||||
Err(SmolStr::new("invalid user ID"))
|
||||
}
|
||||
|
||||
macro_rules! impl_enum {
|
||||
($name:ident ($pretty_name:expr): $($variant:ident),*) => {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue