Enable ping keepalive
This commit is contained in:
parent
0ff3f9754b
commit
659bc4c3aa
21
hybridbot.py
21
hybridbot.py
@ -15,7 +15,6 @@ class IRCBot:
|
|||||||
self.client = SingleServerIRCBot([(opts['server'], opts['port'])],
|
self.client = SingleServerIRCBot([(opts['server'], opts['port'])],
|
||||||
opts['nick'], opts['nick'])
|
opts['nick'], opts['nick'])
|
||||||
self.conn = self.client.connection
|
self.conn = self.client.connection
|
||||||
self.opts = opts
|
|
||||||
self.nick = opts['nick']
|
self.nick = opts['nick']
|
||||||
self.pure_nick = self.nick
|
self.pure_nick = self.nick
|
||||||
self.chan = opts['chan']
|
self.chan = opts['chan']
|
||||||
@ -114,13 +113,20 @@ class IRCBot:
|
|||||||
class XMPPBot:
|
class XMPPBot:
|
||||||
def __init__(self, opts, inter, timeout=5.0):
|
def __init__(self, opts, inter, timeout=5.0):
|
||||||
self.client = slixmpp.ClientXMPP(opts['jid'], opts['passwd'])
|
self.client = slixmpp.ClientXMPP(opts['jid'], opts['passwd'])
|
||||||
self.opts = opts
|
|
||||||
|
self.client.register_plugin('xep_0199') # XMPP Ping.
|
||||||
|
self.client_ping = self.client.plugin['xep_0199']
|
||||||
|
self.client.register_plugin('xep_0045') # XMPP MUC.
|
||||||
|
self.client_muc = self.client.plugin['xep_0045']
|
||||||
|
|
||||||
|
self.muc_is_joined = False
|
||||||
|
self.client_ping.timeout = self.timeout = timeout
|
||||||
|
self.client_ping.keepalive = True
|
||||||
|
|
||||||
self.nick = opts['nick']
|
self.nick = opts['nick']
|
||||||
self.pure_nick = self.nick
|
self.pure_nick = self.nick
|
||||||
self.muc = opts['muc']
|
self.muc = opts['muc']
|
||||||
self.inter = inter
|
self.inter = inter
|
||||||
self.timeout = timeout
|
|
||||||
self.muc_is_joined = False
|
|
||||||
|
|
||||||
def register_handlers(self):
|
def register_handlers(self):
|
||||||
self.client.add_event_handler('failed_all_auth',
|
self.client.add_event_handler('failed_all_auth',
|
||||||
@ -136,7 +142,6 @@ class XMPPBot:
|
|||||||
self.client.connect()
|
self.client.connect()
|
||||||
|
|
||||||
def join_muc(self):
|
def join_muc(self):
|
||||||
muc_plugin = self.client.plugin['xep_0045']
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def loop_cycle():
|
def loop_cycle():
|
||||||
if self._join_muc_block > 0:
|
if self._join_muc_block > 0:
|
||||||
@ -144,7 +149,7 @@ class XMPPBot:
|
|||||||
self._join_muc_block += 1
|
self._join_muc_block += 1
|
||||||
|
|
||||||
while not self.muc_is_joined:
|
while not self.muc_is_joined:
|
||||||
muc_plugin.join_muc(self.muc, self.nick)
|
self.client_muc.join_muc(self.muc, self.nick)
|
||||||
yield from asyncio.sleep(self.timeout)
|
yield from asyncio.sleep(self.timeout)
|
||||||
|
|
||||||
self._join_muc_block -= 1
|
self._join_muc_block -= 1
|
||||||
@ -198,7 +203,7 @@ class XMPPBot:
|
|||||||
elif typ == 'error':
|
elif typ == 'error':
|
||||||
self.muc_is_joined = False
|
self.muc_is_joined = False
|
||||||
if event['error']['code'] == '409':
|
if event['error']['code'] == '409':
|
||||||
self.nick = self.nick + '_'
|
self.nick += '_'
|
||||||
self.join_muc()
|
self.join_muc()
|
||||||
|
|
||||||
elif typ == 'unavailable':
|
elif typ == 'unavailable':
|
||||||
@ -231,8 +236,6 @@ class XMPPBot:
|
|||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def run(self):
|
def run(self):
|
||||||
self.client.register_plugin('xep_0045') # XMPP MUC.
|
|
||||||
self.client.register_plugin('xep_0199') # XMPP Ping.
|
|
||||||
self.register_handlers()
|
self.register_handlers()
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user