From 29258a13b4522cb5fad5057560e2fcaa36bc998a Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 2 Nov 2020 16:54:14 +0100 Subject: [PATCH] sleep: allow multiple sleep/wakeup messages --- config.json.example | 4 ++-- edmond/plugins/sleep.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config.json.example b/config.json.example index a168ff9..06a8da7 100644 --- a/config.json.example +++ b/config.json.example @@ -62,8 +62,8 @@ "sleep_time": 23, "wakeup_time": 7, "snore": "Zzzz", - "sleep_message": "/me falls asleep", - "wakeup_message": "/me wakes up", + "sleep_messages": ["/me falls asleep"], + "wakeup_messages": ["/me wakes up"], "snore_rate": 1.0 }, "wikipedia": { diff --git a/edmond/plugins/sleep.py b/edmond/plugins/sleep.py index de3a4a7..65cb93e 100644 --- a/edmond/plugins/sleep.py +++ b/edmond/plugins/sleep.py @@ -1,3 +1,4 @@ +import random from datetime import datetime, timedelta from edmond.plugin import Plugin @@ -8,8 +9,8 @@ class SleepPlugin(Plugin): """Handle sleep state of the bot, snore a little bit.""" REQUIRED_CONFIGS = [ - "commands", "sleep_time", "wakeup_time", "snore", "sleep_message", - "wakeup_message", "snore_rate" + "commands", "sleep_time", "wakeup_time", "snore", "sleep_messages", + "wakeup_messages", "snore_rate" ] def __init__(self, bot): @@ -58,7 +59,7 @@ class SleepPlugin(Plugin): if not self.get_runtime_value("awake"): return 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) def wake_up(self): @@ -66,7 +67,7 @@ class SleepPlugin(Plugin): return self.set_runtime_value("awake", True) 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): """Return True if the bot should be sleeping by now.