Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #181] Redirect stderr for 'go crazy' command #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, (63 - 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