Guest User

Untitled

a guest
Feb 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. # Controller for the Social leaf.
  2.  
  3. class Controller < Autumn::Leaf
  4. include Formatting::Mirc
  5.  
  6. def did_receive_channel_message(stem, sender, channel, msg)
  7. unless sender[:nick].match(/pixie/)
  8. logger.debug "I heard from #{sender[:nick]}"
  9. text_source = "kafka.txt"
  10. if msg.downcase.match(/beam|scott|space|star|trek|kirk|data/)
  11. ramble(stem, 'startrek.txt', nil, 8, 3)
  12. elsif msg.downcase.match(/picard|enterprise|captain|uss/)
  13. File.open(File.join(options[:root], "data/picard.txt")) do |f|
  14. f.each_line do |line|
  15. line = line.chomp
  16. next unless line.to_s.size > 0
  17. sleep(1)
  18. stem.message "#{color(:blue)}#{line}#{uncolor}"
  19. end
  20. end
  21. elsif msg.downcase.match(/dungeon|magic|gygax|d\&d/)
  22. ramble(stem, 'dd.txt', nil, 4)
  23. elsif msg.downcase.match(/dow|finance|stock|market|crash|bank/)
  24. static_message = "#{color(:red)}ZOMG! DOOOOOOMED. DOOOOOOOOOOOOOOOOOOOOOMED.#{uncolor}"
  25. stem.message static_message
  26. elsif msg.downcase.match(/whoops/)
  27. static_message = "#{color(:red)}You're a screw-up, #{sender[:nick]}.#{uncolor}"
  28. stem.message static_message
  29. elsif msg.downcase.match(/white|black|race|nationality|racist|latin|hisp|jew|muslim|honk|color/)
  30. static_message = "#{color(:red)}That's racist!#{uncolor}"
  31. stem.message static_message
  32. elsif msg.downcase.match(/food|lunch|hungry|\seat/)
  33. static_message = "#{color(:teal)}I'm hungry, too.#{uncolor}"
  34. stem.message static_message
  35. elsif msg.downcase.match(/mccain|palin|republican|gop/)
  36. static_message = "#{color(:red)}Boo!#{uncolor}"
  37. stem.message static_message
  38. elsif msg.downcase.match(/hr|ouch|jerk|wrong|hurt|rules/)
  39. static_message = "#{color(:red)}#{sender[:nick]}: Call Tess Dedman!#{uncolor}"
  40. stem.message static_message
  41. elsif msg.downcase.match(/vote/)
  42. static_message = "#{color(:teal)}Vote Pixie 2008!#{uncolor}"
  43. stem.message static_message
  44. elsif msg.downcase.match(/obama|democrat|biden|barack/)
  45. static_message = "#{color(:green)}Yay!#{uncolor}"
  46. stem.message static_message
  47. elsif msg.match(/pixie.*\?/)
  48. text_source = "rails.txt"
  49. answers = ["Yes!", "No.", "Maybe?"]
  50. append = answers[rand(answers.size)]
  51. ramble(stem, text_source, append, 2)
  52. elsif msg.match(/pixie/)
  53. ramble(stem, text_source, append, 1)
  54. else
  55. if (rand(33) == 1)
  56. preamble = ["I was thinking...", "What about:", "Did you consider:", "Sweet!", "Yuck.",
  57. "So.", "Hmmm.", "How about this.", "Did you know-", "This is cool."]
  58. append = preamble[rand(preamble.size)]
  59. ramble(stem, :random, append, 4)
  60. end
  61. end
  62. else
  63. logger.debug "Don't respond to myself!"
  64. end
  65. end
  66.  
  67. private
  68.  
  69. def ramble(stem, text_source="rails.txt", append=nil, sentences=2, order=2)
  70. text = nil
  71. if text_source == :random
  72. t_sources = ["startrek.txt", "rails.txt", "kafka.txt", "dd.txt"]
  73. text_source = t_sources[rand(t_sources.size)]
  74. end
  75. File.open(File.join(options[:root], "data/#{text_source}")) do |f|
  76. text = f.read
  77. end
  78. mc = MarkovChainer.new(order)
  79. mc.add_text(text)
  80. markov_sentences = [append]
  81. sentences.times do
  82. markov_sentences << mc.generate_sentence
  83. end
  84. markov_output = [markov_sentences].compact.join(" ")
  85. stem.message "#{color(:teal)}#{markov_output}#{uncolor}"
  86. end
  87.  
  88. end
Add Comment
Please, Sign In to add comment