aboutsummaryrefslogtreecommitdiff
path: root/api/ruleset.py
blob: 3dc59f2d23f08024bcf8fb276a2a4790f5ba4dda (plain)
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
27
28
29
30
from mergedeep import merge
import json

rulesets = {
    "default": {
        "timelimit": {
            "enabled": False,
            "minutes": 0,
            "seconds": 0,
            "addmove": 0,
            "shared": False,
        },
        "ranked": True,
    }
}

def resolve_ruleset(ruleset):
    export = {}
    try:
        export = json.loads(ruleset)
        merged = dict(rulesets["default"])
        merge(merged, export)
        export = merged
    except ValueError as e:
        if ruleset in rulesets:
            export = rulesets[ruleset]
    if not export:
        export = rulesets["default"]
    return export