Created
June 21, 2013 06:30
-
-
Save drusepth/5829285 to your computer and use it in GitHub Desktop.
Ruby markov bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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