Last active
August 29, 2015 14:09
-
-
Save sebastian/7f9897c318d7586caf82 to your computer and use it in GitHub Desktop.
Script that you can run in the background that solves the dreaded "old" status syndrome on Sqwiggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'sqwiggle-ruby' | |
# If a status stays the same for more than | |
# a certain time, it should most definitively | |
# be iradicated | |
killit_after = 60 | |
puts "Status assasin hiding in the bushes" | |
Sqwiggle.token = "<YOUR-TOKEN>" # "standard" token. Can be gotten in Sqwiggle App settings | |
same_message_for_minutes = 0 | |
message = "" | |
def set_status p={} | |
@me.update(status: p[:status] || :busy, message: p[:message] || "") | |
end | |
while true do | |
# It caches the message, so we need to re-instantiate | |
# the user to make sure we really see the new and latest message | |
begin | |
@me = Sqwiggle::User.find(:me) | |
rescue | |
# Darn... the internets is broken? | |
sleep 10 | |
next | |
end | |
current_message = begin | |
@me.message | |
rescue | |
# If we have problems, we'll just pretend we had an empty message. | |
# At least that can't be all too wrong. | |
puts "Network connectivity issues?" | |
"" | |
end | |
if message != "" and message == current_message | |
same_message_for_minutes += 1 | |
else | |
message = current_message | |
same_message_for_minutes == 0 | |
end | |
if same_message_for_minutes > killit_after | |
begin | |
@me.update status: :available, message: "" | |
puts "KILLED IT, you are welcome!" | |
rescue | |
puts "Would have wanted to kill it, but network connectivity issues?" | |
end | |
message = "" | |
same_message_for_minutes = 0 | |
end | |
sleep 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment