Fix duplicate slash name (/media); registry now refuses duplicate slash names

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
astar76 2026-10-24 14:47:42 -05:00
commit b2e8106e8a
2 changed files with 12 additions and 1 deletions

View file

@ -536,7 +536,17 @@ impl Registry {
assert!(old.is_none(), "duplicate command name {name}");
}
}
let slash_index = commands.iter().enumerate().filter(|(_, c)| c.slash).map(|(i, c)| (c.slash_name.unwrap_or(c.name).to_lowercase(), i)).collect();
let mut slash_index = HashMap::new();
for (i, c) in commands.iter().enumerate().filter(|(_, c)| c.slash) {
// Discord refuses the whole command list if two slash commands share a name (a menu entry and a slash command may)
let key = format!("{}:{}", c.message_menu as u8 + 2 * c.user_menu as u8, c.slash_name.unwrap_or(c.name).to_lowercase());
let old = slash_index.insert(c.slash_name.unwrap_or(c.name).to_lowercase(), i);
if let Some(o) = old {
let other = &commands[o];
let same_kind = (other.message_menu, other.user_menu) == (c.message_menu, c.user_menu);
assert!(!same_kind, "two slash commands are both called {key}");
}
}
Self { commands, index, slash_index }
}
pub fn find(&self, name: &str) -> Option<&Command> {

View file

@ -188,6 +188,7 @@ async fn vote(state: &State, channel: Id<ChannelMarker>, message: Id<MessageMark
pub fn commands() -> Vec<Command> {
vec![
Command::new("media", "server", "Make a channel media-only (or back to normal)", |c| media(c).boxed())
.slash_as("mediaonly")
.usage("<lock|unlock> [#channel]")
.opt(Opt::opt("action", "Lock to media-only, or unlock", OptKind::String).choices(&["lock", "unlock"]))
.opt(Opt::opt("channel", "Defaults to this channel", OptKind::Channel))