Skip to content

Commit

Permalink
message history
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jun 15, 2022
1 parent a3ebac7 commit 7f29c2e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions mycroft/skills/intent_services/converse_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7f29c2e

Please sign in to comment.