Update Discord trade listings
This commit is contained in:
@@ -34,12 +34,24 @@ UNIT_PATTERN = re.compile(
|
||||
re.IGNORECASE,
|
||||
)
|
||||
MY_PREFIX = re.compile(r"\bmy\s+$", re.IGNORECASE)
|
||||
OWNED_BEFORE_FOR = re.compile(r"\bmy\b[^|]*?\bfor\b", re.IGNORECASE)
|
||||
OWNED_AFTER_FOR = re.compile(r"\bfor\s+my\b[^|]*", re.IGNORECASE)
|
||||
|
||||
|
||||
def variants(text: str, *, request: bool = False) -> set[str]:
|
||||
"""Find explicit unit variants, counting each at most once per side."""
|
||||
found: set[str] = set()
|
||||
owned_spans: list[tuple[int, int]] = []
|
||||
if request:
|
||||
for match in OWNED_BEFORE_FOR.finditer(text):
|
||||
# The units between 'my' and 'for' are the trader's offer.
|
||||
owned_spans.append((match.start(), match.end() - len("for")))
|
||||
for match in OWNED_AFTER_FOR.finditer(text):
|
||||
if not any(start <= match.start() < end for start, end in owned_spans):
|
||||
owned_spans.append((match.start(), match.end()))
|
||||
for match in UNIT_PATTERN.finditer(text):
|
||||
if request and any(start <= match.start() < end for start, end in owned_spans):
|
||||
continue
|
||||
if request and MY_PREFIX.search(text[max(0, match.start() - 12):match.start()]):
|
||||
continue
|
||||
name = CANONICAL_NAMES[canonical_key(match.group("unit"))]
|
||||
|
||||
Reference in New Issue
Block a user