support markov targets with identical names on different servers

markov targets are queried and autogenerated based on chatter, but had a
legacy name which is no longer in use for this, preferring the foreign
keys to channel and consequently server. the name is really just
informative these days, but was still being used to find targets, and
thus was breaking when two servers had the same channel name in them.
this fixes that
This commit is contained in:
Brian S. Stephan 2023-05-04 17:21:27 -05:00
parent 98abab560e
commit 333424025b
4 changed files with 23 additions and 5 deletions

View File

@ -118,7 +118,7 @@ class IrcChannel(models.Model):
def __str__(self):
"""Provide string representation."""
return "{0:s}".format(self.name)
return "{0:s} on {1:s}".format(self.name, self.server.name)
class IrcPlugin(models.Model):

View File

@ -119,12 +119,12 @@ class Markov(Plugin):
target_name = target_name.lower()
# find the stuff, or create it
channel, c = IrcChannel.objects.get_or_create(name=target_name, server=self.connection.server_config)
try:
target = MarkovTarget.objects.get(name=target_name)
target = MarkovTarget.objects.get(channel=channel)
except MarkovTarget.DoesNotExist:
# we need to create a context and a target, and we have to make the context first
# make a context --- lacking a good idea, just create one with this target name until configured otherwise
channel, c = IrcChannel.objects.get_or_create(name=target_name, server=self.connection.server_config)
context, c = MarkovContext.objects.get_or_create(name=target_name)
target, c = MarkovTarget.objects.get_or_create(name=target_name, context=context, channel=channel)

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-05-04 22:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('markov', '0007_alter_markovtarget_channel'),
]
operations = [
migrations.AlterField(
model_name='markovtarget',
name='name',
field=models.CharField(max_length=200),
),
]

View File

@ -21,7 +21,7 @@ class MarkovContext(models.Model):
class MarkovTarget(models.Model):
"""Define IRC targets that relate to a context, and can occasionally be talked to."""
name = models.CharField(max_length=200, unique=True)
name = models.CharField(max_length=200)
context = models.ForeignKey(MarkovContext, on_delete=models.CASCADE)
channel = models.ForeignKey(IrcChannel, on_delete=models.CASCADE)
@ -29,7 +29,7 @@ class MarkovTarget(models.Model):
def __str__(self):
"""Provide string representation."""
return "{0:s} -> {1:s}".format(self.name, self.context.name)
return "{0:s} -> {1:s}".format(str(self.channel), self.context.name)
class MarkovState(models.Model):