96 lines
2.4 KiB
Python
96 lines
2.4 KiB
Python
"""Track basic IRC settings and similar."""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import logging
|
|
import re
|
|
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
|
|
|
|
log = logging.getLogger('ircbot.models')
|
|
|
|
|
|
class Alias(models.Model):
|
|
|
|
"""Allow for aliasing of arbitrary regexes to normal supported commands."""
|
|
|
|
pattern = models.CharField(max_length=200, unique=True)
|
|
replacement = models.CharField(max_length=200)
|
|
|
|
class Meta:
|
|
verbose_name_plural = "aliases"
|
|
|
|
def __unicode__(self):
|
|
"""String representation."""
|
|
|
|
return "{0:s} -> {1:s}".format(self.pattern, self.replacement)
|
|
|
|
def replace(self, what):
|
|
command = None
|
|
if re.search(self.pattern, what, flags=re.IGNORECASE):
|
|
command = re.sub(self.pattern, self.replacement, what, flags=re.IGNORECASE)
|
|
|
|
return command
|
|
|
|
|
|
class BotUser(models.Model):
|
|
|
|
"""Configure bot users, which can do things through the bot and standard Django auth."""
|
|
|
|
nickmask = models.CharField(max_length=200, unique=True)
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL)
|
|
|
|
class Meta:
|
|
permissions = (
|
|
('quit_bot', "Can tell the bot to quit via IRC"),
|
|
)
|
|
|
|
def __unicode__(self):
|
|
"""String representation."""
|
|
|
|
return "{0:s} (Django user {1:s})".format(self.nickmask, self.user.username)
|
|
|
|
|
|
class IrcChannel(models.Model):
|
|
|
|
"""Track channel settings."""
|
|
|
|
name = models.CharField(max_length=200, unique=True)
|
|
autojoin = models.BooleanField(default=False)
|
|
|
|
topic_msg = models.TextField(default='', blank=True)
|
|
topic_time = models.DateTimeField(default=timezone.now)
|
|
topic_by = models.CharField(max_length=200, default='', blank=True)
|
|
|
|
class Meta:
|
|
permissions = (
|
|
('manage_current_channels', "Can join/part channels via IRC"),
|
|
)
|
|
|
|
def __unicode__(self):
|
|
"""String representation."""
|
|
|
|
return "{0:s}".format(self.name)
|
|
|
|
|
|
class IrcPlugin(models.Model):
|
|
|
|
"""Represent an IRC plugin and its loading settings."""
|
|
|
|
path = models.CharField(max_length=200, unique=True)
|
|
autoload = models.BooleanField(default=False)
|
|
|
|
class Meta:
|
|
ordering = ['path']
|
|
permissions = (
|
|
('manage_loaded_plugins', "Can load/unload plugins via IRC"),
|
|
)
|
|
|
|
def __unicode__(self):
|
|
"""String representation."""
|
|
|
|
return "{0:s}".format(self.path)
|