-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdefinitions.py
26 lines (24 loc) · 1.13 KB
/
definitions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import json
class CoCMessageDefinitions:
@classmethod
def read(cls):
messages = {}
for entry in os.scandir(os.path.join(os.path.dirname(os.path.abspath(__file__)), "definitions")):
if entry.is_dir() and entry.name[:1] is not ".":
if entry.name == "component":
messages[entry.name] = {}
for file in os.scandir(entry.path):
if file.name[:1] is not ".":
with open(file.path, 'r') as fh:
data = json.load(fh)
if entry.name == "component":
if "extensions" in data:
extensions = {}
for extension in data["extensions"]:
extensions[extension["id"]] = extension
data["extensions"] = extensions
messages[entry.name][data["name"]] = data
else:
messages[data["id"]] = data
return messages