Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(MPDControlPlugin, self).__init__(*args, **kwargs)
        self._logger = logging.getLogger(__name__)

        server = profile.get(['mpdclient', 'server'], 'localhost')
        try:
            port = int(profile.get(['mpdclient', 'port'], 6600))
        except ValueError:
            port = 6600
            self._logger.warning(
                "Configured port is invalid, using %d instead",
                port
            )

        password = profile.get(['mpdclient', 'password'], '')
        self._autoplay = profile.get(['mpdclient', 'autoplay'], False)

        # In reticent mode Naomi is quieter.
        self._reticient = profile.get_profile_flag(
            ['mpdclient', 'reticient'],
            False
        )

        self._music = mpdclient.MPDClient(
            server=server,
            port=port,
            password=password
        )
Ejemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     self.passive_listen = profile.get_profile_flag(["passive_listen"])
     keyword = profile.get_profile_var(['keyword'], 'NAOMI')
     if isinstance(keyword, list):
         self._keyword = keyword[0]
     else:
         self._keyword = keyword
     return
Ejemplo n.º 3
0
    def handle(self, text, mic):
        """
        Responds to user-input, typically speech text, with a summary of
        the day's top news headlines, sending them to the user over email
        if desired.

        Arguments:
        intent -- intentparser result with the following layout:
            intent['action'] = the action to take when the intent is activated
            intent['input'] = the original words
            intent['matches'] = dictionary of lists with matching elements,
                each with a list of the actual words matched
            intent['score'] = how confident Naomi is that it matched the
                correct intent.
        mic -- used to interact with the user (for both input and output)
        """
        _ = self.gettext
        num_headlines = profile.get(['hacker-news', 'num-headlines'], 4)

        mic.say(
            _("Getting the top {} stories from Hacker News...").format(
                num_headlines))

        articles = get_top_articles(num_headlines=num_headlines)
        if len(articles) == 0:
            mic.say(" ".join([
                _("Sorry, I'm unable to get the top stories from"),
                _("Hacker News right now.")
            ]))
            return

        text = _('These are the current top stories... ')
        text += '... '.join(f'{i}) {a.title}'
                            for i, a in enumerate(articles, start=1))
        mic.say(text)

        if profile.get_profile_flag(['allows_email']):
            mic.say(_('Would you like me to send you these articles?'))

            answers = mic.active_listen()
            if any(_('YES').upper() in answer.upper() for answer in answers):
                mic.say(_("Sure, just give me a moment."))
                email_text = self.make_email_text(articles)
                email_sent = app_utils.email_user(
                    SUBJECT=_("Top Stories from Hacker News"), BODY=email_text)
                if email_sent:
                    mic.say(_("Okay, I've sent you an email."))
                else:
                    mic.say(
                        _("Sorry, I'm having trouble sending you these articles."
                          ))
            else:
                mic.say(_("Okay, I will not send any articles."))
Ejemplo n.º 4
0
    def handle(self, text, mic):
        """
        Responds to user-input, typically speech text, with a summary of
        the day's top news headlines, sending them to the user over email
        if desired.

        Arguments:
        text -- user-input, typically transcribed speech
        mic -- used to interact with the user (for both input and output)
        """
        _ = self.gettext
        mic.say(self.gettext("Pulling up the news..."))

        lang = profile.get(['language'], 'en-US').split('-')[0]

        articles = get_top_articles(language=lang, num_headlines=5)
        if len(articles) == 0:
            mic.say(
                _("Sorry, I'm unable to get the latest headlines right now."))
            return
        del articles[0]  # fixing "This RSS feed URL is deprecated"
        text = _('These are the current top headlines...')
        text += ' '
        text += '... '.join('%d) %s' % (i, a.title)
                            for i, a in enumerate(articles, start=1))
        mic.say(text)

        email = profile.get(['email', 'address'])
        if not email:
            return

        if profile.get_profile_flag(['allows_email'], False):

            mic.say(_('Would you like me to send you these articles?'))

            answers = mic.active_listen()
            if any(
                    self.gettext('YES').upper() in answer.upper()
                    for answer in answers):
                mic.say(self.gettext("Sure, just give me a moment."))
                SUBJECT = self.gettext("Your Top Headlines")
                email_text = self.make_email_text(articles)
                email_sent = app_utils.email_user(SUBJECT=SUBJECT,
                                                  BODY=email_text)
                if email_sent:
                    mic.say(_("Okay, I've sent you an email."))
                else:
                    mic.say(
                        _("Sorry, I'm having trouble sending you these articles."
                          ))
            else:
                mic.say(self.gettext("Okay, I will not send any articles."))
Ejemplo n.º 5
0
 def __init__(
     self,
     passive_stt_engine,
     active_stt_engine,
     special_stt_slug,
     plugins,
     batch_file,
     keyword='JASPER'
 ):
     self._logger = logging.getLogger(__name__)
     self._keyword = keyword
     self.passive_stt_engine = passive_stt_engine
     self.active_stt_engine = active_stt_engine
     self.special_stt_slug = special_stt_slug
     self.plugins = plugins
     self._commands = parse_batch_file(batch_file)
     self.passive_listen = profile.get_profile_flag(["passive_listen"])
Ejemplo n.º 6
0
 def detect_plugins(self, category=None):
     # Set a flag to let ourselves know if we
     # detected any new plugins this launch,
     # so we can save the changes to the profile.
     save_profile = False
     for plugin_dir in self._plugin_dirs:
         for root, dirs, files in os.walk(plugin_dir, topdown=True):
             for name in files:
                 if name != self._info_fname:
                     continue
                 current_category = os.path.split(root[len(plugin_dir) +
                                                       1:])[0]
                 if current_category == (current_category
                                         if category is None else category):
                     cp = parse_info_file(os.path.join(root, name))
                     if not profile.check_profile_var_exists([
                             'plugins', current_category,
                             cp['Plugin']['name']
                     ]):
                         profile.set_profile_var([
                             'plugins', current_category,
                             cp['Plugin']['name']
                         ], 'Enabled')
                         save_profile = True
                     self._logger.debug(
                         "Found plugin candidate at: {}".format(root))
                     if (profile.get_profile_flag([
                             'plugins', current_category,
                             cp['Plugin']['name']
                     ], False)):
                         try:
                             plugin_info = self.parse_plugin(root)
                         except Exception as e:
                             reason = ''
                             if hasattr(e, 'strerror') and e.strerror:
                                 reason = e.strerror
                                 if hasattr(e, 'errno') and e.errno:
                                     reason += ' [Errno %d]' % e.errno
                             elif hasattr(e, 'message'):
                                 reason = e.message
                             elif hasattr(e, 'msg'):
                                 reason = e.msg
                             if not reason:
                                 reason = 'Unknown'
                             self._logger.warning(
                                 "Plugin at '{}' skipped! (Reason: {})".
                                 format(root, reason),
                                 exc_info=True)
                         else:
                             if plugin_info.name in self._plugins:
                                 self._logger.warning(
                                     "Duplicate plugin: {}".format(
                                         plugin_info.name))
                             else:
                                 self._plugins[
                                     plugin_info.name] = plugin_info
                                 self._logger.debug(
                                     "Found valid plugin: {} {}".format(
                                         plugin_info.name,
                                         plugin_info.version))
                     else:
                         self._logger.debug("{} plugin {} disabled".format(
                             current_category, cp['Plugin']['name']))
     if (save_profile):
         profile.save_profile()