Skip to content

Commit

Permalink
[Fix #181] Redirect stderr for 'go crazy' command
Browse files Browse the repository at this point in the history
  • Loading branch information
jmks committed Oct 11, 2016
1 parent 5722907 commit 883b632
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/fun.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Fun
def self.interpret(command)
responses = []

if command.match(/^what\'?s?(\s+is)?\s+the\s+meaning\s+of\s+life\??$/i)
responses << {
:say => "42."
}
end

if command.match(/^superman\s+vs\s+batman$/i)
responses << {
say: [true,false].sample ? "Batman" : "Superman"
Expand All @@ -20,82 +20,84 @@ def self.interpret(command)
}
end


if command.match(/^open\s(the\s)?pod\sbay\sdoor(s)?$/i)
responses << {
:say => "I'm sorry, Dave. I'm afraid I can't do that."
}
end

if command.match(/^make\s+me\s+a\s+(.+)$/i)
thing = "#{ $1 }"
responses << {
:call => lambda { self.make_me_a(thing) }
}
end

if command.match(/^sudo\s+make\s+me\s+a\s+(.+)$/i)
responses << {
:say => "I think you meant to place sudo at the start of the command."
}
end

if command.match(/^what\'?s?(\s+is)?\s+my\s(mother\s+fucking?)\s+name\??$/i)
responses << {
:say => "Snoop Doggy Dogg."
}
end

if command.match(/^you\'?(re)?\s+(are\s+)?(cool|awesome|amazing|fun(ny)?|rock\s+my\s+world|rule)$/i)
responses << {
:say => "You betcha."
}
end

if command.match(/^go\s+crazy$/i) || command.match(/^trip\s+(out|acid)$/i)
responses << {
:call => lambda { self.go_crazy },
:say => "Woah."
}
end

if command.match(/go home/)
responses << {
:command => "cd ~"
}
end

if command.match(/sing (.*)/)
responses << {
:command => "say -v cello #{$~}"
}
end

responses
end

def self.make_me_a(thing)
if Process.uid != 0
puts "Make your own damn #{thing}."
else
puts "Ha, like sudo has any effect on me!"
end
end

def self.go_crazy
term_color_cmd = "osascript -e \"tell application \\\"Terminal\\\" to set background color of window 1 to {%d,%d,%d,0}\" 2> /dev/null".freeze

(0...63).step(3) do |i|
system "osascript -e \"tell application \\\"Terminal\\\" to set background color of window 1 to {64000,#{ 64 - i }000,63000,0}\""
system format(term_color_cmd, 64_000, (64 - i) * 1_000, 63_000)
end

(0...63).step(3) do |i|
system "osascript -e \"tell application \\\"Terminal\\\" to set background color of window 1 to {#{ 64 - i }000,#{ i }000,63000,0}\""
system format(term_color_cmd, (64 - i) * 1_000, 64_000, 63_000)
end

(0...63).step(3) do |i|
system "osascript -e \"tell application \\\"Terminal\\\" to set background color of window 1 to {#{ i }000,63000,#{ 63 - i }000,0}\""
system format(term_color_cmd, 64_000, 64_000, (64 - i) * 1_000)
end
system 'osascript -e "tell application \"Terminal\" to set background color of window 1 to {64000,64000,64000,0}"'

system format(term_color_cmd, 64_000, 64_000, 64_0000)
end

def self.help
Expand Down

0 comments on commit 883b632

Please sign in to comment.