Browse Source

only sleep when inactive

master
Hendrik Langer 2 years ago
parent
commit
eb3a03874d
  1. 11
      matrix_pygmalion_bot/bot/core.py

11
matrix_pygmalion_bot/bot/core.py

@ -277,11 +277,12 @@ class ChatBot(object):
for room_id in self.rooms.keys(): for room_id in self.rooms.keys():
self.rooms[room_id]["tick"] += 1 self.rooms[room_id]["tick"] += 1
if datetime.now().hour >= 1 and datetime.now().hour < 5: if datetime.now().hour >= 1 and datetime.now().hour < 5:
load1, load5, load15 = [x / psutil.cpu_count() * 100 for x in psutil.getloadavg()] if not hasattr(self, "last_conversation") or self.last_conversation + timedelta(minutes=30) < datetime.now():
if load5 < 25 and load1 < 25: load1, load5, load15 = [x / psutil.cpu_count() * 100 for x in psutil.getloadavg()]
if not hasattr(self, "last_sleep") or self.last_sleep + timedelta(hours=6) < datetime.now(): if load5 < 25 and load1 < 25:
await self.ai.sleep() if not hasattr(self, "last_sleep") or self.last_sleep + timedelta(hours=6) < datetime.now():
self.last_sleep = datetime.now() await self.ai.sleep()
self.last_sleep = datetime.now()
finally: finally:

Loading…
Cancel
Save