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_time = models.DateTimeField(default=timezone.now)
|
||||||
topic_by = models.CharField(max_length=200, default='', blank=True)
|
topic_by = models.CharField(max_length=200, default='', blank=True)
|
||||||
|
|
||||||
|
markov_learn_from_channel = models.BooleanField(default=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
('manage_current_channels', "Can join/part channels via IRC"),
|
('manage_current_channels', "Can join/part channels via IRC"),
|
||||||
|
|
|
@ -4,6 +4,7 @@ import re
|
||||||
import irc.client
|
import irc.client
|
||||||
|
|
||||||
from ircbot.lib import Plugin, reply_destination_for_event
|
from ircbot.lib import Plugin, reply_destination_for_event
|
||||||
|
from ircbot.models import IrcChannel
|
||||||
import markov.lib as markovlib
|
import markov.lib as markovlib
|
||||||
|
|
||||||
log = logging.getLogger('markov.ircplugin')
|
log = logging.getLogger('markov.ircplugin')
|
||||||
|
@ -70,12 +71,20 @@ class Markov(Plugin):
|
||||||
nick = irc.client.NickMask(event.source).nick
|
nick = irc.client.NickMask(event.source).nick
|
||||||
target = reply_destination_for_event(event)
|
target = reply_destination_for_event(event)
|
||||||
|
|
||||||
# learn the line
|
# check to see whether or not we should learn from this channel
|
||||||
recursing = getattr(event, '_recursing', False)
|
channel = None
|
||||||
if not recursing:
|
if irc.client.is_channel(target):
|
||||||
log.debug(u"learning %s", trimmed_what)
|
channel, c = IrcChannel.objects.get_or_create(name=target)
|
||||||
context = markovlib.get_or_create_target_context(target)
|
|
||||||
markovlib.learn_line(trimmed_what, context)
|
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)
|
log.debug(u"searching '%s' for '%s'", what, my_nick)
|
||||||
if re.search(my_nick, what, re.IGNORECASE) is not None:
|
if re.search(my_nick, what, re.IGNORECASE) is not None:
|
||||||
|
|
Loading…
Reference in New Issue