sleep: add sleep/wakeup commands

master
dece 4 years ago
parent 127ad5c895
commit a7b68a1596

@ -56,6 +56,7 @@
"separator": "or"
},
"sleep": {
"commands": ["sleep", "wake up"],
"sleep_time": 23,
"wakeup_time": 7,
"snore": "Zzzz",

@ -64,6 +64,8 @@ class NotesPlugin(Plugin):
self.deliver_notes(event.target, event.source.nick)
return True
return False
def deliver_notes(self, target, nick):
"""Deliver all notes for this user in the target channel/user."""
notes = self.get_storage_value("notes", [])

@ -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"])

Loading…
Cancel
Save