Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_exp_parrot.py @ 4332:71c939e34ca6
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
526
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) |
3479 | 5 # Copyright (C) 2009-2021 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 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
20 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
21 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
22 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
927
diff
changeset
|
24 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
|
25 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
|
26 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
27 from libervia.backend.core.exceptions import UnknownEntityError |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
28 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
29 # 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
|
30 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
32 C.PI_NAME: "Parrot Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
33 C.PI_IMPORT_NAME: "EXP-PARROT", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
34 C.PI_TYPE: "EXP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
35 C.PI_PROTOCOLS: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
36 C.PI_DEPENDENCIES: ["XEP-0045"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
37 C.PI_RECOMMENDATIONS: [C.TEXT_CMDS], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
38 C.PI_MAIN: "Exp_Parrot", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
39 C.PI_HANDLER: "no", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 C.PI_DESCRIPTION: _( |
3028 | 41 """Implementation of parrot mode (repeat messages between 2 entities)""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 ), |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 } |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
45 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
46 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
|
47 """Parrot mode plugin: repeat messages from one entity or MUC room to another one""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 |
2128 | 49 # XXX: This plugin can be potentially dangerous if we don't trust entities linked |
50 # this is specially true if we have other triggers. | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
51 # send_message_trigger avoid other triggers execution, it's deactivated to allow |
2128 | 52 # /unparrot command in text commands plugin. |
53 # FIXME: potentially unsecure, specially with e2e encryption | |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
927
diff
changeset
|
56 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
|
57 self.host = host |
4051
c23cad65ae99
core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
58 host.trigger.add("message_received", self.message_received_trigger, priority=100) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
59 # host.trigger.add("sendMessage", self.send_message_trigger, 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
|
60 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
61 self.host.plugins[C.TEXT_CMDS].register_text_commands(self) |
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
|
62 except KeyError: |
3028 | 63 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
|
64 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
65 # def send_message_trigger(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
|
66 # """ 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
|
67 # try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 # _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
|
69 # except AttributeError: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 # return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
71 # |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 # 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
|
73 # log.debug("Parrot link detected, skipping other triggers") |
1374
0befb14ecf62
renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
74 # 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
|
75 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
76 def message_received_trigger(self, client, message_elt, post_treat): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
77 """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
|
78 # TODO: many things are not repeated (subject, thread, etc) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
79 from_jid = message_elt["from"] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
80 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 _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
|
83 except AttributeError: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
85 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 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
|
87 return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
88 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
89 message = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 for e in message_elt.elements(C.NS_CLIENT, "body"): |
3028 | 91 body = str(e) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 lang = e.getAttribute("lang") or "" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
93 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
94 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
95 entity_type = self.host.memory.entity_data_get( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
96 client, from_jid, [C.ENTITY_TYPE] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
97 )[C.ENTITY_TYPE] |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
98 except (UnknownEntityError, KeyError): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
99 entity_type = "contact" |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
100 if entity_type == C.ENTITY_TYPE_MUC: |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
101 src_txt = from_jid.resource |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
102 if src_txt == self.host.plugins["XEP-0045"].get_room_nick( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 client, from_jid.userhostJID() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 # we won't repeat our own messages |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
106 return True |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
107 else: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
108 src_txt = from_jid.user |
3028 | 109 message[lang] = "[{}] {}".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
|
110 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
111 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
|
112 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 client.sendMessage( |
3028 | 114 jid.JID(str(linked)), message, None, "auto", no_trigger=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
116 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 return True |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
119 def add_parrot(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
|
120 """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
|
121 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 @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
|
123 @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
|
124 """ |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 _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
|
127 except AttributeError: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 _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
|
129 |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 _links[source_jid.userhostJID()] = dest_jid |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 log.info( |
3028 | 132 "Parrot mode: %s will be repeated to %s" |
133 % (source_jid.userhost(), str(dest_jid)) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 ) |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
136 def remove_parrot(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
|
137 """Remove parrot link |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
138 |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 @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
|
140 """ |
526
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 try: |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 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
|
143 except (AttributeError, KeyError): |
d67f0ce83530
new plugin: Parrot is an experimental plugin which repeat messages between 2 entities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 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
|
145 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
146 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
|
147 """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
|
148 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
|
149 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
|
150 |
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 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
|
152 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
|
153 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
|
154 raise jid.InvalidFormat |
1742
244a605623d6
complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
155 except (RuntimeError, jid.InvalidFormat, AttributeError): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
156 txt_cmd.feed_back( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 client, "Can't activate Parrot mode for invalid jid", mess_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 ) |
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
|
159 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
|
160 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 link_right_jid = mess_data["to"] |
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
|
162 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
163 self.add_parrot(client, link_left_jid, link_right_jid) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
164 self.add_parrot(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
|
165 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
166 txt_cmd.feed_back( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 client, |
3028 | 168 "Parrot mode activated for {}".format(str(link_left_jid)), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 mess_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 ) |
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
|
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 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
|
173 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
174 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
|
175 """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
|
176 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
|
177 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
|
178 |
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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 except jid.InvalidFormat: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
184 txt_cmd.feed_back( |
3028 | 185 client, "Can't deactivate Parrot mode for invalid jid", mess_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 ) |
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
|
187 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
|
188 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 link_right_jid = mess_data["to"] |
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
|
190 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
191 self.remove_parrot(client, link_left_jid) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
192 self.remove_parrot(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
|
193 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
194 txt_cmd.feed_back( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 client, |
3028 | 196 "Parrot mode deactivated for {} and {}".format( |
197 str(link_left_jid), str(link_right_jid) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 mess_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 ) |
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
|
201 |
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
|
202 return False |