diff options
author | mathieui <mathieui@mathieui.net> | 2020-12-07 20:58:16 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2020-12-07 20:58:16 +0100 |
commit | 91c3d64ca216aa663a5e98840163403707d63670 (patch) | |
tree | 16ab52af08c79f1421e032c72e588e562b560746 | |
parent | a61f2248fdc24dd85a286abc9032ea87628dd643 (diff) | |
download | slixmpp-91c3d64ca216aa663a5e98840163403707d63670.tar.gz slixmpp-91c3d64ca216aa663a5e98840163403707d63670.tar.bz2 slixmpp-91c3d64ca216aa663a5e98840163403707d63670.tar.xz slixmpp-91c3d64ca216aa663a5e98840163403707d63670.zip |
XEP-0439: Add events
-rw-r--r-- | slixmpp/plugins/xep_0439/quickresponse.py | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/slixmpp/plugins/xep_0439/quickresponse.py b/slixmpp/plugins/xep_0439/quickresponse.py index 74e299d6..f6836731 100644 --- a/slixmpp/plugins/xep_0439/quickresponse.py +++ b/slixmpp/plugins/xep_0439/quickresponse.py @@ -11,9 +11,12 @@ from typing import ( Tuple, ) -from slixmpp import JID +from slixmpp import JID, Message from slixmpp.plugins import BasePlugin from slixmpp.plugins.xep_0439 import stanza +from slixmpp.xmlstream.matcher import StanzaPath +from slixmpp.xmlstream.handler import Callback + class XEP_0439(BasePlugin): @@ -27,11 +30,40 @@ class XEP_0439(BasePlugin): def plugin_init(self) -> None: stanza.register_plugins() + self.xmpp.register_handler(Callback( + 'Action received', + StanzaPath('message/action'), + self._handle_action, + )) + self.xmpp.register_handler(Callback( + 'Response received', + StanzaPath('message/response'), + self._handle_response, + )) + self.xmpp.register_handler(Callback( + 'ActionSelected received', + StanzaPath('message/action_selected'), + self._handle_action_selected, + )) + + def plugin_send(self): + self.xmpp.remove_handler('Action received') + self.xmpp.remove_handler('Response received') + self.xmpp.remove_handler('ActionSelected received') + + def _handle_response(self, msg: Message): + self.xmpp.event('responses_received', msg) + + def _handle_action(self, msg: Message): + self.xmpp.event('action_received', msg) + + def _handle_action_selected(self, msg: Message): + self.xmpp.event('action_selected', msg) - def ask_for_responses(self, mto: JID, body: str, - responses: Iterable[Tuple[str, str]], - mtype: str = 'chat', lang: Optional[str] = None, *, - mfrom: Optional[JID] = None): + def ask_for_response(self, mto: JID, body: str, + responses: Iterable[Tuple[str, str]], + mtype: str = 'chat', lang: Optional[str] = None, *, + mfrom: Optional[JID] = None): """ Send a message with a set of responses. |