XEP-0280: More typing and docs, new kwargs
This commit is contained in:
parent
3b43d8eb7f
commit
febfb6d6ca
@ -5,7 +5,10 @@
|
|||||||
# See the file LICENSE for copying permissio
|
# See the file LICENSE for copying permissio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import slixmpp
|
from asyncio import Future
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from slixmpp import JID
|
||||||
from slixmpp.stanza import Message, Iq
|
from slixmpp.stanza import Message, Iq
|
||||||
from slixmpp.xmlstream.handler import Callback
|
from slixmpp.xmlstream.handler import Callback
|
||||||
from slixmpp.xmlstream.matcher import StanzaPath
|
from slixmpp.xmlstream.matcher import StanzaPath
|
||||||
@ -21,6 +24,11 @@ class XEP_0280(BasePlugin):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
XEP-0280 Message Carbons
|
XEP-0280 Message Carbons
|
||||||
|
|
||||||
|
Events triggered by this plugin:
|
||||||
|
|
||||||
|
- :term:`carbon_received`
|
||||||
|
- :term:`carbon_sent`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = 'xep_0280'
|
name = 'xep_0280'
|
||||||
@ -57,28 +65,22 @@ class XEP_0280(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:carbons:2')
|
self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:carbons:2')
|
||||||
|
|
||||||
def _handle_carbon_received(self, msg):
|
def _handle_carbon_received(self, msg: Message):
|
||||||
if msg['from'].bare == self.xmpp.boundjid.bare:
|
if msg['from'].bare == self.xmpp.boundjid.bare:
|
||||||
self.xmpp.event('carbon_received', msg)
|
self.xmpp.event('carbon_received', msg)
|
||||||
|
|
||||||
def _handle_carbon_sent(self, msg):
|
def _handle_carbon_sent(self, msg: Message):
|
||||||
if msg['from'].bare == self.xmpp.boundjid.bare:
|
if msg['from'].bare == self.xmpp.boundjid.bare:
|
||||||
self.xmpp.event('carbon_sent', msg)
|
self.xmpp.event('carbon_sent', msg)
|
||||||
|
|
||||||
def enable(self, ifrom=None, timeout=None, callback=None,
|
def enable(self, ifrom: Optional[JID] = None, **iqkwargs) -> Future:
|
||||||
timeout_callback=None):
|
"""Enable carbons."""
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.make_iq_set(ifrom=ifrom)
|
||||||
iq['type'] = 'set'
|
|
||||||
iq['from'] = ifrom
|
|
||||||
iq.enable('carbon_enable')
|
iq.enable('carbon_enable')
|
||||||
return iq.send(timeout_callback=timeout_callback, timeout=timeout,
|
return iq.send(**iqkwargs)
|
||||||
callback=callback)
|
|
||||||
|
|
||||||
def disable(self, ifrom=None, timeout=None, callback=None,
|
def disable(self, ifrom: Optional[JID] = None, **iqkwargs) -> Future:
|
||||||
timeout_callback=None):
|
"""Disable carbons."""
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.make_iq_set(ifrom=ifrom)
|
||||||
iq['type'] = 'set'
|
|
||||||
iq['from'] = ifrom
|
|
||||||
iq.enable('carbon_disable')
|
iq.enable('carbon_disable')
|
||||||
return iq.send(timeout_callback=timeout_callback, timeout=timeout,
|
return iq.send(**iqkwargs)
|
||||||
callback=callback)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user