plamoni / SiriProxy

A (tampering) proxy server for Apple's Siri
GNU General Public License v3.0
2.12k stars 343 forks source link

Stuck in a question for next request #467

Open maciekish opened 11 years ago

maciekish commented 11 years ago

Hi, I have set siriproxy to control my tellstick net. If i ask it to "Set the kitchen light to 50%", it will do so and ask if i want it any darker or brighter. If i respond to that, everything is nice and dandy. If i just lock my phone without anwering her question, and unlock it a moment later and say something else like "Turn the kitchen light off", she will respond as if i had answered the previous question (She will say "Happy to be of service", instead of turning the light off).

So my question is, how do i "cancel" the question after inactivity/phone lock?

Here is the code:

listenfor /set(?: the)? ([a-z])(?: to)? ([0-9]_)(?: %)*/i do |light_name, value| light_name = light_name.strip print value + "\n"

value_original = String.new(value)
value = value.strip.to_f / 100.0
value = value * 255.0
light_id = get_light(light_name)

if (light_id.nil?)
  say "You dont have a " + light_name + " light."
else
  if (dim(light_id, value))
    value = value / 255.0
    value = value * 100.0
    response = ask "I have set the " + light_name + " light to " + value.to_s[0...-2] + "%, Do you want it any brighter or darker?"

    if (response =~ /dark/i)
      say "Okay, i made it a little darker."
      value = value_original.strip.to_f / 100.0
      value = (value * 255.0) - 50
      dim(light_id, value)
    elsif (response =~ /bright/i or response =~ /lighter/i )
      say "Okay, i made it a little brighter."
      value = value_original.strip.to_f / 100.0
      value = (value * 255.0) + 50
      dim(light_id, value)
    else
      say "Happy to be of service."
      request_completed
    end
  else
    say "I couldnt set the dimmer for the " + light_name + ", sorry about that."
    request_completed
  end
end

request_completed

end

bgottsch commented 11 years ago

its a problem with the plugins execution on the SiriProxy server. I think that if you send a request_completed after you lock it or after a timeout it should work. Im not sure about it. Im having the same problem but i'm trying to figure it out. I have discovered that Apple uses callbacks to resolve some of this issues. I'll post if a have progress.

plamoni commented 11 years ago

I agree with @bgottsch... I think that your best bet might be to set up a worker thread when you ask the question and if they don't respond in like 10 seconds you can issue a request_completed.

Might not hurt to add a timeout to ask, but I think it lives in @chendo's cora code.

maciekish commented 11 years ago

Is it possible for you to provide a simple example of how to set up the worker thread after asking a question please? I'm very new to this language.