mirror of
https://github.com/evennia/evennia.git
synced 2026-04-03 06:27:17 +02:00
OBS: run migrations! This changes the Msg model to work with ManyToManyFields rather than with custom string representations for storing multiple receivers or channels. It also expands the Msg object with a "title" field and various filter options. This should make it easier to implement mail-like operations using the comms system.
This commit is contained in:
parent
7995c91eee
commit
dcc7f29a91
8 changed files with 656 additions and 381 deletions
|
|
@ -21,12 +21,12 @@ Models covered:
|
|||
Channel
|
||||
Players
|
||||
"""
|
||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import IntegrityError
|
||||
from src.utils.idmapper.models import SharedMemoryModel
|
||||
from src.utils import utils, logger
|
||||
from src.utils.utils import make_iter
|
||||
|
||||
# delayed imports
|
||||
_User = None
|
||||
|
|
@ -306,7 +306,7 @@ help_entry = create_help_entry
|
|||
#
|
||||
|
||||
def create_message(senderobj, message, channels=None,
|
||||
receivers=None, locks=None):
|
||||
receivers=None, locks=None, title=None):
|
||||
"""
|
||||
Create a new communication message. Msgs are used for all
|
||||
player-to-player communication, both between individual players
|
||||
|
|
@ -326,52 +326,25 @@ def create_message(senderobj, message, channels=None,
|
|||
at the same time, it's up to the command definitions to limit this as
|
||||
desired.
|
||||
"""
|
||||
global _Msg, _PlayerDB, _to_object
|
||||
global _Msg
|
||||
if not _Msg:
|
||||
from src.comms.models import Msg as _Msg
|
||||
if not _PlayerDB:
|
||||
from src.players.models import PlayerDB as _PlayerDB
|
||||
if not _to_object:
|
||||
from src.comms.managers import to_object as _to_object
|
||||
|
||||
def to_player(obj):
|
||||
"Make sure the object is a player object"
|
||||
if isinstance(obj, _PlayerDB):
|
||||
return obj
|
||||
elif hasattr(obj, 'user'):
|
||||
return obj.dbobj
|
||||
elif hasattr(obj, 'db_player'):
|
||||
return obj.db_player
|
||||
else:
|
||||
return None
|
||||
|
||||
if not message:
|
||||
# we don't allow empty messages.
|
||||
return
|
||||
|
||||
new_message = _Msg()
|
||||
new_message.sender = to_player(senderobj)
|
||||
new_message.message = message
|
||||
new_message = _Msg(db_message=message)
|
||||
new_message.save()
|
||||
if channels:
|
||||
if not utils.is_iter(channels):
|
||||
channels = [channels]
|
||||
new_message.channels = [channel for channel in
|
||||
[_to_object(channel, objtype='channel')
|
||||
for channel in channels] if channel]
|
||||
if receivers:
|
||||
#print "Found receiver:", receivers
|
||||
if not utils.is_iter(receivers):
|
||||
receivers = [receivers]
|
||||
#print "to_player: %s" % to_player(receivers[0])
|
||||
new_message.receivers = [to_player(receiver) for receiver in
|
||||
[_to_object(receiver) for receiver in receivers]
|
||||
if receiver]
|
||||
for sender in make_iter(senderobj):
|
||||
new_message.senders = sender
|
||||
new_message.title = title
|
||||
for channel in make_iter(channels):
|
||||
new_message.channels = channel
|
||||
for receiver in make_iter(receivers):
|
||||
new_message.receivers = receiver
|
||||
if locks:
|
||||
new_message.locks.add(locks)
|
||||
new_message.save()
|
||||
return new_message
|
||||
|
||||
message = create_message
|
||||
|
||||
def create_channel(key, aliases=None, desc=None,
|
||||
|
|
|
|||
|
|
@ -134,6 +134,15 @@ def c_creates_button(client):
|
|||
'@desc %s = test red button!' % objname)
|
||||
return cmd, "creates button ..."
|
||||
|
||||
def c_socialize(client):
|
||||
"socializechats on channel"
|
||||
cmd = ('ooc Hello!',
|
||||
'ooc Testing ...',
|
||||
'ooc Testing ... times 2',
|
||||
'say Yo!',
|
||||
'emote stands looking around.')
|
||||
return cmd, "socializes ..."
|
||||
|
||||
def c_moves(client):
|
||||
"moves to a previously created room, using the stored exits"
|
||||
cmd = client.exits # try all exits - finally one will work
|
||||
|
|
@ -151,17 +160,7 @@ def c_moves(client):
|
|||
# otherwise the system will normalize them.
|
||||
#
|
||||
|
||||
# "heavy" builder definition
|
||||
ACTIONS = ( c_login,
|
||||
c_logout,
|
||||
(0.2, c_looks),
|
||||
(0.1, c_examines),
|
||||
(0.2, c_help),
|
||||
(0.1, c_digs),
|
||||
(0.1, c_creates_obj),
|
||||
#(0.01, c_creates_button),
|
||||
(0.2, c_moves))
|
||||
# "normal builder" definition
|
||||
## "normal builder" definition
|
||||
#ACTIONS = ( c_login,
|
||||
# c_logout,
|
||||
# (0.5, c_looks),
|
||||
|
|
@ -171,7 +170,17 @@ ACTIONS = ( c_login,
|
|||
# (0.01, c_creates_obj),
|
||||
# #(0.1, c_creates_button),
|
||||
# (0.3, c_moves))
|
||||
# "passive player" definition
|
||||
## "heavy" builder definition
|
||||
#ACTIONS = ( c_login,
|
||||
# c_logout,
|
||||
# (0.2, c_looks),
|
||||
# (0.1, c_examines),
|
||||
# (0.2, c_help),
|
||||
# (0.1, c_digs),
|
||||
# (0.1, c_creates_obj),
|
||||
# #(0.01, c_creates_button),
|
||||
# (0.2, c_moves))
|
||||
## "passive player" definition
|
||||
#ACTIONS = ( c_login,
|
||||
# c_logout,
|
||||
# (0.7, c_looks),
|
||||
|
|
@ -181,4 +190,11 @@ ACTIONS = ( c_login,
|
|||
# #(0.1, c_creates_obj),
|
||||
# #(0.1, c_creates_button),
|
||||
# #(0.4, c_moves))
|
||||
|
||||
## "socializing heavy builder" definition
|
||||
ACTIONS = (c_login,
|
||||
c_logout,
|
||||
(0.3, c_socialize),
|
||||
(0.1, c_looks),
|
||||
(0.1, c_help),
|
||||
(0.2, c_digs),
|
||||
(0.3, c_moves))
|
||||
|
|
|
|||
|
|
@ -724,7 +724,5 @@ def string_suggestions(string, vocabulary, cutoff=0.6, maxnum=3):
|
|||
Returns:
|
||||
list of suggestions from vocabulary (could be empty if there are no matches)
|
||||
"""
|
||||
#if string in vocabulary:
|
||||
# return [string]
|
||||
return [tup[1] for tup in sorted([(string_similarity(string, sugg), sugg) for sugg in vocabulary],
|
||||
key=lambda tup: tup[0], reverse=True) if tup[0] >= cutoff][:maxnum]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue