2015-05-10 10:02:25 -05:00
|
|
|
"""Track basic IRC settings and similar."""
|
|
|
|
|
|
|
|
import logging
|
2015-05-14 21:39:20 -05:00
|
|
|
import re
|
2015-05-10 10:02:25 -05:00
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger('ircbot.models')
|
|
|
|
|
|
|
|
|
2015-05-14 21:39:20 -05:00
|
|
|
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 u"{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
|
|
|
|
|
|
|
|
|
2015-05-12 20:45:18 -05:00
|
|
|
class BotAdmin(models.Model):
|
|
|
|
|
|
|
|
"""Configure admins, which can do things through the bot that others can't."""
|
|
|
|
|
|
|
|
nickmask = models.CharField(max_length=200, unique=True)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
"""String representation."""
|
|
|
|
|
|
|
|
return u"{0:s}".format(self.nickmask)
|
|
|
|
|
|
|
|
|
2015-05-10 10:02:25 -05:00
|
|
|
class IrcChannel(models.Model):
|
|
|
|
|
|
|
|
"""Track channel settings."""
|
|
|
|
|
|
|
|
name = models.CharField(max_length=200, unique=True)
|
|
|
|
autojoin = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
"""String representation."""
|
|
|
|
|
|
|
|
return u"{0:s}".format(self.name)
|
2015-05-12 20:45:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
"""String representation."""
|
|
|
|
|
|
|
|
return u"{0:s}".format(self.path)
|