-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsiriproxy-example1.rb
More file actions
144 lines (101 loc) · 4.68 KB
/
Copy pathsiriproxy-example1.rb
File metadata and controls
144 lines (101 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'cora'
require 'siri_objects'
require 'pp'
require 'net/http'
require 'uri'
#######
# This is a "hello world" style plugin. It simply intercepts the phrase "test siri proxy" and responds
# with a message about the proxy being up and running (along with a couple other core features). This
# is good base code for other plugins.
#
# Remember to add other plugins to the "config.yml" file if you create them!
######
class SiriProxy::Plugin::Example1 < SiriProxy::Plugin
#如果你是无线,则这个要换为wlan0
LOCAL_IP = `ifconfig eth0`.match(/inet addr:(\d*\.\d*\.\d*\.\d*)/)[1] || "localhost"
def initialize(config)
#if you have custom configuration options, process them here!
end
#get the user's location and display it in the logs
#filters are still in their early stages. Their interface may be modified
filter "SetRequestOrigin", direction: :from_iphone do |object|
puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"
#Note about returns from filters:
# - Return false to stop the object from being forwarded
# - Return a Hash to substitute or update the object
# - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
# modifications made to it)
end
listen_for /网络地址/i do
say "Your IP is: #{LOCAL_IP}"
end
listen_for /打开/i do
initData = Net::HTTP.post_form(URI.parse("http://#{LOCAL_IP}:8000/GPIO/23/function/out"),{'post'=>'value'})
puts initData.body
#todo.....
#if initData.body == out
postData = Net::HTTP.post_form(URI.parse("http://#{LOCAL_IP}:8000/GPIO/23/value/0"), {'postKey'=>'postValue'})
puts postData.body
if postData.body === "0"
say "我操,打开成功了!"
else
say "你妹,打开失败了!"
end
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
listen_for /关闭/i do
initData = Net::HTTP.post_form(URI.parse("http://#{LOCAL_IP}:8000/GPIO/23/function/out"),{'post'=>'value'})
puts initData.body
postData = Net::HTTP.post_form(URI.parse("http://#{LOCAL_IP}:8000/GPIO/23/value/1"), {'postKey'=>'postValue'})
puts postData.body
if postData.body === "1"
say "哦也,关闭成功!"
else
say "哎,可能网络遇到问题了,再关闭一次吧"
end
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#Demonstrate that you can have Siri say one thing and write another"!
listen_for /you don't say/i do
say "Sometimes I don't write what I say", spoken: "Sometimes I don't say what I write"
end
#demonstrate state change
listen_for /siri proxy test state/i do
set_state :some_state #set a state... this is useful when you want to change how you respond after certain conditions are met!
say "I set the state, try saying 'confirm state change'"
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
listen_for /confirm state change/i, within_state: :some_state do #this only gets processed if you're within the :some_state state!
say "State change works fine!"
set_state nil #clear out the state!
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#demonstrate asking a question
listen_for /siri proxy test question/i do
response = ask "Is this thing working?" #ask the user for something
if(response =~ /yes/i) #process their response
say "Great!"
else
say "You could have just said 'yes'!"
end
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#demonstrate capturing data from the user (e.x. "Siri proxy number 15")
listen_for /siri proxy number ([0-9,]*[0-9])/i do |number|
say "Detected number: #{number}"
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
#demonstrate injection of more complex objects without shortcut methods.
listen_for /test map/i do
add_views = SiriAddViews.new
add_views.make_root(last_ref_id)
map_snippet = SiriMapItemSnippet.new
map_snippet.items << SiriMapItem.new
utterance = SiriAssistantUtteranceView.new("Testing map injection!")
add_views.views << utterance
add_views.views << map_snippet
#you can also do "send_object object, target: :guzzoni" in order to send an object to guzzoni
send_object add_views #send_object takes a hash or a SiriObject object
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
end