2025-05-03 17:58:02 +02:00
|
|
|
# SPDX-License-Identifier: MIT
|
2026-02-28 15:24:24 +01:00
|
|
|
# Copyright: 2024-2026 Paillat-dev
|
2025-05-03 17:58:02 +02:00
|
|
|
|
2025-05-03 18:13:58 +02:00
|
|
|
import pathlib
|
2025-05-03 16:22:11 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
from download_build import dowload
|
2025-10-01 20:38:30 +02:00
|
|
|
from parsers import PARSERS
|
2025-05-03 16:22:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
2025-05-03 18:13:58 +02:00
|
|
|
"""Download the latest discord build and extract emojis."""
|
|
|
|
|
build_path = pathlib.Path.cwd() / "build"
|
2025-05-03 16:22:11 +02:00
|
|
|
build_path.mkdir(exist_ok=True)
|
|
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
changes: bool = False
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
build_download: str = dowload()
|
|
|
|
|
for parser_cls in PARSERS:
|
|
|
|
|
parser = parser_cls(build_download)
|
|
|
|
|
out_path = build_path / parser.FILE_NAME
|
|
|
|
|
hash_path = build_path / f".{parser.FILE_NAME}.hash"
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
if not out_path.exists():
|
|
|
|
|
out_path.touch()
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
if hash_path.exists():
|
|
|
|
|
with hash_path.open("r", encoding="utf-8") as hash_file:
|
|
|
|
|
current_hash = hash_file.read()
|
|
|
|
|
else:
|
|
|
|
|
current_hash = ""
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
new_dump: bytes
|
|
|
|
|
new_hash: str
|
|
|
|
|
new_dump, new_hash = parser()
|
|
|
|
|
|
|
|
|
|
if current_hash == new_hash:
|
|
|
|
|
print(f"No changes for {parser.FILE_NAME}")
|
|
|
|
|
continue
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
with out_path.open("wb") as out_file:
|
|
|
|
|
out_file.write(new_dump)
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
with hash_path.open("w", encoding="utf-8") as hash_file:
|
|
|
|
|
hash_file.write(new_hash)
|
2025-05-03 16:22:11 +02:00
|
|
|
|
2025-10-01 20:38:30 +02:00
|
|
|
changes = True
|
|
|
|
|
print("Updated emojis.json")
|
|
|
|
|
|
|
|
|
|
if not changes:
|
|
|
|
|
sys.exit(3) # No changes
|
2025-05-03 16:22:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|