mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 18:26:32 +01:00
Actually, I did mess up and not commit the channels app. Yick. Fixed.
This commit is contained in:
parent
829b91dcce
commit
5ec19c2645
3 changed files with 117 additions and 0 deletions
0
src/channels/__init__.py
Normal file
0
src/channels/__init__.py
Normal file
10
src/channels/admin.py
Normal file
10
src/channels/admin.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from django.contrib import admin
|
||||
from src.channels.models import CommChannel, CommChannelMessage
|
||||
|
||||
class CommChannelAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'owner')
|
||||
admin.site.register(CommChannel, CommChannelAdmin)
|
||||
|
||||
class CommChannelMessageAdmin(admin.ModelAdmin):
|
||||
list_display = ('channel', 'message')
|
||||
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)
|
||||
107
src/channels/models.py
Normal file
107
src/channels/models.py
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
"""
|
||||
Models for the help system.
|
||||
"""
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Group
|
||||
from src.objects.models import Object
|
||||
from src.ansi import parse_ansi
|
||||
|
||||
class CommChannel(models.Model):
|
||||
"""
|
||||
The CommChannel class represents a comsys channel in the vein of MUX/MUSH.
|
||||
"""
|
||||
name = models.CharField(max_length=255)
|
||||
ansi_name = models.CharField(max_length=255)
|
||||
owner = models.ForeignKey(Object, related_name="chan_owner")
|
||||
description = models.CharField(max_length=80, blank=True, null=True)
|
||||
is_joined_by_default = models.BooleanField(default=False)
|
||||
req_grp = models.ManyToManyField(Group, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return "%s" % (self.name,)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-name']
|
||||
permissions = (
|
||||
('emit_commchannel', 'May @cemit over channels.'),
|
||||
('channel_admin', 'May administer comm channels.')
|
||||
)
|
||||
|
||||
def get_name(self):
|
||||
"""
|
||||
Returns a channel's name.
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def get_header(self):
|
||||
"""
|
||||
Returns the channel's header text, or what is shown before each channel
|
||||
message.
|
||||
"""
|
||||
return parse_ansi(self.ansi_name)
|
||||
|
||||
def get_owner(self):
|
||||
"""
|
||||
Returns a channels' owner.
|
||||
"""
|
||||
return self.owner
|
||||
|
||||
def set_name(self, new_name):
|
||||
"""
|
||||
Rename a channel
|
||||
"""
|
||||
self.name = parse_ansi(new_name, strip_ansi=True)
|
||||
self.header = "[%s]" % (parse_ansi(new_name),)
|
||||
self.save()
|
||||
|
||||
def set_header(self, new_header):
|
||||
"""
|
||||
Sets a channel's header text.
|
||||
"""
|
||||
self.header = parse_ansi(new_header)
|
||||
self.save()
|
||||
|
||||
def set_owner(self, new_owner):
|
||||
"""
|
||||
Sets a channel's owner.
|
||||
"""
|
||||
self.owner = new_owner
|
||||
self.save()
|
||||
|
||||
def controlled_by(self, pobject):
|
||||
"""
|
||||
Use this to see if another object controls the channel. This is means
|
||||
that the specified object either owns the channel or has special
|
||||
permissions to control it.
|
||||
|
||||
pobject: (Object) Player object to check for control.
|
||||
"""
|
||||
if pobject.is_superuser():
|
||||
return True
|
||||
|
||||
if self.owner and self.owner.id == pobject.id:
|
||||
# If said object owns the target, then give it the green.
|
||||
return True
|
||||
|
||||
# They've failed to meet any of the above conditions.
|
||||
return False
|
||||
|
||||
def get_default_chan_alias(self):
|
||||
"""
|
||||
Returns a default channel alias for the channel if none is provided.
|
||||
"""
|
||||
return self.name[:3].lower()
|
||||
|
||||
class CommChannelMessage(models.Model):
|
||||
"""
|
||||
A single logged channel message.
|
||||
"""
|
||||
channel = models.ForeignKey(CommChannel, related_name="msg_channel")
|
||||
message = models.CharField(max_length=255)
|
||||
date_sent = models.DateTimeField(editable=False, auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return "%s: %s" % (self.sender.name, self.message)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-date_sent']
|
||||
Loading…
Add table
Add a link
Reference in a new issue