Skip to content

Commit

Permalink
Fix reconnect call
Browse files Browse the repository at this point in the history
  • Loading branch information
gagath committed Apr 26, 2017
1 parent 973dd49 commit 94159d1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions hms_irc/ircbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from irc.client import NickMask, ServerConnectionError

from hms_irc.irc import IRCCommand
from hms_irc import settings


def get_logger():
Expand Down Expand Up @@ -118,11 +119,21 @@ def handle_reconnection_request(self, signum, frame):
self.reconnect_if_disconnected()

def reconnect_if_disconnected(self):
if self.serv:
try:
get_logger().error('Reconnection request received, processing..')
self.serv.connect()
except ServerConnectionError as e:
get_logger().error(e)
else:
get_logger().error('Reconnection request received but no serv is currently set. Ignoring.')
if not self.serv:
get_logger().error('Reconnection request received but no serv is'
' currently set. Ignoring.')
return

try:
get_logger().info(
'Reconnection request received, processing...')

if self.serv.connected:
get_logger().info('Server already connected, nothing to do')
else:
get_logger().info('Server was disconnected, reconnecting')
self.serv.reconnect()

except ServerConnectionError as e:
get_logger().error(e)

0 comments on commit 94159d1

Please sign in to comment.