Skip to content

Instantly share code, notes, and snippets.

@jlindley
Created October 10, 2008 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlindley/16074 to your computer and use it in GitHub Desktop.
Save jlindley/16074 to your computer and use it in GitHub Desktop.
# Controller for the Social leaf.
class Controller < Autumn::Leaf
include Formatting::Mirc
def did_receive_channel_message(stem, sender, channel, msg)
unless sender[:nick].match(/pixie/)
logger.debug "I heard from #{sender[:nick]}"
text_source = "kafka.txt"
if msg.downcase.match(/beam|scott|space|star|trek|kirk|data/)
ramble(stem, 'startrek.txt', nil, 8, 3)
elsif msg.downcase.match(/picard|enterprise|captain|uss/)
File.open(File.join(options[:root], "data/picard.txt")) do |f|
f.each_line do |line|
line = line.chomp
next unless line.to_s.size > 0
sleep(1)
stem.message "#{color(:blue)}#{line}#{uncolor}"
end
end
elsif msg.downcase.match(/dungeon|magic|gygax|d\&d/)
ramble(stem, 'dd.txt', nil, 4)
elsif msg.downcase.match(/dow|finance|stock|market|crash|bank/)
static_message = "#{color(:red)}ZOMG! DOOOOOOMED. DOOOOOOOOOOOOOOOOOOOOOMED.#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/whoops/)
static_message = "#{color(:red)}You're a screw-up, #{sender[:nick]}.#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/white|black|race|nationality|racist|latin|hisp|jew|muslim|honk|color/)
static_message = "#{color(:red)}That's racist!#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/food|lunch|hungry|\seat/)
static_message = "#{color(:teal)}I'm hungry, too.#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/mccain|palin|republican|gop/)
static_message = "#{color(:red)}Boo!#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/hr|ouch|jerk|wrong|hurt|rules/)
static_message = "#{color(:red)}#{sender[:nick]}: Call Tess Dedman!#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/vote/)
static_message = "#{color(:teal)}Vote Pixie 2008!#{uncolor}"
stem.message static_message
elsif msg.downcase.match(/obama|democrat|biden|barack/)
static_message = "#{color(:green)}Yay!#{uncolor}"
stem.message static_message
elsif msg.match(/pixie.*\?/)
text_source = "rails.txt"
answers = ["Yes!", "No.", "Maybe?"]
append = answers[rand(answers.size)]
ramble(stem, text_source, append, 2)
elsif msg.match(/pixie/)
ramble(stem, text_source, append, 1)
else
if (rand(33) == 1)
preamble = ["I was thinking...", "What about:", "Did you consider:", "Sweet!", "Yuck.",
"So.", "Hmmm.", "How about this.", "Did you know-", "This is cool."]
append = preamble[rand(preamble.size)]
ramble(stem, :random, append, 4)
end
end
else
logger.debug "Don't respond to myself!"
end
end
private
def ramble(stem, text_source="rails.txt", append=nil, sentences=2, order=2)
text = nil
if text_source == :random
t_sources = ["startrek.txt", "rails.txt", "kafka.txt", "dd.txt"]
text_source = t_sources[rand(t_sources.size)]
end
File.open(File.join(options[:root], "data/#{text_source}")) do |f|
text = f.read
end
mc = MarkovChainer.new(order)
mc.add_text(text)
markov_sentences = [append]
sentences.times do
markov_sentences << mc.generate_sentence
end
markov_output = [markov_sentences].compact.join(" ")
stem.message "#{color(:teal)}#{markov_output}#{uncolor}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment