-
-
Save plamoni/1390689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SiriProxy::Plugin::Twitter < SiriProxy::Plugin | |
# this watches when in the default context | |
listen_for /tweet (.*)/ do |data, tweetText| | |
show_rich_snippet do | |
image 'http://cl.ly/1l040J1A392n0M1n1g35/content' # this just makes things looks nice, but is obviously specific to my username | |
text tweetText | |
end | |
# this locks out other plugins until a confirmation or deny | |
confirm do | |
confirmed do | |
send_tweet tweet | |
say "Tweet posted" | |
end | |
cancelled { say "Ok I wont send it." } | |
end | |
end | |
end | |
class SiriProxy::Plugin::MelbourneMetroTrains < SiriProxy::Plugin | |
# this watches when in the default context | |
listen_for /when is my next train/ do |data| | |
respond_with_next_train data | |
end | |
# after showing a schedule, user can ask to see a map | |
# if another plugin accepts a command, context gets cleared | |
listen_for :show_map, /map/ do |data| | |
show_map Map.new(@train_details.station.coordinates) # Automatic bounding box | |
end | |
#returns the train after the one currently displayed | |
listen_for :next_train, /next train/ do |data| | |
respond_with_next_train(data, @after_this + 1) | |
end | |
def respond_with_next_train(data, after_this=0) | |
@after_this = after_this | |
train_details = fetch_train_details(data.current_location, default_station, @after_this) | |
if train_details | |
say "The next #{train_details.line} train to #{default_station} departs from #{train_details.source} at #{train_details.time}" | |
# this adds the context to any existing contexts | |
add_context :show_map | |
# you can also replace_context to clear all contexts and replace with given one | |
# adds another context | |
add_context :next_train | |
else | |
say "Sorry, I'm unable to retrieve your train details." | |
clear_context() | |
end | |
end | |
def ask_and_store_default_station | |
say "I don't know where you usually go in the #{morning_or_afternoon}" | |
#next response when issuing an ask is not sent to other plugins | |
station = ask "What is the station?", all_stations | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment