Mercurial > libervia-backend
annotate src/plugins/plugin_exp_parrot.py @ 975:b37b1d183ac3
reverted changeset 5c7707c958d8 (revision 969)
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 03 Apr 2014 14:38:48 +0200 |
parents | cd150dd947e3 |
children | 301b342c697a |
rev | line source |
---|---|
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
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) |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 | 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 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from logging import debug, info, warning, error |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 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
|
24 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core.exceptions import UnknownEntityError |
603
1d6f48ae31d1
plugin parrot: sendMessage now avoid triggers
Goffi <goffi@goffi.org>
parents:
602
diff
changeset
|
26 #from sat.tools.misc import SkipOtherTriggers |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
29 "name": "Parrot Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
30 "import_name": "EXP-PARROT", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
31 "type": "EXP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
32 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
33 "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
|
34 "recommendations": [C.TEXT_CMDS], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
35 "main": "Exp_Parrot", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "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
|
38 } |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
41 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
|
42 """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
|
43 #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
|
44 # this is specially true if we have other triggers. |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 # sendMessageTrigger avoid other triggers execution, it's deactivated to allow |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 # /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
|
47 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 def __init__(self, host): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 info(_("Plugin Parrot initialization")) |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.host = host |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100) |
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("sendMessage", self.sendMessageTrigger, 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
|
53 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
|
54 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
|
55 except KeyError: |
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 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
|
57 |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
58 #def sendMessageTrigger(self, mess_data, treatments, profile): |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 # """ 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
|
60 # client = self.host.getClient(profile) |
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(): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 # debug("Parrot link detected, skipping other triggers") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
68 # raise SkipOtherTriggers |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
663 | 70 def MessageReceivedTrigger(self, message, post_treat, profile): |
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 """ |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 client = self.host.getClient(profile) |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 from_jid = jid.JID(message["from"]) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
74 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 _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
|
77 except AttributeError: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
79 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 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
|
81 return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
82 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 for e in message.elements(): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 if e.name == "body": |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 mess_body = e.children[0] if e.children else "" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
86 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 entity_type = self.host.memory.getEntityData(from_jid, ['type'], profile)["type"] |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 except (UnknownEntityError, KeyError): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 entity_type = "contact" |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 if entity_type == 'chatroom': |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 src_txt = from_jid.resource |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 if src_txt == self.host.plugins["XEP-0045"].getRoomNick(from_jid.userhost(), profile): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 #we won't repeat our own messages |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 return True |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 else: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 src_txt = from_jid.user |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 msg = "[%s] %s" % (src_txt, mess_body) |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 linked = _links[from_jid.userhostJID()] |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
603
1d6f48ae31d1
plugin parrot: sendMessage now avoid triggers
Goffi <goffi@goffi.org>
parents:
602
diff
changeset
|
102 self.host.sendMessage(jid.JID(unicode(linked)), msg, None, "auto", no_trigger=True, profile_key=profile) |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 else: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 warning("No body element found in message, following normal behaviour") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
105 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 return True |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 def addParrot(self, source_jid, dest_jid, profile): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 """Add a parrot link from one entity to another one |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 @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
|
111 @param dest_jid: entity where the 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
|
112 @param profile: %(doc_profile_key)s""" |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 client = self.host.getClient(profile) |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 _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
|
116 except AttributeError: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 _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
|
118 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 _links[source_jid.userhostJID()] = dest_jid |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 info("Parrot mode: %s will be repeated to %s" % (source_jid.userhost(), unicode(dest_jid))) |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 def removeParrot(self, source_jid, profile): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 """Remove parrot link |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 @param source_jid: this entity will no more be repeated |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @param profile: %(doc_profile_key)s""" |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 client = self.host.getClient(profile) |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 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
|
129 except (AttributeError, KeyError): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 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
|
131 |
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 def cmd_parrot(self, mess_data, profile): |
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
|
133 """activate Parrot mode between 2 entities, in both directions.""" |
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 debug("Catched parrot command") |
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
|
135 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
|
136 |
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 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
|
138 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
|
139 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
|
140 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
|
141 except 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
|
142 txt_cmd.feedBack("Can't activate Parrot mode for invalid jid", mess_data, profile) |
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
|
143 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
|
144 |
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 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
|
146 |
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 self.addParrot(link_left_jid, link_right_jid, profile) |
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
|
148 self.addParrot(link_right_jid, link_left_jid, profile) |
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
|
149 |
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 txt_cmd.feedBack("Parrot mode activated for %s" % (unicode(link_left_jid), ), mess_data, profile) |
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
|
151 |
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 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
|
153 |
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 def cmd_unparrot(self, mess_data, profile): |
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
|
155 """remove Parrot mode between 2 entities, in both directions.""" |
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 debug("Catched unparrot command") |
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
|
157 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
|
158 |
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 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
|
160 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
|
161 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
|
162 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
|
163 except 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 txt_cmd.feedBack("Can't deactivate Parrot mode for invalid jid", mess_data, profile) |
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
|
165 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
|
166 |
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 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
|
168 |
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 self.removeParrot(link_left_jid, profile) |
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
|
170 self.removeParrot(link_right_jid, profile) |
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
|
171 |
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 txt_cmd.feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile) |
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
|
173 |
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 return False |