title: SleekXMPP automatically accept all chat room invites
body: <p>I want to use SleekXMPP and automatically accept all chat room invites that are sent to me. I know that the xep_0045 plugin can detect when I receive an invite, as I am notified in the debugger. I am still pretty new to Python and any help would be appreciated.</p>
  
  <p>So far, I've found a function called <code>handle_groupchat_invite</code> in the xep_0045 plugin. Specifically, this code:</p>
  
  <pre><code>def plugin_init(self):
          #...
          self.xmpp.registerHandler(Callback('MUCInvite', MatchXMLMask("&lt;message xmlns='%s'&gt;&lt;x xmlns='http://jabber.org/protocol/muc#user'&gt;&lt;invite&gt;&lt;/invite&gt;&lt;/x&gt;&lt;/message&gt;" % self.xmpp.default_ns), self.handle_groupchat_invite))
  
  #...
  
  def handle_groupchat_invite(self, inv):
          """ Handle an invite into a muc.
          """
          logging.debug("MUC invite to %s from %s: %s", inv['from'], inv["from"], inv)
          if inv['from'].bare not in self.rooms.keys():
              self.xmpp.event("groupchat_invite", inv)
  </code></pre>
  
  <p>So I see this method at work as I see the "MUC invite to..." message in the Terminal log. From there, I would expect that I need to use <code>self.plugin['xep_0045'].joinMUC()</code> to join the chat room's URL (given by <code>inv["from"]</code>). However, I am not exactly sure where I should call this code in my script.</p>
  
  <p>Thanks again for the help.</p>
  
  <p><strong>Update:</strong> I've also tried using <code>add_event_handler</code> in the <code>__init__</code> function. Specifically my code is:</p>
  
  <pre><code>def __init__(self, jid, password, room, nick):
      sleekxmpp.ClientXMPP.__init__(self, jid, password)
  
      self.room = room
      self.nick = nick
  
      # The session_start event will be triggered when
      # the bot establishes its connection with the server
      # and the XML streams are ready for use. We want to
      # listen for this event so that we we can initialize
      # our roster.
      self.add_event_handler("session_start", self.start)
  
      # The groupchat_message event is triggered whenever a message
      # stanza is received from any chat room. If you also also
      # register a handler for the 'message' event, MUC messages
      # will be processed by both handlers.
      self.add_event_handler("groupchat_message", self.muc_message)
  
      # The groupchat_presence event is triggered whenever a
      # presence stanza is received from any chat room, including
      # any presences you send yourself. To limit event handling
      # to a single room, use the events muc::room@server::presence,
      # muc::room@server::got_online, or muc::room@server::got_offline.
      self.add_event_handler("muc::%s::got_online" % self.room,
                             self.muc_online)
  
      self.add_event_hander("groupchat_invite", self.sent_invite)
  </code></pre>
  
  <p>From there, I created the <code>sent_invite</code> function, code is here:</p>
  
  <pre><code>def sent_invite(self, inv):
      self.plugin['xep_0045'].joinMUC(inv["from"], self.nick, wait=True)
  </code></pre>
  
  <p>However, I get the following error when I do this:</p>
  
  <blockquote>
    <p>File "muc.py", line 66, in <strong>init</strong>
        self.add_event_hander("groupchat_invite", self.sent_invite) AttributeError: 'MUCBot' object has no attribute 'add_event_hander'</p>
  </blockquote>
  
  <p>Yet in the xep_0045 plugin I see this code: <code>self.xmpp.event("groupchat_invite", inv)</code>. According to the Event Handlers SleekXMPP <a href="https://github.com/fritzy/SleekXMPP/wiki/Event-Handlers" rel="nofollow">wiki page</a>, </p>
  
  <blockquote>
    <p>Stream events arise whenever particular stanzas are received from the XML stream. Triggered events are created whenever <strong>xmpp.event(name, data)</strong> is called (where xmpp is a SleekXMPP object).</p>
  </blockquote>
  
  <p>Can someone please explain why I am getting the error? I've also tried using </p>
  
  <pre><code>self.add_event_hander("muc::groupchat_invite", self.sent_invite)
  </code></pre>
  
  <p>but also without success.</p>