main.py 1.5 KB

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