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
This commit is contained in:
souliane 2014-04-30 16:34:09 +02:00
commit 42b1b6c4ed

View file

@ -47,6 +47,7 @@ PLUGIN_INFO = {
"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 @@ class XEP_0249(object):
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 @@ class XEP_0249(object):
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):