mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Core] Improved exit codes handling
Clean exits on crashes should not happen anymore
This commit is contained in:
parent
bc20177d36
commit
7b6dbd201e
16
red.py
16
red.py
@ -66,7 +66,7 @@ class Bot(commands.Bot):
|
||||
self._message_modifiers = []
|
||||
self.settings = Settings()
|
||||
self._intro_displayed = False
|
||||
self._restart_requested = False
|
||||
self._shutdown_mode = None
|
||||
self.logger = set_logger(self)
|
||||
if 'self_bot' in kwargs:
|
||||
self.settings.self_bot = kwargs['self_bot']
|
||||
@ -101,8 +101,7 @@ class Bot(commands.Bot):
|
||||
|
||||
If restart is True, the exit code will be 26 instead
|
||||
The launcher automatically restarts Red when that happens"""
|
||||
if restart:
|
||||
self._restart_requested = True
|
||||
self._shutdown_mode = not restart
|
||||
await self.logout()
|
||||
|
||||
def add_message_modifier(self, func):
|
||||
@ -594,12 +593,10 @@ if __name__ == '__main__':
|
||||
errors="replace",
|
||||
line_buffering=True)
|
||||
bot = initialize()
|
||||
error = False
|
||||
loop = asyncio.get_event_loop()
|
||||
try:
|
||||
loop.run_until_complete(main(bot))
|
||||
except discord.LoginFailure:
|
||||
error = True
|
||||
bot.logger.error(traceback.format_exc())
|
||||
if not bot.settings.no_prompt:
|
||||
choice = input("Invalid login credentials. If they worked before "
|
||||
@ -616,13 +613,14 @@ if __name__ == '__main__':
|
||||
except KeyboardInterrupt:
|
||||
loop.run_until_complete(bot.logout())
|
||||
except Exception as e:
|
||||
error = True
|
||||
bot.logger.exception("Fatal exception, attempting graceful logout",
|
||||
exc_info=e)
|
||||
loop.run_until_complete(bot.logout())
|
||||
finally:
|
||||
loop.close()
|
||||
if error:
|
||||
if bot._shutdown_mode is True:
|
||||
exit(0)
|
||||
elif bot._shutdown_mode is False:
|
||||
exit(26) # Restart
|
||||
else:
|
||||
exit(1)
|
||||
if bot._restart_requested:
|
||||
exit(26)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user