[feat]. Add username and custom bot mention tags
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from collections.abc import Iterable
|
||||
|
||||
from gitea_codex_bot.types import ParsedCommand
|
||||
|
||||
COMMAND_RE = re.compile(r"^@codex\s+(review|explain|fix|ignore|rerun)\b(.*)$", re.IGNORECASE | re.DOTALL)
|
||||
COMMAND_RE = re.compile(r"^@([^\s]+)\s+(review|explain|fix|ignore|rerun)\b(.*)$", re.IGNORECASE | re.DOTALL)
|
||||
|
||||
|
||||
def parse_command(body: str) -> ParsedCommand | None:
|
||||
def parse_command(body: str, aliases: Iterable[str] | None = None) -> ParsedCommand | None:
|
||||
stripped = body.strip()
|
||||
match = COMMAND_RE.match(stripped)
|
||||
if not match:
|
||||
return None
|
||||
name = match.group(1).lower()
|
||||
rest = match.group(2).strip()
|
||||
command_alias = match.group(1).lstrip("@").lower()
|
||||
allowed_aliases = {alias.lstrip("@").lower() for alias in (aliases or {"codex"})}
|
||||
if command_alias not in allowed_aliases:
|
||||
return None
|
||||
|
||||
name = match.group(2).lower()
|
||||
rest = match.group(3).strip()
|
||||
tokens = [token for token in rest.split() if token]
|
||||
|
||||
parsed = ParsedCommand(name=name, raw=stripped, arguments=tokens)
|
||||
|
||||
Reference in New Issue
Block a user