PluralKit/crates/command_definitions/src/group.rs

201 lines
7.1 KiB
Rust
Raw Normal View History

use command_parser::token::TokensIterator;
use crate::utils::get_list_flags;
use super::*;
pub fn group() -> (&'static str, [&'static str; 2]) {
("group", ["g", "groups"])
}
pub fn targeted() -> TokensIterator {
tokens!(group(), GroupRef)
}
pub fn cmds() -> impl Iterator<Item = Command> {
let group = group();
let group_target = targeted();
let group_new = tokens!(group, ("new", ["n"]));
let group_new_cmd = [
command!(group_new, Remainder(("name", OpaqueString)) => "group_new")
.help("Creates a new group"),
]
.into_iter();
let group_info_cmd = [command!(group_target => "group_info")
2025-10-08 04:29:48 +00:00
.flag(ALL)
.help("Shows information about a group")]
.into_iter();
let group_name = tokens!(
group_target,
("name", ["rename", "changename", "setname", "rn"])
);
let group_name_cmd = [
command!(group_name => "group_show_name").help("Shows the group's name"),
2025-10-08 04:29:48 +00:00
command!(group_name, CLEAR => "group_clear_name")
.flag(YES)
.help("Clears the group's name"),
command!(group_name, Remainder(("name", OpaqueString)) => "group_rename")
.help("Renames the group"),
]
.into_iter();
let group_display_name = tokens!(group_target, ("displayname", ["dn", "nick", "nickname"]));
let group_display_name_cmd = [
command!(group_display_name => "group_show_display_name")
.help("Shows the group's display name"),
2025-10-08 04:29:48 +00:00
command!(group_display_name, CLEAR => "group_clear_display_name")
.flag(YES)
.help("Clears the group's display name"),
command!(group_display_name, Remainder(("name", OpaqueString)) => "group_change_display_name")
.help("Changes the group's display name"),
]
.into_iter();
let group_description = tokens!(
group_target,
(
"description",
["desc", "describe", "d", "bio", "info", "text", "intro"]
)
);
let group_description_cmd = [
command!(group_description => "group_show_description")
.help("Shows the group's description"),
2025-10-08 04:29:48 +00:00
command!(group_description, CLEAR => "group_clear_description")
.flag(YES)
.help("Clears the group's description"),
command!(group_description, Remainder(("description", OpaqueString)) => "group_change_description")
.help("Changes the group's description"),
]
.into_iter();
let group_icon = tokens!(
group_target,
("icon", ["avatar", "picture", "image", "pic", "pfp"])
);
let group_icon_cmd = [
command!(group_icon => "group_show_icon").help("Shows the group's icon"),
2025-10-08 04:29:48 +00:00
command!(group_icon, CLEAR => "group_clear_icon")
.flag(YES)
.help("Clears the group's icon"),
command!(group_icon, ("icon", Avatar) => "group_change_icon")
.help("Changes the group's icon"),
]
.into_iter();
let group_banner = tokens!(group_target, ("banner", ["splash", "cover"]));
let group_banner_cmd = [
command!(group_banner => "group_show_banner").help("Shows the group's banner"),
2025-10-08 04:29:48 +00:00
command!(group_banner, CLEAR => "group_clear_banner")
.flag(YES)
.help("Clears the group's banner"),
command!(group_banner, ("banner", Avatar) => "group_change_banner")
.help("Changes the group's banner"),
]
.into_iter();
let group_color = tokens!(group_target, ("color", ["colour"]));
let group_color_cmd = [
command!(group_color => "group_show_color").help("Shows the group's color"),
2025-10-08 04:29:48 +00:00
command!(group_color, CLEAR => "group_clear_color")
.flag(YES)
.help("Clears the group's color"),
command!(group_color, ("color", OpaqueString) => "group_change_color")
.help("Changes the group's color"),
]
.into_iter();
let group_privacy = tokens!(group_target, ("privacy", ["priv"]));
let group_privacy_cmd = [
command!(group_privacy => "group_show_privacy")
.help("Shows the group's privacy settings"),
2025-10-08 04:29:48 +00:00
command!(group_privacy, ALL, ("level", PrivacyLevel) => "group_change_privacy_all")
.help("Changes all privacy settings for the group"),
command!(group_privacy, ("privacy", GroupPrivacyTarget), ("level", PrivacyLevel) => "group_change_privacy")
.help("Changes a specific privacy setting for the group"),
]
.into_iter();
let group_public_cmd = [
command!(group_target, ("public", ["pub"]) => "group_set_public")
.help("Sets the group to public"),
]
.into_iter();
let group_private_cmd = [
command!(group_target, ("private", ["priv"]) => "group_set_private")
.help("Sets the group to private"),
]
.into_iter();
let group_delete_cmd = [
command!(group_target, ("delete", ["destroy", "erase", "yeet"]) => "group_delete")
2025-10-08 04:29:48 +00:00
.flag(YES)
.help("Deletes the group"),
]
.into_iter();
let group_id_cmd =
[command!(group_target, "id" => "group_id").help("Shows the group's ID")].into_iter();
let group_front = tokens!(group_target, ("front", ["fronter", "fronters", "f"]));
let group_front_cmd = [
command!(group_front, ("percent", ["p", "%"]) => "group_fronter_percent")
.flag(("duration", OpaqueString))
.flag(("fronters-only", ["fo"]))
.flag("flat"),
]
.into_iter();
let apply_list_opts = |cmd: Command| cmd.flags(get_list_flags());
let search = tokens!(
("search", ["find", "query"]),
Remainder(("query", OpaqueString))
);
let group_list_members = tokens!(group_target, ("members", ["list", "ls"]));
let group_list_members_cmd = [
command!(group_list_members => "group_list_members"),
command!(group_list_members, "list" => "group_list_members"),
command!(group_list_members, search => "group_search_members"),
]
.into_iter()
.map(apply_list_opts);
let group_modify_members_cmd = [
command!(group_target, "add", Optional(MemberRefs) => "group_add_member")
2025-10-08 04:29:48 +00:00
.flag(ALL).flag(YES),
command!(group_target, ("remove", ["delete", "del", "rem"]), Optional(MemberRefs) => "group_remove_member")
2025-10-08 04:29:48 +00:00
.flag(ALL).flag(YES),
]
.into_iter();
let system_groups_cmd = [
command!(group, ("list", ["ls"]) => "group_list_groups"),
command!(group, search => "group_search_groups"),
]
.into_iter()
.map(apply_list_opts);
group_new_cmd
.chain(group_info_cmd)
.chain(group_name_cmd)
.chain(group_display_name_cmd)
.chain(group_description_cmd)
.chain(group_icon_cmd)
.chain(group_banner_cmd)
.chain(group_color_cmd)
.chain(group_privacy_cmd)
.chain(group_public_cmd)
.chain(group_private_cmd)
.chain(group_front_cmd)
.chain(group_modify_members_cmd)
.chain(group_delete_cmd)
.chain(group_id_cmd)
.chain(group_list_members_cmd)
.chain(system_groups_cmd)
}