3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

Irc: add "was_successful" data key to PYLINK_DISCONNECT

This stores whether the network was actually connected before this disconnect message fired (i.e. the disconnect wasn't caused by a configuration error, etc.)
This commit is contained in:
James Lu 2017-02-24 21:42:44 -08:00
parent cd3d795296
commit b30d696e3a

View File

@ -192,6 +192,7 @@ class Irc():
ip = self.serverdata["ip"]
port = self.serverdata["port"]
checks_ok = True
errored = False
try:
# Set the socket type (IPv6 or IPv4).
stype = socket.AF_INET6 if self.serverdata.get("ipv6") else socket.AF_INET
@ -317,11 +318,12 @@ class Irc():
# exception, meaning we've disconnected!
log.error('(%s) Disconnected from IRC: %s: %s',
self.name, type(e).__name__, str(e))
errored = True
self.disconnect()
# Internal hook signifying that a network has disconnected.
self.callHooks([None, 'PYLINK_DISCONNECT', {}])
self.callHooks([None, 'PYLINK_DISCONNECT', {'was_successful': checks_ok and not errored}])
# If autoconnect is enabled, loop back to the start. Otherwise,
# return and stop.