Mention user of erroneous message
This commit is contained in:
parent
9c57a40387
commit
3181e52c20
1 changed files with 28 additions and 15 deletions
|
@ -4,6 +4,12 @@ import sys
|
|||
import re
|
||||
import json
|
||||
|
||||
|
||||
try:
|
||||
USERS = __import__("users").users()
|
||||
except ImportError:
|
||||
USERS = None
|
||||
|
||||
NUMBER_EMOJI = {
|
||||
"zero": "0",
|
||||
"one": "1",
|
||||
|
@ -31,13 +37,20 @@ for line in sys.stdin:
|
|||
if line.get("type") is not None:
|
||||
continue
|
||||
|
||||
if "user_id" in line and USERS is not None:
|
||||
line["username"] = USERS.get(line["user_id"])
|
||||
if "username" in line:
|
||||
line["mention"] = f" (@{line['username']})"
|
||||
else:
|
||||
line["mention"] = ""
|
||||
|
||||
if "message" in line and line["message"] != "":
|
||||
message = line["message"]
|
||||
message = re.sub(r"^[#>]* *|[*_`]*", "", message)
|
||||
for emoji, numb in NUMBER_EMOJI.items():
|
||||
message = re.sub(f":{emoji}: *", numb, message)
|
||||
message = re.sub(f" *:{emoji}: *", numb, message)
|
||||
for numb in range(0, 9+1):
|
||||
message = re.sub(f":(green)?num{numb}: *", str(numb), message)
|
||||
message = re.sub(f" *:(green)?num{numb}: *", str(numb), message)
|
||||
message = message.replace("\ufe0f", "").replace("\u20e3", "")
|
||||
message = message.strip()
|
||||
else:
|
||||
|
@ -45,19 +58,19 @@ for line in sys.stdin:
|
|||
message = line["metadata"]["files"][0]["name"].split(".")[0]
|
||||
except (KeyError, IndexError):
|
||||
messages.append(
|
||||
f"- [Unrecognized post]({URL_PREFIX}{line['id']})"
|
||||
f"- [Unrecognized post]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||
)
|
||||
continue
|
||||
|
||||
if line.get("edit_at") is not None:
|
||||
messages.append(
|
||||
f"- Edited message [{message}]({URL_PREFIX}{line['id']})"
|
||||
f"- Edited message [{message}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||
)
|
||||
|
||||
m = re.fullmatch(r"-?[1-9][0-9]*|0", message)
|
||||
if not m:
|
||||
messages.append(
|
||||
f"- Non-number message [{message}]({URL_PREFIX}{line['id']})"
|
||||
f"- Non-number message [{message}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||
)
|
||||
else:
|
||||
number = int(m.group(0))
|
||||
|
@ -67,28 +80,28 @@ for line in sys.stdin:
|
|||
second_last_number = number - 2
|
||||
|
||||
if number != last_number + 1:
|
||||
if number == last_number:
|
||||
if number == second_last_number + 2 and last_number != second_last_number + 1:
|
||||
messages.pop()
|
||||
messages.append(
|
||||
f"- Duplicate [{number}]({URL_PREFIX}{line['id']})"
|
||||
f"- [{last_number}]({URL_PREFIX}{last_line['id']}) should have been {number - 1}{last_line['mention']}"
|
||||
)
|
||||
elif number == last_number:
|
||||
messages.append(
|
||||
f"- Duplicate [{number}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||
)
|
||||
elif number == second_last_number + 1 and last_number != second_last_number + 1:
|
||||
messages.pop()
|
||||
messages.append(
|
||||
f"- Stray [{last_number}]({URL_PREFIX}{last_line['id']})"
|
||||
)
|
||||
elif number == second_last_number + 2 and last_number != second_last_number + 1:
|
||||
messages.pop()
|
||||
messages.append(
|
||||
f"- [{last_number}]({URL_PREFIX}{last_line['id']}) should have been {number - 1}"
|
||||
f"- Stray [{last_number}]({URL_PREFIX}{last_line['id']}){last_line['mention']}"
|
||||
)
|
||||
elif number == last_number + 2:
|
||||
messages.append(
|
||||
f"- Skipped [{last_number + 1}]({URL_PREFIX}{line['id']})"
|
||||
f"- Skipped [{last_number + 1}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||
)
|
||||
else:
|
||||
messages.append(
|
||||
f"- Going from [{last_number}]({URL_PREFIX}{last_line['id']}) "
|
||||
f"to [{number}]({URL_PREFIX}{line['id']})"
|
||||
f"to [{number}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||
)
|
||||
|
||||
second_last_number = last_number
|
||||
|
|
Loading…
Reference in a new issue