Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Nov 26, 2024
1 parent f16d3e6 commit 9eff8fc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def run_bot():
if bl in bots_and_required_configs:
abort = False
for c in bots_and_required_configs[bl]:
if not Config(c):
if not Config(c, _global=True):
Logger.error(f'Bot {bl} requires config {c} but not found, abort to launch.')
abort = True
break
Expand Down
66 changes: 41 additions & 25 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,52 @@ def get(cls,
None] = None,
secret: bool = False,
table_name: Optional[str] = None,
_global: bool = False,
_generate: bool = False) -> Any:
cls.watch()
q = q.lower()
value = None

if not table_name: # if table_name is not provided, search for the value in config.toml tables
for t in cls.values['config'].keys():
if isinstance(cls.values['config'][t], Table):
"""
[config]
foo = bar <- get the value inside the table
"""
if secret:
value = cls.values['config']['secret'].get(q)
if value is not None:
found = True
break
if not _global:
for t in cls.values['config'].keys():
if isinstance(cls.values['config'][t], Table):
"""
[config]
foo = bar <- get the value inside the table
"""
if secret:
value = cls.values['config']['secret'].get(q)
if value is not None:
break
else:
value = cls.values['config']['config'].get(q)
if value is not None:
break
else:
value = cls.values['config']['config'].get(q)
if value is not None:
found = True
"""
foo = bar <- if the item is not a table, assume it's a key-value pair outside the table
[config]
foo = bar
"""
if t == q:
value = cls.values['config'][t]
break
else:
"""
foo = bar <- if the item is not a table, assume it's a key-value pair outside the table
[config]
foo = bar
"""
if t == q:
value = cls.values['config'][t]
found = True
else:
found = False
for t in cls.values.keys(): # search for the value in all tables
for tt in cls.values[t].keys():
if isinstance(cls.values[t][tt], Table):
value = cls.values[t][tt].get(q)
if value is not None:
found = True
break
else:
if tt == q:
value = cls.values[t][tt]
found = True
break
if found:
break
else:
# if table_name is provided, write the value to the specified table
Expand Down Expand Up @@ -335,12 +350,13 @@ def Config(q: str,
secret: bool = False,
table_name: Optional[str] = None,
get_url: bool = False,
_global: bool = False,
_generate: bool = False):
if get_url:
v = CFGManager.get(q, default, str, secret, table_name, _generate)
v = CFGManager.get(q, default, str, secret, table_name, _global, _generate)
if v:
if v[-1] != '/':
v += '/'
else:
v = CFGManager.get(q, default, cfg_type, secret, table_name, _generate)
v = CFGManager.get(q, default, cfg_type, secret, table_name, _global, _generate)
return v

0 comments on commit 9eff8fc

Please sign in to comment.