markov: configure what channels to learn from
This commit is contained in:
parent
75dc2ae2cb
commit
505dc8799c
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ircbot', '0011_auto_20150620_0951'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ircchannel',
|
||||
name='markov_learn_from_channel',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
@ -65,6 +65,8 @@ class IrcChannel(models.Model):
|
||||
topic_time = models.DateTimeField(default=timezone.now)
|
||||
topic_by = models.CharField(max_length=200, default='', blank=True)
|
||||
|
||||
markov_learn_from_channel = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
('manage_current_channels', "Can join/part channels via IRC"),
|
||||
|
@ -4,6 +4,7 @@ import re
|
||||
import irc.client
|
||||
|
||||
from ircbot.lib import Plugin, reply_destination_for_event
|
||||
from ircbot.models import IrcChannel
|
||||
import markov.lib as markovlib
|
||||
|
||||
log = logging.getLogger('markov.ircplugin')
|
||||
@ -70,12 +71,20 @@ class Markov(Plugin):
|
||||
nick = irc.client.NickMask(event.source).nick
|
||||
target = reply_destination_for_event(event)
|
||||
|
||||
# learn the line
|
||||
recursing = getattr(event, '_recursing', False)
|
||||
if not recursing:
|
||||
log.debug(u"learning %s", trimmed_what)
|
||||
context = markovlib.get_or_create_target_context(target)
|
||||
markovlib.learn_line(trimmed_what, context)
|
||||
# check to see whether or not we should learn from this channel
|
||||
channel = None
|
||||
if irc.client.is_channel(target):
|
||||
channel, c = IrcChannel.objects.get_or_create(name=target)
|
||||
|
||||
if channel and not channel.markov_learn_from_channel:
|
||||
log.debug("not learning from %s as i've been told to ignore it", channel)
|
||||
else:
|
||||
# learn the line
|
||||
recursing = getattr(event, '_recursing', False)
|
||||
if not recursing:
|
||||
log.debug(u"learning %s", trimmed_what)
|
||||
context = markovlib.get_or_create_target_context(target)
|
||||
markovlib.learn_line(trimmed_what, context)
|
||||
|
||||
log.debug(u"searching '%s' for '%s'", what, my_nick)
|
||||
if re.search(my_nick, what, re.IGNORECASE) is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user