Eichhoernchen/SiriServer — Issue #100: AlarmSnippet making springboard crash
Author: mendeel
Created: 2012-02-06 02:05:43+00:00
State: open

Hello y'all. I'm trying to plugin to create alarms.

````python
import re

from plugin import *
from siriObjects.baseObjects import AceObject, ClientBoundCommand
from siriObjects.uiObjects import AddViews, AssistantUtteranceView
from siriObjects.systemObjects import DomainObject
from siriObjects.alarmObjects import AlarmSearch, AlarmSnippet, AlarmObject

class SetUpAlarm(Plugin):
@register("en-US", "(.*wake me.* ([0]?[1-9]|1[0-2]) (am|pm))|(.*set.* alarm for.* ([0]?[1-9]|1[0-2]) (am|pm))|(.*wake me.* ([0]?[1-9]|1[0-2]) and ([0-5][0-9]) (am|pm))")
def setAnAlarm(self, speech, language):
spokenText = re.match(".* ([0]?[1-9]|1[0-2]) (am|pm)$", speech, re.IGNORECASE)
if spokenText != None:
hours = spokenText.group(1).strip()
minutes = 0
ampm = spokenText.group(2).strip()
else:
spokenText = re.match(".* ([0]?[1-9]|1[0-2]) and ([0-5][0-9]) (am|pm)$", speech, re.IGNORECASE)
hours = spokenText.group(1).strip()
minutes = spokenText.group(2).strip()
ampm = spokenText.group(3).strip()
if hours != None:
local = {"timeWithMinutes" : "Your alarm's set for {0}:{1} {2}".format(hours, minutes, ampm), "time" : "Your alarm's set for {0} {1}".format(hours, ampm)}
view = AddViews(self.refId)
if minutes == 0:
speakThis = local["time"]
else:
speakThis = local["timeWithMinutes"]
view1 = AssistantUtteranceView(text=speakThis, speakableText=speakThis,	dialogIdentifier="Alarm#armed")
#alarm = AlarmObject()
#alarmSearch = AlarmSearch(alarm)
#alarmSearch.hour = hours
#alarmSearch.minute = minutes
#view2 = AlarmSnippet()
view.views = [view1]
self.sendRequestWithoutAnswer(view)
answer = self.ask("Should I create it?")
if answer == "yes":
self.say("Alright then, I'll not create it.")
else:
self.say("Alright then.")
self.complete_request()
else:
self.say("Something went wrong!")
self.complete_request()
````