Skip to content

Commit

Permalink
Merge pull request #3 from Crystalwarrior/master
Browse files Browse the repository at this point in the history
Fix list hubs and musiclist (Crystalwarrior#150)
  • Loading branch information
UnDeviato authored Jul 9, 2024
2 parents 506e1b4 + 8f2f8d7 commit affa364
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
22 changes: 15 additions & 7 deletions server/commands/hubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def ooc_cmd_save_hub(client, arg):
hub = client.area.area_manager.save(ignore=["can_gm", "max_areas"])
if len(args) == 2 and args[1] == "read_only":
hub["read_only"] = True
if "music_ref" in hub and hub["music_ref"] == "unsaved":
del hub["music_ref"]
for i in range(0, len(hub["areas"])):
if "music_ref" in hub["areas"][i] and hub["areas"][i]["music_ref"] == "unsaved":
del hub["areas"][i]["music_ref"]
with open(args[0], "w", encoding="utf-8") as stream:
yaml.dump(
hub,
Expand Down Expand Up @@ -239,13 +244,16 @@ def ooc_cmd_list_hubs(client, arg):
hubs_editable = []
hubs_read_only = []
for F in os.listdir("storage/hubs/"):
if F.lower().endswith(".yaml"):
with open(f"storage/hubs/{F}", "r", encoding="utf-8") as stream:
hub = yaml.safe_load(stream)
if "read_only" in hub and hub["read_only"] is True:
hubs_read_only.append(F[:-5])
else:
hubs_editable.append(F[:-5])
try:
if F.lower().endswith(".yaml"):
with open(f"storage/hubs/{F}", "r", encoding="utf-8") as stream:
hub = yaml.safe_load(stream)
if "read_only" in hub and hub["read_only"] is True:
hubs_read_only.append(F[:-5])
else:
hubs_editable.append(F[:-5])
except:
continue

hubs_read_only.sort()
msg = "\n⛩️ Available Read Only Hubs: ⛩️\n"
Expand Down
25 changes: 14 additions & 11 deletions server/commands/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,20 @@ def ooc_cmd_musiclists(client, arg):
musiclist_editable = []
musiclist_read_only = []
for F in os.listdir("storage/musiclists/"):
if F.lower().endswith(".yaml"):
with open(f"storage/musiclists/{F}", "r", encoding="utf-8") as stream:
musiclist = yaml.safe_load(stream)
read_only = False
for item in musiclist:
if "read_only" in item and item["read_only"] is True:
musiclist_read_only.append(F[:-5])
read_only = True
break
if not read_only:
musiclist_editable.append(F[:-5])
try:
if F.lower().endswith(".yaml"):
with open(f"storage/musiclists/{F}", "r", encoding="utf-8") as stream:
musiclist = yaml.safe_load(stream)
read_only = False
for item in musiclist:
if "read_only" in item and item["read_only"] is True:
musiclist_read_only.append(F[:-5])
read_only = True
break
if not read_only:
musiclist_editable.append(F[:-5])
except:
continue

musiclist_read_only.sort()
msg = "\n🎶 Available Read Only Musiclists: 🎶\n"
Expand Down

0 comments on commit affa364

Please sign in to comment.