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 re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
USERS = __import__("users").users()
|
||||||
|
except ImportError:
|
||||||
|
USERS = None
|
||||||
|
|
||||||
NUMBER_EMOJI = {
|
NUMBER_EMOJI = {
|
||||||
"zero": "0",
|
"zero": "0",
|
||||||
"one": "1",
|
"one": "1",
|
||||||
|
@ -31,13 +37,20 @@ for line in sys.stdin:
|
||||||
if line.get("type") is not None:
|
if line.get("type") is not None:
|
||||||
continue
|
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"] != "":
|
if "message" in line and line["message"] != "":
|
||||||
message = line["message"]
|
message = line["message"]
|
||||||
message = re.sub(r"^[#>]* *|[*_`]*", "", message)
|
message = re.sub(r"^[#>]* *|[*_`]*", "", message)
|
||||||
for emoji, numb in NUMBER_EMOJI.items():
|
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):
|
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.replace("\ufe0f", "").replace("\u20e3", "")
|
||||||
message = message.strip()
|
message = message.strip()
|
||||||
else:
|
else:
|
||||||
|
@ -45,19 +58,19 @@ for line in sys.stdin:
|
||||||
message = line["metadata"]["files"][0]["name"].split(".")[0]
|
message = line["metadata"]["files"][0]["name"].split(".")[0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
messages.append(
|
messages.append(
|
||||||
f"- [Unrecognized post]({URL_PREFIX}{line['id']})"
|
f"- [Unrecognized post]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.get("edit_at") is not None:
|
if line.get("edit_at") is not None:
|
||||||
messages.append(
|
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)
|
m = re.fullmatch(r"-?[1-9][0-9]*|0", message)
|
||||||
if not m:
|
if not m:
|
||||||
messages.append(
|
messages.append(
|
||||||
f"- Non-number message [{message}]({URL_PREFIX}{line['id']})"
|
f"- Non-number message [{message}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
number = int(m.group(0))
|
number = int(m.group(0))
|
||||||
|
@ -67,28 +80,28 @@ for line in sys.stdin:
|
||||||
second_last_number = number - 2
|
second_last_number = number - 2
|
||||||
|
|
||||||
if number != last_number + 1:
|
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(
|
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:
|
elif number == second_last_number + 1 and last_number != second_last_number + 1:
|
||||||
messages.pop()
|
messages.pop()
|
||||||
messages.append(
|
messages.append(
|
||||||
f"- Stray [{last_number}]({URL_PREFIX}{last_line['id']})"
|
f"- Stray [{last_number}]({URL_PREFIX}{last_line['id']}){last_line['mention']}"
|
||||||
)
|
|
||||||
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}"
|
|
||||||
)
|
)
|
||||||
elif number == last_number + 2:
|
elif number == last_number + 2:
|
||||||
messages.append(
|
messages.append(
|
||||||
f"- Skipped [{last_number + 1}]({URL_PREFIX}{line['id']})"
|
f"- Skipped [{last_number + 1}]({URL_PREFIX}{line['id']}){line['mention']}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
messages.append(
|
messages.append(
|
||||||
f"- Going from [{last_number}]({URL_PREFIX}{last_line['id']}) "
|
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
|
second_last_number = last_number
|
||||||
|
|
Loading…
Reference in a new issue