mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2026-01-24 00:52:59 -05:00
[Config] Asynchronous getters (#907)
* Make config get async * Asyncify alias * Asyncify bank * Asyncify cog manager * IT BOOTS * Asyncify core commands * Asyncify repo manager * Asyncify downloader * Asyncify economy * Asyncify alias TESTS * Asyncify economy TESTS * Asyncify downloader TESTS * Asyncify config TESTS * A bank thing * Asyncify Bank cog * Warning message in docs * Update docs with await syntax * Update docs with await syntax
This commit is contained in:
27
main.py
27
main.py
@@ -73,6 +73,17 @@ def determine_main_folder() -> Path:
|
||||
return Path(os.path.dirname(__file__)).resolve()
|
||||
|
||||
|
||||
async def _get_prefix_and_token(red, indict):
|
||||
"""
|
||||
Again, please blame <@269933075037814786> for this.
|
||||
:param indict:
|
||||
:return:
|
||||
"""
|
||||
indict['token'] = await red.db.token()
|
||||
indict['prefix'] = await red.db.prefix()
|
||||
indict['enable_sentry'] = await red.db.enable_sentry()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli_flags = parse_cli_flags()
|
||||
log, sentry_log = init_loggers(cli_flags)
|
||||
@@ -89,8 +100,13 @@ if __name__ == '__main__':
|
||||
if cli_flags.dev:
|
||||
red.add_cog(Dev())
|
||||
|
||||
token = os.environ.get("RED_TOKEN", red.db.token())
|
||||
prefix = cli_flags.prefix or red.db.prefix()
|
||||
loop = asyncio.get_event_loop()
|
||||
tmp_data = {}
|
||||
loop.run_until_complete(_get_prefix_and_token(red, tmp_data))
|
||||
|
||||
token = os.environ.get("RED_TOKEN", tmp_data['token'])
|
||||
prefix = cli_flags.prefix or tmp_data['prefix']
|
||||
enable_sentry = tmp_data['enable_sentry']
|
||||
|
||||
if token is None or not prefix:
|
||||
if cli_flags.no_prompt is False:
|
||||
@@ -102,13 +118,14 @@ if __name__ == '__main__':
|
||||
log.critical("Token and prefix must be set in order to login.")
|
||||
sys.exit(1)
|
||||
|
||||
if red.db.enable_sentry() is None:
|
||||
if enable_sentry is None:
|
||||
ask_sentry(red)
|
||||
|
||||
if red.db.enable_sentry():
|
||||
loop.run_until_complete(_get_prefix_and_token(red, tmp_data))
|
||||
|
||||
if tmp_data['enable_sentry']:
|
||||
init_sentry_logging(sentry_log)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
cleanup_tasks = True
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user