# HG changeset patch # User Goffi # Date 1472410853 -7200 # Node ID ed33cd382bf956c10329ea081253e622c8488e7d # Parent 24827e5509910682474d0cb0b602ceaf6ee6c33a plugin XEP-0245: removed plugin XEP-0245: at the end it adds complications to handle XEP-0245 in backend (because edge cases must be handled: info type with group chat, history when message is info but for a group chat, etc) while it's trivial to handle it in frontend. So /me detection is handled in QuickFrontend and cmd_me is back into plugin_misc_text_commands, it is the choice of the frontend to display or not the "/me" (for frontends based on QuickFrontend it remains automatic). diff -r 24827e550991 -r ed33cd382bf9 frontends/src/quick_frontend/quick_chat.py --- a/frontends/src/quick_frontend/quick_chat.py Sun Aug 28 20:24:25 2016 +0200 +++ b/frontends/src/quick_frontend/quick_chat.py Sun Aug 28 21:00:53 2016 +0200 @@ -71,6 +71,7 @@ if self.parent.nick.lower() in m.lower(): self._mention = True break + self.handleMe() self.widgets = set() # widgets linked to this message @property @@ -139,6 +140,28 @@ for w in self.widgets: w.updated(["status"]) + def handleMe(self): + """Check if messages starts with "/me " and change them if it is the case + + if several messages (different languages) are presents, they all need to start with "/me " + """ + # TODO: XHTML-IM /me are not handled + me = False + # we need to check /me for every message + for m in self.message.itervalues(): + if m.startswith(u"/me "): + me = True + else: + me = False + break + if me: + self.type = C.MESS_TYPE_INFO + self.extra['info_type'] = 'me' + nick = self.nick + for lang, mess in self.message.iteritems(): + self.message[lang] = u"* " + nick + mess[3:] + + class Occupant(object): """Occupant metadata""" diff -r 24827e550991 -r ed33cd382bf9 src/plugins/plugin_misc_text_commands.py --- a/src/plugins/plugin_misc_text_commands.py Sun Aug 28 20:24:25 2016 +0200 +++ b/src/plugins/plugin_misc_text_commands.py Sun Aug 28 21:00:53 2016 +0200 @@ -31,7 +31,7 @@ "name": "Text commands", "import_name": C.TEXT_CMDS, "type": "Misc", - "protocols": [], + "protocols": ["XEP-0245"], "dependencies": [], "main": "TextCommands", "handler": "no", @@ -351,6 +351,16 @@ return strings + def cmd_me(self, client, mess_data): + """display a message at third person + + @command (all): message + - message: message to show at third person + e.g.: "/me clenches his fist" will give "[YOUR_NICK] clenches his fist" + """ + # We just ignore the command as the match is done on receiption by clients + return True + def cmd_help(self, client, mess_data): """show help on available commands diff -r 24827e550991 -r ed33cd382bf9 src/plugins/plugin_xep_0245.py --- a/src/plugins/plugin_xep_0245.py Sun Aug 28 20:24:25 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -#!/usr/bin/env python2 -# -*- coding: utf-8 -*- - -# SAT plugin for managing xep-245 -# Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -from sat.core.i18n import _ -from sat.core.constants import Const as C -from sat.core.log import getLogger -log = getLogger(__name__) - - -PLUGIN_INFO = { - "name": "XEP-0245 Plugin", - "import_name": "XEP-0245", - "type": "XEP", - "protocols": ["XEP-0245"], - "recommendations": [C.TEXT_CMDS], - "main": "XEP_0245", - "handler": "no", - "description": _("""/me syntax handling""") -} - - -class XEP_0245(object): - - def __init__(self, host): - log.info(_("Plugin XEP_245 initialization")) - self.host = host - try: - self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) - except KeyError: - pass - host.trigger.add("messageSend", self.MessageSendTrigger) - host.trigger.add("MessageReceived", self.MessageReceivedTrigger) - - def handleMe(self, mess_data, client): - """Check if messages starts with "/me " and change them if it is the case - - if several messages (different languages) are presents, they all need to start with "/me " - if it is for a group chat, resource is used as nick, else roster.getNick is used - """ - # TODO: XHTML-IM /me are not handled - for lang, mess in mess_data['message'].iteritems(): - if not mess.startswith('/me '): - # if not all messages start with "/me", no need to continue - return mess_data - try: - nick = mess_data['nick'] - except KeyError: - if mess_data['type'] == C.MESS_TYPE_GROUPCHAT: - nick = mess_data['nick'] = mess_data['from'].resource - else: - from_jid = mess_data['from'] - try: - ent_type = self.host.memory.getEntityDatum(from_jid.userhostJID(), C.ENTITY_TYPE, client.profile) - except KeyError: - ent_type = None - if ent_type == 'MUC': - nick = mess_data['nick'] = from_jid.resource - else: - nick = mess_data['nick'] = client.roster.getNick(from_jid) - mess_data.setdefault('me_update', {})[lang] = u"* {}{}".format(nick, mess[3:]) - - if 'me_update' in mess_data: - mess_data['message'].update(mess_data.pop('me_update')) - mess_data["type"] = C.MESS_TYPE_INFO - mess_data["extra"][C.MESS_EXTRA_INFO] = "me" - return mess_data - - def MessageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): - post_xml_treatments.addCallback(self.handleMe, client) - return True - - def MessageReceivedTrigger(self, client, message_elt, post_treat): - """ Check if source is linked and repeat message, else do nothing """ - post_treat.addCallback(self.handleMe, client) - return True - - def cmd_me(self, client, mess_data): - """display a message at third person - - @command (all): message - - message: message to show at third person - e.g.: "/me clenches his fist" will give "[YOUR_NICK] clenches his fist" - """ - # We just ignore the command as the match is done on receiption by clients - return True