hitomi/markov/bot.py
Brian S. Stephan 51edb54ed7 add markov module and irc plugin
just listens to servers right now, doesn't speak up (yet)
2018-01-10 09:38:12 -06:00

34 lines
1.0 KiB
Python

"""Observe Markov chains from Discord."""
import logging
from bot import hitomi
from markov import lib
logger = logging.getLogger(__name__)
logger.info("loading markov plugin")
def on_message(message):
"""Keep the observed Markov chains."""
# ignore self
if message.author == hitomi.user:
logger.debug("markov ignoring message authored by self")
return
if message.channel.is_private:
# DMs have a context of the author
context_name = message.author
else:
# channels have a context of the server, but we should ignore channels that override @everyone's read ability
for changed_role in message.channel.changed_roles:
if changed_role.is_everyone:
if not changed_role.permissions.read_messages:
logger.debug("markov ignoring channel that @everyone can't read")
return
context_name = message.server.id
lib.learn_line(message.content, context_name)
hitomi.on_message_handlers.append(on_message)