Skip to content

Instantly share code, notes, and snippets.

@muffinista
Created June 3, 2011 15:37
Show Gist options
  • Save muffinista/1006546 to your computer and use it in GitHub Desktop.
Save muffinista/1006546 to your computer and use it in GitHub Desktop.
A Twitter Bot that responds to "Mirror Mirror on the wall"
#!/usr/bin/env ruby
require 'rubygems'
require 'chatterbot/dsl'
@reply_list = [
"#USER#, Why it's you!",
"#USER# it's you of course!",
"It's totally #USER#",
"Since you asked, it's definitely #USER#"
]
def random_reply(s)
random_from_array(@reply_list, s)
end
def random_from_array(src, s)
username = tweet_user(s)
src[rand(src.size)].gsub("#USER#", username)
end
# people are tweeting this weird mirror mirror blurb with the words 'stop crying' in it
exclude "stop crying"
search "'mirror mirror on the wall'" do |tweet|
if tweet[:text].downcase.gsub(/[[:punct:]]/x, " ").squeeze(" ").strip.include?("mirror mirror on the wall who")
puts tweet[:text]
result = random_reply(tweet)
reply result, tweet
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment