lint cleanups

This commit is contained in:
Brian S. Stephan 2021-04-24 19:18:45 -05:00
parent cbbf6eb311
commit d518cb2b77
1 changed files with 16 additions and 14 deletions

View File

@ -1,5 +1,4 @@
"""Track basic IRC settings and similar.""" """Track basic IRC settings and similar."""
import logging import logging
import re import re
@ -7,12 +6,14 @@ from django.conf import settings
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
log = logging.getLogger('ircbot.models') log = logging.getLogger('ircbot.models')
class LowerCaseCharField(models.CharField): class LowerCaseCharField(models.CharField):
"""Provide a case-insensitive, forced-lower CharField."""
def get_prep_value(self, value): def get_prep_value(self, value):
"""Manipulate the field value to make it lowercase."""
value = super(LowerCaseCharField, self).get_prep_value(value) value = super(LowerCaseCharField, self).get_prep_value(value)
if value is not None: if value is not None:
value = value.lower() value = value.lower()
@ -20,21 +21,22 @@ class LowerCaseCharField(models.CharField):
class Alias(models.Model): class Alias(models.Model):
"""Allow for aliasing of arbitrary regexes to normal supported commands.""" """Allow for aliasing of arbitrary regexes to normal supported commands."""
pattern = models.CharField(max_length=200, unique=True) pattern = models.CharField(max_length=200, unique=True)
replacement = models.CharField(max_length=200) replacement = models.CharField(max_length=200)
class Meta: class Meta:
"""Settings for the model."""
verbose_name_plural = "aliases" verbose_name_plural = "aliases"
def __str__(self): def __str__(self):
"""String representation.""" """Provide string representation."""
return "{0:s} -> {1:s}".format(self.pattern, self.replacement) return "{0:s} -> {1:s}".format(self.pattern, self.replacement)
def replace(self, what): def replace(self, what):
"""Match the regex and replace with the command."""
command = None command = None
if re.search(self.pattern, what, flags=re.IGNORECASE): if re.search(self.pattern, what, flags=re.IGNORECASE):
command = re.sub(self.pattern, self.replacement, what, flags=re.IGNORECASE) command = re.sub(self.pattern, self.replacement, what, flags=re.IGNORECASE)
@ -43,25 +45,24 @@ class Alias(models.Model):
class BotUser(models.Model): class BotUser(models.Model):
"""Configure bot users, which can do things through the bot and standard Django auth.""" """Configure bot users, which can do things through the bot and standard Django auth."""
nickmask = models.CharField(max_length=200, unique=True) nickmask = models.CharField(max_length=200, unique=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
class Meta: class Meta:
"""Settings for the model."""
permissions = ( permissions = (
('quit_bot', "Can tell the bot to quit via IRC"), ('quit_bot', "Can tell the bot to quit via IRC"),
) )
def __str__(self): def __str__(self):
"""String representation.""" """Provide string representation."""
return "{0:s} (Django user {1:s})".format(self.nickmask, self.user.username) return "{0:s} (Django user {1:s})".format(self.nickmask, self.user.username)
class IrcChannel(models.Model): class IrcChannel(models.Model):
"""Track channel settings.""" """Track channel settings."""
name = LowerCaseCharField(max_length=200, unique=True) name = LowerCaseCharField(max_length=200, unique=True)
@ -74,30 +75,31 @@ class IrcChannel(models.Model):
markov_learn_from_channel = models.BooleanField(default=True) markov_learn_from_channel = models.BooleanField(default=True)
class Meta: class Meta:
"""Settings for the model."""
permissions = ( permissions = (
('manage_current_channels', "Can join/part channels via IRC"), ('manage_current_channels', "Can join/part channels via IRC"),
) )
def __str__(self): def __str__(self):
"""String representation.""" """Provide string representation."""
return "{0:s}".format(self.name) return "{0:s}".format(self.name)
class IrcPlugin(models.Model): class IrcPlugin(models.Model):
"""Represent an IRC plugin and its loading settings.""" """Represent an IRC plugin and its loading settings."""
path = models.CharField(max_length=200, unique=True) path = models.CharField(max_length=200, unique=True)
autoload = models.BooleanField(default=False) autoload = models.BooleanField(default=False)
class Meta: class Meta:
"""Settings for the model."""
ordering = ['path'] ordering = ['path']
permissions = ( permissions = (
('manage_loaded_plugins', "Can load/unload plugins via IRC"), ('manage_loaded_plugins', "Can load/unload plugins via IRC"),
) )
def __str__(self): def __str__(self):
"""String representation.""" """Provide string representation."""
return "{0:s}".format(self.path) return "{0:s}".format(self.path)