Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ def _nick_blocked(self, nick: str) -> bool:
def _shutdown(self) -> None:
"""Internal bot shutdown method."""
LOGGER.info("Shutting down")
# Proactively tell plugins (at least the ones that bother to check)
self._connection_registered = False
# Stop Job Scheduler
LOGGER.info("Stopping the Job Scheduler.")
self._scheduler.stop()
Expand Down
2 changes: 1 addition & 1 deletion sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def startup(bot, trigger):
bot.say(privmsg, bot.config.core.owner)

# set flag
bot.connection_registered = True
bot._connection_registered = True

# handle auth method
auth_after_register(bot)
Expand Down
11 changes: 10 additions & 1 deletion sopel/irc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, settings: Config):

self.backend: Optional[AbstractIRCBackend] = None
"""IRC Connection Backend."""
self.connection_registered = False
self._connection_registered = False
"""Flag stating whether the IRC Connection is registered yet."""
self.settings = settings
"""Bot settings."""
Expand All @@ -92,6 +92,13 @@ def __init__(self, settings: Config):
self.wantsrestart = False
self.last_raw_line = '' # last raw line received

@property
def connection_registered(self) -> bool:
return (
self.backend is not None
and self.backend.is_connected()
and self._connection_registered)

@property
def nick(self) -> identifiers.Identifier:
"""Sopel's current nick.
Expand Down Expand Up @@ -413,6 +420,7 @@ def change_current_nick(self, new_nick: str) -> None:

def on_close(self) -> None:
"""Call shutdown methods."""
self._connection_registered = False
self._shutdown()

def _shutdown(self) -> None:
Expand Down Expand Up @@ -646,6 +654,7 @@ def quit(self, message: Optional[str] = None) -> None:
if self.backend is None:
raise RuntimeError(ERR_BACKEND_NOT_INITIALIZED)

self._connection_registered = False
self.backend.send_quit(reason=message)
self.hasquit = True
# Wait for acknowledgment from the server. Per RFC 2812 it should be
Expand Down
8 changes: 6 additions & 2 deletions test/test_coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def test_execute_perform_send_commands(mockbot):
]

mockbot.config.core.commands_on_connect = commands
mockbot.connection_registered = True
# For testing, pretend connection already happened
mockbot.backend.connected = True
mockbot._connection_registered = True

coretasks._execute_perform(mockbot)
assert mockbot.backend.message_sent == rawlist(*commands)
Expand All @@ -234,7 +236,9 @@ def test_execute_perform_replaces_nickname(mockbot):
sent_command = 'MODE {} +Xxw'.format(mockbot.config.core.nick)

mockbot.config.core.commands_on_connect = [command, ]
mockbot.connection_registered = True # For testing, simulate connected
# For testing, pretend connection already happened
mockbot.backend.connected = True
mockbot._connection_registered = True

coretasks._execute_perform(mockbot)
assert mockbot.backend.message_sent == rawlist(sent_command)
Expand Down