-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
37 lines (28 loc) · 889 Bytes
/
config.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
27
28
29
30
31
32
33
34
35
36
37
import json
from functools import cache
from typing import Optional, TypedDict
from discord.abc import Snowflake
class AlwaysGiveRole(TypedDict):
discord_user_id: Snowflake
discord_role_id: str
class ConfigData(TypedDict):
guild_id: str
discord_access_token: str
patreon_access_token: str
patreon_campaign_id: str
always_give_roles: Optional[list[AlwaysGiveRole]]
class ConfigurationManager:
__cache: Optional[ConfigData] = None
@classmethod
@cache
def get_config(cls) -> ConfigData:
""" Get the configuration data from configurations.json
:return: the configuration data
"""
# read configuration.json
with open('configuration.json') as f:
if cls.__cache:
return cls.__cache
config = json.load(f)
cls.__cache = config
return config