def bot_runner(thread_statuses, q_offer, bot_settings_file, bot_configs_dir): """ Function creates a Telegram Bot and supplies it with offers from q_offer queue. :param thread_statuses: used for debugging and checking up on threads :param q_offer: offers which are supplied to the bot :param bot_settings_file: settings file path :param bot_configs_dir: configs directory path """ # Starting the bot thread_statuses[current_thread().name] = "Booting" try: bot = TelegramBot(bot_settings_file, bot_configs_dir) except Exception as err: thread_statuses[current_thread().name] = "Error -- %s" % err.__str__() return bot.start() while not current_thread().is_stopped(): thread_statuses[current_thread().name] = "Waiting" while q_offer.qsize() > 0: # Get an offer and update status thread_statuses[current_thread().name] = "Work %02d" % q_offer.qsize() offer = q_offer.get() # Process the offer (and send it if that's needed bot.process_offer(offer) bot.stop() thread_statuses[current_thread().name] = "Stopped"
ssl_context, subnet_filters) else: raise ValueError( "Unknown scanner type. Should be one of ['arping', 'routeros_api']" ) scanner.set_new_device_alert(new_device_alert) bot = TelegramBot(TOKEN, BotMainState) bot.allow_chat(ADMIN_CHAT) print("Starting bot...") bot.start() print("Bot started") print("Starting scanner...") scanner.start() print("Scanner started") try: while True: sleep(300) except KeyboardInterrupt as e: print("Interrupted") print("Stop bot") bot.stop() print("Stop scanner") scanner.stop() print("Exit") sys.exit(e)