Skip to content

Instantly share code, notes, and snippets.

@alucky0707
Created May 26, 2013 10:23
Show Gist options
  • Save alucky0707/5652357 to your computer and use it in GitHub Desktop.
Save alucky0707/5652357 to your computer and use it in GitHub Desktop.
@defined_patterns = File.read("defined_patterns.dat", encoding: Encoding::UTF_8).split("\n").map{|s|s.split(":#")}
@default_messages = File.read("default_messages.dat", encoding: Encoding::UTF_8).split("\n")
def generateReply(inputMessage)
matched = [@default_messages[rand @default_messages.length]]
@defined_patterns.each do|pattern, result|
if inputMessage.index(pattern)
matched << result
end
end
if matched.length == 0
matched = @default_messages
end
return matched[rand matched.length]
end
while (print "you> "; input = gets.encode(Encoding::UTF_8, Encoding::Shift_JIS)) !~ /exit/
puts "bot> #{generateReply(input)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment