Last active
April 24, 2018 06:24
-
-
Save Widdershin/58df01b4f11fa8f9589800654b5f9b7b to your computer and use it in GitHub Desktop.
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
# requires anybar https://github.com/tonsky/AnyBar (brew cask install anybar) | |
# to get your player_id and your authorization_header, open the devtools and go to the network inspector | |
# refresh the games list, and then inspect the /games request | |
# set authorization_header to the value of the authorization header | |
# you can find your steam id in the json response of that same request | |
# | |
# to automatically update, make a cronjob | |
# run crontab -e and add this line | |
# | |
# * * * * ruby <path-to-this-script> | |
# | |
# that should update every minute | |
# | |
# enjoy :) | |
require 'json' | |
require 'socket' | |
player_id = '<fill me in>' | |
hashed_password = '<fill me in>' | |
def anybar(color) | |
socket = UDPSocket.new | |
socket.connect 'localhost', '1738' | |
socket.send color, 0 | |
socket.close | |
end | |
if `ps x | grep 'AnyBar' | grep -v 'grep'`.strip == '' | |
puts 'Starting AnyBar' | |
`open -a AnyBar` | |
end | |
if `ps x | grep Civ6 | grep -v grep`.strip != '' | |
puts 'Civ is running! Play your turn or close it!' | |
anybar('orange') | |
exit | |
end | |
games_json = `curl 'https://api.playyourdamnturn.com/user/games' -s -H 'authorization: #{hashed_password}' -H 'accept: application/json' &2>/dev/null` | |
games = JSON.parse(games_json) | |
playing = games['data'].any? { |game| game['currentPlayerSteamId'] == player_id } | |
if playing | |
color = 'exclamation' | |
puts 'Play your damn turn!' | |
else | |
color = 'white' | |
puts 'Wait your damn turn!' | |
end | |
anybar(color) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment