mirror of
https://github.com/Noettore/lagomareGateKeeperBot.git
synced 2025-10-15 03:26:40 +02:00
Complete refactor... Some issue...
This commit is contained in:
59
config.py
59
config.py
@@ -1,21 +1,50 @@
|
||||
import json
|
||||
from telegram import BotCommand
|
||||
|
||||
ACCESS_FILE = "./data/config.json"
|
||||
class BotConfig:
|
||||
|
||||
def load_config():
|
||||
try:
|
||||
with open(ACCESS_FILE, "r") as f:
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
def __init__(self, bot_username: str, json_path: str = "./data/config.json"):
|
||||
self._json_path: str = json_path
|
||||
self._bot_username: str = bot_username
|
||||
self._token: str = ""
|
||||
self._name: str = ""
|
||||
self._description: str = ""
|
||||
self._short_description: str = ""
|
||||
self._commands: list[BotCommand] = []
|
||||
|
||||
def get_bot_token(bot_name):
|
||||
config = load_config().get(str(bot_name), {})
|
||||
return config.get("token", "")
|
||||
self._load_config()
|
||||
|
||||
def _load_config(self):
|
||||
try:
|
||||
with open(self._json_path, "r") as f:
|
||||
config = json.load(f).get(self._bot_username, {})
|
||||
self._token = config.get("token", "")
|
||||
self._name = config.get("name", "")
|
||||
self._description = config.get("description", "")
|
||||
self._short_description = config.get("short_description", "")
|
||||
self._commands = [
|
||||
BotCommand(command, description)
|
||||
for command, description in config.get("commands", {}).items()
|
||||
]
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def get_commands(bot_name):
|
||||
config = load_config().get(str(bot_name), {})
|
||||
commands = config.get("commands", {})
|
||||
bot_commands = []
|
||||
return [BotCommand(command, description) for command, description in commands.items()]
|
||||
@property
|
||||
def token(self) -> str:
|
||||
return self._token
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@property
|
||||
def short_description(self) -> str:
|
||||
return self._short_description
|
||||
|
||||
@property
|
||||
def commands(self) -> list[BotCommand]:
|
||||
return self._commands
|
Reference in New Issue
Block a user