Implement plans
This commit is contained in:
@@ -23,8 +23,15 @@ from core.models import (
|
||||
Message,
|
||||
)
|
||||
|
||||
_BP_SET_RE = re.compile(r"^\s*#bp\s+set#(?P<rest>.*)$", re.IGNORECASE | re.DOTALL)
|
||||
_BP_SET_RANGE_RE = re.compile(r"^\s*#bp\s+set\s+range#(?:.*)$", re.IGNORECASE | re.DOTALL)
|
||||
_BP_ROOT_RE = re.compile(r"^\s*(?:\.bp\b|#bp#?)\s*$", re.IGNORECASE)
|
||||
_BP_SET_RE = re.compile(
|
||||
r"^\s*(?:\.bp\s+set\b|#bp\s+set#?)(?P<rest>.*)$",
|
||||
re.IGNORECASE | re.DOTALL,
|
||||
)
|
||||
_BP_SET_RANGE_RE = re.compile(
|
||||
r"^\s*(?:\.bp\s+set\s+range\b|#bp\s+set\s+range#?)(?:.*)$",
|
||||
re.IGNORECASE | re.DOTALL,
|
||||
)
|
||||
|
||||
|
||||
class BPParsedCommand(dict):
|
||||
@@ -49,17 +56,26 @@ def parse_bp_subcommand(text: str) -> BPParsedCommand:
|
||||
return BPParsedCommand(command=None, remainder_text="")
|
||||
|
||||
|
||||
def bp_subcommands_enabled() -> bool:
|
||||
raw = getattr(settings, "BP_SUBCOMMANDS_V1", True)
|
||||
if raw is None:
|
||||
return True
|
||||
return bool(raw)
|
||||
|
||||
|
||||
def bp_trigger_matches(message_text: str, trigger_token: str, exact_match_only: bool) -> bool:
|
||||
body = str(message_text or "").strip()
|
||||
trigger = str(trigger_token or "").strip()
|
||||
parsed = parse_bp_subcommand(body)
|
||||
if parsed.command and bool(getattr(settings, "BP_SUBCOMMANDS_V1", True)):
|
||||
if parsed.command and bp_subcommands_enabled():
|
||||
return True
|
||||
if _BP_ROOT_RE.match(body):
|
||||
return True
|
||||
if not trigger:
|
||||
return False
|
||||
if exact_match_only:
|
||||
return body == trigger
|
||||
return trigger in body
|
||||
return body.lower() == trigger.lower()
|
||||
return trigger.lower() in body.lower()
|
||||
|
||||
|
||||
def bp_reply_is_optional_for_trigger(message_text: str) -> bool:
|
||||
@@ -119,7 +135,8 @@ class BPCommandHandler(CommandHandler):
|
||||
"generation_mode": str(policy.generation_mode or "verbatim"),
|
||||
"send_plan_to_egress": bool(policy.send_plan_to_egress)
|
||||
and ("post_result" in action_types),
|
||||
"send_status_to_source": bool(policy.send_status_to_source),
|
||||
"send_status_to_source": bool(policy.send_status_to_source)
|
||||
or str(profile.visibility_mode or "") == "status_in_source",
|
||||
"send_status_to_egress": bool(policy.send_status_to_egress),
|
||||
"store_document": bool(getattr(policy, "store_document", True)),
|
||||
}
|
||||
@@ -614,7 +631,7 @@ class BPCommandHandler(CommandHandler):
|
||||
return CommandResult(ok=False, status="skipped", error=run.error)
|
||||
|
||||
parsed = parse_bp_subcommand(ctx.message_text)
|
||||
if parsed.command and bool(getattr(settings, "BP_SUBCOMMANDS_V1", True)):
|
||||
if parsed.command and bp_subcommands_enabled():
|
||||
return await self._execute_set_or_range(
|
||||
trigger=trigger,
|
||||
run=run,
|
||||
|
||||
Reference in New Issue
Block a user