comparison 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
comparison
equal deleted inserted replaced
1001:eb3601ff73bc 1002:291eb8216f6e
45 "name": "XEP 0249 Plugin", 45 "name": "XEP 0249 Plugin",
46 "import_name": "XEP-0249", 46 "import_name": "XEP-0249",
47 "type": "XEP", 47 "type": "XEP",
48 "protocols": ["XEP-0249"], 48 "protocols": ["XEP-0249"],
49 "dependencies": ["XEP-0045"], 49 "dependencies": ["XEP-0045"],
50 "recommendations": [C.TEXT_CMDS],
50 "main": "XEP_0249", 51 "main": "XEP_0249",
51 "handler": "yes", 52 "handler": "yes",
52 "description": _("""Implementation of Direct MUC Invitations""") 53 "description": _("""Implementation of Direct MUC Invitations""")
53 } 54 }
54 55
78 def __init__(self, host): 79 def __init__(self, host):
79 log.info(_("Plugin XEP_0249 initialization")) 80 log.info(_("Plugin XEP_0249 initialization"))
80 self.host = host 81 self.host = host
81 host.memory.updateParams(self.params) 82 host.memory.updateParams(self.params)
82 host.bridge.addMethod("inviteMUC", ".plugin", in_sign='sssa{ss}s', out_sign='', method=self._invite) 83 host.bridge.addMethod("inviteMUC", ".plugin", in_sign='sssa{ss}s', out_sign='', method=self._invite)
84 try:
85 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
86 except KeyError:
87 log.info(_("Text commands not available"))
83 88
84 def getHandler(self, profile): 89 def getHandler(self, profile):
85 return XEP_0249_handler(self) 90 return XEP_0249_handler(self)
86 91
87 def invite(self, target, room, options={}, profile_key=C.PROF_KEY_NONE): 92 def invite(self, target, room, options={}, profile_key=C.PROF_KEY_NONE):
151 if conf_id == room and accepted: 156 if conf_id == room and accepted:
152 self._accept(room, profile) 157 self._accept(room, profile)
153 158
154 if autojoin == "always": 159 if autojoin == "always":
155 self._accept(room, profile) 160 self._accept(room, profile)
156 elif autojoin == "ask": 161 elif autojoin == "never":
162 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)
163 else: # leave the default value here
157 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")} 164 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")}
158 self.host.askConfirmation(room, "YES/NO", data, accept_cb, profile) 165 self.host.askConfirmation(room, "YES/NO", data, accept_cb, profile)
159 else: 166
160 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) 167 def cmd_invite(self, mess_data, profile):
168 """invite someone in the room
169
170 @command (group): (JID)
171 - JID: the JID of the person to invite
172 """
173 log.debug("Catched invite command")
174
175 if mess_data['type'] != "groupchat":
176 self.host.plugins[C.TEXT_CMDS].feedBackWrongContext('invite', 'groupchat', mess_data, profile)
177 return False
178
179 jid_s = mess_data["unparsed"].strip()
180 try:
181 assert(jid_s)
182 jid_ = jid.JID(jid_s)
183 assert(jid_.user)
184 assert(jid_.host)
185 except (jid.InvalidFormat, AssertionError):
186 feedback = _(u"You must provide a valid JID to invite, like in '/invite contact@example.net'")
187 self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile)
188 return False
189
190 self.invite(jid_, mess_data["to"], {}, profile)
191 return False
161 192
162 193
163 class XEP_0249_handler(XMPPHandler): 194 class XEP_0249_handler(XMPPHandler):
164 implements(iwokkel.IDisco) 195 implements(iwokkel.IDisco)
165 196