Class: ActionsNlp
- Inherits:
-
Object
- Object
- ActionsNlp
- Includes:
- AppRoutes
- Defined in:
- lib/ruby-macrodroid/macro.rb
Instance Method Summary collapse
- #actions(params) ⇒ Object
-
#initialize(macro = nil) ⇒ ActionsNlp
constructor
A new instance of ActionsNlp.
Constructor Details
#initialize(macro = nil) ⇒ ActionsNlp
Returns a new instance of ActionsNlp.
175 176 177 178 179 180 181 182 |
# File 'lib/ruby-macrodroid/macro.rb', line 175 def initialize(macro=nil) super() params = {macro: macro} actions(params) end |
Instance Method Details
#actions(params) ⇒ Object
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 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/ruby-macrodroid/macro.rb', line 184 def actions(params) # -- Conditions/Loops --------------------------------------------- # get /else if (.*)/i do [ElseIfConditionAction, {}] end #e.g a: if Airplane mode enabled # get /if (.*)/i do [IfConditionAction, {}] end get /else/i do [ElseAction, {}] end get /End If/i do [EndIfAction, {}] end # -- Connectivity ------------------------------------------------------ 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 # e.g. message popup: hello world! get /^(?:message popup|popup message): (.*)/i do |msg| [ToastAction, {msg: msg}] end # e.g. Popup Message 'hello world!' get /^Popup[ _]Message ['"]([^'"]+)/i do |msg| [ToastAction, {msg: msg}] end # e.g. Popup Message\n hello world! get /^Popup Message\n\s+(.*)/im do |msg| [ToastAction, {msg: msg}] end # e.g. Popup Message get /^Popup Message$/i do [ToastAction, {}] end # e.g. say current time 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 # -- DEVICE ACTIONS ------------------------------------------------------ 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 /^Vibrate \(([^\)]+)/i do |pattern| [VibrateAction, {pattern: pattern}] end get /^Vibrate$/i do |pattern| [VibrateAction, {pattern: 'short buzz'}] end # e.g. Display Notification: Hi there: This is the body of the message get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text| [NotificationAction, {subject: subject, text: text}] end # e.g. Enable Wifi get /^(Enable|Disable) Wifi$/i do |raw_state| state = raw_state.downcase.to_sym == :enable ? 0 : 1 [SetWifiAction, {state: state}] end # e.g. Play: Altair get /^Play: (.*)$/i do |name| [PlaySoundAction, {file_path: name}] end # e.g. Launch Settings get /^Launch (.*)$/i do |application| h = { application_name: application, package_to_launch: 'com.android.' + application.downcase } [LaunchActivityAction, h] end # e.g. HTTP GET http://someurl.com/something get /^HTTP GET ([^$]+)$/i do |url| [OpenWebPageAction, url_to_open: url] end get /^HTTP GET$/i do [OpenWebPageAction, {}] end # e.g. webhook entered_kitchen # 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 # e.g. webhook entered_kitchen # get /^webhook$/i do [OpenWebPageAction, {}, params[:macro]] end # -- Location --------------------------------------------------------- get /^Force Location Update$/i do [ForceLocationUpdateAction, params] end get /^Share Location$/i do [ShareLocationAction, {}] end #a: Keep Device Awake Screen On Until Disabled # get /Keep Device Awake Screen On Until Disabled/i do [KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}] end #a: Keep Device Awake Screen On 1h 1m 1s # 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 #a: Disable Keep Awake # get /Disable Keep Awake|stay awake off/i do [KeepAwakeAction, {enabled: false, screen_option: 0}] end # -- MacroDroid Specific ------------------------------------------------ # get /^((?:En|Dis)able) Macro$/i do |rawstate| state = %w(enable disable toggle).index(rawstate.downcase) [DisableMacroAction, {state: state}] end get /^Set Variable$/i do [SetVariableAction, {}] end get /^wait (\d+) seconds$/i do |seconds| [PauseAction, {delay_in_seconds: seconds.to_i}] end # -- Screen ------------------------------------------------ # get /^Screen (On|Off)$/i do |state| [ScreenOnAction, {screen_off: state.downcase == 'off'}] end end |