Add Msg.db_receiver_external field. Resolve #2193.
This commit is contained in:
parent
e38604ab02
commit
ac459572f5
4 changed files with 35 additions and 23 deletions
|
|
@ -53,6 +53,7 @@
|
||||||
list `PROTOTYPE_LIST` of dicts before loading all dicts in the module as prototypes.
|
list `PROTOTYPE_LIST` of dicts before loading all dicts in the module as prototypes.
|
||||||
- New Channel-System using the `channel` command and nicks. Removed the `ChannelHandler` and the
|
- New Channel-System using the `channel` command and nicks. Removed the `ChannelHandler` and the
|
||||||
concept of a dynamically created `ChannelCmdSet`.
|
concept of a dynamically created `ChannelCmdSet`.
|
||||||
|
- Add `Msg.db_receiver_external` field to allowe external, string-id message-receivers.
|
||||||
|
|
||||||
### Evennia 0.9.5 (2019-2020)
|
### Evennia 0.9.5 (2019-2020)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,13 +61,17 @@ You can search for `Msg` objects in various ways:
|
||||||
|
|
||||||
### Properties on Msg
|
### Properties on Msg
|
||||||
|
|
||||||
- `senders` - there must always be at least one sender. This is one of [Account](./Accounts), [Object](./Objects), [Script](./Scripts)
|
- `senders` - there must always be at least one sender. This is a set of
|
||||||
or _external_ - which is a string uniquely identifying the sender. The latter can be used by
|
- [Account](./Accounts), [Object](./Objects), [Script](./Scripts)
|
||||||
a sender-system that doesn't fit into Evennia's normal typeclass-system.
|
or `str` in any combination (but usually a message only targets one type).
|
||||||
While most systems expect a single sender, it's possible to have any number of them.
|
Using a `str` for a sender indicates it's an 'external' sender and
|
||||||
- `receivers` - these are the ones to see the Msg. These are again one of
|
and can be used to point to a sender that is not a typeclassed entity. This is not used by default
|
||||||
[Account](./Accounts), [Object](./Objects) or [Script](./Scripts). It's in principle possible to have
|
and what this would be depends on the system (it could be a unique id or a
|
||||||
zero receivers but most usages of Msg expects one or more.
|
python-path, for example). While most systems expect a single sender, it's
|
||||||
|
possible to have any number of them.
|
||||||
|
- `receivers` - these are the ones to see the Msg. These are again any combination of
|
||||||
|
[Account](./Accounts), [Object](./Objects) or [Script](./Scripts) or `str` (an 'external' receiver).
|
||||||
|
It's in principle possible to have zero receivers but most usages of Msg expects one or more.
|
||||||
- `header` - this is an optional text field that can contain meta-information about the message. For
|
- `header` - this is an optional text field that can contain meta-information about the message. For
|
||||||
an email-like system it would be the subject line. This can be independently searched, making
|
an email-like system it would be the subject line. This can be independently searched, making
|
||||||
this a powerful place for quickly finding messages.
|
this a powerful place for quickly finding messages.
|
||||||
|
|
|
||||||
|
|
@ -196,19 +196,21 @@ class Msg(SharedMemoryModel):
|
||||||
list(self.db_sender_accounts.all())
|
list(self.db_sender_accounts.all())
|
||||||
+ list(self.db_sender_objects.all())
|
+ list(self.db_sender_objects.all())
|
||||||
+ list(self.db_sender_scripts.all())
|
+ list(self.db_sender_scripts.all())
|
||||||
+ [self.db_sender_external]
|
+ ([self.db_sender_external] if self.db_sender_external else [])
|
||||||
)
|
)
|
||||||
|
|
||||||
@senders.setter
|
@senders.setter
|
||||||
def senders(self, senders):
|
def senders(self, senders):
|
||||||
"Setter. Allows for self.sender = value"
|
"Setter. Allows for self.sender = value"
|
||||||
|
|
||||||
|
if isinstance(senders, str):
|
||||||
|
self.db_sender_external = senders
|
||||||
|
self.save(update_fields=["db_sender_external"])
|
||||||
|
return
|
||||||
|
|
||||||
for sender in make_iter(senders):
|
for sender in make_iter(senders):
|
||||||
if not sender:
|
if not sender:
|
||||||
continue
|
continue
|
||||||
if isinstance(sender, str):
|
|
||||||
self.db_sender_external = sender
|
|
||||||
self.save(update_fields=["db_sender_external"])
|
|
||||||
continue
|
|
||||||
if not hasattr(sender, "__dbclass__"):
|
if not hasattr(sender, "__dbclass__"):
|
||||||
raise ValueError("This is a not a typeclassed object!")
|
raise ValueError("This is a not a typeclassed object!")
|
||||||
clsname = sender.__dbclass__.__name__
|
clsname = sender.__dbclass__.__name__
|
||||||
|
|
@ -267,7 +269,7 @@ class Msg(SharedMemoryModel):
|
||||||
list(self.db_receivers_accounts.all())
|
list(self.db_receivers_accounts.all())
|
||||||
+ list(self.db_receivers_objects.all())
|
+ list(self.db_receivers_objects.all())
|
||||||
+ list(self.db_receivers_scripts.all())
|
+ list(self.db_receivers_scripts.all())
|
||||||
+ [self.db_receiver_external]
|
+ ([self.db_receiver_external] if self.db_receiver_external else [])
|
||||||
)
|
)
|
||||||
|
|
||||||
@receivers.setter
|
@receivers.setter
|
||||||
|
|
|
||||||
|
|
@ -139,10 +139,15 @@ class TestCreateMessage(EvenniaTest):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_create_msg__simple(self):
|
def test_create_msg__simple(self):
|
||||||
|
# from evennia import set_trace;set_trace()
|
||||||
msg = create.create_message(self.char1, self.msgtext, header="TestHeader")
|
msg = create.create_message(self.char1, self.msgtext, header="TestHeader")
|
||||||
|
msg.senders = "ExternalSender"
|
||||||
|
msg.receivers = self.char2
|
||||||
|
msg.receivers = "ExternalReceiver"
|
||||||
self.assertEqual(msg.message, self.msgtext)
|
self.assertEqual(msg.message, self.msgtext)
|
||||||
self.assertEqual(msg.header, "TestHeader")
|
self.assertEqual(msg.header, "TestHeader")
|
||||||
self.assertEqual(msg.senders, [self.char1])
|
self.assertEqual(msg.senders, [self.char1, "ExternalSender"])
|
||||||
|
self.assertEqual(msg.receivers, [self.char2, "ExternalReceiver"])
|
||||||
|
|
||||||
def test_create_msg__custom(self):
|
def test_create_msg__custom(self):
|
||||||
locks = "foo:false();bar:true()"
|
locks = "foo:false();bar:true()"
|
||||||
|
|
@ -151,11 +156,11 @@ class TestCreateMessage(EvenniaTest):
|
||||||
self.char1,
|
self.char1,
|
||||||
self.msgtext,
|
self.msgtext,
|
||||||
header="TestHeader",
|
header="TestHeader",
|
||||||
receivers=[self.char1, self.char2],
|
receivers=[self.char1, self.char2, "ExternalReceiver"],
|
||||||
locks=locks,
|
locks=locks,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
)
|
)
|
||||||
self.assertEqual(set(msg.receivers), set([self.char1, self.char2]))
|
self.assertEqual(set(msg.receivers), set([self.char1, self.char2, "ExternalReceiver"]))
|
||||||
self.assertTrue(all(lock in msg.locks.all() for lock in locks.split(";")))
|
self.assertTrue(all(lock in msg.locks.all() for lock in locks.split(";")))
|
||||||
self.assertEqual(msg.tags.all(), tags)
|
self.assertEqual(msg.tags.all(), tags)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue