jlindley (owner)

Revisions

  • 632181 jlindley Fri Oct 10 11:31:19 -0700 2008
  • 91ad17 jlindley Fri Oct 10 08:26:09 -0700 2008
gist: 16074 Download_button fork
public
Public Clone URL: git://gist.github.com/16074.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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