sleep: allow multiple sleep/wakeup messages
This commit is contained in:
parent
4480a3b44a
commit
29258a13b4
|
@ -62,8 +62,8 @@
|
||||||
"sleep_time": 23,
|
"sleep_time": 23,
|
||||||
"wakeup_time": 7,
|
"wakeup_time": 7,
|
||||||
"snore": "Zzzz",
|
"snore": "Zzzz",
|
||||||
"sleep_message": "/me falls asleep",
|
"sleep_messages": ["/me falls asleep"],
|
||||||
"wakeup_message": "/me wakes up",
|
"wakeup_messages": ["/me wakes up"],
|
||||||
"snore_rate": 1.0
|
"snore_rate": 1.0
|
||||||
},
|
},
|
||||||
"wikipedia": {
|
"wikipedia": {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import random
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from edmond.plugin import Plugin
|
from edmond.plugin import Plugin
|
||||||
|
@ -8,8 +9,8 @@ class SleepPlugin(Plugin):
|
||||||
"""Handle sleep state of the bot, snore a little bit."""
|
"""Handle sleep state of the bot, snore a little bit."""
|
||||||
|
|
||||||
REQUIRED_CONFIGS = [
|
REQUIRED_CONFIGS = [
|
||||||
"commands", "sleep_time", "wakeup_time", "snore", "sleep_message",
|
"commands", "sleep_time", "wakeup_time", "snore", "sleep_messages",
|
||||||
"wakeup_message", "snore_rate"
|
"wakeup_messages", "snore_rate"
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -58,7 +59,7 @@ class SleepPlugin(Plugin):
|
||||||
if not self.get_runtime_value("awake"):
|
if not self.get_runtime_value("awake"):
|
||||||
return
|
return
|
||||||
for channel in self.bot.channels:
|
for channel in self.bot.channels:
|
||||||
self.bot.say(channel, self.config["sleep_message"])
|
self.bot.say(channel, random.choice(self.config["sleep_messages"]))
|
||||||
self.set_runtime_value("awake", False)
|
self.set_runtime_value("awake", False)
|
||||||
|
|
||||||
def wake_up(self):
|
def wake_up(self):
|
||||||
|
@ -66,7 +67,7 @@ class SleepPlugin(Plugin):
|
||||||
return
|
return
|
||||||
self.set_runtime_value("awake", True)
|
self.set_runtime_value("awake", True)
|
||||||
for channel in self.bot.channels:
|
for channel in self.bot.channels:
|
||||||
self.bot.say(channel, self.config["wakeup_message"])
|
self.bot.say(channel, random.choice(self.config["wakeup_messages"]))
|
||||||
|
|
||||||
def is_sleep_time(self, now):
|
def is_sleep_time(self, now):
|
||||||
"""Return True if the bot should be sleeping by now.
|
"""Return True if the bot should be sleeping by now.
|
||||||
|
|
Loading…
Reference in a new issue