|
|
|
@ -8,16 +8,18 @@ class SleepPlugin(Plugin):
|
|
|
|
|
"""Handle sleep state of the bot, snore a little bit."""
|
|
|
|
|
|
|
|
|
|
REQUIRED_CONFIGS = [
|
|
|
|
|
"sleep_time", "wakeup_time", "snore", "sleep_message", "wakeup_message",
|
|
|
|
|
"snore_rate"
|
|
|
|
|
"commands", "sleep_time", "wakeup_time", "snore", "sleep_message",
|
|
|
|
|
"wakeup_message", "snore_rate"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
super().__init__(bot)
|
|
|
|
|
|
|
|
|
|
def on_welcome(self, event):
|
|
|
|
|
self.set_runtime_value("awake", True)
|
|
|
|
|
|
|
|
|
|
def on_ping(self, event):
|
|
|
|
|
awake = self.get_runtime_value("awake")
|
|
|
|
|
self.bot.log_w(f"{self.bot.channels}")
|
|
|
|
|
in_sleep_hours = self.is_sleep_time(datetime.now())
|
|
|
|
|
if awake and in_sleep_hours:
|
|
|
|
|
self.fall_asleep()
|
|
|
|
@ -30,12 +32,38 @@ class SleepPlugin(Plugin):
|
|
|
|
|
for channel in self.bot.channels:
|
|
|
|
|
self.bot.say(channel, self.config["snore"])
|
|
|
|
|
|
|
|
|
|
def on_pubmsg(self, event):
|
|
|
|
|
if not self.should_handle_command(
|
|
|
|
|
event.arguments[0],
|
|
|
|
|
no_content=True,
|
|
|
|
|
exclude_conditions=["sleep"],
|
|
|
|
|
):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# "sleep" command.
|
|
|
|
|
command0 = self.config["commands"][0]
|
|
|
|
|
if self.command.ident.startswith(command0):
|
|
|
|
|
self.fall_asleep()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# "wake up" command.
|
|
|
|
|
command1 = self.config["commands"][1]
|
|
|
|
|
if self.command.ident.startswith(command1):
|
|
|
|
|
self.wake_up()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def fall_asleep(self):
|
|
|
|
|
if not self.get_runtime_value("awake"):
|
|
|
|
|
return
|
|
|
|
|
for channel in self.bot.channels:
|
|
|
|
|
self.bot.say(channel, self.config["sleep_message"])
|
|
|
|
|
self.set_runtime_value("awake", False)
|
|
|
|
|
|
|
|
|
|
def wake_up(self):
|
|
|
|
|
if self.get_runtime_value("awake"):
|
|
|
|
|
return
|
|
|
|
|
self.set_runtime_value("awake", True)
|
|
|
|
|
for channel in self.bot.channels:
|
|
|
|
|
self.bot.say(channel, self.config["wakeup_message"])
|
|
|
|
|