main.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import config
  2. from EchoBot import JabberBot
  3. import sys
  4. import logging
  5. from argparse import ArgumentParser
  6. import importlib
  7. import asyncio
  8. if __name__ == '__main__':
  9. # Setup the command line arguments.
  10. parser = ArgumentParser(description=JabberBot.__doc__)
  11. # Output verbosity options.
  12. parser.add_argument("-q", "--quiet", help="set logging to ERROR",
  13. action="store_const", dest="loglevel",
  14. const=logging.ERROR, default=logging.INFO)
  15. parser.add_argument("-d", "--debug", help="set logging to DEBUG",
  16. action="store_const", dest="loglevel",
  17. const=logging.DEBUG, default=logging.INFO)
  18. # JID and password options.
  19. parser.add_argument("-b", "--bot", dest="bot",
  20. help="Bot name")
  21. args = parser.parse_args()
  22. # Setup logging.
  23. logging.basicConfig(level=args.loglevel,
  24. format='%(levelname)-8s %(message)s')
  25. if args.bot and args.bot in config.BOTLIST:
  26. module = importlib.import_module("handlers." + args.bot)
  27. JID = module.JID
  28. PASSWORD = module.PASSWORD
  29. start_handler = module.start_handler
  30. message_handler = module.message_handler
  31. bot = JabberBot(JID, PASSWORD)
  32. bot.add_event_handler("message", message_handler)
  33. bot.run()
  34. start_handler(bot)
  35. # bot.stop()
  36. asyncio.get_event_loop().run_forever()
  37. else:
  38. print("Select using -n flag for select availible bot from botlist:\n")
  39. for botname in config.BOTLIST:
  40. print(f"- {botname}")