Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
mycroft.skills.core.MycroftSkill Class Reference

MycroftSkill base class. More...

Inheritance diagram for mycroft.skills.core.MycroftSkill:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, name=None, bus=None, use_settings=True)
 
def acknowledge (self)
 
def add_event (self, name, handler, handler_info=None, once=False)
 
def ask_yesno (self, prompt, data=None)
 
def bind (self, bus)
 
def bus (self)
 
def cancel_all_repeating_events (self)
 
def cancel_scheduled_event (self, name)
 
def config (self)
 
def converse (self, utterances, lang=None)
 
def default_shutdown (self)
 
def detach (self)
 
def disable_intent (self, intent_name)
 
def enable_intent (self, intent_name)
 
def enclosure (self)
 
def find_resource (self, res_name, res_dirname=None)
 
def get_intro_message (self)
 
def get_response (self, dialog='', data=None, validator=None, on_fail=None, num_retries=-1)
 
def get_scheduled_event_status (self, name)
 
def handle_disable_intent (self, message)
 
def handle_enable_intent (self, message)
 
def handle_remove_cross_context (self, message)
 
def handle_set_cross_context (self, message)
 
def init_dialog (self, root_directory)
 
def initialize (self)
 
def lang (self)
 
def load_data_files (self, root_directory)
 
def load_regex_files (self, root_directory)
 
def load_vocab_files (self, root_directory)
 
def location (self)
 
def location_pretty (self)
 
def location_timezone (self)
 
def make_active (self)
 
def register_entity_file (self, entity_file)
 
def register_intent (self, intent_parser, handler)
 
def register_intent_file (self, intent_file, handler)
 
def register_regex (self, regex_str)
 
def register_resting_screen (self)
 
def register_vocabulary (self, entity, entity_type)
 
def remove_context (self, context)
 
def remove_cross_skill_context (self, context)
 
def remove_event (self, name)
 
def report_metric (self, name, data)
 
def schedule_event (self, handler, when, data=None, name=None)
 
def schedule_repeating_event (self, handler, when, frequency, data=None, name=None)
 
def send_email (self, title, body)
 
def set_context (self, context, word='', origin=None)
 
def set_cross_skill_context (self, context, word='')
 
def shutdown (self)
 
def speak (self, utterance, expect_response=False, wait=False)
 
def speak_dialog (self, key, data=None, expect_response=False, wait=False)
 
def stop (self)
 
def translate (self, text, data=None)
 
def translate_list (self, list_name, data=None)
 
def translate_namedvalues (self, name, delim=None)
 
def translate_template (self, template_name, data=None)
 
def update_scheduled_event (self, name, data=None)
 
def voc_match (self, utt, voc_filename, lang=None)
 

Public Attributes

 config_core
 
 converse
 
 dialog_renderer
 
 events
 
 file_system
 
 gui
 
 log
 
 name
 
 registered_intents
 
 reload_skill
 
 resting_name
 
 root_dir
 
 scheduled_repeats
 
 settings
 
 skill_id
 
 voc_match_cache
 

Private Member Functions

def __get_response (self)
 
def __handle_stop (self, event)
 
def __translate_file (self, name, data)
 
def _handle_collect_resting (self, message=None)
 
def _register_decorated (self)
 
def _schedule_event (self, handler, when, data=None, name=None, repeat=None)
 
def _unique_name (self, name)
 

Private Attributes

 _bus
 
 _config
 
 _dir
 
 _enclosure
 

Detailed Description

MycroftSkill base class.

Abstract base class which provides common behaviour and parameters to all
Skills implementation.

Definition at line 483 of file core.py.

Constructor & Destructor Documentation

def mycroft.skills.core.MycroftSkill.__init__ (   self,
  name = None,
  bus = None,
  use_settings = True 
)

Definition at line 489 of file core.py.

Member Function Documentation

def mycroft.skills.core.MycroftSkill.__get_response (   self)
private
Helper to get a reponse from the user

Returns:
    str: user's response or None on a timeout

Definition at line 653 of file core.py.

def mycroft.skills.core.MycroftSkill.__handle_stop (   self,
  event 
)
private
    Handler for the "mycroft.stop" signal. Runs the user defined
    `stop()` method.

Definition at line 1458 of file core.py.

def mycroft.skills.core.MycroftSkill.__translate_file (   self,
  name,
  data 
)
private
Load and render lines from dialog/<lang>/<name>

Definition at line 1032 of file core.py.

def mycroft.skills.core.MycroftSkill._handle_collect_resting (   self,
  message = None 
)
private
Handler for collect resting screen messages.

    Sends info on how to trigger this skills resting page.

Definition at line 844 of file core.py.

def mycroft.skills.core.MycroftSkill._register_decorated (   self)
private
Register all intent handlers that are decorated with an intent.

Looks for all functions that have been marked by a decorator
and read the intent data from them

Definition at line 881 of file core.py.

def mycroft.skills.core.MycroftSkill._schedule_event (   self,
  handler,
  when,
  data = None,
  name = None,
  repeat = None 
)
private
    Underlying method for schedule_event and schedule_repeating_event.
    Takes scheduling information and sends it off on the message bus.

Definition at line 1537 of file core.py.

def mycroft.skills.core.MycroftSkill._unique_name (   self,
  name 
)
private
    Return a name unique to this skill using the format
    [skill_id]:[name].

    Args:
name:   Name to use internally

    Returns:
str: name unique to this skill

Definition at line 1523 of file core.py.

def mycroft.skills.core.MycroftSkill.acknowledge (   self)
Acknowledge a successful request.

This method plays a sound to acknowledge a request that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was handled successfully.

Definition at line 1681 of file core.py.

def mycroft.skills.core.MycroftSkill.add_event (   self,
  name,
  handler,
  handler_info = None,
  once = False 
)
Create event handler for executing intent

Args:
    name (string): IntentParser name
    handler (func): Method to call
    handler_info (string): Base message when reporting skill event
                   handler status on messagebus.
    once (bool, optional): Event handler will be removed after it has
                   been run once.

Definition at line 1042 of file core.py.

def mycroft.skills.core.MycroftSkill.ask_yesno (   self,
  prompt,
  data = None 
)
Read prompt and wait for a yes/no answer

This automatically deals with translation and common variants,
such as 'yeah', 'sure', etc.

Args:
      prompt (str): a dialog id or string to read
Returns:
      string:  'yes', 'no' or whatever the user response if not
       one of those, including None

Definition at line 754 of file core.py.

def mycroft.skills.core.MycroftSkill.bind (   self,
  bus 
)
Register messagebus emitter with skill.

Arguments:
    bus: Mycroft messagebus connection

Definition at line 582 of file core.py.

def mycroft.skills.core.MycroftSkill.bus (   self)

Definition at line 533 of file core.py.

def mycroft.skills.core.MycroftSkill.cancel_all_repeating_events (   self)
Cancel any repeating events started by the skill. 

Definition at line 1674 of file core.py.

def mycroft.skills.core.MycroftSkill.cancel_scheduled_event (   self,
  name 
)
    Cancel a pending event. The event will no longer be scheduled
    to be executed

    Args:
name (str): reference name of event (from original scheduling)

Definition at line 1617 of file core.py.

def mycroft.skills.core.MycroftSkill.config (   self)
Provide deprecation warning when accessing config.
TODO: Remove in 19.08

Definition at line 543 of file core.py.

def mycroft.skills.core.MycroftSkill.converse (   self,
  utterances,
  lang = None 
)
Handle conversation.

This method gets a peek at utterances before the normal intent
handling process after a skill has been invoked once.

To use, override the converse() method and return True to
indicate that the utterance has been handled.

Args:
    utterances (list): The utterances from the user.  If there are
               multiple utterances, consider them all to be
               transcription possibilities.  Commonly, the
               first entry is the user utt and the second
               is normalized() version of the first utterance
    lang:       language the utterance is in, None for default

Returns:
    bool: True if an utterance was handled, otherwise False

Definition at line 631 of file core.py.

def mycroft.skills.core.MycroftSkill.default_shutdown (   self)
Parent function called internally to shut down everything.

Shuts down known entities and calls skill specific shutdown method.

Definition at line 1491 of file core.py.

def mycroft.skills.core.MycroftSkill.detach (   self)

Definition at line 608 of file core.py.

def mycroft.skills.core.MycroftSkill.disable_intent (   self,
  intent_name 
)
Disable a registered intent if it belongs to this skill

Args:
    intent_name (string): name of the intent to be disabled

Returns:
bool: True if disabled, False if it wasn't registered

Definition at line 1246 of file core.py.

def mycroft.skills.core.MycroftSkill.enable_intent (   self,
  intent_name 
)
(Re)Enable a registered intent if it belongs to this skill

Args:
intent_name: name of the intent to be enabled

Returns:
bool: True if enabled, False if it wasn't registered

Definition at line 1267 of file core.py.

def mycroft.skills.core.MycroftSkill.enclosure (   self)

Definition at line 523 of file core.py.

def mycroft.skills.core.MycroftSkill.find_resource (   self,
  res_name,
  res_dirname = None 
)
Find a resource file

Searches for the given filename using this scheme:
1) Search the resource lang directory:
     <skill>/<res_dirname>/<lang>/<res_name>
2) Search the resource directory:
     <skill>/<res_dirname>/<res_name>
3) Search the locale lang directory or other subdirectory:
     <skill>/locale/<lang>/<res_name> or
     <skill>/locale/<lang>/.../<res_name>

Args:
    res_name (string): The resource name to be found
    res_dirname (string, optional): A skill resource directory, such
                            'dialog', 'vocab', 'regex' or 'ui'.
                            Defaults to None.

Returns:
    string: The full path to the resource file or None if not found

Definition at line 916 of file core.py.

def mycroft.skills.core.MycroftSkill.get_intro_message (   self)
Get a message to speak on first load of the skill.

Useful for post-install setup instructions.

Returns:
    str: message that will be spoken to the user

Definition at line 621 of file core.py.

def mycroft.skills.core.MycroftSkill.get_response (   self,
  dialog = '',
  data = None,
  validator = None,
  on_fail = None,
  num_retries = -1 
)
Prompt user and wait for response

The given dialog is spoken, followed immediately by listening
for a user response.  The response can optionally be
validated before returning.

Example:
    color = self.get_response('ask.favorite.color')

Args:
    dialog (str): Announcement dialog to speak to the user
    data (dict): Data used to render the dialog
    validator (any): Function with following signature
def validator(utterance):
    return utterance != "red"
    on_fail (any): Dialog or function returning literal string
           to speak on invalid input.  For example:
def on_fail(utterance):
    return "nobody likes the color red, pick another"
    num_retries (int): Times to ask user for input, -1 for infinite
NOTE: User can not respond and timeout or say "cancel" to stop

Returns:
    str: User's reply or None if timed out or canceled

Definition at line 676 of file core.py.

def mycroft.skills.core.MycroftSkill.get_scheduled_event_status (   self,
  name 
)
    Get scheduled event data and return the amount of time left

    Args:
name (str): reference name of event (from original scheduling)

    Return:
int: the time left in seconds

    Raises:
Exception: Raised if event is not found

Definition at line 1633 of file core.py.

def mycroft.skills.core.MycroftSkill.handle_disable_intent (   self,
  message 
)
Listener to disable a registered intent if it belongs to this skill

Definition at line 1237 of file core.py.

def mycroft.skills.core.MycroftSkill.handle_enable_intent (   self,
  message 
)
Listener to enable a registered intent if it belongs to this skill

Definition at line 1228 of file core.py.

def mycroft.skills.core.MycroftSkill.handle_remove_cross_context (   self,
  message 
)
    Remove global context from intent service

Definition at line 1324 of file core.py.

def mycroft.skills.core.MycroftSkill.handle_set_cross_context (   self,
  message 
)
    Add global context to intent service

Definition at line 1313 of file core.py.

def mycroft.skills.core.MycroftSkill.init_dialog (   self,
  root_directory 
)

Definition at line 1422 of file core.py.

def mycroft.skills.core.MycroftSkill.initialize (   self)
Perform any final setup needed for the skill.

Invoked after the skill is fully constructed and registered with the
system.

Definition at line 613 of file core.py.

def mycroft.skills.core.MycroftSkill.lang (   self)

Definition at line 579 of file core.py.

def mycroft.skills.core.MycroftSkill.load_data_files (   self,
  root_directory 
)

Definition at line 1434 of file core.py.

def mycroft.skills.core.MycroftSkill.load_regex_files (   self,
  root_directory 
)

Definition at line 1450 of file core.py.

def mycroft.skills.core.MycroftSkill.load_vocab_files (   self,
  root_directory 
)

Definition at line 1440 of file core.py.

def mycroft.skills.core.MycroftSkill.location (   self)
Get the JSON data struction holding location information. 

Definition at line 556 of file core.py.

def mycroft.skills.core.MycroftSkill.location_pretty (   self)
Get a more 'human' version of the location as a string. 

Definition at line 563 of file core.py.

def mycroft.skills.core.MycroftSkill.location_timezone (   self)
Get the timezone code, such as 'America/Los_Angeles' 

Definition at line 571 of file core.py.

def mycroft.skills.core.MycroftSkill.make_active (   self)
Bump skill to active_skill list in intent_service

This enables converse method to be called even without skill being
used in last 5 minutes.

Definition at line 835 of file core.py.

def mycroft.skills.core.MycroftSkill.register_entity_file (   self,
  entity_file 
)
Register an Entity file with the intent service.

An Entity file lists the exact values that an entity can hold.
For example:

=== ask.day.intent ===
Is it {weekend}?

=== weekend.entity ===
Saturday
Sunday

Args:
    entity_file (string): name of file that contains examples of an
                  entity.  Must end with '.entity'

Definition at line 1196 of file core.py.

def mycroft.skills.core.MycroftSkill.register_intent (   self,
  intent_parser,
  handler 
)
Register an Intent with the intent service.

Args:
    intent_parser: Intent or IntentBuilder object to parse
           utterance for the handler.
    handler (func): function to register with intent

Definition at line 1133 of file core.py.

def mycroft.skills.core.MycroftSkill.register_intent_file (   self,
  intent_file,
  handler 
)
    Register an Intent file with the intent service.
    For example:

    === food.order.intent ===
    Order some {food}.
    Order some {food} from {place}.
    I'm hungry.
    Grab some {food} from {place}.

    Optionally, you can also use <register_entity_file>
    to specify some examples of {food} and {place}

    In addition, instead of writing out multiple variations
    of the same sentence you can write:

    === food.order.intent ===
    (Order | Grab) some {food} (from {place} | ).
    I'm hungry.

    Args:
intent_file: name of file that contains example queries
             that should activate the intent.  Must end with
             '.intent'
handler:     function to register with intent

Definition at line 1153 of file core.py.

def mycroft.skills.core.MycroftSkill.register_regex (   self,
  regex_str 
)
Register a new regex.
    Args:
regex_str: Regex string

Definition at line 1373 of file core.py.

def mycroft.skills.core.MycroftSkill.register_resting_screen (   self)
Registers resting screen from the resting_screen_handler decorator.

    This only allows one screen and if two is registered only one
    will be used.

Definition at line 854 of file core.py.

def mycroft.skills.core.MycroftSkill.register_vocabulary (   self,
  entity,
  entity_type 
)
Register a word to a keyword

    Args:
entity:         word to register
entity_type:    Intent handler entity to tie the word to

Definition at line 1362 of file core.py.

def mycroft.skills.core.MycroftSkill.remove_context (   self,
  context 
)
    remove a keyword from the context manager.

Definition at line 1353 of file core.py.

def mycroft.skills.core.MycroftSkill.remove_cross_skill_context (   self,
  context 
)
   tell all skills to remove a keyword from the context manager.

Definition at line 1344 of file core.py.

def mycroft.skills.core.MycroftSkill.remove_event (   self,
  name 
)
Removes an event from bus emitter and events list

Args:
    name (string): Name of Intent or Scheduler Event
Returns:
    bool: True if found and removed, False if not found

Definition at line 1105 of file core.py.

def mycroft.skills.core.MycroftSkill.report_metric (   self,
  name,
  data 
)
Report a skill metric to the Mycroft servers

Args:
    name (str): Name of metric. Must use only letters and hyphens
    data (dict): JSON dictionary to report. Must be valid JSON

Definition at line 816 of file core.py.

def mycroft.skills.core.MycroftSkill.schedule_event (   self,
  handler,
  when,
  data = None,
  name = None 
)
    Schedule a single-shot event.

    Args:
handler:               method to be called
when (datetime/int/float):   datetime (in system timezone) or
                       number of seconds in the future when the
                       handler should be called
data (dict, optional): data to send when the handler is called
name (str, optional):  reference name
                       NOTE: This will not warn or replace a
                       previously scheduled event of the same
                       name.

Definition at line 1558 of file core.py.

def mycroft.skills.core.MycroftSkill.schedule_repeating_event (   self,
  handler,
  when,
  frequency,
  data = None,
  name = None 
)
    Schedule a repeating event.

    Args:
handler:                method to be called
when (datetime):        time (in system timezone) for first
                        calling the handler, or None to
                        initially trigger <frequency> seconds
                        from now
frequency (float/int):  time in seconds between calls
data (dict, optional):  data to send when the handler is called
name (str, optional):   reference name, must be unique

Definition at line 1579 of file core.py.

def mycroft.skills.core.MycroftSkill.send_email (   self,
  title,
  body 
)
Send an email to the registered user's email

Args:
    title (str): Title of email
    body  (str): HTML body of email. This supports
         simple HTML like bold and italics

Definition at line 825 of file core.py.

def mycroft.skills.core.MycroftSkill.set_context (   self,
  context,
  word = '',
  origin = None 
)
    Add context to intent service

    Args:
context:    Keyword
word:       word connected to keyword

Definition at line 1294 of file core.py.

def mycroft.skills.core.MycroftSkill.set_cross_skill_context (   self,
  context,
  word = '' 
)
    Tell all skills to add a context to intent service

    Args:
context:    Keyword
word:       word connected to keyword

Definition at line 1332 of file core.py.

def mycroft.skills.core.MycroftSkill.shutdown (   self)
This method is intended to be called during the skill
process termination. The skill implementation must
shutdown all processes and operations in execution.

Definition at line 1483 of file core.py.

def mycroft.skills.core.MycroftSkill.speak (   self,
  utterance,
  expect_response = False,
  wait = False 
)
Speak a sentence.

    Args:
utterance (str):        sentence mycroft should speak
expect_response (bool): set to True if Mycroft should listen
                        for a response immediately after
                        speaking the utterance.
wait (bool):            set to True to block while the text
                        is being spoken.

Definition at line 1382 of file core.py.

def mycroft.skills.core.MycroftSkill.speak_dialog (   self,
  key,
  data = None,
  expect_response = False,
  wait = False 
)
Speak a random sentence from a dialog file.

    Args:
key (str): dialog file key (e.g. "hello" to speak from the file
                            "locale/en-us/hello.dialog")
data (dict): information used to populate sentence
expect_response (bool): set to True if Mycroft should listen
                        for a response immediately after
                        speaking the utterance.
wait (bool):            set to True to block while the text
                        is being spoken.

Definition at line 1405 of file core.py.

def mycroft.skills.core.MycroftSkill.stop (   self)

Definition at line 1480 of file core.py.

def mycroft.skills.core.MycroftSkill.translate (   self,
  text,
  data = None 
)
Load a translatable single string resource

The string is loaded from a file in the skill's dialog subdirectory
  'dialog/<lang>/<text>.dialog'
The string is randomly chosen from the file and rendered, replacing
mustache placeholders with values found in the data dictionary.

Args:
    text (str): The base filename  (no extension needed)
    data (dict, optional): a JSON dictionary

Returns:
    str: A randomly chosen string from the file

Definition at line 899 of file core.py.

def mycroft.skills.core.MycroftSkill.translate_list (   self,
  list_name,
  data = None 
)
Load a list of translatable string resources

The strings are loaded from a list file in the skill's dialog
subdirectory.
  'dialog/<lang>/<list_name>.list'
The strings are loaded and rendered, replacing mustache placeholders
with values found in the data dictionary.

Args:
    list_name (str): The base filename (no extension needed)
    data (dict, optional): a JSON dictionary

Returns:
    list of str: The loaded list of strings with items in consistent
         positions regardless of the language.

Definition at line 1013 of file core.py.

def mycroft.skills.core.MycroftSkill.translate_namedvalues (   self,
  name,
  delim = None 
)
Load translation dict containing names and values.

This loads a simple CSV from the 'dialog' folders.
The name is the first list item, the value is the
second.  Lines prefixed with # or // get ignored

Args:
    name (str): name of the .value file, no extension needed
    delim (char): delimiter character used, default is ','

Returns:
    dict: name and value dictionary, or empty dict if load fails

Definition at line 957 of file core.py.

def mycroft.skills.core.MycroftSkill.translate_template (   self,
  template_name,
  data = None 
)
Load a translatable template

The strings are loaded from a template file in the skill's dialog
subdirectory.
  'dialog/<lang>/<template_name>.template'
The strings are loaded and rendered, replacing mustache placeholders
with values found in the data dictionary.

Args:
    template_name (str): The base filename (no extension needed)
    data (dict, optional): a JSON dictionary

Returns:
    list of str: The loaded template file

Definition at line 995 of file core.py.

def mycroft.skills.core.MycroftSkill.update_scheduled_event (   self,
  name,
  data = None 
)
    Change data of event.

    Args:
name (str): reference name of event (from original scheduling)

Definition at line 1603 of file core.py.

def mycroft.skills.core.MycroftSkill.voc_match (   self,
  utt,
  voc_filename,
  lang = None 
)
Determine if the given utterance contains the vocabulary provided

Checks for vocabulary match in the utterance instead of the other
way around to allow the user to say things like "yes, please" and
still match against "Yes.voc" containing only "yes". The method first
checks in the current skill's .voc files and secondly the "res/text"
folder of mycroft-core. The result is cached to avoid hitting the
disk each time the method is called.

Args:
    utt (str): Utterance to be tested
    voc_filename (str): Name of vocabulary file (e.g. 'yes' for
                'res/text/en-us/yes.voc')
    lang (str): Language code, defaults to self.long

Returns:
    bool: True if the utterance has the given vocabulary it

Definition at line 775 of file core.py.

Member Data Documentation

mycroft.skills.core.MycroftSkill._bus
private

Definition at line 501 of file core.py.

mycroft.skills.core.MycroftSkill._config
private

Definition at line 507 of file core.py.

mycroft.skills.core.MycroftSkill._dir
private

Definition at line 493 of file core.py.

mycroft.skills.core.MycroftSkill._enclosure
private

Definition at line 502 of file core.py.

mycroft.skills.core.MycroftSkill.config_core

Definition at line 505 of file core.py.

mycroft.skills.core.MycroftSkill.converse

Definition at line 670 of file core.py.

mycroft.skills.core.MycroftSkill.dialog_renderer

Definition at line 508 of file core.py.

mycroft.skills.core.MycroftSkill.events

Definition at line 517 of file core.py.

mycroft.skills.core.MycroftSkill.file_system

Definition at line 513 of file core.py.

mycroft.skills.core.MycroftSkill.gui

Definition at line 499 of file core.py.

mycroft.skills.core.MycroftSkill.log

Definition at line 515 of file core.py.

mycroft.skills.core.MycroftSkill.name

Definition at line 490 of file core.py.

mycroft.skills.core.MycroftSkill.registered_intents

Definition at line 514 of file core.py.

mycroft.skills.core.MycroftSkill.reload_skill

Definition at line 516 of file core.py.

mycroft.skills.core.MycroftSkill.resting_name

Definition at line 491 of file core.py.

mycroft.skills.core.MycroftSkill.root_dir

Definition at line 509 of file core.py.

mycroft.skills.core.MycroftSkill.scheduled_repeats

Definition at line 518 of file core.py.

mycroft.skills.core.MycroftSkill.settings

Definition at line 495 of file core.py.

mycroft.skills.core.MycroftSkill.skill_id

Definition at line 519 of file core.py.

mycroft.skills.core.MycroftSkill.voc_match_cache

Definition at line 520 of file core.py.


The documentation for this class was generated from the following file:


mycroft_ros
Author(s):
autogenerated on Mon Apr 26 2021 02:35:41