Răsfoiți Sursa

create exmaple

blezz-tech 1 lună în urmă
părinte
comite
86ae541bee
2 a modificat fișierele cu 89 adăugiri și 0 ștergeri
  1. 22 0
      handlers/EchoBot.py
  2. 67 0
      handlers/main.py

+ 22 - 0
handlers/EchoBot.py

@@ -0,0 +1,22 @@
+import logging
+from getpass import getpass
+from argparse import ArgumentParser
+
+import asyncio
+import slixmpp
+
+
+class EchoBot(slixmpp.ClientXMPP):
+    """
+    EchoBot
+    """
+
+    def __init__(self, jid, password):
+        slixmpp.ClientXMPP.__init__(self, jid, password)
+
+        self.add_event_handler("session_start", self.start)
+
+    async def start(self, event):
+        self.send_presence()
+        await self.get_roster()
+

+ 67 - 0
handlers/main.py

@@ -0,0 +1,67 @@
+import hashlib
+from datetime import datetime
+import config
+import jsonAndRequest as jsreq
+from EchoBot import EchoBot
+
+import logging
+from getpass import getpass
+from argparse import ArgumentParser
+import asyncio
+
+botname = "open_basic_bot"
+operating_status = 0
+
+JID = botname + "@" + config.JSERVER
+PORT = config.PORT
+PASSWORD = hashlib.md5((botname + config.PASSWORD).encode('utf-8')).hexdigest()
+
+
+
+if __name__ == '__main__':
+    # Setup the command line arguments.
+    parser = ArgumentParser(description=EchoBot.__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.jid is None:
+    #     args.jid = input("Username: ")
+    # if args.password is None:
+    #     args.password = getpass("Password: ")
+
+    # Setup the EchoBot and register plugins. Note that while plugins may
+    # have interdependencies, the order in which you register them does
+    # not matter.
+
+    print(JID, PASSWORD)
+
+
+    xmpp = EchoBot(JID, PASSWORD)
+    xmpp.register_plugin('xep_0030') # Service Discovery
+    xmpp.register_plugin('xep_0004') # Data Forms
+    xmpp.register_plugin('xep_0060') # PubSub
+    xmpp.register_plugin('xep_0199') # XMPP Ping
+
+    # Connect to the XMPP server and start processing XMPP stanzas.
+    xmpp.connect()
+
+    xmpp.send_message(JID, "message1")
+    xmpp.send_message(JID, "message2")
+    xmpp.send_message(JID, "message3")
+    asyncio.get_event_loop().run_forever()