Update Discord trade listings
This commit is contained in:
+83
-2
@@ -18,6 +18,9 @@ Use --detailed to additionally export LF / MLF / NLF, hashed authors,
|
||||
repost counts, and update counts. An SQLite database preserves the latest
|
||||
observed listing across multiple processing runs. Process older files first.
|
||||
Reported scam warnings with named accounts go to scammer_warnings.csv.
|
||||
Offer cleanup removes copied channel labels, timestamps, and chat instructions.
|
||||
Standalone SSS stat listings and broad offered options such as "All Gamepasses"
|
||||
remain in the CSV. A broad option does not mean every item will be exchanged.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -75,6 +78,7 @@ UNIT_NAME_RULES = tuple(
|
||||
(r"\bZABUZA\b", "Mist Ninja"),
|
||||
(r"\bDAZAI\b", "Inhuman"),
|
||||
(r"\bILLUSIONIST\b", "Aizen"),
|
||||
(r"\bILLUSIONST\b", "Aizen"),
|
||||
(r"\bFRIEREN\b", "Elf Mage"),
|
||||
(r"\bLORD\s+ALIEN\s+(?:EVO\s+)?KING\b", "Boros"),
|
||||
(r"\bLORD\s+ALIEN\b", "Boros"),
|
||||
@@ -441,6 +445,36 @@ BOILERPLATE = re.compile(
|
||||
r"\(?come with an offer.*|units?|inv|inventory|unit \(all evo\))$",
|
||||
re.I,
|
||||
)
|
||||
NON_ITEM_OFFER = re.compile(
|
||||
r"^(?:channel\s+for\b.*|market\s+in\s+bio|"
|
||||
r"have\s+units\s+to\s+sell\s+or\s+cross\s+trade\b.*|"
|
||||
r"(?:please\s+use\b|total\s+value\s*:)\s*.*|"
|
||||
r"i\s+can\s+also\s+buy\s+things\s+for\s+robux|"
|
||||
r"(?:i\s+answer|i\s+respond)\s+.*|im\s+real\s+human\b.*|"
|
||||
r"(?:no\s+response|ignore)\s*=\s*nty|"
|
||||
r"(?:first\s+of\s+all\s+)?read\s+tiers|"
|
||||
r"(?:no|not\s+looking\s+for)\s+shiny\s+units?|"
|
||||
r"willing\s+to\s+(?:down|up)grade\b.*|"
|
||||
r"(?:just|or\s+send|bring\s+an?|come\s+with\s+an?)\s+offers?\b.*|"
|
||||
r"just\s+offer\s*/\s*dm\s+me|"
|
||||
r"(?:all\s+evoed|all\s+of\s+this\s+are\s+evo|"
|
||||
r"all\s+units?\s+(?:are\s+evolve|have\s+good\s+stats?)|"
|
||||
r"all\s+good\s+stat)|"
|
||||
r"these\s+all\s+till\s+i\s+get\b.*|"
|
||||
r"(?:way\s+to|until)\s+\w+\s+evo\b.*|"
|
||||
r"dont\s+.*?\s+evo\s+unless\b.*|"
|
||||
r"(?:any\s+offer\s+is\s+appreciated|taking\s+offers|"
|
||||
r"reply\s+to\s+all\s+dms|will\s+reply\s+to\s+any\s+offers|"
|
||||
r"feel\s+free\s+to+\s+offer|pls\s+come\s+with\s+an?\s+offer|"
|
||||
r"come\s+with\s+offer|"
|
||||
r"\(?\s*looking\s+for\s+offers\s+on\s+my\s+unit\s*\)?)|"
|
||||
r"(?:also|only|just|pre|pre-trade|offer|offers|my\s+offer|"
|
||||
r"what\s+im|i\s+need|for\?|to\s+end|"
|
||||
r"-?\s*\(\s*(?:units?|stats?|rr|bundles?|gamepass)\s*\)\s*-?|"
|
||||
r"\(?\s*lf\s+offers?\s+too\s*\)?))\s*[:/?.]*$",
|
||||
re.I,
|
||||
)
|
||||
OFFER_TIMESTAMP = re.compile(r"\d+\s*[•·]\s*\d{1,2}:\d{2}")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -1241,6 +1275,39 @@ def is_boilerplate(line: str) -> bool:
|
||||
return bool(BOILERPLATE.fullmatch(simple) or BOILERPLATE.fullmatch(simple.strip(" ()[]")))
|
||||
|
||||
|
||||
def clean_offer_items(offer: str) -> str:
|
||||
"""Remove clear chat/UI fragments while retaining unnamed tradeable items."""
|
||||
# A pipe inside a stat tuple is a separator within one unit, not a new item.
|
||||
offer = re.sub(r"\([^()]*\)|\{[^{}]*\}",
|
||||
lambda match: match.group().replace("|", "/"), offer)
|
||||
kept: list[str] = []
|
||||
for raw in offer.split("|"):
|
||||
segment = raw.strip().strip("'\"").strip()
|
||||
if (not segment or OFFER_TIMESTAMP.fullmatch(segment)
|
||||
or re.fullmatch(r"[\W_]+", segment, re.UNICODE)
|
||||
or NON_ITEM_OFFER.fullmatch(segment)
|
||||
or is_boilerplate(segment)):
|
||||
continue
|
||||
segment = re.sub(r"^'?[+•⟡-]\s*", "", segment)
|
||||
segment = re.sub(r"^(?:also\s+got|can\s+add)\s+", "", segment, flags=re.I)
|
||||
segment = re.sub(r"\(\s*(?:LF|MLF|NOT\s+LOOKING\s+FOR|DM\s+FOR\s+THE\s+STATS)\b[^)]*\)",
|
||||
"", segment, flags=re.I)
|
||||
segment = re.sub(r"\s+(?:dm\s+me(?:\s+good\s+offers)?|i['’]?ll\s+reply|"
|
||||
r"can\s+do\s+any\s+proof\s+u\s+want)\s*$", "", segment, flags=re.I)
|
||||
segment = re.sub(r"\s+-\s*$", "", segment).strip(" ,;")
|
||||
if re.fullmatch(r"(?:SSS|SS|S[+-]?|A[+-]?|B[+-]?)", segment, re.I):
|
||||
if kept and re.search(r"\b(?:SSS|SS|S[+-]?|A[+-]?|B[+-]?)$", kept[-1], re.I):
|
||||
kept[-1] += " / " + segment
|
||||
continue
|
||||
if (re.fullmatch(r"\d+(?:\.\d+)?%", segment) and kept
|
||||
and re.search(r"\bFULL\s+SSS\b", kept[-1], re.I)):
|
||||
kept[-1] += " / " + segment
|
||||
continue
|
||||
if segment and not NON_ITEM_OFFER.fullmatch(segment):
|
||||
kept.append(segment)
|
||||
return " | ".join(kept)
|
||||
|
||||
|
||||
def normalized_chunk(lines: list[str]) -> str:
|
||||
cleaned: list[str] = []
|
||||
for raw in lines:
|
||||
@@ -1403,7 +1470,7 @@ def parse_listing(msg: Message) -> Listing | None:
|
||||
else:
|
||||
return None
|
||||
|
||||
offer = distinct_chunks(groups["offer"])
|
||||
offer = clean_offer_items(distinct_chunks(groups["offer"]))
|
||||
if not offer:
|
||||
return None
|
||||
lf = distinct_chunks(groups["lf"])
|
||||
@@ -1797,7 +1864,21 @@ def export_csv(conn: sqlite3.Connection, output: Path, detailed: bool) -> int:
|
||||
writer.writerow(["offer", "looking_for"])
|
||||
rows = conn.execute("SELECT offer,looking_for FROM trades ORDER BY id")
|
||||
for row in rows:
|
||||
writer.writerow([csv_safe(v) if isinstance(v, str) else v for v in row])
|
||||
offer = clean_offer_items(clean_export_text(row[0]))
|
||||
if not offer:
|
||||
continue
|
||||
values = list(row)
|
||||
if detailed:
|
||||
old_lf = clean_export_text(values[2])
|
||||
moved_offer, lf = split_inline_offer_for(offer, old_lf)
|
||||
if (moved_offer, lf) != (offer, old_lf):
|
||||
values[2] = lf
|
||||
values[1] = Listing("", moved_offer, lf, values[3], values[4]).looking_for
|
||||
offer = moved_offer
|
||||
else:
|
||||
offer, values[1] = split_inline_offer_for(offer, values[1])
|
||||
values[0] = offer
|
||||
writer.writerow([csv_safe(v) if isinstance(v, str) else v for v in values])
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
Reference in New Issue
Block a user