2016-03-29 11:56:58 +00:00
|
|
|
import signal
|
2018-10-12 17:07:23 +00:00
|
|
|
from src import Config, ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-07 10:28:51 +00:00
|
|
|
@utils.export("serverset", {"setting": "quit-quote",
|
|
|
|
"help": "Set whether I pick a random quote to /quit with",
|
|
|
|
"validate": utils.bool_or_none})
|
2018-10-12 17:07:23 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
def on_load(self):
|
2016-03-29 11:56:58 +00:00
|
|
|
signal.signal(signal.SIGINT, self.SIGINT)
|
|
|
|
signal.signal(signal.SIGUSR1, self.SIGUSR1)
|
|
|
|
|
|
|
|
def SIGINT(self, signum, frame):
|
|
|
|
print()
|
2018-11-27 14:25:12 +00:00
|
|
|
self.bot.trigger(lambda: self._kill(signum))
|
|
|
|
|
|
|
|
def _kill(self, signum):
|
|
|
|
self.events.on("signal.interrupt").call(signum=signum)
|
2018-07-15 14:15:52 +00:00
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
for server in self.bot.servers.values():
|
2018-08-13 15:04:27 +00:00
|
|
|
reason = "Leaving"
|
|
|
|
if server.get_setting("quit-quote", True):
|
2018-08-31 11:55:52 +00:00
|
|
|
reason = self.events.on("get.quit-quote"
|
2018-10-07 10:28:51 +00:00
|
|
|
).call_for_result(default=reason)
|
2018-08-13 15:04:27 +00:00
|
|
|
server.send_quit(reason)
|
2018-07-15 14:15:52 +00:00
|
|
|
|
2018-11-27 11:56:03 +00:00
|
|
|
self.events.on("writebuffer.empty").hook(
|
|
|
|
lambda event: self.bot.disconnect(event["server"]))
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def SIGUSR1(self, signum, frame):
|
2018-09-02 10:43:52 +00:00
|
|
|
self.bot.log.info("Reloading config file", [])
|
2018-09-29 19:27:20 +00:00
|
|
|
self.bot.config.load()
|
2018-09-02 10:43:52 +00:00
|
|
|
self.bot.log.info("Reloaded config file", [])
|