From 1d851bf622a36a35dcb7ce6c4cb8dc661bf0817d Mon Sep 17 00:00:00 2001 From: Ken Smith Date: Mon, 17 May 2021 15:29:25 -0400 Subject: [PATCH 1/2] handle stop properly and make stateful --- __init__.py | 26 +++++++++++++++++++++++++- vocab/en-us/Stop.voc | 10 ++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 vocab/en-us/Stop.voc diff --git a/__init__.py b/__init__.py index 8557a17..d7cc911 100644 --- a/__init__.py +++ b/__init__.py @@ -196,6 +196,13 @@ def initialize(self): # Longer titles or alternative common names of feeds for searching self.alt_feed_names = self.translate_namedvalues('alt.feed.name') + self.skill_control.states = { + 'inactive':['handle_latest_news'], + 'active':['restart_playback'] + } + self.skill_control.state = 'inactive' + self.skill_control.category = 'common_play' + def CPS_match_query_phrase(self, phrase): matched_feed = { 'key': None, 'conf': 0.0 } @@ -334,6 +341,21 @@ def get_media_url(self, station_url): media_url = media_url.split('?')[0] return media_url + def converse(self, utterances, lang="en-us"): + LOG.debug("NPR converse entered, utterances:%s" % (utterances,)) + """if playing see if user wants to quit""" + # custom stop handler + # note this will work for now but really this should + # be an intent which is enabled while in the active state + # and disabled otherwise + if utterances and self.voc_match(utterances[0], "Stop"): + self.stop() + return True # consume this phrase + else: + self.log.info("NewsSkill:Converse confused by %s - let common play handle it" % (utterances,)) + + return False # don't consume this phrase + @intent_file_handler("PlayTheNews.intent") def handle_latest_news_alt(self, message): # Capture some alternative ways of requesting the news via Padatious @@ -389,7 +411,8 @@ def handle_latest_news(self, message=None, feed=None): self.CPS_send_status(image=image or image_path('generic.png'), track=self.now_playing) self.last_message = (True, message) - self.enable_intent('restart_playback') + self.change_state('active') + self.enable_intent('restart_playback') # should be unnecessary except Exception as e: self.log.error("Error: {0}".format(e)) @@ -403,6 +426,7 @@ def restart_playback(self, message): self.handle_latest_news(self.last_message[1]) def stop(self): + self.change_state('inactive') # Disable restarting when stopped if self.last_message: self.disable_intent('restart_playback') diff --git a/vocab/en-us/Stop.voc b/vocab/en-us/Stop.voc new file mode 100644 index 0000000..6eb5cd0 --- /dev/null +++ b/vocab/en-us/Stop.voc @@ -0,0 +1,10 @@ +silence +quit +end +stop +shut +off +turn +quiet +terminate +abort From b24747d8ba9cc0a048aac306140a6a72272b2db9 Mon Sep 17 00:00:00 2001 From: Kris Gesling Date: Thu, 17 Jun 2021 07:12:10 +0930 Subject: [PATCH 2/2] fix bs4 import --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 33e6647..13b13c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -bs4==4.9.0 +beautifulsoup4==4.9.0 feedparser~=6.0.0