add x alias for edit -regex

This commit is contained in:
dawn 2026-01-20 00:51:30 +03:00
parent 0a3b15eb45
commit 516eaa5292
No known key found for this signature in database
3 changed files with 29 additions and 5 deletions

View file

@ -1,4 +1,7 @@
use command_parser::parameter::{MESSAGE_LINK, MESSAGE_REF}; use command_parser::{
parameter::{MESSAGE_LINK, MESSAGE_REF},
token::TokensIterator,
};
use super::*; use super::*;
@ -11,6 +14,8 @@ pub fn cmds() -> impl IntoIterator<Item = Command> {
let edit = ("edit", ["e"]); let edit = ("edit", ["e"]);
let new_content_param = Optional(Remainder(("new_content", OpaqueString))); let new_content_param = Optional(Remainder(("new_content", OpaqueString)));
let edit_short_subcmd = tokens!(Optional(MESSAGE_LINK), new_content_param);
let apply_edit = |cmd: Command| { let apply_edit = |cmd: Command| {
cmd.flag(("append", ["a"])) cmd.flag(("append", ["a"]))
.flag(("prepend", ["p"])) .flag(("prepend", ["p"]))
@ -20,14 +25,17 @@ pub fn cmds() -> impl IntoIterator<Item = Command> {
.flag(("clear-attachments", ["clear-attachment", "ca"])) .flag(("clear-attachments", ["clear-attachment", "ca"]))
.help("Edits a previously proxied message") .help("Edits a previously proxied message")
}; };
let make_edit_cmd = |tokens: TokensIterator| apply_edit(command!(tokens => "message_edit"));
[ [
apply_edit(command!(edit, Optional(MESSAGE_LINK), new_content_param => "message_edit")), make_edit_cmd(tokens!(edit, edit_short_subcmd)),
// this one always does regex
make_edit_cmd(tokens!("x", edit_short_subcmd)).flag_value("regex", None),
command!(reproxy, Optional(("msg", MESSAGE_REF)), ("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"),
apply_edit(command!(message, edit, new_content_param => "message_edit")), make_edit_cmd(tokens!(message, edit, new_content_param)),
command!(message => "message_info") command!(message => "message_info")
.flag(delete) .flag(delete)
.flag(author) .flag(author)

View file

@ -1,12 +1,12 @@
use std::{ use std::{
collections::HashSet, collections::{HashMap, HashSet},
fmt::{Debug, Display}, fmt::{Debug, Display},
sync::Arc, sync::Arc,
}; };
use smol_str::SmolStr; use smol_str::SmolStr;
use crate::{flag::Flag, token::Token}; use crate::{flag::Flag, parameter::ParameterValue, token::Token};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Command { pub struct Command {
@ -18,6 +18,7 @@ pub struct Command {
pub show_in_suggestions: bool, pub show_in_suggestions: bool,
pub parse_flags_before: usize, pub parse_flags_before: usize,
pub hidden_flags: HashSet<SmolStr>, pub hidden_flags: HashSet<SmolStr>,
pub flag_values: HashMap<SmolStr, Option<ParameterValue>>,
pub original: Option<Arc<Command>>, pub original: Option<Arc<Command>>,
} }
@ -43,6 +44,7 @@ impl Command {
parse_flags_before, parse_flags_before,
tokens, tokens,
hidden_flags: HashSet::new(), hidden_flags: HashSet::new(),
flag_values: HashMap::new(),
original: None, original: None,
} }
} }
@ -73,6 +75,15 @@ impl Command {
self.flags.insert(flag); self.flags.insert(flag);
self self
} }
pub fn flag_value(
mut self,
flag_name: impl Into<SmolStr>,
value: impl Into<Option<ParameterValue>>,
) -> Self {
self.flag_values.insert(flag_name.into(), value.into());
self
}
} }
impl PartialEq for Command { impl PartialEq for Command {

View file

@ -350,6 +350,11 @@ pub fn parse_command(
.expect("oom"); .expect("oom");
return Err(error); return Err(error);
} }
for (name, value) in &full_cmd.flag_values {
flags.insert(name.to_string(), value.clone());
}
println!("{} {flags:?} {params:?}", command.cb); println!("{} {flags:?} {params:?}", command.cb);
return Ok(ParsedCommand { return Ok(ParsedCommand {
command_def: command, command_def: command,