Skip to content

Commit

Permalink
feat/ocp_skill_name_from_voc (#220)
Browse files Browse the repository at this point in the history
* feat/ocp_skill_name_from_voc

solve TODO, allow devs to specify a .voc file with skill name strings, instead of deriving from class name

* feat/ocp_skill_name_from_voc

solve TODO, allow devs to specify a .voc file with skill name strings, instead of deriving from class name
  • Loading branch information
JarbasAl authored Jul 11, 2024
1 parent 3b7ab46 commit b46a893
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions ovos_workshop/skills/common_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ def ...
vocab for starting playback is needed.
"""

def __init__(self, supported_media=None, skill_icon="", *args, **kwargs):
def __init__(self, supported_media: List[MediaType] = None,
skill_icon: str = "",
skill_voc_filename: str = "",
*args, **kwargs):
self.supported_media = supported_media or [MediaType.GENERIC]
skill_name = camel_case_split(self.__class__.__name__)
alt = skill_name.replace(" skill", "").replace(" Skill", "")
self.skill_aliases = [skill_name, alt]

self.skill_aliases = []
self.skill_voc_filename = skill_voc_filename
self._search_handlers = [] # added via decorators
self._featured_handlers = [] # added via decorators
self._current_query = None
Expand All @@ -78,6 +79,18 @@ def __init__(self, supported_media=None, skill_icon="", *args, **kwargs):
self.ocp_matchers = {}
super().__init__(*args, **kwargs)

def _read_skill_name_voc(self):
"""read voc file to allow requesting a skill by name"""
if self.skill_voc_filename:
for lang in self.native_langs:
self.skill_aliases += self.voc_list(self.skill_voc_filename, lang)
if not self.skill_aliases:
skill_name = camel_case_split(self.__class__.__name__)
alt = skill_name.replace(" skill", "").replace(" Skill", "")
self.skill_aliases = [skill_name, alt]
# deduplicate and sort by str len
self.skill_aliases = sorted(list(set(self.skill_aliases)), reverse=True)

@property
def ocp_cache_dir(self):
"""path to cached .csv file with ocp entities data
Expand Down Expand Up @@ -142,6 +155,7 @@ def __handle_ocp_skills_get(self, message=None):
it will search netflix instead of spotify
"""
message = message or Message("")
# TODO - aliases per lang
self.bus.emit(
message.reply('ovos.common_play.announce',
{"skill_id": self.skill_id,
Expand Down Expand Up @@ -337,11 +351,14 @@ def _register_decorated(self):

super()._register_decorated()

# needs to be after super() because it needs self.config_core
self._read_skill_name_voc()
# volunteer info to OCP
self.bus.emit(
Message('ovos.common_play.announce',
{"skill_id": self.skill_id,
"skill_name": self.skill_aliases[0],
"aliases": self.skill_aliases,
"thumbnail": self.skill_icon,
"media_types": self.supported_media,
"featured_tracks": len(self._featured_handlers) >= 1}))
Expand Down

0 comments on commit b46a893

Please sign in to comment.