Commit f1ab9ab9 authored by mathieui's avatar mathieui

Change session_start callback to async in most examples

If we fetch the roster, we should probably wait until we get it back
parent e520ab1f
......@@ -33,7 +33,7 @@ class CommandBot(slixmpp.ClientXMPP):
# our roster.
self.add_event_handler("session_start", self.start)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -47,7 +47,7 @@ class CommandBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
# We add the command after session_start has fired
# to ensure that the correct full JID is used.
......
......@@ -37,7 +37,7 @@ class CommandUserBot(slixmpp.ClientXMPP):
self.add_event_handler("session_start", self.start)
self.add_event_handler("message", self.message)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -51,7 +51,7 @@ class CommandUserBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
# We first create a session dictionary containing:
# 'next' -- the handler to execute on a successful response
......
......@@ -30,7 +30,7 @@ class AdminCommands(slixmpp.ClientXMPP):
self.add_event_handler("session_start", self.start)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -44,7 +44,7 @@ class AdminCommands(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
def command_success(iq, session):
print('Command completed')
......
......@@ -69,7 +69,7 @@ class Disco(slixmpp.ClientXMPP):
event does not provide any additional
data.
"""
self.get_roster()
await self.get_roster()
self.send_presence()
try:
......
......@@ -38,7 +38,7 @@ class EchoBot(slixmpp.ClientXMPP):
# MUC messages and error messages.
self.add_event_handler("message", self.message)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -52,7 +52,7 @@ class EchoBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
def message(self, msg):
"""
......
......@@ -58,7 +58,7 @@ class GTalkBot(slixmpp.ClientXMPP):
logging.error(err.message)
self.disconnect()
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -72,7 +72,7 @@ class GTalkBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
def message(self, msg):
"""
......
......@@ -39,7 +39,7 @@ class EchoBot(slixmpp.ClientXMPP):
# MUC messages and error messages.
self.add_event_handler("message", self.message)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -53,7 +53,7 @@ class EchoBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
def message(self, msg):
"""
......
......@@ -52,7 +52,7 @@ class MUCBot(slixmpp.ClientXMPP):
self.muc_online)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -65,7 +65,7 @@ class MUCBot(slixmpp.ClientXMPP):
event does not provide any additional
data.
"""
self.get_roster()
await self.get_roster()
self.send_presence()
self.plugin['xep_0045'].join_muc(self.room,
self.nick,
......
......@@ -51,7 +51,7 @@ class PingTest(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
try:
rtt = await self['xep_0199'].ping(self.pingjid,
......
......@@ -38,7 +38,7 @@ class EchoBot(slixmpp.ClientXMPP):
# MUC messages and error messages.
self.add_event_handler("message", self.message)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -52,7 +52,7 @@ class EchoBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
def message(self, msg):
"""
......
......@@ -32,7 +32,7 @@ class PubsubClient(slixmpp.ClientXMPP):
self.add_event_handler('session_start', self.start)
async def start(self, event):
self.get_roster()
await self.get_roster()
self.send_presence()
try:
......
......@@ -38,8 +38,8 @@ class PubsubEvents(slixmpp.ClientXMPP):
# self.add_event_handler('event_prefix_purge', handler)
# self.add_event_handler('event_prefix_delete', handler)
def start(self, event):
self.get_roster()
async def start(self, event):
await self.get_roster()
self.send_presence()
def _publish(self, msg):
......
......@@ -47,7 +47,7 @@ class RegisterBot(slixmpp.ClientXMPP):
# for data forms and OOB links that will make that easier.
self.add_event_handler("register", self.register)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -61,7 +61,7 @@ class RegisterBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
# We're only concerned about registering, so nothing more to do here.
self.disconnect()
......
......@@ -51,12 +51,8 @@ class RosterBrowser(slixmpp.ClientXMPP):
event does not provide any additional
data.
"""
future = asyncio.Future()
def callback(result):
future.set_result(None)
try:
self.get_roster(callback=callback)
await future
await self.get_roster()
except IqError as err:
print('Error: %s' % err.iq['error']['condition'])
except IqTimeout:
......
......@@ -38,7 +38,7 @@ class SendMsgBot(slixmpp.ClientXMPP):
# our roster.
self.add_event_handler("session_start", self.start)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -52,7 +52,7 @@ class SendMsgBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
self.send_message(mto=self.recipient,
mbody=self.msg,
......
......@@ -46,7 +46,7 @@ class AvatarSetter(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
avatar_file = None
try:
......
......@@ -60,7 +60,7 @@ class ThirdPartyAuthBot(slixmpp.ClientXMPP):
# MUC messages and error messages.
self.add_event_handler("message", self.message)
def start(self, event):
async def start(self, event):
"""
Process the session_start event.
......@@ -74,7 +74,7 @@ class ThirdPartyAuthBot(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
def message(self, msg):
"""
......
......@@ -38,9 +38,9 @@ class LocationBot(ClientXMPP):
self.current_tune = None
def start(self, event):
async def start(self, event):
self.send_presence()
self.get_roster()
await self.get_roster()
self['xep_0115'].update_caps()
print("Using freegeoip.net to get geolocation.")
......
......@@ -35,9 +35,9 @@ class TuneBot(ClientXMPP):
self.current_tune = None
def start(self, event):
async def start(self, event):
self.send_presence()
self.get_roster()
await self.get_roster()
self['xep_0115'].update_caps()
def _update_tune(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment