Fix custom stanza examples
This commit is contained in:
parent
5bf69dca76
commit
cc4522d9cd
@ -50,7 +50,7 @@ class ActionBot(slixmpp.ClientXMPP):
|
|||||||
|
|
||||||
register_stanza_plugin(Iq, Action)
|
register_stanza_plugin(Iq, Action)
|
||||||
|
|
||||||
def start(self, event):
|
async def start(self, event):
|
||||||
"""
|
"""
|
||||||
Process the session_start event.
|
Process the session_start event.
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ class ActionBot(slixmpp.ClientXMPP):
|
|||||||
"""
|
"""
|
||||||
self.event('custom_action', iq)
|
self.event('custom_action', iq)
|
||||||
|
|
||||||
def _handle_action_event(self, iq):
|
async def _handle_action_event(self, iq):
|
||||||
"""
|
"""
|
||||||
Respond to the custom action event.
|
Respond to the custom action event.
|
||||||
"""
|
"""
|
||||||
@ -82,17 +82,20 @@ class ActionBot(slixmpp.ClientXMPP):
|
|||||||
|
|
||||||
if method == 'is_prime' and param == '2':
|
if method == 'is_prime' and param == '2':
|
||||||
print("got message: %s" % iq)
|
print("got message: %s" % iq)
|
||||||
iq.reply()
|
rep = iq.reply()
|
||||||
iq['action']['status'] = 'done'
|
rep['action']['status'] = 'done'
|
||||||
iq.send()
|
await rep.send()
|
||||||
elif method == 'bye':
|
elif method == 'bye':
|
||||||
print("got message: %s" % iq)
|
print("got message: %s" % iq)
|
||||||
|
rep = iq.reply()
|
||||||
|
rep['action']['status'] = 'done'
|
||||||
|
await rep.send()
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
else:
|
else:
|
||||||
print("got message: %s" % iq)
|
print("got message: %s" % iq)
|
||||||
iq.reply()
|
rep = iq.reply()
|
||||||
iq['action']['status'] = 'error'
|
rep['action']['status'] = 'error'
|
||||||
iq.send()
|
await rep.send()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Setup the command line arguments.
|
# Setup the command line arguments.
|
||||||
|
@ -43,7 +43,7 @@ class ActionUserBot(slixmpp.ClientXMPP):
|
|||||||
|
|
||||||
register_stanza_plugin(Iq, Action)
|
register_stanza_plugin(Iq, Action)
|
||||||
|
|
||||||
def start(self, event):
|
async def start(self, event):
|
||||||
"""
|
"""
|
||||||
Process the session_start event.
|
Process the session_start event.
|
||||||
|
|
||||||
@ -57,11 +57,11 @@ class ActionUserBot(slixmpp.ClientXMPP):
|
|||||||
data.
|
data.
|
||||||
"""
|
"""
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
self.get_roster()
|
await self.get_roster()
|
||||||
|
|
||||||
self.send_custom_iq()
|
await self.send_custom_iq()
|
||||||
|
|
||||||
def send_custom_iq(self):
|
async def send_custom_iq(self):
|
||||||
"""Create and send two custom actions.
|
"""Create and send two custom actions.
|
||||||
|
|
||||||
If the first action was successful, then send
|
If the first action was successful, then send
|
||||||
@ -74,14 +74,14 @@ class ActionUserBot(slixmpp.ClientXMPP):
|
|||||||
iq['action']['param'] = '2'
|
iq['action']['param'] = '2'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = iq.send()
|
resp = await iq.send()
|
||||||
if resp['action']['status'] == 'done':
|
if resp['action']['status'] == 'done':
|
||||||
#sending bye
|
#sending bye
|
||||||
iq2 = self.Iq()
|
iq2 = self.Iq()
|
||||||
iq2['to'] = self.action_provider
|
iq2['to'] = self.action_provider
|
||||||
iq2['type'] = 'set'
|
iq2['type'] = 'set'
|
||||||
iq2['action']['method'] = 'bye'
|
iq2['action']['method'] = 'bye'
|
||||||
iq2.send(block=False)
|
await iq2.send()
|
||||||
|
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
except XMPPError:
|
except XMPPError:
|
||||||
|
Loading…
Reference in New Issue
Block a user