aboutsummaryrefslogtreecommitdiff
path: root/modules/signals.py
blob: 627becfe4cc5465ac34829d013dd96c9d13c5cc4 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import signal
from src import Config, ModuleManager, utils

@utils.export("serverset", {"setting": "quit-quote",
    "help": "Set whether I pick a random quote to /quit with",
    "validate": utils.bool_or_none})
class Module(ModuleManager.BaseModule):
    def on_load(self):
        signal.signal(signal.SIGINT, self.SIGINT)
        signal.signal(signal.SIGUSR1, self.SIGUSR1)

    def SIGINT(self, signum, frame):
        print()
        self.events.on("signal.interrupt").call(signum=signum, frame=frame)

        for server in self.bot.servers.values():
            reason = "Leaving"
            if server.get_setting("quit-quote", True):
                reason = self.events.on("get.quit-quote"
                    ).call_for_result(default=reason)
            server.send_quit(reason)
            self.bot.trigger()

        self.bot.running = False

    def SIGUSR1(self, signum, frame):
        self.bot.log.info("Reloading config file", [])
        self.bot.config.load()
        self.bot.log.info("Reloaded config file", [])