"""Chatter bot using Markov chains."""
import dave.module
import dave.config
import random
import re
from dave.models import Message
FACTOR = 0.05
@dave.module.help("Syntax: babble [optional seeds].")
@dave.module.command(["babble"], "?(.*)")
@dave.module.priority(dave.module.Priority.HIGHEST)
def babble(bot, args, sender, source):
msg = args[0].strip()
if msg:
args = msg.split(" ")
if len(args) == 2:
resp = dave.config.markov.make_sentence(tuple(dave.config.markov.word_split(" ".join(args))), tries=10000)
else:
resp = None
else:
resp = dave.config.markov.make_sentence(tries=10000)
if not resp is None:
bot.msg(source, resp.encode("utf-8"))