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).
This commit is contained in:
parent
f378675f78
commit
eb1dd1d177
2 changed files with 34 additions and 102 deletions
|
|
@ -31,7 +31,7 @@ PLUGIN_INFO = {
|
|||
"name": "Text commands",
|
||||
"import_name": C.TEXT_CMDS,
|
||||
"type": "Misc",
|
||||
"protocols": [],
|
||||
"protocols": ["XEP-0245"],
|
||||
"dependencies": [],
|
||||
"main": "TextCommands",
|
||||
"handler": "no",
|
||||
|
|
@ -351,6 +351,16 @@ class TextCommands(object):
|
|||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
Loading…
Reference in a new issue