mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix pk;e taking in id, only take message ref
This commit is contained in:
parent
aec01d6245
commit
5daa4777f5
4 changed files with 73 additions and 44 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use command_parser::parameter::MESSAGE_REF;
|
||||
|
||||
use super::*;
|
||||
|
||||
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"),
|
||||
command!(debug, perms, ("guild", ["g"]), GuildRef => "permcheck_guild")
|
||||
.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"),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use command_parser::parameter::{MESSAGE_LINK, MESSAGE_REF};
|
||||
|
||||
use super::*;
|
||||
|
||||
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 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")),
|
||||
command!(reproxy, Optional(("msg", MessageRef)), ("member", MemberRef) => "message_reproxy")
|
||||
apply_edit(command!(edit, Optional(MESSAGE_LINK), new_content_param => "message_edit")),
|
||||
command!(reproxy, Optional(("msg", MESSAGE_REF)), ("member", MemberRef) => "message_reproxy")
|
||||
.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, delete => "message_delete").help("Deletes a proxied message"),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,15 @@ use smol_str::{SmolStr, format_smolstr};
|
|||
|
||||
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)]
|
||||
pub enum ParameterKind {
|
||||
OpaqueString,
|
||||
|
|
@ -18,7 +27,7 @@ pub enum ParameterKind {
|
|||
GroupRefs,
|
||||
SystemRef,
|
||||
UserRef,
|
||||
MessageRef,
|
||||
MessageRef { id: bool, link: bool },
|
||||
ChannelRef,
|
||||
GuildRef,
|
||||
MemberPrivacyTarget,
|
||||
|
|
@ -41,7 +50,7 @@ impl ParameterKind {
|
|||
ParameterKind::GroupRefs => "targets",
|
||||
ParameterKind::SystemRef => "target",
|
||||
ParameterKind::UserRef => "target",
|
||||
ParameterKind::MessageRef => "target",
|
||||
ParameterKind::MessageRef { .. } => "target",
|
||||
ParameterKind::ChannelRef => "target",
|
||||
ParameterKind::GuildRef => "target",
|
||||
ParameterKind::MemberPrivacyTarget => "member_privacy_target",
|
||||
|
|
@ -153,11 +162,14 @@ impl Parameter {
|
|||
Toggle::from_str(input).map(|t| ParameterValue::Toggle(t.into()))
|
||||
}
|
||||
ParameterKind::Avatar => Ok(ParameterValue::Avatar(input.into())),
|
||||
ParameterKind::MessageRef => {
|
||||
ParameterKind::MessageRef { id, link } => {
|
||||
if id {
|
||||
if let Ok(message_id) = input.parse::<u64>() {
|
||||
return Ok(ParameterValue::MessageRef(None, None, message_id));
|
||||
}
|
||||
}
|
||||
|
||||
if link {
|
||||
static SERVER_RE: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(
|
||||
|| {
|
||||
regex::Regex::new(
|
||||
|
|
@ -167,12 +179,14 @@ impl Parameter {
|
|||
},
|
||||
);
|
||||
|
||||
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+)",
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(captures) = SERVER_RE.captures(input) {
|
||||
let guild_id = captures.parse_id("guild")?;
|
||||
|
|
@ -196,6 +210,9 @@ impl Parameter {
|
|||
} else {
|
||||
Err(SmolStr::new("invalid message reference"))
|
||||
}
|
||||
} else {
|
||||
unreachable!("link and id both cant be false")
|
||||
}
|
||||
}
|
||||
ParameterKind::ChannelRef => {
|
||||
let mut text = input;
|
||||
|
|
@ -234,7 +251,15 @@ impl Display for Parameter {
|
|||
ParameterKind::GroupRefs => write!(f, "<group 1> <group 2> <group 3>"),
|
||||
ParameterKind::SystemRef => write!(f, "<target system>"),
|
||||
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::GuildRef => write!(f, "<target guild>"),
|
||||
ParameterKind::MemberPrivacyTarget => write!(f, "<privacy target>"),
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ fn get_param_ty(kind: ParameterKind) -> &'static str {
|
|||
ParameterKind::PrivacyLevel => "PrivacyLevel",
|
||||
ParameterKind::Toggle => "bool",
|
||||
ParameterKind::Avatar => "ParsedImage",
|
||||
ParameterKind::MessageRef => "Message.Reference",
|
||||
ParameterKind::MessageRef { .. } => "Message.Reference",
|
||||
ParameterKind::ChannelRef => "Channel",
|
||||
ParameterKind::GuildRef => "Guild",
|
||||
ParameterKind::ProxySwitchAction => "SystemConfig.ProxySwitchAction",
|
||||
|
|
@ -299,7 +299,7 @@ fn get_param_param_ty(kind: ParameterKind) -> &'static str {
|
|||
ParameterKind::PrivacyLevel => "PrivacyLevel",
|
||||
ParameterKind::Toggle => "Toggle",
|
||||
ParameterKind::Avatar => "Avatar",
|
||||
ParameterKind::MessageRef => "Message",
|
||||
ParameterKind::MessageRef { .. } => "Message",
|
||||
ParameterKind::ChannelRef => "Channel",
|
||||
ParameterKind::GuildRef => "Guild",
|
||||
ParameterKind::ProxySwitchAction => "ProxySwitchAction",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue