Created
February 23, 2012 13:13
-
-
Save elliottkember/1892735 to your computer and use it in GitHub Desktop.
Riot's Servor Script
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/ruby | |
puts `pwd` | |
Dir.chdir File.dirname(__FILE__) | |
puts `pwd` | |
# Servor client for @theriothq. | |
# Be careful moving things up and down as some strings cause deadlocks. | |
# I don't know why, but I imagine it's something to do with memory | |
# conflicts as we're adding callbacks to asynch code. Bit funny. | |
require 'xmpp4r/client' | |
include Jabber | |
Dir.chdir File.dirname(__FILE__) | |
# initialize critical variables | |
jid = JID.new "riot-servor@gmail.com" | |
password = "" # as if we'd tell you | |
mainthread = Thread.current | |
boner_count = 0 | |
# Tell the service we're online | |
@client = Client.new(jid) | |
@client.connect | |
@client.auth(password) | |
@client.send(Presence.new) | |
# Output to stdout real quick | |
puts "Connected ! send messages to #{jid.strip.to_s}." | |
@jaconda = "riothq@jaconda.im/Jaconda.1231231" | |
def say(message) | |
@client.send Message.new(@jaconda, message.dup.to_s) | |
end | |
# Let the guys know | |
# say "Servor is alive and ready to do your bidding!" | |
# This is our thing. | |
@client.add_message_callback do |message| | |
begin | |
if message.type != :error | |
# Let's hope nobody else messages us... | |
@jaconda = message.from | |
body = message.body.to_s.clone | |
# I imagine this is a fairly self-explanatory line. | |
boner_count += body.scan('boner').length | |
# Messages start with "My name: " so let's remove that | |
first_colon = body.index(':').to_i + 2 | |
# and get their actual message | |
text = body[first_colon..-1].to_s | |
# If we start with "servor," everything else is a command. If it's open X, we open x. | |
if text.downcase[0..14] == "servor, volume " | |
volume = text.downcase[15] | |
if volume.to_i > 6 | |
say ["That's probably a bit much.", "I don't think Knight Frank would appreciate that.", "At this hour?", "No way, dude."].shuffle.first | |
else | |
`osascript -e 'set volume #{volume}'` | |
end | |
elsif text.downcase[0..11] == "servor, run " | |
say "Say please." | |
elsif text.downcase[0..18] == "servor, please run " | |
command = text[19..-1].to_s.clone | |
if command.match('rm -rf') | |
say "I don't think that's a great idea." | |
else | |
say `#{command}` | |
end | |
elsif text.downcase[0..13] == "servor, fetch " | |
file = text[14..-1] | |
`curl -u #{ENV['jaconda_username']} -F "upload[file]=@#{file}" https://riothq.jaconda.im/api/v2/rooms/riothq/uploads.xml` | |
elsif text.downcase[0..13] == "hey, servor" | |
say "Heyaaa!" | |
elsif text.downcase[0..13] == "thanks, servor" | |
say "My pleasure :)" | |
elsif text.downcase[0..12] == 'servor, open ' | |
say ["Okey doke!", "Just a second!", "Opening it now!", "Your wish is my command."].shuffle.first | |
`open #{text[13..-1]}` | |
elsif text[-8..-1] == ", servor" | |
response = [ | |
"That's what I was thinking.", | |
"Yeah.", | |
"Hmm, I think you're right.", | |
"Probably, yeah" | |
].shuffle.first | |
say response | |
elsif text.downcase[0..7] == 'servor, ' | |
command = text[8..-1] | |
# This is the main list of "servor," commands. Add more if you like. | |
case command | |
when "smudge" | |
`afplay -v 5 smudge.mp3` | |
when "charge" | |
`afplay charge.mp3` | |
when "warface" | |
`afplay warface.mp3` | |
when "how you doing?" | |
say "Here's my vital statistics, friend: #{`uptime`}" | |
when "how you feeling?" | |
say "I'm feeling pretty good!" | |
when "boner count?" | |
say "Boner count so far: #{boner_count}" | |
when "what song is this?" | |
say `osascript -s o song.scpt` | |
when "next" | |
`osascript next.scpt` | |
when "previous" | |
`osascript previous.scpt` | |
when "pause" | |
`osascript playpause.scpt` | |
when "play" | |
`osascript playpause.scpt` | |
when "unpause" | |
`osascript playpause.scpt` | |
when "quieter" | |
`osascript -e 'set volume 1'` | |
when "quiet" | |
`osascript -e 'set volume 2'` | |
when "unquiet" | |
`osascript -e 'set volume 3'` | |
when "loud" | |
`osascript -e 'set volume 5'` | |
when "partymode" | |
say "Really?" | |
when "partymode --really" | |
`osascript -e 'set volume 7'` | |
when "no!" | |
`osascript -e 'tell application "System Events" to key code 53'` | |
when "close" | |
`osascript -e 'tell application "System Events" to keystroke "w" using command down'` | |
`open -a Plainview` | |
when "dashboard" | |
`open -a Plainview` | |
end | |
end | |
end | |
rescue => exception | |
puts exception.inspect | |
end | |
end | |
Thread.stop | |
@client.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment