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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/ruby-macrodroid/actionsnlp.rb', line 18
def actions(params)
get /else if (.*)/i do
[ElseIfConditionAction, {}]
end
get /if (.*)/i do
[IfConditionAction, {}]
end
get /else/i do
[ElseAction, {}]
end
get /End If/i do
[EndIfAction, {}]
end
get /^(Enable|Disable) HotSpot/i do |state|
enable, state = if state.downcase == 'enable' then
[true, 0]
else
[false, 1]
end
[SetHotspotAction, {turn_wifi_on: enable, state: state }]
end
get /^(?:message popup|popup message): (.*)/i do |msg|
[ToastAction, {msg: msg}]
end
get /^Popup[ _]Message ['"]([^'"]+)/i do |msg|
[ToastAction, {msg: msg}]
end
get /^Popup Message\n\s+(.*)/im do |msg|
[ToastAction, {msg: msg}]
end
get /^Popup Message$/i do
[ToastAction, {}]
end
get /^say current[ _]time/i do
[SayTimeAction, {}]
end
get /^Torch :?(.*)/i do |onoffstate|
state = %w(on off toggle).index onoffstate.downcase
[CameraFlashLightAction, {state: state}]
end
get /^Take Picture/i do
[TakePictureAction, {}]
end
get /^take_picture/i do
[TakePictureAction, {}]
end
get /^Take Screenshot/i do
[TakeScreenshotAction, {}]
end
get /^Speak text \(([^\)]+)\)/i do |text|
[SpeakTextAction, {text: text}]
end
get /^Speak text ['"]([^'"]+)/i do |text|
[SpeakTextAction, {text: text}]
end
get /^Speak text$/i do |text|
[SpeakTextAction, {}]
end
get /^UI Interaction$/i do
[UIInteractionAction, {}]
end
get /^Vibrate \(([^\)]+)/i do |pattern|
[VibrateAction, {pattern: pattern}]
end
get /^Vibrate$/i do |pattern|
[VibrateAction, {pattern: 'short buzz'}]
end
get /^Voice Search$/i do
[VoiceSearchAction, {}]
end
get /^Auto Rotate (On|Off|Toggle)$/i do |state|
a = %w(on off toggle)
[SetAutoRotateAction, {state: a.map(&:downcase).index(state.downcase)}]
end
get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
[NotificationAction, {subject: subject, text: text}]
end
get /^(Enable|Disable) Wifi$/i do |raw_state|
state = raw_state.downcase.to_sym == :enable ? 0 : 1
[SetWifiAction, {state: state}]
end
get /^Fill Clipboard$/i do
[ClipboardAction, {}]
end
get /^Play: (.*)$/i do |name|
[PlaySoundAction, {file_path: name}]
end
get /^Launch Shortcut:? (?:Amazon|Ask) Alexa$/i do
[LaunchShortcutAction, {shortcut: 'Ask Alexa'}]
end
get /^Shortcut:? (?:Amazon|Ask) Alexa$/i do
[LaunchShortcutAction, {shortcut: 'Ask Alexa'}]
end
get /^Launch (.*)$/i do |s|
h = {}
if s[0] == '[' then
h[:launch_by_package_name] = s
h[:option] = 1
else
application = s
h[:application_name] = application
h[:package_to_launch] = APPS[application] || 'com.android.' +
application.downcase.split().join('.')
h[:option] = 0
end
[LaunchActivityAction, h]
end
get /^HTTP GET ([^$]+)$/i do |url|
[OpenWebPageAction, url_to_open: url]
end
get /^HTTP GET$/i do
[OpenWebPageAction, {}]
end
get /^Open Website \/ HTTP GET$/i do
[OpenWebPageAction, {http_get: false}]
end
get /^(?:open|goto) ((?:https?:\/\/|\[lv=)[^$]+)$/i do |url|
[OpenWebPageAction, url_to_open: url, http_get: false]
end
get /(?:webhook|HTTP GET) ([^$]+)$/i do |s|
key = s =~ /^http/ ? :url_to_open : :identifier
[OpenWebPageAction, {key => s}]
end
get /^WebHook \(Url\)/i do
[OpenWebPageAction, {}]
end
get /^webhook$/i do
[OpenWebPageAction, {}, params[:macro]]
end
get /^Force Location Update$/i do
[ForceLocationUpdateAction, params]
end
get /^Share Location$/i do
[ShareLocationAction, {}]
end
get /Keep Device Awake Screen On Until Disabled/i do
[KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
end
get /Keep Device Awake Screen On ([^$]+)/i do |duration|
a = duration.split.map(&:to_i)
secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
h = {
permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
}
[KeepAwakeAction, h]
end
get /(?:Keep Device|stay) Awake$/i do
[KeepAwakeAction, {}]
end
get /Disable Keep Awake|stay awake off/i do
[KeepAwakeAction, {enabled: false, screen_option: 0}]
end
get /^((?:En|Dis)able) Macro$/i do |rawstate|
state = %w(enable disable toggle).index(rawstate.downcase)
[DisableMacroAction, {state: state}]
end
get /^Macro Run$/i do
[ForceMacroRunAction, {}]
end
get /^Run Macro$/i do
[ForceMacroRunAction, {}]
end
get /^Set Variable$/i do
[SetVariableAction, {}]
end
get /^wait (\d+) seconds$/i do |seconds|
[PauseAction, {delay_in_seconds: seconds.to_i}]
end
get /^Media ([^$]+)$/i do |option|
[ControlMediaAction, {option: option}]
end
get /^Screen (On|Off)$/i do |state|
[ScreenOnAction, {screen_off: state.downcase == 'off'}]
end
end
|