Only try to send QUITs on ctrl+c when we're connected - sys.exit otherwise
This commit is contained in:
parent
768059fcf4
commit
b8f778d7bd
3 changed files with 13 additions and 5 deletions
|
@ -11,6 +11,7 @@ def handle_001(event):
|
|||
event["server"].name = event["prefix"].hostmask
|
||||
event["server"].set_own_nickname(event["args"][0])
|
||||
event["server"].send_whois(event["server"].nickname)
|
||||
event["server"].connected = True
|
||||
|
||||
def handle_005(events, event):
|
||||
isupport_list = event["args"][1:-1]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import signal
|
||||
import signal, sys
|
||||
from src import Config, ModuleManager, utils
|
||||
|
||||
class Module(ModuleManager.BaseModule):
|
||||
|
@ -19,11 +19,17 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
self.events.on("signal.interrupt").call(signum=signum)
|
||||
|
||||
written = False
|
||||
for server in self.bot.servers.values():
|
||||
server.socket.clear_send_buffer()
|
||||
line = server.send_quit("Shutting down")
|
||||
server.send_enabled = False
|
||||
line.on_send(self._make_hook(server))
|
||||
if server.connected:
|
||||
server.socket.clear_send_buffer()
|
||||
line = server.send_quit("Shutting down")
|
||||
server.send_enabled = False
|
||||
line.on_send(self._make_hook(server))
|
||||
written = True
|
||||
|
||||
if not written:
|
||||
sys.exit()
|
||||
|
||||
def _make_hook(self, server):
|
||||
return lambda: self.bot.disconnect(server)
|
||||
|
|
|
@ -17,6 +17,7 @@ class Server(IRCObject.Object):
|
|||
self.id = id
|
||||
self.alias = alias
|
||||
self.connection_params = connection_params
|
||||
self.connected = False
|
||||
self.name = None # type: typing.Optional[str]
|
||||
self.version = None # type: typing.Optional[str]
|
||||
|
||||
|
|
Loading…
Reference in a new issue