dr.botzo/dispatch/models.py

48 lines
1.3 KiB
Python
Raw Normal View History

"""Track dispatcher configurations."""
import logging
from django.db import models
log = logging.getLogger('dispatch.models')
class Dispatcher(models.Model):
"""Organize dispatchers by key."""
key = models.CharField(max_length=16, unique=True)
bot_xmlrpc_host = models.CharField(max_length=200, default='localhost')
bot_xmlrpc_port = models.PositiveSmallIntegerField(default=13132)
class Meta:
"""Meta options."""
permissions = (
('send_message', "Can send messages to dispatchers"),
)
2016-01-16 18:21:46 -06:00
def __str__(self):
"""Provide string representation."""
2015-06-19 21:07:45 -05:00
return "{0:s}".format(self.key)
class DispatcherAction(models.Model):
"""Handle requests to dispatchers and do something with them."""
PRIVMSG_TYPE = 'privmsg'
FILE_TYPE = 'file'
TYPE_CHOICES = (
(PRIVMSG_TYPE, "IRC privmsg"),
(FILE_TYPE, "Write to file"),
)
dispatcher = models.ForeignKey('Dispatcher', related_name='actions', on_delete=models.CASCADE)
type = models.CharField(max_length=16, choices=TYPE_CHOICES)
destination = models.CharField(max_length=200)
include_key = models.BooleanField(default=False)
2016-01-16 18:21:46 -06:00
def __str__(self):
"""Provide string representation."""
2015-06-19 21:07:45 -05:00
return "{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.type, self.destination)