Mercurial > libervia-backend
diff src/plugins/plugin_xep_0249.py @ 1002:291eb8216f6e
plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
- give a feedback instead of sending the message when the command is invalid or used in a wrong context
- add command /join for XEP-0249
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 30 Apr 2014 16:34:09 +0200 |
parents | 301b342c697a |
children | bf3f669a6052 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0249.py Sun Apr 27 18:51:03 2014 +0200 +++ b/src/plugins/plugin_xep_0249.py Wed Apr 30 16:34:09 2014 +0200 @@ -47,6 +47,7 @@ "type": "XEP", "protocols": ["XEP-0249"], "dependencies": ["XEP-0045"], + "recommendations": [C.TEXT_CMDS], "main": "XEP_0249", "handler": "yes", "description": _("""Implementation of Direct MUC Invitations""") @@ -80,6 +81,10 @@ self.host = host host.memory.updateParams(self.params) host.bridge.addMethod("inviteMUC", ".plugin", in_sign='sssa{ss}s', out_sign='', method=self._invite) + try: + self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) + except KeyError: + log.info(_("Text commands not available")) def getHandler(self, profile): return XEP_0249_handler(self) @@ -153,11 +158,37 @@ if autojoin == "always": self._accept(room, profile) - elif autojoin == "ask": + elif autojoin == "never": + self.host.bridge.newAlert(_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_, 'room': room}, _("MUC invitation"), "INFO", profile) + else: # leave the default value here data = {"message": _("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_, 'room': room}, "title": _("MUC invitation")} self.host.askConfirmation(room, "YES/NO", data, accept_cb, profile) - else: - self.host.bridge.newAlert(_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_, 'room': room}, _("MUC invitation"), "INFO", profile) + + def cmd_invite(self, mess_data, profile): + """invite someone in the room + + @command (group): (JID) + - JID: the JID of the person to invite + """ + log.debug("Catched invite command") + + if mess_data['type'] != "groupchat": + self.host.plugins[C.TEXT_CMDS].feedBackWrongContext('invite', 'groupchat', mess_data, profile) + return False + + jid_s = mess_data["unparsed"].strip() + try: + assert(jid_s) + jid_ = jid.JID(jid_s) + assert(jid_.user) + assert(jid_.host) + except (jid.InvalidFormat, AssertionError): + feedback = _(u"You must provide a valid JID to invite, like in '/invite contact@example.net'") + self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile) + return False + + self.invite(jid_, mess_data["to"], {}, profile) + return False class XEP_0249_handler(XMPPHandler):