morristech
6/8/2019 - 7:04 PM

Greetbot

import sleekxmpp

def main() :
    bot = GreetBot("echobot@pjlantz.com/HelloWorld", "mypass")
    bot.run()

class GreetBot :
    
    def __init__(self, jid, password) :
        self.xmpp = sleekxmpp.ClientXMPP(jid, password)
        self.xmpp.registerPlugin("xep_0045")
        self.xmpp.add_event_handler("session_start", self.handleXMPPConnected)
                
    def run(self) :
        self.xmpp.connect()
        self.xmpp.process(threaded=False)

    def handleXMPPConnected(self, event):
        self.xmpp.getRoster()
        self.xmpp.sendPresence()
        muc = self.xmpp.plugin["xep_0045"]
        join = muc.joinMUC("test@conference.pjlantz.com", "echobot")
        self.xmpp.sendMessage("test@conference.pjlantz.com", "Hello!", None, "groupchat")

if __name__ == "__main__" :
  main()