mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-15 10:10:12 +00:00
fix reproxy command not accepting member ref
This commit is contained in:
parent
ca9f25ff64
commit
134855f8f8
5 changed files with 52 additions and 19 deletions
|
|
@ -283,7 +283,8 @@ public partial class CommandTree
|
||||||
Commands.MessageAuthor(var param, var flags) => ctx.Execute<ProxiedMessage>(Message, m => m.GetMessage(ctx, param.target.MessageId, flags.GetReplyFormat(), false, true)),
|
Commands.MessageAuthor(var param, var flags) => ctx.Execute<ProxiedMessage>(Message, m => m.GetMessage(ctx, param.target.MessageId, flags.GetReplyFormat(), false, true)),
|
||||||
Commands.MessageDelete(var param, var flags) => ctx.Execute<ProxiedMessage>(Message, m => m.GetMessage(ctx, param.target.MessageId, flags.GetReplyFormat(), true, false)),
|
Commands.MessageDelete(var param, var flags) => ctx.Execute<ProxiedMessage>(Message, m => m.GetMessage(ctx, param.target.MessageId, flags.GetReplyFormat(), true, false)),
|
||||||
Commands.MessageEdit(var param, var flags) => ctx.Execute<ProxiedMessage>(MessageEdit, m => m.EditMessage(ctx, param.target.MessageId, param.new_content, flags.regex, flags.mutate_space, flags.append, flags.prepend, flags.clear_embeds, flags.clear_attachments)),
|
Commands.MessageEdit(var param, var flags) => ctx.Execute<ProxiedMessage>(MessageEdit, m => m.EditMessage(ctx, param.target.MessageId, param.new_content, flags.regex, flags.mutate_space, flags.append, flags.prepend, flags.clear_embeds, flags.clear_attachments)),
|
||||||
Commands.MessageReproxy(var param, _) => ctx.Execute<ProxiedMessage>(MessageReproxy, m => m.ReproxyMessage(ctx, param.msg.MessageId, param.member)),
|
Commands.MessageReproxySpecified(var param, _) => ctx.Execute<ProxiedMessage>(MessageReproxy, m => m.ReproxyMessage(ctx, param.msg.MessageId, param.member)),
|
||||||
|
Commands.MessageReproxy(var param, _) => ctx.Execute<ProxiedMessage>(MessageReproxy, m => m.ReproxyMessage(ctx, null, param.member)),
|
||||||
Commands.Import(var param, var flags) => ctx.Execute<ImportExport>(Import, m => m.Import(ctx, param.url, flags.yes)),
|
Commands.Import(var param, var flags) => ctx.Execute<ImportExport>(Import, m => m.Import(ctx, param.url, flags.yes)),
|
||||||
Commands.Export(_, _) => ctx.Execute<ImportExport>(Export, m => m.Export(ctx)),
|
Commands.Export(_, _) => ctx.Execute<ImportExport>(Export, m => m.Export(ctx)),
|
||||||
Commands.ServerConfigShow => ctx.Execute<ServerConfig>(null, m => m.ShowConfig(ctx)),
|
Commands.ServerConfigShow => ctx.Execute<ServerConfig>(null, m => m.ShowConfig(ctx)),
|
||||||
|
|
|
||||||
|
|
@ -183,15 +183,15 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
||||||
[
|
[
|
||||||
command!(member_keep_proxy => "member_keepproxy_show")
|
command!(member_keep_proxy => "member_keepproxy_show")
|
||||||
.help("Shows a member's keep-proxy setting"),
|
.help("Shows a member's keep-proxy setting"),
|
||||||
command!(member_keep_proxy, Skip(("value", Toggle)) => "member_keepproxy_update")
|
command!(member_keep_proxy, ("value", Toggle) => "member_keepproxy_update")
|
||||||
.help("Changes a member's keep-proxy setting"),
|
.help("Changes a member's keep-proxy setting"),
|
||||||
command!(member_server_keep_proxy => "member_server_keepproxy_show")
|
command!(member_server_keep_proxy => "member_server_keepproxy_show")
|
||||||
.help("Shows a member's server-specific keep-proxy setting"),
|
.help("Shows a member's server-specific keep-proxy setting"),
|
||||||
command!(member_server_keep_proxy, Skip(("value", Toggle)) => "member_server_keepproxy_update")
|
|
||||||
.help("Changes a member's server-specific keep-proxy setting"),
|
|
||||||
command!(member_server_keep_proxy, CLEAR => "member_server_keepproxy_clear")
|
command!(member_server_keep_proxy, CLEAR => "member_server_keepproxy_clear")
|
||||||
.flag(YES)
|
.flag(YES)
|
||||||
.help("Clears a member's server-specific keep-proxy setting"),
|
.help("Clears a member's server-specific keep-proxy setting"),
|
||||||
|
command!(member_server_keep_proxy, ("value", Toggle) => "member_server_keepproxy_update")
|
||||||
|
.help("Changes a member's server-specific keep-proxy setting"),
|
||||||
].into_iter()
|
].into_iter()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ use super::*;
|
||||||
pub fn cmds() -> impl Iterator<Item = Command> {
|
pub fn cmds() -> impl Iterator<Item = Command> {
|
||||||
let message = tokens!(("message", ["msg", "messageinfo"]), MessageRef);
|
let message = tokens!(("message", ["msg", "messageinfo"]), MessageRef);
|
||||||
|
|
||||||
|
let author = ("author", ["sender", "a"]);
|
||||||
|
let delete = ("delete", ["del", "d"]);
|
||||||
|
let reproxy = ("reproxy", ["rp", "crimes", "crime"]);
|
||||||
|
|
||||||
let edit = tokens!(("edit", ["e"]), ("new_content", OpaqueStringRemainder));
|
let edit = tokens!(("edit", ["e"]), ("new_content", OpaqueStringRemainder));
|
||||||
let apply_edit = |cmd: Command| {
|
let apply_edit = |cmd: Command| {
|
||||||
cmd.flag(("append", ["a"]))
|
cmd.flag(("append", ["a"]))
|
||||||
|
|
@ -16,16 +20,16 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
||||||
|
|
||||||
[
|
[
|
||||||
command!(message => "message_info")
|
command!(message => "message_info")
|
||||||
.flag(("delete", ["d"]))
|
.flag(delete)
|
||||||
.flag(("author", ["a"]))
|
.flag(author)
|
||||||
.help("Shows information about a proxied message"),
|
.help("Shows information about a proxied message"),
|
||||||
command!(message, ("author", ["sender"]) => "message_author")
|
command!(message, author => "message_author").help("Shows the author of a proxied message"),
|
||||||
.help("Shows the author of a proxied message"),
|
command!(message, delete => "message_delete").help("Deletes a proxied message"),
|
||||||
command!(message, ("delete", ["del"]) => "message_delete")
|
|
||||||
.help("Deletes a proxied message"),
|
|
||||||
apply_edit(command!(message, edit => "message_edit")),
|
apply_edit(command!(message, edit => "message_edit")),
|
||||||
apply_edit(command!(edit => "message_edit")),
|
apply_edit(command!(edit => "message_edit")),
|
||||||
command!(("reproxy", ["rp", "crimes", "crime"]), ("msg", MessageRef), ("member", MemberRef) => "message_reproxy")
|
command!(reproxy, ("member", MemberRef) => "message_reproxy")
|
||||||
|
.help("Reproxies a message with a different member"),
|
||||||
|
command!(reproxy, ("msg", MessageRef), ("member", MemberRef) => "message_reproxy_specified")
|
||||||
.help("Reproxies a message with a different member"),
|
.help("Reproxies a message with a different member"),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,25 @@ pub fn parse_command(
|
||||||
let mut params: HashMap<String, ParameterValue> = HashMap::new();
|
let mut params: HashMap<String, ParameterValue> = HashMap::new();
|
||||||
let mut raw_flags: Vec<(usize, MatchedFlag)> = Vec::new();
|
let mut raw_flags: Vec<(usize, MatchedFlag)> = Vec::new();
|
||||||
|
|
||||||
|
let mut matched_tokens: Vec<(Tree, (Token, TokenMatchResult, usize))> = Vec::new();
|
||||||
|
let mut filtered_tokens: Vec<Token> = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
println!(
|
println!(
|
||||||
"possible: {:?}",
|
"possible: {:?}",
|
||||||
local_tree.possible_tokens().collect::<Vec<_>>()
|
local_tree
|
||||||
|
.possible_tokens()
|
||||||
|
.filter(|t| filtered_tokens.contains(t))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
);
|
||||||
|
let next = next_token(
|
||||||
|
local_tree
|
||||||
|
.possible_tokens()
|
||||||
|
.filter(|t| !filtered_tokens.contains(t)),
|
||||||
|
&input,
|
||||||
|
current_pos,
|
||||||
);
|
);
|
||||||
let next = next_token(local_tree.possible_tokens(), &input, current_pos);
|
|
||||||
println!("next: {:?}", next);
|
println!("next: {:?}", next);
|
||||||
match next {
|
match &next {
|
||||||
Some((found_token, result, new_pos)) => {
|
Some((found_token, result, new_pos)) => {
|
||||||
match &result {
|
match &result {
|
||||||
// todo: better error messages for these?
|
// todo: better error messages for these?
|
||||||
|
|
@ -74,21 +85,37 @@ pub fn parse_command(
|
||||||
|
|
||||||
// add parameter if any
|
// add parameter if any
|
||||||
if let TokenMatchResult::MatchedParameter { name, value } = result {
|
if let TokenMatchResult::MatchedParameter { name, value } = result {
|
||||||
params.insert(name.to_string(), value);
|
params.insert(name.to_string(), value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// move to the next branch
|
// move to the next branch
|
||||||
if let Some(next_tree) = local_tree.get_branch(&found_token) {
|
if let Some(next_tree) = local_tree.get_branch(&found_token) {
|
||||||
|
matched_tokens.push((
|
||||||
|
local_tree.clone(),
|
||||||
|
(found_token.clone(), result.clone(), *new_pos),
|
||||||
|
));
|
||||||
|
filtered_tokens.clear(); // new branch, new tokens
|
||||||
local_tree = next_tree.clone();
|
local_tree = next_tree.clone();
|
||||||
} else {
|
} else {
|
||||||
panic!("found token {found_token:?} could not match tree, at {input}");
|
panic!("found token {found_token:?} could not match tree, at {input}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance our position on the input
|
// advance our position on the input
|
||||||
current_pos = new_pos;
|
current_pos = *new_pos;
|
||||||
current_token_idx += 1;
|
current_token_idx += 1;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
// redo the previous branches if we didnt match on a parameter
|
||||||
|
// this is a bit of a hack, but its necessary for making parameters on the same depth work
|
||||||
|
if let Some((match_tree, match_next)) = matched_tokens
|
||||||
|
.pop()
|
||||||
|
.and_then(|m| matches!(m.1, (Token::Parameter(_), _, _)).then_some(m))
|
||||||
|
{
|
||||||
|
local_tree = match_tree;
|
||||||
|
filtered_tokens.push(match_next.0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let mut error = format!("Unknown command `{prefix}{input}`.");
|
let mut error = format!("Unknown command `{prefix}{input}`.");
|
||||||
|
|
||||||
let possible_commands =
|
let possible_commands =
|
||||||
|
|
@ -239,7 +266,7 @@ fn next_token<'a>(
|
||||||
possible_tokens: impl Iterator<Item = &'a Token>,
|
possible_tokens: impl Iterator<Item = &'a Token>,
|
||||||
input: &str,
|
input: &str,
|
||||||
current_pos: usize,
|
current_pos: usize,
|
||||||
) -> Option<(&'a Token, TokenMatchResult, usize)> {
|
) -> Option<(Token, TokenMatchResult, usize)> {
|
||||||
// get next parameter, matching quotes
|
// get next parameter, matching quotes
|
||||||
let matched = string::next_param(&input, current_pos);
|
let matched = string::next_param(&input, current_pos);
|
||||||
println!("matched: {matched:?}\n---");
|
println!("matched: {matched:?}\n---");
|
||||||
|
|
@ -267,7 +294,7 @@ fn next_token<'a>(
|
||||||
match token.try_match(input_to_match) {
|
match token.try_match(input_to_match) {
|
||||||
Some(result) => {
|
Some(result) => {
|
||||||
//println!("matched token: {}", token);
|
//println!("matched token: {}", token);
|
||||||
return Some((token, result, next_pos));
|
return Some((token.clone(), result, next_pos));
|
||||||
}
|
}
|
||||||
None => {} // continue matching until we exhaust all tokens
|
None => {} // continue matching until we exhaust all tokens
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub enum Token {
|
||||||
Parameter(Parameter),
|
Parameter(Parameter),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum TokenMatchResult {
|
pub enum TokenMatchResult {
|
||||||
MatchedValue,
|
MatchedValue,
|
||||||
MatchedParameter {
|
MatchedParameter {
|
||||||
|
|
@ -36,6 +36,7 @@ pub enum TokenMatchResult {
|
||||||
// a: because we want to differentiate between no match and match failure (it matched with an error)
|
// a: because we want to differentiate between no match and match failure (it matched with an error)
|
||||||
// "no match" has a different charecteristic because we want to continue matching other tokens...
|
// "no match" has a different charecteristic because we want to continue matching other tokens...
|
||||||
// ...while "match failure" means we should stop matching and return the error
|
// ...while "match failure" means we should stop matching and return the error
|
||||||
|
// Option fits this better (and it makes some code look a bit nicer)
|
||||||
pub type TryMatchResult = Option<TokenMatchResult>;
|
pub type TryMatchResult = Option<TokenMatchResult>;
|
||||||
|
|
||||||
impl Token {
|
impl Token {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue