Изменён парсинг конфига

Добавлена обратная связь
This commit is contained in:
2023-03-28 09:49:46 +03:00
parent 2faebd6e93
commit 42a0579f2e
12 changed files with 76 additions and 92 deletions

View File

@@ -1,32 +1,28 @@
from configparser import ConfigParser
from .module import Config
from easydict import EasyDict as edict
CONFIG_FILE = 'config.ini'
class Configure(Config):
class Configure:
def __init__(self):
self.config = ConfigParser()
config = ConfigParser()
config.read(CONFIG_FILE)
self.data = dict()
self.__readconfig()
def __readconfig(self):
self.config.read(CONFIG_FILE)
for section in self.config.sections():
for section in config.sections():
self.data[section] = dict()
for (key, value) in self.config.items(section):
for key, value in config.items(section):
self.data[section][key] = value
def bot(self, key):
return self.data["Bot"][key]
def db(self, key):
return self.data["DataBase"][key]
def anons(self, key):
return self.data["announcements"][key]
def __getattr__(self, name):
for key in self.data.keys():
if name not in self.data[key]:
continue
return self.data[key][name]
raise NameError("Config options not found!")

View File

@@ -1,54 +0,0 @@
class Config():
@property
def config_folder(self):
return self.config.get("Docs_Settings", "Config_folder").rstrip("/")
@property
def documentid(self):
return self.config.get("Docs_Settings", 'Document_ID')
@property
def token_file(self):
file = self.config.get("Docs_Settings", "token_file")
return (self.config_folder + "/" + file)
@property
def data_file(self):
file = self.config.get("Docs_Settings", "data_file")
return (self.config_folder + "/" + file)
@property
def credentials_file(self):
file = self.config.get("Docs_Settings", "credentials_file")
return (self.config_folder + "/" + file)
@property
def allowed_users(self):
usrs = self.config.get("Users", "allowed_users").split(',')
return [int(user_id) for user_id in usrs]
@property
def admin_user(self):
usrs = self.config.get("Users", "admin_users").split(',')
return [int(user_id) for user_id in usrs]
@property
def exclude_send_msg(self):
usrs = self.config.get("Users", "exclude").split(',')
return [int(user_id) for user_id in usrs]
@property
def telegram_bot_api_server(self):
server = self.config.get("Bot", "telegram_bot_api_server")
if str(server).lower() == "none":
return "https://api.telegram.org"
else:
return server
@property
def logging_user(self):
o = self.config.get("DataBase", "enable_logging")
if o.lower() in ['t', "yes", "true"]:
return True
return False