main.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import hashlib
  2. from datetime import datetime
  3. import config
  4. import jsonAndRequest as jsreq
  5. from EchoBot import EchoBot
  6. import logging
  7. from getpass import getpass
  8. from argparse import ArgumentParser
  9. import asyncio
  10. botname = "open_basic_bot"
  11. operating_status = 0
  12. JID = botname + "@" + config.JSERVER
  13. PORT = config.PORT
  14. PASSWORD = hashlib.md5((botname + config.PASSWORD).encode('utf-8')).hexdigest()
  15. if __name__ == '__main__':
  16. # Setup the command line arguments.
  17. parser = ArgumentParser(description=EchoBot.__doc__)
  18. # Output verbosity options.
  19. parser.add_argument("-q", "--quiet", help="set logging to ERROR",
  20. action="store_const", dest="loglevel",
  21. const=logging.ERROR, default=logging.INFO)
  22. parser.add_argument("-d", "--debug", help="set logging to DEBUG",
  23. action="store_const", dest="loglevel",
  24. const=logging.DEBUG, default=logging.INFO)
  25. # JID and password options.
  26. # parser.add_argument("-b", "--bot", dest="bot",
  27. # help="Bot name")
  28. args = parser.parse_args()
  29. # Setup logging.
  30. logging.basicConfig(level=args.loglevel,
  31. format='%(levelname)-8s %(message)s')
  32. # if args.jid is None:
  33. # args.jid = input("Username: ")
  34. # if args.password is None:
  35. # args.password = getpass("Password: ")
  36. # Setup the EchoBot and register plugins. Note that while plugins may
  37. # have interdependencies, the order in which you register them does
  38. # not matter.
  39. print(JID, PASSWORD)
  40. xmpp = EchoBot(JID, PASSWORD)
  41. xmpp.register_plugin('xep_0030') # Service Discovery
  42. xmpp.register_plugin('xep_0004') # Data Forms
  43. xmpp.register_plugin('xep_0060') # PubSub
  44. xmpp.register_plugin('xep_0199') # XMPP Ping
  45. # Connect to the XMPP server and start processing XMPP stanzas.
  46. xmpp.connect()
  47. xmpp.send_message(JID, "message1")
  48. xmpp.send_message(JID, "message2")
  49. xmpp.send_message(JID, "message3")
  50. asyncio.get_event_loop().run_forever()