fix pk;e taking in id, only take message ref

This commit is contained in:
dawn 2026-01-18 22:09:58 +03:00
parent aec01d6245
commit 5daa4777f5
No known key found for this signature in database
4 changed files with 73 additions and 44 deletions

View file

@ -1,3 +1,5 @@
use command_parser::parameter::MESSAGE_REF;
use super::*; use super::*;
pub fn debug() -> (&'static str, [&'static str; 1]) { pub fn debug() -> (&'static str, [&'static str; 1]) {
@ -12,7 +14,7 @@ pub fn cmds() -> impl IntoIterator<Item = Command> {
.help("Checks if PluralKit has the required permissions in a channel"), .help("Checks if PluralKit has the required permissions in a channel"),
command!(debug, perms, ("guild", ["g"]), GuildRef => "permcheck_guild") command!(debug, perms, ("guild", ["g"]), GuildRef => "permcheck_guild")
.help("Checks whether a server's permission setup is correct"), .help("Checks whether a server's permission setup is correct"),
command!(debug, ("proxy", ["proxying", "proxycheck"]), MessageRef => "message_proxy_check") command!(debug, ("proxy", ["proxying", "proxycheck"]), MESSAGE_REF => "message_proxy_check")
.help("Checks why a message has not been proxied"), .help("Checks why a message has not been proxied"),
] ]
} }

View file

@ -1,7 +1,9 @@
use command_parser::parameter::{MESSAGE_LINK, MESSAGE_REF};
use super::*; use super::*;
pub fn cmds() -> impl IntoIterator<Item = Command> { pub fn cmds() -> impl IntoIterator<Item = Command> {
let message = tokens!(("message", ["msg", "messageinfo"]), Optional(MessageRef)); let message = tokens!(("message", ["msg", "messageinfo"]), Optional(MESSAGE_REF));
let author = ("author", ["sender", "a"]); let author = ("author", ["sender", "a"]);
let delete = ("delete", ["del", "d"]); let delete = ("delete", ["del", "d"]);
@ -20,8 +22,8 @@ pub fn cmds() -> impl IntoIterator<Item = Command> {
}; };
[ [
apply_edit(command!(edit, Optional(MessageRef), new_content_param => "message_edit")), apply_edit(command!(edit, Optional(MESSAGE_LINK), new_content_param => "message_edit")),
command!(reproxy, Optional(("msg", MessageRef)), ("member", MemberRef) => "message_reproxy") command!(reproxy, Optional(("msg", MESSAGE_REF)), ("member", MemberRef) => "message_reproxy")
.help("Reproxies a previously proxied message with a different member"), .help("Reproxies a previously proxied message with a different member"),
command!(message, author => "message_author").help("Shows the author of a proxied message"), command!(message, author => "message_author").help("Shows the author of a proxied message"),
command!(message, delete => "message_delete").help("Deletes a proxied message"), command!(message, delete => "message_delete").help("Deletes a proxied message"),

View file

@ -8,6 +8,15 @@ use smol_str::{SmolStr, format_smolstr};
use crate::token::{Token, TokenMatchResult}; use crate::token::{Token, TokenMatchResult};
pub const MESSAGE_REF: ParameterKind = ParameterKind::MessageRef {
id: true,
link: true,
};
pub const MESSAGE_LINK: ParameterKind = ParameterKind::MessageRef {
id: false,
link: true,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ParameterKind { pub enum ParameterKind {
OpaqueString, OpaqueString,
@ -18,7 +27,7 @@ pub enum ParameterKind {
GroupRefs, GroupRefs,
SystemRef, SystemRef,
UserRef, UserRef,
MessageRef, MessageRef { id: bool, link: bool },
ChannelRef, ChannelRef,
GuildRef, GuildRef,
MemberPrivacyTarget, MemberPrivacyTarget,
@ -41,7 +50,7 @@ impl ParameterKind {
ParameterKind::GroupRefs => "targets", ParameterKind::GroupRefs => "targets",
ParameterKind::SystemRef => "target", ParameterKind::SystemRef => "target",
ParameterKind::UserRef => "target", ParameterKind::UserRef => "target",
ParameterKind::MessageRef => "target", ParameterKind::MessageRef { .. } => "target",
ParameterKind::ChannelRef => "target", ParameterKind::ChannelRef => "target",
ParameterKind::GuildRef => "target", ParameterKind::GuildRef => "target",
ParameterKind::MemberPrivacyTarget => "member_privacy_target", ParameterKind::MemberPrivacyTarget => "member_privacy_target",
@ -153,48 +162,56 @@ impl Parameter {
Toggle::from_str(input).map(|t| ParameterValue::Toggle(t.into())) Toggle::from_str(input).map(|t| ParameterValue::Toggle(t.into()))
} }
ParameterKind::Avatar => Ok(ParameterValue::Avatar(input.into())), ParameterKind::Avatar => Ok(ParameterValue::Avatar(input.into())),
ParameterKind::MessageRef => { ParameterKind::MessageRef { id, link } => {
if let Ok(message_id) = input.parse::<u64>() { if id {
return Ok(ParameterValue::MessageRef(None, None, message_id)); if let Ok(message_id) = input.parse::<u64>() {
return Ok(ParameterValue::MessageRef(None, None, message_id));
}
} }
static SERVER_RE: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new( if link {
|| { static SERVER_RE: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(
regex::Regex::new( || {
r"https://(?:\w+\.)?discord(?:app)?\.com/channels/(?P<guild>\d+)/(?P<channel>\d+)/(?P<message>\d+)", regex::Regex::new(
) r"https://(?:\w+\.)?discord(?:app)?\.com/channels/(?P<guild>\d+)/(?P<channel>\d+)/(?P<message>\d+)",
.unwrap() )
}, .unwrap()
); },
);
static DM_RE: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(|| { static DM_RE: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(
regex::Regex::new( || {
r"https://(?:\w+\.)?discord(?:app)?\.com/channels/@me/(?P<channel>\d+)/(?P<message>\d+)", regex::Regex::new(
) r"https://(?:\w+\.)?discord(?:app)?\.com/channels/@me/(?P<channel>\d+)/(?P<message>\d+)",
.unwrap() )
}); .unwrap()
},
);
if let Some(captures) = SERVER_RE.captures(input) { if let Some(captures) = SERVER_RE.captures(input) {
let guild_id = captures.parse_id("guild")?; let guild_id = captures.parse_id("guild")?;
let channel_id = captures.parse_id("channel")?; let channel_id = captures.parse_id("channel")?;
let message_id = captures.parse_id("message")?; let message_id = captures.parse_id("message")?;
Ok(ParameterValue::MessageRef( Ok(ParameterValue::MessageRef(
Some(guild_id), Some(guild_id),
Some(channel_id), Some(channel_id),
message_id, message_id,
)) ))
} else if let Some(captures) = DM_RE.captures(input) { } else if let Some(captures) = DM_RE.captures(input) {
let channel_id = captures.parse_id("channel")?; let channel_id = captures.parse_id("channel")?;
let message_id = captures.parse_id("message")?; let message_id = captures.parse_id("message")?;
Ok(ParameterValue::MessageRef( Ok(ParameterValue::MessageRef(
None, None,
Some(channel_id), Some(channel_id),
message_id, message_id,
)) ))
} else {
Err(SmolStr::new("invalid message reference"))
}
} else { } else {
Err(SmolStr::new("invalid message reference")) unreachable!("link and id both cant be false")
} }
} }
ParameterKind::ChannelRef => { ParameterKind::ChannelRef => {
@ -234,7 +251,15 @@ impl Display for Parameter {
ParameterKind::GroupRefs => write!(f, "<group 1> <group 2> <group 3>"), ParameterKind::GroupRefs => write!(f, "<group 1> <group 2> <group 3>"),
ParameterKind::SystemRef => write!(f, "<target system>"), ParameterKind::SystemRef => write!(f, "<target system>"),
ParameterKind::UserRef => write!(f, "<target user>"), ParameterKind::UserRef => write!(f, "<target user>"),
ParameterKind::MessageRef => write!(f, "<target message>"), ParameterKind::MessageRef { link, id } => write!(
f,
"<target message {}>",
link.then_some("link")
.into_iter()
.chain(id.then_some("id"))
.collect::<Vec<_>>()
.join("/")
),
ParameterKind::ChannelRef => write!(f, "<target channel>"), ParameterKind::ChannelRef => write!(f, "<target channel>"),
ParameterKind::GuildRef => write!(f, "<target guild>"), ParameterKind::GuildRef => write!(f, "<target guild>"),
ParameterKind::MemberPrivacyTarget => write!(f, "<privacy target>"), ParameterKind::MemberPrivacyTarget => write!(f, "<privacy target>"),

View file

@ -276,7 +276,7 @@ fn get_param_ty(kind: ParameterKind) -> &'static str {
ParameterKind::PrivacyLevel => "PrivacyLevel", ParameterKind::PrivacyLevel => "PrivacyLevel",
ParameterKind::Toggle => "bool", ParameterKind::Toggle => "bool",
ParameterKind::Avatar => "ParsedImage", ParameterKind::Avatar => "ParsedImage",
ParameterKind::MessageRef => "Message.Reference", ParameterKind::MessageRef { .. } => "Message.Reference",
ParameterKind::ChannelRef => "Channel", ParameterKind::ChannelRef => "Channel",
ParameterKind::GuildRef => "Guild", ParameterKind::GuildRef => "Guild",
ParameterKind::ProxySwitchAction => "SystemConfig.ProxySwitchAction", ParameterKind::ProxySwitchAction => "SystemConfig.ProxySwitchAction",
@ -299,7 +299,7 @@ fn get_param_param_ty(kind: ParameterKind) -> &'static str {
ParameterKind::PrivacyLevel => "PrivacyLevel", ParameterKind::PrivacyLevel => "PrivacyLevel",
ParameterKind::Toggle => "Toggle", ParameterKind::Toggle => "Toggle",
ParameterKind::Avatar => "Avatar", ParameterKind::Avatar => "Avatar",
ParameterKind::MessageRef => "Message", ParameterKind::MessageRef { .. } => "Message",
ParameterKind::ChannelRef => "Channel", ParameterKind::ChannelRef => "Channel",
ParameterKind::GuildRef => "Guild", ParameterKind::GuildRef => "Guild",
ParameterKind::ProxySwitchAction => "ProxySwitchAction", ParameterKind::ProxySwitchAction => "ProxySwitchAction",