Merge branch 'fix-start-handlers' into 'master'

Change session_start callback to async in most examples

See merge request poezio/slixmpp!44
This commit is contained in:
Maxime Buquet 2020-05-02 16:51:51 +02:00
commit 0d3116dbdf
19 changed files with 33 additions and 37 deletions

View file

@ -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.

View file

@ -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

View file

@ -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')

View file

@ -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:

View file

@ -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):
"""

View file

@ -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):
"""

View file

@ -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):
"""

View file

@ -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,

View file

@ -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,

View file

@ -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):
"""

View file

@ -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:

View file

@ -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):

View file

@ -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()

View file

@ -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:

View file

@ -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,

View file

@ -46,7 +46,7 @@ class AvatarSetter(slixmpp.ClientXMPP):
data.
"""
self.send_presence()
self.get_roster()
await self.get_roster()
avatar_file = None
try:

View file

@ -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):
"""

View file

@ -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.")

View file

@ -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):