def update_reminder(self, message): logger.info(f"Reminding user: {message}") bot = Bot(settings.TOKEN) bot.send_message(settings.CHAT_ID, message, parse_mode="MarkdownV2") scheduler.enter( 60 * 60 * 12, 1, update_reminder, )
def pre_run_main() -> None: parser = argparse.ArgumentParser( description="Thanks for using Binance Trade Bot Manager Telegram. " 'By default the program will use "../binance-trade-bot/" as binance-trade-bot installation path.' ) parser.add_argument( "-p", "--path", type=str, help="(optional) binance-trade-bot installation absolute path", default="../binance-trade-bot/", ) parser.add_argument("-t", "--token", type=str, help="(optional) Telegram bot token", default=None) parser.add_argument("-c", "--chat_id", type=str, help="(optional) Telegram chat id", default=None) parser.add_argument( "-d", "--docker", action="store_true", help="(optional) Run the script in a docker container." "NOTE: Run the 'docker_setup.py' file before passing this flag.", ) args = parser.parse_args() if args.docker: run_on_docker() exit(1) settings.ROOT_PATH = args.path settings.TOKEN = args.token settings.CHAT_ID = args.chat_id setup_root_path_constant() if settings.TOKEN is None or settings.CHAT_ID is None: setup_telegram_constants() # Setup update notifications scheduler scheduler.enter(1, 1, update_checker) time.sleep(1) scheduler.run(blocking=False) return False
def update_checker(): logger.info("Checking for updates.") if settings.TG_UPDATE_BROADCASTED_BEFORE is False: if is_tg_bot_update_available(): logger.info("BTB Manager Telegram update found.") message = ( "⚠An update for _BTB Manager Telegram_ is available\.\n\n" "Please update by going to *🛠Maintenance* and pressing the *⬆ Update Telegram Bot* button\." ) settings.TG_UPDATE_BROADCASTED_BEFORE = True bot = Bot(settings.TOKEN) bot.send_message(settings.CHAT_ID, message, parse_mode="MarkdownV2") sleep(1) bot.close() sleep(1) scheduler.enter( 60 * 60 * 12, 1, update_reminder, ("_*Reminder*_:\n\n" + message, ), ) if settings.BTB_UPDATE_BROADCASTED_BEFORE is False: if is_btb_bot_update_available(): logger.info("Binance Trade Bot update found.") message = ( "⚠An update for _Binance Trade Bot_ is available\.\n\n" "Please update by going to *🛠Maintenance* and pressing the *Update Binance Trade Bot* button\." ) settings.BTB_UPDATE_BROADCASTED_BEFORE = True bot = Bot(settings.TOKEN) bot.send_message(settings.CHAT_ID, message, parse_mode="MarkdownV2") sleep(1) bot.close() sleep(1) scheduler.enter( 60 * 60 * 12, 1, update_reminder, ("_*Reminder*_:\n\n" + message, ), ) if (settings.TG_UPDATE_BROADCASTED_BEFORE is False or settings.BTB_UPDATE_BROADCASTED_BEFORE is False): sleep(1) scheduler.enter( 60 * 60, 1, update_checker, )
def pre_run_main() -> None: parser = argparse.ArgumentParser( description="Thanks for using Binance Trade Bot Manager Telegram. " 'By default the program will use "../binance-trade-bot/" as binance-trade-bot installation path.' ) parser.add_argument( "-p", "--path", type=str, help="(optional) binance-trade-bot installation path.", default="../binance-trade-bot/", ) parser.add_argument( "-pp", "--python_path", type=str, help= "(optional) Python binary to be used for the BTB. If unset, uses the same executable (and thus virtual env if any) than the telegram bot.", default=sys.executable, ) parser.add_argument("-t", "--token", type=str, help="(optional) Telegram bot token", default=None) parser.add_argument("-c", "--chat_id", type=str, help="(optional) Telegram chat id", default=None) parser.add_argument( "-d", "--docker", action="store_true", help="(optional) Run the script in a docker container." "NOTE: Run the 'docker_setup.py' file before passing this flag.", ) args = parser.parse_args() if args.docker: run_on_docker() exit(1) settings.ROOT_PATH = args.path settings.PYTHON_PATH = args.python_path settings.TOKEN = args.token settings.CHAT_ID = args.chat_id settings.RAW_ARGS = " ".join(sys.argv[1:]) setup_root_path_constant() if settings.TOKEN is None or settings.CHAT_ID is None: setup_telegram_constants() # Setup update notifications scheduler scheduler.enter(1, 1, update_checker) time.sleep(1) scheduler.run(blocking=False) return False