Skip to content

Commit

Permalink
Changed image sizes a bit, fixed problem where new plugin code was ke…
Browse files Browse the repository at this point in the history
…eping AppleScript functions from running.
  • Loading branch information
alvinj committed Jan 24, 2012
1 parent b5ad947 commit 20f044c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
Binary file modified src/main/resources/com/devdaily/sarah/microphone-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/com/devdaily/sarah/sarah-header-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/main/scala/com/devdaily/sarah/Sarah.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,15 @@ class Sarah {
mainFrameController.displayAvailableVoiceCommands(voiceCommands)
}


def tryToHandleTextWithPlugins(textTheUserSaid: String): Boolean = {
log.info("tryToHandleTextWithPlugins, TEXT = " + textTheUserSaid)
// loop through the plugins, and see if any can handle what was said
for (plugin <- pluginInstances) {
val handled = plugin.handlePhrase(textTheUserSaid)
if (handled) return true
}
return false
}


def loadPlugins {
Expand Down
41 changes: 23 additions & 18 deletions src/main/scala/com/devdaily/sarah/actors/Brain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,25 @@ with Logging
// re-load these to let the user change commands while we run
loadAllUserConfigurationFilesOrDie

log.info("Checking to see if it's a special voice command ...")
if (handleSpecialVoiceCommands(textTheUserSaid)) {
log.info("(Brain) Handled a special voice command, returning.")
log.info("Handled a special voice command, returning.")
return
}

log.info("Wasn't a special voice command, now looping through user-defined voice commands.")
// if the command phrase is in the map, do some work
if (phraseToCommandMap.containsKey(textTheUserSaid)) {
log.info("phraseToCommandMap contained key, trying to process")
// handle whatever the user said
log.info("(Brain) handleVoiceCommand, found your phrase in the map: " + textTheUserSaid)
handleUserDefinedVoiceCommand(textTheUserSaid)
return
log.info("handleVoiceCommand, found your phrase in the map: " + textTheUserSaid)
val handled = handleUserDefinedVoiceCommand(textTheUserSaid)
}
else {
log.info("Sorry, could not handle command.")
// there were no matches; check the plugins registered with sarah
log.info(format("phraseToCommandMap didn't have key (%s), trying plugins", textTheUserSaid))
val handled = sarah.tryToHandleTextWithPlugins(textTheUserSaid)
// this function doesn't care if it was handled (refactor)
}
}

Expand Down Expand Up @@ -290,12 +295,6 @@ with Logging
listAvailableVoiceCommands
return true
}

// special 'wake up' action
// else if (inSleepMode && textTheUserSaid.matches(".*wake up.*")) {
// doWakeUpActions
// return true
// }

return false
}
Expand Down Expand Up @@ -338,27 +337,33 @@ with Logging

}

def handleUserDefinedVoiceCommand(textTheUserSaid: String) {
log.info("(Brain) Entered Brain::handleUserDefinedVoiceCommand")
def handleUserDefinedVoiceCommand(textTheUserSaid: String): Boolean = {
log.info("Entered Brain::handleUserDefinedVoiceCommand")
val commandFileKey = phraseToCommandMap.get(textTheUserSaid) // ex: COMPUTER, JUST_CHECKING
log.info("(Brain) Brain::handleUserDefinedVoiceCommand, commandFileKey = " + commandFileKey)
log.info("Brain::handleUserDefinedVoiceCommand, commandFileKey = " + commandFileKey)
// foreach is enabled by importing JavaConversions._ above
allVoiceCommands.foreach{ voiceCommand =>
val voiceCommandKey = voiceCommand.getCommand()
if (voiceCommandKey.equalsIgnoreCase(commandFileKey)) {
if (voiceCommand.getAppleScript==null || voiceCommand.getAppleScript.trim.equals("")) {
log.info("handleUserDefinedVoiceCommand, appleScript is not defined, passing on it")
return false
}
if (!inSleepMode || voiceCommand.worksInSleepMode()) {
log.info("running runUserDefinedCommand(voiceCommand)")
runUserDefinedCommand(voiceCommand)
printMode()
return
printMode
return true
}
else
{
printMode()
printMode
log.info("In sleep mode, ignoring command.")
return
return false
}
}
}
return false
}


Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/com/devdaily/sarah/plugins/SarahPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ trait SarahPlugin {

def startPlugin

// phrases the plugin can handle
def textPhrasesICanHandle: List[String]

// callback to tell the plugin to handle the given phrase.
// returns true if the phrase was handled.
def handlePhrase(phrase: String): Boolean




}

0 comments on commit 20f044c

Please sign in to comment.