Skip to content

Instantly share code, notes, and snippets.

@chendo
Forked from netpro2k/pluginexamples.rb
Created November 24, 2011 06:20

Revisions

  1. Jack Chen revised this gist Nov 24, 2011. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions pluginexamples.rb
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@

    class SiriProxy::Plugin::Twitter < SiriProxy::Plugin
    # this watches when in the default context
    listen_for /tweet (.*)/ do |data, tweetText|
    show_wolfram_snippet do
    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
    @@ -12,7 +11,7 @@ class SiriProxy::Plugin::Twitter < SiriProxy::Plugin
    send_tweet tweet
    say "Tweet posted"
    end
    canceled do
    cancelled do
    say "Ok I wont send it."
    end
    end
    @@ -42,7 +41,7 @@ class SiriProxy::Plugin::BlockTest < SiriProxy::Plugin
    end

    # define multiple listen_for's in a given state
    in_state :foo do
    within_state :foo do
    listen_for /matched in foo state/ do |data|
    say "foo state"
    end
    @@ -74,14 +73,14 @@ def respond_with_next_train(data)
    set_state :showing_schedule
    else
    say "Sorry, I'm unable to retrieve your train details."
    set_state :default
    set_state :default # or clear_state?
    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
    @station = ask("What is the station?", options: all_stations)
    end
    end
  2. @netpro2k netpro2k created this gist Nov 24, 2011.
    87 changes: 87 additions & 0 deletions pluginexamples.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,87 @@

    class SiriProxy::Plugin::Twitter < SiriProxy::Plugin
    # this watches when in the default context
    listen_for /tweet (.*)/ do |data, tweetText|
    show_wolfram_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
    canceled do
    say "Ok I wont send it."
    end
    end
    end
    end

    class SiriProxy::Plugin::ButtonTest < SiriProxy::Plugin
    listen_for /test buttons/ do |data|
    say "testing buttons"
    show_button "Click me" do
    say "You clicked me"
    end
    end
    end

    class SiriProxy::Plugin::BlockTest < SiriProxy::Plugin
    listen_for /matched in default state/ do |data|
    say "default state"
    end

    listen_for /also matched in default state/ do |data|
    say "Changing state to foo"
    set_state :foo
    end
    listen_for /also matched in default state/, next_state: :foo do |data|
    say "Also changing state to foo"
    end

    # define multiple listen_for's in a given state
    in_state :foo do
    listen_for /matched in foo state/ do |data|
    say "foo state"
    end
    listen_for /also matched in foo state/ do |data|
    say "also foo state"
    end
    end
    end

    class SiriProxy::Plugin::MelbourneMetroTrains < SiriProxy::Plugin
    # this watches when in the default state
    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, state gets cleared
    listen_for /map/, in_state: :showing_schedule, do |data|
    show_map Map.new(@train_details.station.coordinates) # Automatic bounding box
    end

    def respond_with_next_train(data)
    train_details = fetch_train_details(data.current_location, default_station)

    if train_details
    say "Your next #{train_details.line} train to #{default_station} departs from #{train_details.source} at #{train_details.time}"

    # this adds the state to any existing ontexts
    set_state :showing_schedule
    else
    say "Sorry, I'm unable to retrieve your train details."
    set_state :default
    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