1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import config
- from EchoBot import JabberBot
- import sys
- import logging
- from argparse import ArgumentParser
- 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 = __import__("handlers." + args.bot)
- print(module.JID)
- JID = module.JID
- PASSWORD = module.PASSWORD
- fn_start_handler = module.start_handler
- fn_message = module.message
- bot = JabberBot(JID, PASSWORD)
- bot.add_event_handler("message", fn_message)
- bot.run()
- fn_start_handler(bot)
- bot.stop()
- else:
- print("Select using -n flag for select availible bot from botlist:\n")
- for botname in config.BOTLIST:
- print(f"- {botname}")
|