def create_message(senderobj, message, channels=None, receivers=None, locks=None, tags=None, header=None): """ Create a new communication Msg. Msgs represent a unit of database-persistent communication between entites. Args: senderobj (Object or Account): The entity sending the Msg. message (str): Text with the message. Eventual headers, titles etc should all be included in this text string. Formatting will be retained. channels (Channel, key or list): A channel or a list of channels to send to. The channels may be actual channel objects or their unique key strings. receivers (Object, Account, str or list): An Account/Object to send to, or a list of them. May be Account objects or accountnames. locks (str): Lock definition string. tags (list): A list of tags or tuples `(tag, category)`. header (str): Mime-type or other optional information for the message Notes: The Comm system is created very open-ended, so it's fully possible to let a message both go to several channels and to several receivers at the same time, it's up to the command definitions to limit this as desired. """ global _Msg if not _Msg: from evennia.comms.models import Msg as _Msg if not message: # we don't allow empty messages. return None new_message = _Msg(db_message=message) new_message.save() for sender in make_iter(senderobj): new_message.senders = sender new_message.header = header 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) if tags: new_message.tags.batch_add(*tags) new_message.save() return new_message
def create_message(senderobj, message, channels=None, receivers=None, locks=None, header=None): """ Create a new communication message. Msgs are used for all player-to-player communication, both between individual players and over channels. senderobj - the player sending the message. This must be the actual object. message - text with the message. Eventual headers, titles etc should all be included in this text string. Formatting will be retained. channels - a channel or a list of channels to send to. The channels may be actual channel objects or their unique key strings. receivers - a player to send to, or a list of them. May be Player objects or playernames. locks - lock definition string header - mime-type or other optional information for the message The Comm system is created very open-ended, so it's fully possible to let a message both go to several channels and to several receivers at the same time, it's up to the command definitions to limit this as desired. """ global _Msg if not _Msg: from evennia.comms.models import Msg as _Msg if not message: # we don't allow empty messages. return new_message = _Msg(db_message=message) new_message.save() for sender in make_iter(senderobj): new_message.senders = sender new_message.header = header 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
def create_message(senderobj, message, channels=None, receivers=None, locks=None, header=None): """ Create a new communication Msg. Msgs represent a unit of database-persistent communication between entites. Args: senderobj (Object or Player): The entity sending the Msg. message (str): Text with the message. Eventual headers, titles etc should all be included in this text string. Formatting will be retained. channels (Channel, key or list): A channel or a list of channels to send to. The channels may be actual channel objects or their unique key strings. receivers (Object, Player, str or list): A Player/Object to send to, or a list of them. May be Player objects or playernames. locks (str): Lock definition string. header (str): Mime-type or other optional information for the message Notes: The Comm system is created very open-ended, so it's fully possible to let a message both go to several channels and to several receivers at the same time, it's up to the command definitions to limit this as desired. """ global _Msg if not _Msg: from evennia.comms.models import Msg as _Msg if not message: # we don't allow empty messages. return new_message = _Msg(db_message=message) new_message.save() for sender in make_iter(senderobj): new_message.senders = sender new_message.header = header 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