import config from core.JabberBot import JabberBot import logging from argparse import ArgumentParser import importlib if __name__ == '__main__': # Setup the command line arguments. parser = ArgumentParser(description=JabberBot.__doc__) # Output verbosity options. parser.add_argument("-q", "--quiet", help="set logging to ERROR", action="store_const", dest="loglevel", const=logging.ERROR, default=logging.INFO) parser.add_argument("-d", "--debug", help="set logging to DEBUG", action="store_const", dest="loglevel", const=logging.DEBUG, default=logging.INFO) # JID and password options. parser.add_argument("-b", "--bot", dest="bot", help="Bot name") args = parser.parse_args() # Setup logging. logging.basicConfig(level=args.loglevel, format='%(levelname)-8s %(message)s') if args.bot and args.bot in config.BOTLIST: module = importlib.import_module("handlers." + args.bot) start_handler = module.start_handler message_handler = module.message_handler bot = module.bot # Отправляет информацию о присутствии бота, чтобы показать, # что он онлайн и готов к взаимодействию. bot.send_presence() # bot.get_roster() # TODO: Возможно не нужно logging.info(f"Bot {bot.jid} started!") bot.add_event_handler("message", message_handler) # Connect to the XMPP server and start processing XMPP stanzas. bot.connect() start_handler() # TODO: Сделать корректную обработку остановки программы; # Ctrl+C, Ctrl+Z # systemctl stop с последующей отправкой кодов и корректной остановкой программы bot.stop() else: print("Select using -n flag for select availible bot from botlist:\n") for botname in config.BOTLIST: print(f"- {botname}")