annotate src/plugins/plugin_exp_parrot.py @ 2046:b99bd02ea643

plugin XEP-0045, XEP-0054, XEP-0096: deprecated bridge method are not used anymore
author Goffi <goffi@goffi.org>
date Sun, 28 Aug 2016 18:20:55 +0200
parents 200cd707a46d
children aa94f33fd2ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
4 # SAT plugin for parrot mode (experimental)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1742
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
10 # (at your option) any later version.
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
15 # GNU Affero General Public License for more details.
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 603
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 697
diff changeset
20 from sat.core.i18n import _
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
21 from sat.core.constants import Const as C
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
22 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
23 log = getLogger(__name__)
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber import jid
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
25
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.exceptions import UnknownEntityError
1374
0befb14ecf62 renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
27 #from sat.tools import trigger
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
28
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
29 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
30 "name": "Parrot Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
31 "import_name": "EXP-PARROT",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
32 "type": "EXP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
33 "protocols": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
34 "dependencies": ["XEP-0045"],
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
35 "recommendations": [C.TEXT_CMDS],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
36 "main": "Exp_Parrot",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
37 "handler": "no",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 "description": _("""Implementation of parrot mode (repeat messages between 2 entities)""")
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
39 }
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
40
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
42 class Exp_Parrot(object):
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
43 """Parrot mode plugin: repeat messages from one entity or MUC room to another one"""
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
44 #XXX: This plugin can be potentially dangerous if we don't trust entities linked
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
45 # this is specially true if we have other triggers.
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
46 # messageSendTrigger avoid other triggers execution, it's deactivated to allow
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
47 # /unparrot command in text commands plugin.
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
48
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
50 log.info(_("Plugin Parrot initialization"))
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.host = host
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
52 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100)
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
53 #host.trigger.add("messageSend", self.messageSendTrigger, priority=100)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
54 try:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
55 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
56 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
57 log.info(_("Text commands not available"))
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
58
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
59 #def messageSendTrigger(self, client, mess_data, treatments):
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
60 # """ Deactivate other triggers if recipient is in parrot links """
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
61 # try:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
62 # _links = client.parrot_links
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
63 # except AttributeError:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
64 # return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
65 #
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
66 # if mess_data['to'].userhostJID() in _links.values():
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
67 # log.debug("Parrot link detected, skipping other triggers")
1374
0befb14ecf62 renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
68 # raise trigger.SkipOtherTriggers
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
69
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
70 def MessageReceivedTrigger(self, client, message_elt, post_treat):
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
71 """ Check if source is linked and repeat message, else do nothing """
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
72 # TODO: many things are not repeated (subject, thread, etc)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
73 profile = client.profile
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
74 client = self.host.getClient(profile)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
75 from_jid = message_elt["from"]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
76
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
77 try:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
78 _links = client.parrot_links
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
79 except AttributeError:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
80 return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
81
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
82 if not from_jid.userhostJID() in _links:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
83 return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
84
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
85 message = {}
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
86 for e in message_elt.elements(C.NS_CLIENT, 'body'):
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
87 body = unicode(e)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
88 lang = e.getAttribute('lang') or ''
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
89
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
90 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
91 entity_type = self.host.memory.getEntityData(from_jid, ['type'], profile)["type"]
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
92 except (UnknownEntityError, KeyError):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
93 entity_type = "contact"
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
94 if entity_type == 'chatroom':
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
95 src_txt = from_jid.resource
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
96 if src_txt == self.host.plugins["XEP-0045"].getRoomNick(client, from_jid.userhostJID()):
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
97 #we won't repeat our own messages
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
98 return True
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
99 else:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
100 src_txt = from_jid.user
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
101 message[lang] = u"[{}] {}".format(src_txt, body)
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
102
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
103 linked = _links[from_jid.userhostJID()]
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
104
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
105 self.host.messageSend(jid.JID(unicode(linked)), message, None, "auto", no_trigger=True, profile_key=profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
106
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
107 return True
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
108
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
109 def addParrot(self, client, source_jid, dest_jid):
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
110 """Add a parrot link from one entity to another one
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
111
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
112 @param source_jid: entity from who messages will be repeated
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
113 @param dest_jid: entity where the messages will be repeated
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
114 """
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
115 try:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
116 _links = client.parrot_links
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
117 except AttributeError:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
118 _links = client.parrot_links = {}
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
119
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
120 _links[source_jid.userhostJID()] = dest_jid
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
121 log.info(u"Parrot mode: %s will be repeated to %s" % (source_jid.userhost(), unicode(dest_jid)))
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
122
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
123 def removeParrot(self, client, source_jid):
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
124 """Remove parrot link
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
125
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
126 @param source_jid: this entity will no more be repeated
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
127 """
526
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
128 try:
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
129 del client.parrot_links[source_jid.userhostJID()]
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
130 except (AttributeError, KeyError):
d67f0ce83530 new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff changeset
131 pass
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
132
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
133 def cmd_parrot(self, client, mess_data):
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
134 """activate Parrot mode between 2 entities, in both directions."""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
135 log.debug("Catched parrot command")
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
136 txt_cmd = self.host.plugins[C.TEXT_CMDS]
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
137
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
138 try:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
139 link_left_jid = jid.JID(mess_data["unparsed"].strip())
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
140 if not link_left_jid.user or not link_left_jid.host:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
141 raise jid.InvalidFormat
1742
244a605623d6 complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
142 except (RuntimeError, jid.InvalidFormat, AttributeError):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
143 txt_cmd.feedBack(client, "Can't activate Parrot mode for invalid jid", mess_data)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
144 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
145
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
146 link_right_jid = mess_data['to']
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
147
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
148 self.addParrot(client, link_left_jid, link_right_jid)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
149 self.addParrot(client, link_right_jid, link_left_jid)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
150
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
151 txt_cmd.feedBack(client, "Parrot mode activated for {}".format(unicode(link_left_jid)), mess_data)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
152
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
153 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
154
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
155 def cmd_unparrot(self, client, mess_data):
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
156 """remove Parrot mode between 2 entities, in both directions."""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 927
diff changeset
157 log.debug("Catched unparrot command")
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
158 txt_cmd = self.host.plugins[C.TEXT_CMDS]
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
159
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
160 try:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
161 link_left_jid = jid.JID(mess_data["unparsed"].strip())
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
162 if not link_left_jid.user or not link_left_jid.host:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
163 raise jid.InvalidFormat
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
164 except jid.InvalidFormat:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
165 txt_cmd.feedBack(client, u"Can't deactivate Parrot mode for invalid jid", mess_data)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
166 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
167
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
168 link_right_jid = mess_data['to']
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
169
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
170 self.removeParrot(client, link_left_jid)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
171 self.removeParrot(client, link_right_jid)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
172
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
173 txt_cmd.feedBack(client, u"Parrot mode deactivated for {} and {}".format(unicode(link_left_jid), unicode(link_right_jid)), mess_data)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
174
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
175 return False