Skip to content

Instantly share code, notes, and snippets.

@poemdexter
Created April 24, 2012 04:01
Show Gist options
  • Save poemdexter/2476291 to your computer and use it in GitHub Desktop.
Save poemdexter/2476291 to your computer and use it in GitHub Desktop.
class Markovgen
include Cinch::Plugin
listen_to :message
@markov_switch = false
@markovbot = Markov.new
def listen(m)
reject = /http[s?]|www|.com|.net|.biz|/
switch_regex = /!markov\s(?<switch>on|off)/
match = switch_regex.match(m.message)
if match
if match[:switch] == "on" && m.channel.opped?(m.user)
@markov_switch = true
m.reply "[MARKOV] turned on."
elsif match[:switch] == "off" && m.channel.opped?(m.user)
@markov_switch = false
m.reply "[MARKOV] turned off."
end
elsif m.message.match(/![\w]+ (on|off)/) # catch other commands
elsif m.user != "twillbot"
text = m.message
words = text.split
final_words = words
words.each do |word|
final_words.delete(word) if word.match(reject)
end
@markovbot.add(*final_words)
end
if @markov_switch && rand(100) < 100
message = @markovbot.generate(10).join(" ") + "."
m.reply message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment