mirror of
https://github.com/gryf/weechat-highlightxmpp.git
synced 2025-12-18 20:10:23 +01:00
try to recover from a failed send
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# HighlightXMPP for IRC. Requires WeeChat >= 0.3.0.
|
# HighlightXMPP for IRC. Requires WeeChat >= 0.3.0.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009 Jacob Peddicord <jpeddicord@ubuntu.com>
|
# Copyright (c) 2009-2010 Jacob Peddicord <jpeddicord@ubuntu.com>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,13 +25,14 @@
|
|||||||
# JID messages are sent *to* (if not set, defaults to the same jid):
|
# JID messages are sent *to* (if not set, defaults to the same jid):
|
||||||
# /set plugins.var.python.highlightxmpp.jid myid@jabber.org
|
# /set plugins.var.python.highlightxmpp.jid myid@jabber.org
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
import weechat as w
|
import weechat as w
|
||||||
import xmpp
|
import xmpp
|
||||||
|
|
||||||
info = (
|
info = (
|
||||||
'highlightxmpp',
|
'highlightxmpp',
|
||||||
'Jacob Peddicord <jpeddicord@ubuntu.com>',
|
'Jacob Peddicord <jpeddicord@ubuntu.com>',
|
||||||
'0.1',
|
'0.2',
|
||||||
'GPL3',
|
'GPL3',
|
||||||
"Relay highlighted & private IRC messages over XMPP (Jabber)",
|
"Relay highlighted & private IRC messages over XMPP (Jabber)",
|
||||||
'',
|
'',
|
||||||
@@ -66,7 +67,7 @@ def connect_xmpp():
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_xmpp(data, signal, msg):
|
def send_xmpp(data, signal, msg, trial=1):
|
||||||
global client
|
global client
|
||||||
# connect to xmpp if we need to
|
# connect to xmpp if we need to
|
||||||
if not connect_xmpp():
|
if not connect_xmpp():
|
||||||
@@ -77,7 +78,17 @@ def send_xmpp(data, signal, msg):
|
|||||||
jid_to = w.config_get_plugin('jid')
|
jid_to = w.config_get_plugin('jid')
|
||||||
# send the message
|
# send the message
|
||||||
msg = xmpp.protocol.Message(jid_to, msg)
|
msg = xmpp.protocol.Message(jid_to, msg)
|
||||||
client.send(msg)
|
try:
|
||||||
|
client.send(msg)
|
||||||
|
except IOError:
|
||||||
|
# every now and then the connection will still exist but a send will
|
||||||
|
# fail. catch that here and try to reconnect. isConnected() should
|
||||||
|
# start to realize that once this exception is triggered.
|
||||||
|
if trial > 3:
|
||||||
|
w.prnt('', "Could send to XMPP server.")
|
||||||
|
else:
|
||||||
|
w.prnt('', "Lost connection to XMPP server. Trying to send again... (trial %d)" % trial + 1)
|
||||||
|
send_xmpp(data, signal, msg, trial + 1)
|
||||||
return w.WEECHAT_RC_OK
|
return w.WEECHAT_RC_OK
|
||||||
|
|
||||||
# register with weechat
|
# register with weechat
|
||||||
|
|||||||
Reference in New Issue
Block a user