added permission wrapper
This commit is contained in:
parent
f7042ed8a7
commit
f186e079da
29 changed files with 860 additions and 788 deletions
|
@ -2,17 +2,19 @@ import json
|
|||
import os
|
||||
from typing import List, Mapping, Any, TypedDict
|
||||
from modules.keys import Language
|
||||
import logging
|
||||
import logging
|
||||
import copy
|
||||
|
||||
logger = logging.getLogger("goober")
|
||||
|
||||
|
||||
class MiscBotOptions(TypedDict):
|
||||
ping_line: str
|
||||
active_song: str
|
||||
positive_gifs: List[str]
|
||||
block_profanity: bool
|
||||
|
||||
|
||||
class BotSettings(TypedDict):
|
||||
prefix: str
|
||||
owner_ids: List[int]
|
||||
|
@ -24,6 +26,7 @@ class BotSettings(TypedDict):
|
|||
enabled_cogs: List[str]
|
||||
active_memory: str
|
||||
|
||||
|
||||
class SettingsType(TypedDict):
|
||||
bot: BotSettings
|
||||
locale: Language
|
||||
|
@ -32,20 +35,21 @@ class SettingsType(TypedDict):
|
|||
disable_checks: bool
|
||||
splash_text_loc: str
|
||||
|
||||
|
||||
class Settings:
|
||||
def __init__(self) -> None:
|
||||
self.path: str = os.path.join(".", "settings", "settings.json")
|
||||
|
||||
if not os.path.exists(self.path):
|
||||
raise ValueError("settings.json file does not exist!")
|
||||
|
||||
|
||||
self.settings: SettingsType
|
||||
self.original_settings: SettingsType
|
||||
|
||||
|
||||
with open(self.path, "r") as f:
|
||||
self.__kv_store: dict = json.load(f)
|
||||
|
||||
self.settings = SettingsType(self.__kv_store) # type: ignore
|
||||
|
||||
self.settings = SettingsType(self.__kv_store) # type: ignore
|
||||
self.original_settings = copy.deepcopy(self.settings)
|
||||
|
||||
def commit(self) -> None:
|
||||
|
@ -53,6 +57,6 @@ class Settings:
|
|||
json.dump(self.settings, f, indent=4)
|
||||
|
||||
self.original_settings = self.settings
|
||||
|
||||
|
||||
def discard(self) -> None:
|
||||
self.settings = self.original_settings
|
||||
self.settings = self.original_settings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue