storkit: merge 439_refactor_unify_story_stuck_states_into_a_single_status_field
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
//! that the next `start` invocation picks it up automatically.
|
||||
|
||||
use crate::agents::{AgentPool, AgentStatus};
|
||||
use crate::chat::util::strip_bot_mention;
|
||||
use crate::io::story_metadata::{parse_front_matter, set_front_matter_field};
|
||||
use std::path::Path;
|
||||
|
||||
@@ -43,7 +44,7 @@ pub fn extract_assign_command(
|
||||
bot_name: &str,
|
||||
bot_user_id: &str,
|
||||
) -> Option<AssignCommand> {
|
||||
let stripped = strip_mention(message, bot_name, bot_user_id);
|
||||
let stripped = strip_bot_mention(message, bot_name, bot_user_id);
|
||||
let trimmed = stripped
|
||||
.trim()
|
||||
.trim_start_matches(|c: char| !c.is_alphanumeric());
|
||||
@@ -234,38 +235,6 @@ pub async fn handle_assign(
|
||||
}
|
||||
}
|
||||
|
||||
/// Strip the bot mention prefix from a raw Matrix message body.
|
||||
///
|
||||
/// Mirrors the logic in `commands::strip_bot_mention` and `start::strip_mention`.
|
||||
fn strip_mention<'a>(message: &'a str, bot_name: &str, bot_user_id: &str) -> &'a str {
|
||||
let trimmed = message.trim();
|
||||
if let Some(rest) = strip_prefix_ci(trimmed, bot_user_id) {
|
||||
return rest;
|
||||
}
|
||||
if let Some(localpart) = bot_user_id.split(':').next()
|
||||
&& let Some(rest) = strip_prefix_ci(trimmed, localpart)
|
||||
{
|
||||
return rest;
|
||||
}
|
||||
if let Some(rest) = strip_prefix_ci(trimmed, bot_name) {
|
||||
return rest;
|
||||
}
|
||||
trimmed
|
||||
}
|
||||
|
||||
fn strip_prefix_ci<'a>(text: &'a str, prefix: &str) -> Option<&'a str> {
|
||||
let candidate = text.get(..prefix.len())?;
|
||||
if !candidate.eq_ignore_ascii_case(prefix) {
|
||||
return None;
|
||||
}
|
||||
let rest = &text[prefix.len()..];
|
||||
match rest.chars().next() {
|
||||
None => Some(rest),
|
||||
Some(c) if c.is_alphanumeric() || c == '-' || c == '_' => None,
|
||||
_ => Some(rest),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user