From eb3a03874d4b31527c58f1f54eb5c5ad8ff9fa10 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Sat, 6 May 2023 01:21:06 +0200 Subject: [PATCH] only sleep when inactive --- matrix_pygmalion_bot/bot/core.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/matrix_pygmalion_bot/bot/core.py b/matrix_pygmalion_bot/bot/core.py index fc48f45..48d2e5d 100644 --- a/matrix_pygmalion_bot/bot/core.py +++ b/matrix_pygmalion_bot/bot/core.py @@ -277,11 +277,12 @@ class ChatBot(object): for room_id in self.rooms.keys(): self.rooms[room_id]["tick"] += 1 if datetime.now().hour >= 1 and datetime.now().hour < 5: - load1, load5, load15 = [x / psutil.cpu_count() * 100 for x in psutil.getloadavg()] - if load5 < 25 and load1 < 25: - if not hasattr(self, "last_sleep") or self.last_sleep + timedelta(hours=6) < datetime.now(): - await self.ai.sleep() - self.last_sleep = datetime.now() + if not hasattr(self, "last_conversation") or self.last_conversation + timedelta(minutes=30) < datetime.now(): + load1, load5, load15 = [x / psutil.cpu_count() * 100 for x in psutil.getloadavg()] + if load5 < 25 and load1 < 25: + if not hasattr(self, "last_sleep") or self.last_sleep + timedelta(hours=6) < datetime.now(): + await self.ai.sleep() + self.last_sleep = datetime.now() finally: