From 7f29c2ee60889059fdb2f9770f2247cda4f5f8eb Mon Sep 17 00:00:00 2001 From: jarbasai Date: Wed, 15 Jun 2022 17:34:56 +0100 Subject: [PATCH] message history --- .../skills/intent_services/converse_service.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mycroft/skills/intent_services/converse_service.py b/mycroft/skills/intent_services/converse_service.py index 02093429f95..b270e740206 100644 --- a/mycroft/skills/intent_services/converse_service.py +++ b/mycroft/skills/intent_services/converse_service.py @@ -24,14 +24,12 @@ def activate_skill(self, skill_id): self.deactivate_skill(skill_id) # add skill with timestamp to start of active list self.active_skills.insert(0, [skill_id, time.time()]) - self._prune_history() def deactivate_skill(self, skill_id): active_ids = [s[0] for s in self.active_skills] if skill_id in active_ids: idx = active_ids.index(skill_id) self.active_skills.pop(idx) - self._prune_history() def is_active(self, skill_id): self._prune_history() @@ -52,13 +50,18 @@ def clear(self): self.history = [] # [Message , timestamp] def as_dict(self): - self._prune_history() return { "active_skills": self.active_skills, "session_id": self.session_id, "history": self.history } + def update_history(self, message=None): + message = message or dig_for_message() + if message: + self.history.append(message) + self._prune_history() + @staticmethod def from_dict(data): uid = data.get("session_id") @@ -151,6 +154,8 @@ def deactivate_skill(self, skill_id, source_skill=None, message=None): session = self.get_session(message) if session.is_active(skill_id): # update converse session + if message: + session.update_history(message) session.deactivate_skill(skill_id) # also update default session if session.session_id != self.default_session.session_id: @@ -177,6 +182,8 @@ def activate_skill(self, skill_id, source_skill=None, message=None): if self._activate_allowed(skill_id, source_skill): # update converse session session = self.get_session(message) + if message: + session.update_history(message) session.activate_skill(skill_id) # also update default session if session.session_id != self.default_session.session_id: @@ -336,6 +343,8 @@ def converse(self, utterances, skill_id, lang, message): handled (bool): True if handled otherwise False. """ if self._converse_allowed(skill_id): + session = self.get_session(message) + session.update_history(message) converse_msg = message.reply("skill.converse.request", {"skill_id": skill_id, "utterances": utterances,