def stop(self, _, main_bot=True):
    if (not BotCache(main_bot).exists()):
        return log.error('Could not stop the bot (cache file does not exist)')
    bot_cache = BotCache(main_bot).parse()
    pid = bot_cache['pid']
    if (pid is None):
        return log.error('Could not stop the bot (cache file does not contain pid)')
    if psutil.pid_exists(pid):
        if (sys.platform == 'win32'):
            import ctypes
            kernel = ctypes.windll.kernel32
            kernel.FreeConsole()
            kernel.AttachConsole(pid)
            kernel.SetConsoleCtrlHandler(None, 1)
            kernel.GenerateConsoleCtrlEvent(0, 0)
        else:
            os.kill(pid, signal.SIGINT)
        while psutil.pid_exists(pid):
            log.debug('Bot is still running. Please, wait...')
            time.sleep(0.5)
        log.info('Bot is stopped!')
    else:
        log.error('Could not stop the bot (bot is not running)')
        BotCache(main_bot).remove()
def stop(self, _, main_bot=True):
    if (not BotCache(main_bot).exists()):
        return log.error('Could not stop the bot (cache file does not exist)')
    bot_cache = BotCache(main_bot).parse()
    pid = bot_cache['pid']
    if (pid is None):
        return log.error('Could not stop the bot (cache file does not contain pid)')
    if psutil.pid_exists(pid):
        if (sys.platform == 'win32'):
            import ctypes
            kernel = ctypes.windll.kernel32
            kernel.FreeConsole()
            kernel.AttachConsole(pid)
            kernel.SetConsoleCtrlHandler(None, 1)
            kernel.GenerateConsoleCtrlEvent(0, 0)
        else:
            os.kill(pid, signal.SIGINT)
        while psutil.pid_exists(pid):
            log.debug('Bot is still running. Please, wait...')
            time.sleep(0.5)
        log.info('Bot is stopped!')
    else:
        log.error('Could not stop the bot (bot is not running)')
        BotCache(main_bot).remove()