Skip to content

Instantly share code, notes, and snippets.

@drusepth
Created June 21, 2013 06:30
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 drusepth/5829285 to your computer and use it in GitHub Desktop.
Save drusepth/5829285 to your computer and use it in GitHub Desktop.
Ruby markov bot
#!/usr/bin/ruby
require 'cinch' # IRC framework
require 'marky_markov' # Markov chains
# Create persistent markov dictionary to read from
markov = MarkyMarkov::Dictionary.new('thunked', 3)
# Create IRC bot to feed data into markov dictionary
bot = Cinch::Bot.new do
configure do |c|
c.nick = "ankov"
c.realname = "ankov"
c.server = "irc.tddirc.net"
c.channels = [ "#thunked", "#shells", "#hackerthreads" ]
# c.channels = [ "#test" ]
end
# Learn from all messages
on :message, /(.*)/ do |m, message|
# Save dictionary state every ~50 messages
if rand(50) == 0
markov.save_dictionary!
end
# Learn from every message
markov.parse_string message
end
# Respond to messages when mentioned
on :message, /ankov/ do |m, message|
m.reply markov.generate_n_sentences 1# if rand(15) == 0
end
end
# Start bot
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment