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