Update Discord trade listings

This commit is contained in:
2026-11-20 00:40:07 +01:00
parent f37559ad6a
commit af8b173abd
13 changed files with 2120 additions and 996 deletions
+12
View File
@@ -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"))]