2017-01-31 21:50:28 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2017-01-30 11:05:11 +00:00
|
|
|
from django.db import models
|
2017-02-01 00:09:21 +00:00
|
|
|
from django.utils import timezone
|
2021-07-19 13:06:10 +00:00
|
|
|
|
2020-02-12 12:10:41 +00:00
|
|
|
from utils.models import CreatedUpdatedModel
|
|
|
|
|
2017-01-30 11:05:11 +00:00
|
|
|
|
|
|
|
class OutgoingIrcMessage(CreatedUpdatedModel):
|
|
|
|
target = models.CharField(max_length=100)
|
|
|
|
message = models.CharField(max_length=200)
|
|
|
|
processed = models.BooleanField(default=False)
|
2017-01-31 21:50:28 +00:00
|
|
|
timeout = models.DateTimeField()
|
|
|
|
expired = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
def __str__(self):
|
2019-06-16 12:32:24 +00:00
|
|
|
return "PRIVMSG %s %s (%s)" % (
|
|
|
|
self.target,
|
|
|
|
self.message,
|
|
|
|
"processed" if self.processed else "unprocessed",
|
|
|
|
)
|
2017-01-31 21:50:28 +00:00
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
if not self.pk:
|
|
|
|
# this is a new outgoing message being saved
|
|
|
|
if self.timeout < timezone.now():
|
2019-06-16 12:32:24 +00:00
|
|
|
raise ValidationError({"timeout": "The timeout can not be in the past"})
|