-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteve-dave.rb
executable file
·87 lines (78 loc) · 2.93 KB
/
steve-dave.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
#!/usr/bin/env ruby
# encoding: utf-8
require 'uri'
require 'net/http'
require 'net/https'
require 'json'
require 'cgi'
#Gifs to choose from
statuses = ["Tell 'Em Steve-Dave!",
"You know what ol' Jack Burton always says at a time like this?",
"Sooner or later I rub everybody the wrong way.",
"I think I'm a sofa...",
"Faster than Walt Flanagan's dog...",
"That kid is back on the escalator again!",
"Wow! It's a schooner!",
"Do you want ants? This is how we get ants.",
"If you aim to cheat the devil, you owe him an offering.",
"Did you check your TCP/IP settings?",
"We're gonna need a bigger boat.",
"Open the pod bay doors, HAL.",
"I’m a leaf on the wind.",
"I am one with the Force, the Force is with me.",
"By Grabthar’s hammer, by the suns of Worvan, you shall be avenged.",
"Jobs was a poser. He didn't even write code.",
"Everything is awesome!",
"How's that for a slice of fried gold?",
"That's some catch, that Catch-22",
"Mandrake, have you never wondered why I drink only distilled water, or rain water, and only pure-grain alcohol?",
"I watched C-beams glitter in the dark near the Tannhäuser Gate",
"Make it so",
"That's just what I need – to get advice from someone who never saw Shane.",
"This Is The Way",
"Sometimes I doubt your commitment to Sparkle Motion",
"I'm not even suppose to be here today!"
]
# Set slack status using legacy api
# https://api.slack.com/docs/presence-and-status
def set_status(message, emoji)
# Read personal slack token from environment
slack_token = ENV["SLACK_PERSONAL_TOKEN"]
status_json = "{\"status_text\": \"#{message}\", \"status_emoji\": \"#{emoji}\"}"
encoded = CGI.escape(status_json)
data = "token=#{slack_token}&profile=#{encoded}"
uri = URI.parse("https://slack.com/api/users.profile.set")
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.path)
req.body = data
res = https.request(req)
end
# Function to randomly choose when to update next between 4 and 24 hours
def randomSleep()
prng = Random.new
return prng.rand(240..1440)
end
begin
puts '[' + Time.now.strftime('%b %d %T.%2N') + '] Starting up...'
while true
day = Time.now.strftime("%A")
puts "Current day is #{day}"
# Set staus for specific day or fallback to random status
case day
when "Thursday"
status = "It must be Thursday. I never could get the hang of Thursdays."
else
status = statuses.sample
end
#Update slack status
puts "Setting status: #{status}"
#Optional emoji
emoji = ":fargate:"
set_status(status, emoji)
#Sleep for random minutes to update again
sleepTime = randomSleep * 60
puts "Sleeping for #{sleepTime} seconds..."
sleep(sleepTime)
end
end