mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 12:56:30 +01:00
Tag pages with page, category comms, add lock:read check (backwards compatible)
This commit is contained in:
parent
6f00c8cfc0
commit
b51f3b5a5e
4 changed files with 44 additions and 29 deletions
|
|
@ -15,14 +15,13 @@ import time
|
|||
import typing
|
||||
from random import getrandbits
|
||||
|
||||
import evennia
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import authenticate, password_validation
|
||||
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||
from django.utils import timezone
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
import evennia
|
||||
from evennia.accounts.manager import AccountManager
|
||||
from evennia.accounts.models import AccountDB
|
||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||
|
|
@ -30,24 +29,17 @@ from evennia.comms.models import ChannelDB
|
|||
from evennia.objects.models import ObjectDB
|
||||
from evennia.scripts.scripthandler import ScriptHandler
|
||||
from evennia.server.models import ServerConfig
|
||||
from evennia.server.signals import (
|
||||
SIGNAL_ACCOUNT_POST_CREATE,
|
||||
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
|
||||
SIGNAL_OBJECT_POST_PUPPET,
|
||||
SIGNAL_OBJECT_POST_UNPUPPET,
|
||||
)
|
||||
from evennia.server.signals import (SIGNAL_ACCOUNT_POST_CREATE,
|
||||
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
|
||||
SIGNAL_OBJECT_POST_PUPPET,
|
||||
SIGNAL_OBJECT_POST_UNPUPPET)
|
||||
from evennia.server.throttle import Throttle
|
||||
from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler
|
||||
from evennia.typeclasses.models import TypeclassBase
|
||||
from evennia.utils import class_from_module, create, logger
|
||||
from evennia.utils.optionhandler import OptionHandler
|
||||
from evennia.utils.utils import (
|
||||
is_iter,
|
||||
lazy_property,
|
||||
make_iter,
|
||||
to_str,
|
||||
variable_from_module,
|
||||
)
|
||||
from evennia.utils.utils import (is_iter, lazy_property, make_iter, to_str,
|
||||
variable_from_module)
|
||||
|
||||
__all__ = ("DefaultAccount", "DefaultGuest")
|
||||
|
||||
|
|
@ -1334,7 +1326,8 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
|
|||
if isinstance(searchdata, str):
|
||||
# handle wrapping of common terms
|
||||
if searchdata.lower() in ("me", "*me", "self", "*self"):
|
||||
return self
|
||||
return [self] if quiet else self
|
||||
|
||||
searchdata = self.nicks.nickreplace(
|
||||
searchdata, categories=("account",), include_account=False
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import datetime
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.models import UserManager
|
||||
from django.utils import timezone
|
||||
|
||||
from evennia.server import signals
|
||||
from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager
|
||||
from evennia.utils.utils import class_from_module, dbid_to_obj, make_iter
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Communication commands:
|
|||
"""
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from django.db.models import Q
|
||||
from evennia.accounts import bots
|
||||
from evennia.accounts.models import AccountDB
|
||||
from evennia.comms.comms import DefaultChannel
|
||||
|
|
@ -1338,8 +1338,24 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
# get the messages we've sent (not to channels)
|
||||
pages_we_sent = Msg.objects.get_messages_by_sender(caller).order_by("-db_date_created")
|
||||
# get only messages tagged as pages or not tagged at all (legacy pages)
|
||||
pages_we_sent = pages_we_sent.filter(
|
||||
Q(db_tags__db_key__iexact="page", db_tags__db_category__iexact="comms")
|
||||
| Q(db_tags__isnull=True)
|
||||
)
|
||||
# we need to default to True to allow for legacy pages
|
||||
pages_we_sent = [msg for msg in pages_we_sent if msg.access(caller, "read", default=True)]
|
||||
|
||||
# get last messages we've got
|
||||
pages_we_got = Msg.objects.get_messages_by_receiver(caller).order_by("-db_date_created")
|
||||
pages_we_got = pages_we_got.filter(
|
||||
Q(db_tags__db_key__iexact="page", db_tags__db_category__iexact="comms")
|
||||
| Q(db_tags__isnull=True)
|
||||
)
|
||||
# we need to default to True to allow for legacy pages
|
||||
pages_we_got = [msg for msg in pages_we_got if msg.access(caller, "read", default=True)]
|
||||
|
||||
# get only messages tagged as pages or not tagged at all (legacy pages)
|
||||
targets, message, number = [], None, None
|
||||
|
||||
if "last" in self.switches:
|
||||
|
|
@ -1360,6 +1376,7 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
|
|||
targets.append(target_obj)
|
||||
message = self.rhs.strip()
|
||||
else:
|
||||
# no = sign, handler this as well
|
||||
target, *message = self.args.split(" ", 1)
|
||||
if target and target.isnumeric():
|
||||
# a number to specify a historic page
|
||||
|
|
@ -1395,7 +1412,13 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
|
|||
message = f"{caller.key} {message.strip(':').strip()}"
|
||||
|
||||
# create the persistent message object
|
||||
create.create_message(caller, message, receivers=targets)
|
||||
create.create_message(caller, message, receivers=targets,
|
||||
locks=(f"read:id({caller.id}) or perm(Admin);"
|
||||
f"delete:id({caller.id}) or perm(Admin);"
|
||||
f"edit:id({caller.id}) or perm(Admin)"
|
||||
),
|
||||
tags = [("page", "comms")],
|
||||
)
|
||||
|
||||
# tell the accounts they got a message.
|
||||
received = []
|
||||
|
|
|
|||
|
|
@ -18,18 +18,13 @@ import evennia
|
|||
from anything import Anything
|
||||
from django.conf import settings
|
||||
from django.test import override_settings
|
||||
from evennia import (
|
||||
DefaultCharacter,
|
||||
DefaultExit,
|
||||
DefaultObject,
|
||||
DefaultRoom,
|
||||
ObjectDB,
|
||||
search_object,
|
||||
)
|
||||
from evennia import (DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom,
|
||||
ObjectDB, search_object)
|
||||
from evennia.commands import cmdparser
|
||||
from evennia.commands.cmdset import CmdSet
|
||||
from evennia.commands.command import Command, InterruptCommand
|
||||
from evennia.commands.default import account, admin, batchprocess, building, comms, general
|
||||
from evennia.commands.default import (account, admin, batchprocess, building,
|
||||
comms, general)
|
||||
from evennia.commands.default import help as help_module
|
||||
from evennia.commands.default import syscommands, system, unloggedin
|
||||
from evennia.commands.default.cmdset_character import CharacterCmdSet
|
||||
|
|
@ -373,7 +368,8 @@ class TestCmdTasks(BaseEvenniaCommandTest):
|
|||
self.timedelay = 5
|
||||
global _TASK_HANDLER
|
||||
if _TASK_HANDLER is None:
|
||||
from evennia.scripts.taskhandler import TASK_HANDLER as _TASK_HANDLER
|
||||
from evennia.scripts.taskhandler import \
|
||||
TASK_HANDLER as _TASK_HANDLER
|
||||
_TASK_HANDLER.clock = task.Clock()
|
||||
self.task_handler = _TASK_HANDLER
|
||||
self.task_handler.clear()
|
||||
|
|
@ -2071,6 +2067,10 @@ class TestComms(BaseEvenniaCommandTest):
|
|||
),
|
||||
receiver=self.account,
|
||||
)
|
||||
from evennia.comms.models import Msg
|
||||
msgs = Msg.objects.filter(db_tags__db_key="page", db_tags__db_category="comms")
|
||||
self.assertEqual(msgs[0].senders, [self.account])
|
||||
self.assertEqual(msgs[0].receivers, [self.account2])
|
||||
|
||||
|
||||
@override_settings(DISCORD_BOT_TOKEN="notarealtoken", DISCORD_ENABLED=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue