Skip to content

Commit

Permalink
Better cape management
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Dec 1, 2024
1 parent 2293284 commit 1f8837a
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions cape_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def normalize_uuid(uuid: str) -> str:
update_parser.add_argument("-u", "--uuid", action="store_true",
help="Treat the identifier as a UUID")

# List subcommand
list_parser = subparsers.add_parser("list", help="List users with capes")


args = parser.parse_args(sys.argv[1:])

Expand All @@ -63,6 +66,8 @@ def normalize_uuid(uuid: str) -> str:

dev_capes: list[dict[str, str]] = full_data["dev"]

write = True

if args.command == "add":
if args.uuid:
uid = normalize_uuid(args.identifier)
Expand Down Expand Up @@ -103,21 +108,35 @@ def normalize_uuid(uuid: str) -> str:
else:
print(f"Removed cape from {args.identifier}")
elif args.command == "update":
any = False
for entry in dev_capes:
if args.identifier:
if args.uuid and normalize_uuid(entry["id"]) != normalize_uuid(args.identifer):
continue
if not args.uuid and entry["name"] != args.identifier:
continue
any = True
print(f"Updating username for {entry['name']} ({entry['id']})")
old_name = entry["name"]
entry["name"] = uuid_to_uname(entry["name"])
print(f"New username: {entry['name']}")
if entry["name"] == old_name:
print("> Unchanged")
else:
print(f"> New username: {entry['name']}")
if not any:
print(f"Could not find user {args.identifier}")
elif args.command == "list":
write = False
print("Cape holders:")
for entry in dev_capes:
print(f"\t[{entry['id']}] {entry['name']}")
else:
raise ValueError(f"Invalid command {args.command}")

dev_capes = sorted(dev_capes, key=lambda v: v["id"])
if write:
dev_capes = sorted(dev_capes, key=lambda v: v["id"])

full_data["dev"] = dev_capes
full_data["dev"] = dev_capes

with open("dev_capes.json", "w") as f:
json.dump(full_data, f, indent=4)
with open("dev_capes.json", "w") as f:
json.dump(full_data, f, indent=4)

0 comments on commit 1f8837a

Please sign in to comment.